کامیت اولیه برای پروژه قرعه کشی

This commit is contained in:
2026-07-17 15:00:56 +03:30
commit 958445ceb0
7 changed files with 956 additions and 0 deletions
+289
View File
@@ -0,0 +1,289 @@
# Created by https://www.toptal.com/developers/gitignore/api/python,pycharm
# Edit at https://www.toptal.com/developers/gitignore?templates=python,pycharm
### PyCharm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# SonarLint plugin
.idea/sonarlint/
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### PyCharm Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr
# Sonarlint plugin
# https://plugins.jetbrains.com/plugin/7973-sonarlint
.idea/**/sonarlint/
# SonarQube Plugin
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
.idea/**/sonarIssues.xml
# Markdown Navigator plugin
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator-enh.xml
.idea/**/markdown-navigator/
# Cache file creation bug
# See https://youtrack.jetbrains.com/issue/JBR-2257
.idea/$CACHE_FILE$
# CodeStream plugin
# https://plugins.jetbrains.com/plugin/12206-codestream
.idea/codestream.xml
# Azure Toolkit for IntelliJ plugin
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
.idea/**/azureSettings.xml
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
### Python Patch ###
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
poetry.toml
# ruff
.ruff_cache/
# LSP config files
pyrightconfig.json
# End of https://www.toptal.com/developers/gitignore/api/python,pycharm
+1
View File
@@ -0,0 +1 @@
3.13
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

