Source code for pylottosimu.dialog.show_drawing

# -*- coding: utf-8 -*-

# pyLottoSimu

# Copyright (C) <2012-2024> Markus Hackspacher

# This file is part of pyLottoSimu.

# pyLottoSimu is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# pyLottoSimu is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with pyLottoSimu.  If not, see <http://www.gnu.org/licenses/>.

"""
class DlgShowDrawing
--------------------

show a Dialog with all the ball numbers from the draw
and the bonus numbers.
"""

import os

try:
    from PyQt6 import QtCore, QtGui, QtWidgets
except ImportError:
    from PyQt5 import QtCore, QtGui, QtWidgets


[docs] class DlgShowDrawing(QtWidgets.QDialog): """Show the numbers in a dialog box :param ballnumbers: the number of draw :type ballnumbers: tuple of int :param highestnumber: the number of the PushButtons :type highestnumber: int :param bonusnumbers: the bonus numbers :type bonusnumbers: int :param highestbonus: the highest bonus number (separate numbers) :type highestbonus: int :returns: None """ def __init__(self, ballnumbers, highestnumber, bonusnumbers=False, highestbonus=False): """Init the class DlgShowDrawing """ super(DlgShowDrawing, self).__init__() self.setWindowIcon( QtGui.QIcon(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "misc", "pyLottoSimu.svg")))) self.setModal(True) self.buttonBox = QtWidgets.QDialogButtonBox(self) self.buttonBox.setOrientation(QtCore.Qt.Orientation.Horizontal) self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.StandardButton.Ok) try: self.boxLayout = QtWidgets.QBoxLayout( QtWidgets.QBoxLayout.Direction.TopToBottom, self) except AttributeError: # PyQt5: self.boxLayout = QtWidgets.QBoxLayout( QtWidgets.QBoxLayout.TopToBottom, self) self.gridLayout = QtWidgets.QGridLayout() self.gridbonus = QtWidgets.QGridLayout() self.ballnumbers = ballnumbers self.highestnumber = highestnumber self.bonusnumbers = bonusnumbers self.highestbonus = highestbonus self.initbuttons()
[docs] def initbuttons(self): """Array of buttons from 1 to the highest number and buttons for the additional numbers :return: None """ self.btn_drawnumbers = [QtWidgets.QPushButton(self) for _ in range(self.highestnumber)] for buttonnumber, button in enumerate(self.btn_drawnumbers): button.setMaximumSize(QtCore.QSize(58, 58)) button.setAutoFillBackground(True) self.gridLayout.addWidget( button, int(buttonnumber / 7), int(buttonnumber % 7), 1, 1) button.setText(str(buttonnumber + 1)) button.setFlat(True) if buttonnumber + 1 in self.ballnumbers: button.setFlat(False) button.setStyleSheet("color: red;") elif (self.bonusnumbers and not self.highestbonus and buttonnumber + 1 in self.bonusnumbers): button.setFlat(False) button.setStyleSheet("color: blue;") if self.highestbonus: self.btnnumerarybonus = [QtWidgets.QPushButton(self) for _ in range(self.highestbonus)] for buttonnumber, button in enumerate(self.btnnumerarybonus): button.setMaximumSize(QtCore.QSize(58, 58)) button.setAutoFillBackground(True) self.gridbonus.addWidget( button, int(buttonnumber / 7), int(buttonnumber % 7), 1, 1) button.setText(str(buttonnumber + 1)) if buttonnumber + 1 in self.bonusnumbers: button.setFlat(False) button.setStyleSheet("color: blue;") else: button.setFlat(True) self.setWindowTitle(self.tr("Show Drawing")) self.boxLayout.addLayout(self.gridLayout) if self.highestbonus: self.boxLayout.addLayout(self.gridbonus) self.boxLayout.addWidget(self.buttonBox) self.buttonBox.accepted.connect(self.accept)