""" Provides the graphical front-end for Piket. """ import sys from PySide2.QtWidgets import QApplication, QPushButton, QGridLayout, QWidget from PySide2.QtGui import QFont import requests from piket_client.sound import PLOP_WAVE def plop() -> None: """ Asynchronously play the plop sound. """ PLOP_WAVE.play() from piket_server import PEOPLE FONT = QFont("Helvetica", 15) def get_names() -> {int: (str, int)}: return PEOPLE class NameButton(QPushButton): """ Wraps a QPushButton to provide a counter. """ def __init__(self, name: str, count: int, *args, **kwargs) -> None: self.name = name self.count = count super().__init__(self.current_label, *args, **kwargs) self.clicked.connect(self.plop) @property def current_label(self) -> str: return f"{self.name} ({self.count})" def plop(self) -> None: self.count += 1 plop() self.setText(self.current_label) class NameButtons(QWidget): def __init__(self) -> None: super().__init__() self.layout = None self.init_ui() def init_ui(self) -> None: self.layout = QGridLayout() for index, id in enumerate(PEOPLE): person = PEOPLE[id] button = NameButton(person["name"], person["count"]) self.layout.addWidget(button, index // 2, index % 2) self.setLayout(self.layout) if __name__ == "__main__": app = QApplication(sys.argv) font = app.font() size = font.pointSize() font.setPointSize(size * 1.75) app.setFont(font) name_buttons = NameButtons() name_buttons.show() app.exec_()