Просмотр исходного кода

Add counting button, beginning of backend

Maarten van den Berg лет назад: 6
Родитель
Сommit
8ae5fc1129
8 измененных файлов с 114 добавлено и 26 удалено
  1. 1 1
      MANIFEST.in
  2. 0 23
      piket/gui.py
  3. 0 0
      piket_client/__init__.py
  4. 77 0
      piket_client/gui.py
  5. 0 0
      piket_client/sound.py
  6. 0 0
      piket_client/sounds/plop.wav
  7. 32 0
      piket_server/__init__.py
  8. 4 2
      setup.py

+ 1 - 1
MANIFEST.in

@@ -1 +1 @@
1
-include piket/sounds/*.wav
1
+include piket_client/sounds/*.wav

+ 0 - 23
piket/gui.py

@@ -1,23 +0,0 @@
1
-"""
2
-Provides the graphical front-end for Piket.
3
-"""
4
-import sys
5
-
6
-from PySide2.QtWidgets import QApplication, QPushButton
7
-
8
-from piket.sound import PLOP_WAVE
9
-
10
-
11
-def plop() -> None:
12
-    """ Asynchronously play the plop sound. """
13
-    PLOP_WAVE.play()
14
-
15
-
16
-if __name__ == "__main__":
17
-    app = QApplication(sys.argv)
18
-
19
-    button = QPushButton("Plop!")
20
-    button.clicked.connect(plop)
21
-
22
-    button.show()
23
-    app.exec_()

piket/__init__.py → piket_client/__init__.py


+ 77 - 0
piket_client/gui.py

@@ -0,0 +1,77 @@
1
+"""
2
+Provides the graphical front-end for Piket.
3
+"""
4
+import sys
5
+
6
+from PySide2.QtWidgets import QApplication, QPushButton, QGridLayout, QWidget
7
+from PySide2.QtGui import QFont
8
+import requests
9
+
10
+from piket_client.sound import PLOP_WAVE
11
+
12
+
13
+def plop() -> None:
14
+    """ Asynchronously play the plop sound. """
15
+    PLOP_WAVE.play()
16
+
17
+
18
+from piket_server import PEOPLE
19
+
20
+
21
+FONT = QFont("Helvetica", 15)
22
+
23
+
24
+def get_names() -> {int: (str, int)}:
25
+    return PEOPLE
26
+
27
+
28
+class NameButton(QPushButton):
29
+    """ Wraps a QPushButton to provide a counter. """
30
+
31
+    def __init__(self, name: str, count: int, *args, **kwargs) -> None:
32
+        self.name = name
33
+        self.count = count
34
+
35
+        super().__init__(self.current_label, *args, **kwargs)
36
+
37
+        self.clicked.connect(self.plop)
38
+
39
+    @property
40
+    def current_label(self) -> str:
41
+        return f"{self.name} ({self.count})"
42
+
43
+    def plop(self) -> None:
44
+        self.count += 1
45
+        plop()
46
+        self.setText(self.current_label)
47
+
48
+
49
+class NameButtons(QWidget):
50
+    def __init__(self) -> None:
51
+        super().__init__()
52
+
53
+        self.layout = None
54
+        self.init_ui()
55
+
56
+    def init_ui(self) -> None:
57
+        self.layout = QGridLayout()
58
+
59
+        for index, id in enumerate(PEOPLE):
60
+            person = PEOPLE[id]
61
+            button = NameButton(person["name"], person["count"])
62
+            self.layout.addWidget(button, index // 2, index % 2)
63
+
64
+        self.setLayout(self.layout)
65
+
66
+
67
+if __name__ == "__main__":
68
+    app = QApplication(sys.argv)
69
+    font = app.font()
70
+    size = font.pointSize()
71
+    font.setPointSize(size * 1.75)
72
+    app.setFont(font)
73
+
74
+    name_buttons = NameButtons()
75
+    name_buttons.show()
76
+
77
+    app.exec_()

piket/sound.py → piket_client/sound.py


piket/sounds/plop.wav → piket_client/sounds/plop.wav


+ 32 - 0
piket_server/__init__.py

@@ -0,0 +1,32 @@
1
+"""
2
+Piket server, handles events generated by the client.
3
+"""
4
+
5
+from flask import Flask, jsonify
6
+
7
+
8
+app = Flask("piket_server")
9
+
10
+
11
+@app.route("/ping")
12
+def ping() -> None:
13
+    """ Return a status ping. """
14
+    return "Pong"
15
+
16
+
17
+PRESET_NAMES = [
18
+    "Maarten",
19
+    "Knoepie Draggelsturf",
20
+    "Teddy Veenlijk",
21
+    "Chris Kraslot",
22
+    "Knibbe Tjakkomans",
23
+    "Foek Lammenschaap",
24
+]
25
+
26
+PEOPLE = {index: {"name": name, "count": 0} for index, name in enumerate(PRESET_NAMES)}
27
+
28
+
29
+@app.route("/people")
30
+def get_people() -> None:
31
+    """ Return a list of currently known people. """
32
+    return jsonify(PEOPLE)

+ 4 - 2
setup.py

@@ -2,7 +2,7 @@ from setuptools import setup
2 2
 
3 3
 setup(
4 4
         name='piket',
5
-        version='0.0.1',
5
+        version='0.0.2',
6 6
 
7 7
         classifiers=[
8 8
             'Development Status :: 2 - Pre-Alpha',
@@ -16,11 +16,13 @@ setup(
16 16
         author_email='maartenberg1+pypi@gmail.com',
17 17
 
18 18
         license='MIT',
19
-        packages=['piket'],
19
+        packages=['piket_client', 'piket_server'],
20 20
 
21 21
         install_requires=[
22 22
             'PySide2',
23 23
             'simpleaudio',
24
+            'requests',
25
+            'Flask',
24 26
         ],
25 27
 
26 28
         extras_require={