+580
View File
@@ -0,0 +1,580 @@
import math
import random
import sys
from PySide6.QtCore import Qt, QTimer, Signal
from PySide6.QtGui import (
QPainter, QColor, QPen, QBrush, QFont, QPainterPath,
QLinearGradient, QRadialGradient, QConicalGradient, QPixmap
)
from PySide6.QtWidgets import (
QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
QPushButton, QLineEdit, QListWidget, QListWidgetItem, QLabel,
QTabWidget, QMessageBox, QFrame, QSizePolicy
)
from PySide6.QtWidgets import QDialog
# ─────────────────────────────────────────────────────────────────────────────
# 🎯 برندگان تضمینی - از اینجا تنظیم کنید
# کاربران عادی این بخش را نمی‌بینند
# ─────────────────────────────────────────────────────────────────────────────
GUARANTEED_WINNERS = [
]
# ─────────────────────────────────────────────────────────────────────────────
class WinnerDialog(QDialog):
def __init__(self, winner: str, parent=None):
super().__init__(parent)
self.setWindowTitle("🎉 برنده!")
self.showFullScreen()
self._bg = QPixmap("/home/ali0315/Desktop/3.jpg") # ← مسیر عکست رو اینجا بذار
lay = QVBoxLayout(self)
lay.setSpacing(20)
lay.setContentsMargins(60, 60, 60, 60)
# فاصله از بالا برای آوردن متن کمی بالاتر
lay.addSpacing(80)
name_frame = QFrame()
name_frame.setStyleSheet("""
QFrame {
background: rgba(0, 0, 0, 150);
border-radius: 35px;
}
""")
frame_lay = QVBoxLayout(name_frame)
frame_lay.setContentsMargins(60, 30, 60, 30)
name_label = QLabel(winner)
name_label.setAlignment(Qt.AlignCenter)
name_label.setWordWrap(True)
name_label.setStyleSheet("""
font-size:160px;
font-weight:bold;
color:#e3271e;
font-family:Tahoma;
background:transparent;
""")
frame_lay.addWidget(name_label)
# ارتفاع کارت محدود شود
name_frame.setMaximumHeight(300)
lay.addWidget(name_frame, 0, Qt.AlignCenter)
# فضای خالی پایین تا دکمه پایین بماند
lay.addStretch(1)
btn = QPushButton("✅ ادامه")
btn.setFixedHeight(70)
btn.setFixedWidth(300)
btn.setStyleSheet("""
QPushButton {
background: qlineargradient(x1:0,y1:0,x2:1,y2:1,
stop:0 #27ae60, stop:1 #2ecc71);
color: white;
border: none;
border-radius: 14px;
font-size: 26px;
font-weight: bold;
font-family: Tahoma;
}
QPushButton:hover {
background: qlineargradient(x1:0,y1:0,x2:1,y2:1,
stop:0 #2ecc71, stop:1 #58d68d);
}
QPushButton:pressed {
background: #1e8449;
}
""")
btn.clicked.connect(self.accept)
btn_lay = QHBoxLayout()
btn_lay.addStretch()
btn_lay.addWidget(btn)
btn_lay.addStretch()
lay.addLayout(btn_lay)
def paintEvent(self, event):
painter = QPainter(self)
if not self._bg.isNull():
scaled = self._bg.scaled(
self.size(),
Qt.IgnoreAspectRatio,
Qt.SmoothTransformation
)
painter.drawPixmap(0, 0, scaled)
else:
painter.fillRect(self.rect(), QColor("#1a1a2e"))
class SpinWheel(QWidget):
spin_finished = Signal(str)
COLORS = [
"#E74C3C", "#3498DB", "#2ECC71", "#F39C12",
"#9B59B6", "#1ABC9C", "#E67E22", "#34495E",
"#E91E63", "#00BCD4", "#8BC34A", "#FF5722",
]
def __init__(self, parent=None):
super().__init__(parent)
self.names: list[str] = ["1", "2", "3"]
self._angle: float = 0.0
self._spinning = False
self._target_angle = 0.0
self._velocity = 0.0
self._timer = QTimer(self)
self._timer.timeout.connect(self._tick)
self.setMinimumSize(420, 420)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
# برنده از پیش تعیین‌شده (مخفی)
self._forced_winner: str | None = None
# ── public ───────────────────────────────────────────────────────────────
def set_names(self, names: list[str]):
self.names = names
self._angle = 0
self.update()
def spin(self, forced_winner: str | None = None):
if self._spinning or not self.names:
return
self._forced_winner = forced_winner
self._spinning = True
self._velocity = random.uniform(20, 28)
full_rounds = random.randint(5, 9) * 360
if forced_winner and forced_winner in self.names:
target_angle = self._calc_angle_for(forced_winner)
current_mod = self._angle % 360
diff = (target_angle - current_mod) % 360
self._target_angle = self._angle + full_rounds + diff
else:
self._target_angle = self._angle + full_rounds + random.uniform(0, 360)
self._timer.start(16)
def _calc_angle_for(self, name: str) -> float:
n = len(self.names)
idx = self.names.index(name)
slice_deg = 360.0 / n
# مرکز بخش idx در فضای چرخ:
# mid_qt_angle = 90 - idx*slice_deg - slice_deg/2
# می‌خوایم pointer_in_wheel = mid_qt_angle
# pointer_in_wheel = (90 - angle) % 360
# پس: angle = (90 - mid_qt_angle) % 360
mid_qt_angle = 90 - idx * slice_deg - slice_deg / 2
return (90 - mid_qt_angle) % 360
def _tick(self):
remaining = self._target_angle - self._angle
if remaining <= 0 or self._velocity <= 0.05:
self._angle = self._target_angle % 360
self._spinning = False
self._timer.stop()
self.update()
winner = self._winner()
self.spin_finished.emit(winner)
return
decel = max(0.08, remaining / 350)
self._velocity = min(self._velocity, decel * 24)
self._angle += self._velocity
if self._angle >= self._target_angle:
self._angle = self._target_angle
self.update()
def _winner(self) -> str:
if not self.names:
return ""
n = len(self.names)
slice_deg = 360.0 / n
pointer_in_wheel = (90 - self._angle) % 360
# بخش i از زاویه (90 - i*slice_deg) شروع می‌شه (عقربه ساعت)
# پس: i = int((90 - pointer_in_wheel) / slice_deg)
# اما باید مراقب منفی شدن باشیم
relative = (90 - pointer_in_wheel) % 360
idx = (int(relative / slice_deg) % n)
return self.names[idx]
def paintEvent(self, event):
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing)
side = min(self.width(), self.height()) - 20
cx, cy = self.width() / 2, self.height() / 2
r = side / 2
shadow = QRadialGradient(cx + 6, cy + 6, r)
shadow.setColorAt(0, QColor(0, 0, 0, 70))
shadow.setColorAt(1, QColor(0, 0, 0, 0))
painter.setBrush(QBrush(shadow))
painter.setPen(Qt.NoPen)
from PySide6.QtCore import QPointF
painter.drawEllipse(QPointF(cx + 6, cy + 6), r, r)
if not self.names:
painter.setBrush(QBrush(QColor("#2C3E50")))
painter.setPen(QPen(QColor("#ECF0F1"), 3))
painter.drawEllipse(QPointF(cx, cy), r, r)
painter.setPen(QPen(QColor("#ECF0F1")))
painter.setFont(QFont("Tahoma", 14, QFont.Bold))
painter.drawText(self.rect(), Qt.AlignCenter, "اسامی را وارد کنید")
return
n = len(self.names)
slice_deg = 360.0 / n
painter.save()
painter.translate(cx, cy)
painter.rotate(self._angle)
for i, name in enumerate(self.names):
color = QColor(self.COLORS[i % len(self.COLORS)])
# هر بخش از i*slice_deg شروع می‌شود
start = i * slice_deg
grad = QConicalGradient(0, 0, -(start + slice_deg / 2))
grad.setColorAt(0, color.lighter(130))
grad.setColorAt(1, color.darker(120))
painter.setBrush(QBrush(grad))
painter.setPen(QPen(QColor(255, 255, 255, 180), 1.5))
# drawPie: زاویه شروع از راست (ساعت 3) و خلاف عقربه
# ما می‌خوایم از بالا (ساعت 12) شروع بشه، پس offset = 90
painter.drawPie(
int(-r), int(-r), int(2 * r), int(2 * r),
int((90 - start) * 16),
int(-slice_deg * 16)
)
mid_angle = math.radians(start + slice_deg / 2 - 90)
text_r = r * 0.62
tx = text_r * math.cos(mid_angle)
ty = text_r * math.sin(mid_angle)
painter.save()
painter.translate(tx, ty)
painter.rotate(start + slice_deg / 2)
font = QFont("Tahoma", max(7, int(13 - n * 0.4)), QFont.Bold)
painter.setFont(font)
painter.setPen(QPen(Qt.white))
fm = painter.fontMetrics()
disp = name if len(name) <= 12 else name[:11] + "…"
tw = fm.horizontalAdvance(disp)
painter.drawText(int(-tw / 2), int(fm.height() / 3), disp)
painter.restore()
painter.restore()
# حلقه بیرونی
ring = QLinearGradient(-r, -r, r, r)
ring.setColorAt(0, QColor("#F0F0F0"))
ring.setColorAt(1, QColor("#A0A0A0"))
painter.setBrush(Qt.NoBrush)
painter.setPen(QPen(QBrush(ring), 5))
painter.drawEllipse(QPointF(cx, cy), r, r)
# مرکز
cg = QRadialGradient(cx, cy, 22)
cg.setColorAt(0, QColor("#ECF0F1"))
cg.setColorAt(1, QColor("#95A5A6"))
painter.setBrush(QBrush(cg))
painter.setPen(QPen(QColor("#7F8C8D"), 2))
painter.drawEllipse(QPointF(cx, cy), 22, 22)
# اشاره‌گر - بالای چرخ
px, py = cx, cy - r - 2
path = QPainterPath()
path.moveTo(px, py + 2)
path.lineTo(px - 14, py - 28)
path.lineTo(px + 14, py - 28)
path.closeSubpath()
painter.setBrush(QBrush(QColor("#E74C3C")))
painter.setPen(QPen(QColor("#C0392B"), 2))
painter.drawPath(path)
# ─────────────────────────────────────────────────────────────────────────────
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("🎡 قرعه‌کشی")
self.setMinimumSize(1000, 700)
self._apply_theme()
self.showFullScreen() # ← این خط
self.all_names: list[str] = []
self.disabled_names: set[str] = set()
self.winners_log: list[str] = []
self._guaranteed_queue: list[str] = list(GUARANTEED_WINNERS)
self._build_ui()
# ── تم ───────────────────────────────────────────────────────────────────
def _apply_theme(self):
self.setStyleSheet("""
QMainWindow, QWidget { background:#1a1a2e; color:#e0e0e0; font-family:Tahoma; }
QTabWidget::pane { border:1px solid #16213e; background:#16213e; border-radius:8px; }
QTabBar::tab { background:#0f3460; color:#a0a0c0; padding:10px 22px;
border-radius:6px 6px 0 0; margin-right:3px; font-size:13px; }
QTabBar::tab:selected { background:#e94560; color:white; font-weight:bold; }
QTabBar::tab:hover { background:#533483; }
QPushButton {
background:qlineargradient(x1:0,y1:0,x2:1,y2:1,stop:0 #e94560,stop:1 #533483);
color:white; border:none; border-radius:8px;
padding:10px 20px; font-size:13px; font-weight:bold;
}
QPushButton:hover { background:qlineargradient(x1:0,y1:0,x2:1,y2:1,stop:0 #ff6b81,stop:1 #7b52ab); }
QPushButton:pressed { background:#c0392b; }
QPushButton:disabled { background:#444; color:#888; }
QLineEdit {
background:#0f3460; border:2px solid #533483; border-radius:8px;
padding:8px 12px; color:#e0e0e0; font-size:13px;
}
QLineEdit:focus { border-color:#e94560; }
QListWidget {
background:#0f3460; border:1px solid #533483; border-radius:8px;
font-size:12px; outline:none;
}
QListWidget::item { padding:6px 10px; border-radius:4px; }
QListWidget::item:selected { background:#e94560; color:white; }
QListWidget::item:hover { background:#533483; }
QFrame#card { background:#16213e; border:1px solid #533483; border-radius:12px; padding:10px; }
""")
# ── UI ───────────────────────────────────────────────────────────────────
def _build_ui(self):
central = QWidget()
self.setCentralWidget(central)
root = QHBoxLayout(central)
root.setSpacing(16)
root.setContentsMargins(16, 16, 16, 16)
# ستون چپ
left = QFrame()
left.setObjectName("card")
left.setFixedWidth(320)
left_lay = QVBoxLayout(left)
tabs = QTabWidget()
left_lay.addWidget(tabs)
tabs.addTab(self._tab_names(), "👥 شرکت‌کنندگان")
tabs.addTab(self._tab_log(), "📋 لاگ برندگان")
root.addWidget(left)
# ستون راست
right = QFrame()
right.setObjectName("card")
right_lay = QVBoxLayout(right)
right_lay.setSpacing(14)
title = QLabel("🎡 چرخ قرعه‌کشی")
title.setAlignment(Qt.AlignCenter)
title.setStyleSheet("font-size:22px; font-weight:bold; color:#e94560;")
right_lay.addWidget(title)
self.wheel = SpinWheel()
self.wheel.spin_finished.connect(self._on_spin_finished)
right_lay.addWidget(self.wheel, 1)
self.winner_label = QLabel("برنده: ـــ")
self.winner_label.setAlignment(Qt.AlignCenter)
self.winner_label.setStyleSheet(
"font-size:18px; font-weight:bold; color:#2ecc71;"
"background:#0f3460; border-radius:10px; padding:10px;"
)
right_lay.addWidget(self.winner_label)
btn_row = QHBoxLayout()
self.btn_spin = QPushButton("🎰 بچرخون!")
self.btn_spin.setFixedHeight(48)
self.btn_spin.clicked.connect(self._do_spin)
btn_row.addWidget(self.btn_spin)
btn_reset = QPushButton("🔄 ریست")
btn_reset.setFixedHeight(48)
btn_reset.setStyleSheet(
"background:qlineargradient(x1:0,y1:0,x2:1,y2:1,stop:0 #2980b9,stop:1 #1abc9c);"
)
btn_reset.clicked.connect(self._reset)
btn_row.addWidget(btn_reset)
right_lay.addLayout(btn_row)
root.addWidget(right, 1)
def _tab_names(self) -> QWidget:
w = QWidget()
lay = QVBoxLayout(w)
lay.setSpacing(10)
lay.addWidget(QLabel("اسامی شرکت‌کنندگان:"))
inp_row = QHBoxLayout()
self.name_input = QLineEdit()
self.name_input.setPlaceholderText("نام را بنویسید…")
self.name_input.returnPressed.connect(self._add_name)
inp_row.addWidget(self.name_input)
btn_add = QPushButton("+")
btn_add.setFixedWidth(42)
btn_add.clicked.connect(self._add_name)
inp_row.addWidget(btn_add)
lay.addLayout(inp_row)
self.names_list = QListWidget()
self.names_list.itemDoubleClicked.connect(self._toggle_disable)
lay.addWidget(self.names_list, 1)
btn_del = QPushButton("🗑 حذف انتخاب‌شده")
btn_del.clicked.connect(self._delete_selected)
lay.addWidget(btn_del)
hint = QLabel("💡 دوبار کلیک = غیرفعال/فعال کردن")
hint.setStyleSheet("color:#888; font-size:11px;")
lay.addWidget(hint)
return w
def _tab_log(self) -> QWidget:
w = QWidget()
lay = QVBoxLayout(w)
self.log_list = QListWidget()
lay.addWidget(self.log_list, 1)
btn_clear = QPushButton("🧹 پاک کردن لاگ")
btn_clear.clicked.connect(self._clear_log)
lay.addWidget(btn_clear)
return w
# ── منطق اسامی ───────────────────────────────────────────────────────────
def _add_name(self, a=None):
name = a or self.name_input.text().strip()
if not name:
return
if name in self.all_names:
QMessageBox.warning(self, "تکراری", f"«{name}» قبلاً اضافه شده.")
return
self.all_names.append(name)
item = QListWidgetItem(f"✔ {name}")
item.setData(Qt.UserRole, name)
self.names_list.addItem(item)
self.name_input.clear()
self._refresh_wheel()
def _delete_selected(self):
for item in self.names_list.selectedItems():
name = item.data(Qt.UserRole)
self.all_names.remove(name)
self.disabled_names.discard(name)
self.names_list.takeItem(self.names_list.row(item))
self._refresh_wheel()
def _toggle_disable(self, item: QListWidgetItem):
name = item.data(Qt.UserRole)
if name in self.disabled_names:
self.disabled_names.discard(name)
item.setText(f"✔ {name}")
item.setForeground(QColor("#e0e0e0"))
else:
self.disabled_names.add(name)
item.setText(f"✖ {name} [غیرفعال]")
item.setForeground(QColor("#e74c3c"))
self._refresh_wheel()
# ── منطق اصلی قرعه‌کشی ───────────────────────────────────────────────────
def _do_spin(self):
active = [n for n in self.all_names if n not in self.disabled_names]
if not active:
QMessageBox.warning(self, "خالی", "هیچ شرکت‌کننده فعالی وجود ندارد!")
return
self.btn_spin.setEnabled(False)
# بررسی آیا نوبت یک برنده تضمینی است؟
forced = self._pick_forced_winner(active)
# چرخ را می‌چرخانیم (forced مخفی است، کاربر نمی‌بیند)
self.wheel.spin(forced_winner=forced)
def _pick_forced_winner(self, active_names: list[str]) -> str | None:
# پاک‌سازی افراد غیرفعال از ابتدای صف
while self._guaranteed_queue and self._guaranteed_queue[0] not in active_names:
self._guaranteed_queue.pop(0)
if not self._guaranteed_queue:
return None
return self._guaranteed_queue[0]
def _on_spin_finished(self, winner: str):
self.btn_spin.setEnabled(True)
if not winner:
return
if winner in self._guaranteed_queue:
self._guaranteed_queue.remove(winner)
self.winner_label.setText(f"🕌 برنده: {winner}")
self._log_winner(winner)
dlg = WinnerDialog(winner, self)
dlg.exec()
self.disabled_names.add(winner)
self._mark_disabled_in_list(winner)
self._refresh_wheel() # ── کمکی ─────────────────────────────────────────────────────────────────
def _mark_disabled_in_list(self, name: str):
for i in range(self.names_list.count()):
item = self.names_list.item(i)
if item.data(Qt.UserRole) == name:
item.setText(f"✖ {name} [غیرفعال]")
item.setForeground(QColor("#e74c3c"))
break
def _log_winner(self, name: str):
self.winners_log.append(name)
item = QListWidgetItem(f"{len(self.winners_log)}. {name}")
item.setForeground(QColor("#2ecc71"))
self.log_list.addItem(item)
self.log_list.scrollToBottom()
def _clear_log(self):
self.log_list.clear()
self.winners_log.clear()
def _reset(self):
reply = QMessageBox.question(
self, "ریست",
"همه غیرفعال‌سازی‌ها پاک شوند؟",
QMessageBox.Yes | QMessageBox.No
)
if reply == QMessageBox.Yes:
self.disabled_names.clear()
self._guaranteed_queue = list(GUARANTEED_WINNERS)
for i in range(self.names_list.count()):
item = self.names_list.item(i)
name = item.data(Qt.UserRole)
item.setText(f"✔ {name}")
item.setForeground(QColor("#e0e0e0"))
self.winner_label.setText("برنده: ـــ")
self._refresh_wheel()
def _refresh_wheel(self):
active = [n for n in self.all_names if n not in self.disabled_names]
self.wheel.set_names(active)
# ─────────────────────────────────────────────────────────────────────────────
if __name__ == "__main__":
app = QApplication(sys.argv)
app.setLayoutDirection(Qt.RightToLeft)
win = MainWindow()
for i in range(1, 12):
win._add_name(a=str(i))
win.show()
sys.exit(app.exec())
+8
View File
@@ -0,0 +1,8 @@
[project]
name = "draw"
version = "0.1.0"
description = "draw with gui"
requires-python = ">=3.13"
dependencies = [
"pyside6>=6.11.1",
]
+4
View File
@@ -0,0 +1,4 @@
pyside6==6.11.1
pyside6-addons==6.11.1
pyside6-essentials==6.11.1
shiboken6==6.11.1
Generated
+74
View File
@@ -0,0 +1,74 @@
version = 1
revision = 2
requires-python = ">=3.13"
[[package]]
name = "draw"
version = "0.1.0"
source = { virtual = "." }
dependencies = [
{ name = "pyside6" },
]
[package.metadata]
requires-dist = [{ name = "pyside6", specifier = ">=6.11.1" }]
[[package]]
name = "pyside6"
version = "6.11.1"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "pyside6-addons" },
{ name = "pyside6-essentials" },
{ name = "shiboken6" },
]
wheels = [
{ url = "https://files.pythonhosted.org/packages/da/a6/27ba5947ed48918f7b74b7c43a1e280aac069e36f25adeb4c9adfac835c4/pyside6-6.11.1-cp310-abi3-macosx_13_0_universal2.whl", hash = "sha256:537682c3b7530817203e667c1f5a2f00486b37bf52c52eeab438544c7a0917f6", size = 571921, upload-time = "2026-05-13T09:47:36.402Z" },
{ url = "https://files.pythonhosted.org/packages/d8/de/af89d71410c83b10654d86ff9aff2a4f87c30163658f1cc145242e222526/pyside6-6.11.1-cp310-abi3-manylinux_2_34_x86_64.whl", hash = "sha256:b1fc521ba2bb5109425ab8add06bddbdd524abcad06cfa012cc39a22a189feb2", size = 572102, upload-time = "2026-05-13T09:47:38.249Z" },
{ url = "https://files.pythonhosted.org/packages/b6/0e/d583bd3f7bf5046a4497b36f3902cfb64aa29554489a5a25c18e6b4ac0ac/pyside6-6.11.1-cp310-abi3-manylinux_2_39_aarch64.whl", hash = "sha256:75f0005c3eb95c07cfb65522ec50d0815ac007a96482c21dc3cb4b4c04895d84", size = 572098, upload-time = "2026-05-13T09:47:39.44Z" },
{ url = "https://files.pythonhosted.org/packages/57/f2/d9d8ce1373dabb37e5919f63cd18446556079631d3f2eea3ada03c29f6b8/pyside6-6.11.1-cp310-abi3-win_amd64.whl", hash = "sha256:0968877ab1fb4ef3587a284da6fe05e8647ada56a6a3750b6395188e01f4aba6", size = 578377, upload-time = "2026-05-13T09:47:40.76Z" },
{ url = "https://files.pythonhosted.org/packages/96/02/a6057d8bd2bdb1940820fff2d627fdf4013148c9c57adf69fa40d3452ac3/pyside6-6.11.1-cp310-abi3-win_arm64.whl", hash = "sha256:acee467cb5f256cc47ebb9d815a054c1d8416da380c191b247a76d164aa3f805", size = 561765, upload-time = "2026-05-13T09:47:41.9Z" },
]
[[package]]
name = "pyside6-addons"
version = "6.11.1"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "pyside6-essentials" },
{ name = "shiboken6" },
]
wheels = [
{ url = "https://files.pythonhosted.org/packages/3f/6b/8bc94aff48b63f788f2d84e5467c12362d68906ba742c0942f46cb04c879/pyside6_addons-6.11.1-cp310-abi3-macosx_13_0_universal2.whl", hash = "sha256:54733c77f789bef5f03c6aff4ad3bec8b2eff021f0cfcbc53d5e6c250ded24f9", size = 331714589, upload-time = "2026-05-13T09:39:12.36Z" },
{ url = "https://files.pythonhosted.org/packages/dd/62/fb1428a523b2a4541e232aab50d9e789e6b4526f37fd9593452a7ea5b6b3/pyside6_addons-6.11.1-cp310-abi3-manylinux_2_34_x86_64.whl", hash = "sha256:8e6c65fbd73a512d6f72cda8d8277444a85a34dc99dd1dae9c21d35b8671bb1f", size = 175063224, upload-time = "2026-05-13T09:39:34.185Z" },
{ url = "https://files.pythonhosted.org/packages/ee/9b/2ccd52f66db55c06de65d0501170a1935d04d64d0a230c0d892284a02ce3/pyside6_addons-6.11.1-cp310-abi3-manylinux_2_39_aarch64.whl", hash = "sha256:bf1c6c4e954e5eba3d2a7c661ad4b9689e8f09c7f4a16bdf29713371d11af993", size = 170553429, upload-time = "2026-05-13T09:39:54.424Z" },
{ url = "https://files.pythonhosted.org/packages/9a/bd/8adc4d350b3b363f3dfc8fccdcf5bfed25f7e36c2fff30c64e106f4f1572/pyside6_addons-6.11.1-cp310-abi3-win_amd64.whl", hash = "sha256:0d13c4dfd671b050a48e4f8d8ddc724b7248f9c0437e7fc47fdf316278572923", size = 168816308, upload-time = "2026-05-13T09:40:13.541Z" },
{ url = "https://files.pythonhosted.org/packages/65/b7/9a840d97f0f0f04e372a87e205dd30ee285b4e3b021b188459a917c9dc76/pyside6_addons-6.11.1-cp310-abi3-win_arm64.whl", hash = "sha256:3494f480dee92f415be2f2d989c0b3f4755ac332b28045cbf4ba0f5c5a22ba37", size = 35759347, upload-time = "2026-05-13T09:40:21.199Z" },
]
[[package]]
name = "pyside6-essentials"
version = "6.11.1"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "shiboken6" },
]
wheels = [
{ url = "https://files.pythonhosted.org/packages/b3/da/10d9197e7370eb4fed8df5fc547b7548dec88e5c5949e2d450db4ae96feb/pyside6_essentials-6.11.1-cp310-abi3-macosx_13_0_universal2.whl", hash = "sha256:228de53c2bc26b07e5021fbe3614fc44ca08e4dab9999af08c2b389d2c239957", size = 110352945, upload-time = "2026-05-13T09:43:08.006Z" },
{ url = "https://files.pythonhosted.org/packages/5c/49/0e1237c4400bec7e335d2c4eeb49bc40d9fd88a9ac44ca9083ce1abdc308/pyside6_essentials-6.11.1-cp310-abi3-manylinux_2_34_x86_64.whl", hash = "sha256:e3ef7027b41e4e55fadb56e3b3257dc8ee92154b639fe67fc4c8e05e9d976c60", size = 79908535, upload-time = "2026-05-13T09:43:24.836Z" },
{ url = "https://files.pythonhosted.org/packages/4c/c5/da4c5f23c6540ac5211a1f60177c8dee84b1bf40f2719479587ab8c60731/pyside6_essentials-6.11.1-cp310-abi3-manylinux_2_39_aarch64.whl", hash = "sha256:a039b6da68a3a4b9d243217b2b98d475eed3f617159ef6be925badab53c11b0d", size = 78960051, upload-time = "2026-05-13T09:43:35.423Z" },
{ url = "https://files.pythonhosted.org/packages/64/0e/b663ecc96ca57b5c91b83b6615d6b174380b0faf30338125c26e053d6aa7/pyside6_essentials-6.11.1-cp310-abi3-win_amd64.whl", hash = "sha256:63311bd48e32c584599ab04b9ef7c324082374cd2c9fa533f978fb893bb47e40", size = 77549267, upload-time = "2026-05-13T09:43:44.92Z" },
{ url = "https://files.pythonhosted.org/packages/f1/12/eb6723faf5cb7fa581145da1c15f40d641b96e080f0491af2f1859fdeedb/pyside6_essentials-6.11.1-cp310-abi3-win_arm64.whl", hash = "sha256:11253ea52aabecefe9febddbbe78b43a824129e3af1cec98431028fba7fa954f", size = 57964512, upload-time = "2026-05-13T09:43:52.968Z" },
]
[[package]]
name = "shiboken6"
version = "6.11.1"
source = { registry = "https://pypi.org/simple" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/17/f3/f2b63df0251e7cd3172ea28e32ede52739de9566bcefcd0178681538ac81/shiboken6-6.11.1-cp310-abi3-macosx_13_0_universal2.whl", hash = "sha256:1a16867f103ef1c662a5f09dfed03273a9f81688b174555162c58e83650a3f02", size = 476874, upload-time = "2026-05-13T09:47:01.091Z" },
{ url = "https://files.pythonhosted.org/packages/c7/9b/e0355d8897b5c150770f1d95718aad17d432fcc9c035c04f3f58427d4693/shiboken6-6.11.1-cp310-abi3-manylinux_2_34_x86_64.whl", hash = "sha256:9a8bccfafc8805254cabcfa1edfaf55cd52889f4998c91ad0d9a4433fb1bcdbe", size = 272222, upload-time = "2026-05-13T09:47:02.653Z" },
{ url = "https://files.pythonhosted.org/packages/57/d5/dd4f1defed400be03340f2ede34b61f846776650b4e7ed9ebaf4c71979a2/shiboken6-6.11.1-cp310-abi3-manylinux_2_39_aarch64.whl", hash = "sha256:1bd2f4314414df2d122d9f646e03b731bc6d6b5f77a5f53f99a4fe4e97d84e6f", size = 270350, upload-time = "2026-05-13T09:47:04.02Z" },
{ url = "https://files.pythonhosted.org/packages/52/b5/3f6fb2ee65b534193fb4ef713dd619dc31dadff5d12c16979a7699ad58be/shiboken6-6.11.1-cp310-abi3-win_amd64.whl", hash = "sha256:c2c6863aa80ec18c0f82cea3417837b279cdc60024ac17123461dc9042577df7", size = 1223647, upload-time = "2026-05-13T09:47:05.924Z" },
{ url = "https://files.pythonhosted.org/packages/98/d1/f15ca0e1666faae02c945f48e745ea35f8fcd8243b176109b4e2c4251f47/shiboken6-6.11.1-cp310-abi3-win_arm64.whl", hash = "sha256:7c8d9af17db4495d4fa5b1c393f218311c4855546b9dfa6a0bd21bcd66b55e9d", size = 1784170, upload-time = "2026-05-13T09:47:07.617Z" },
]