Commit a72da914 authored by Tom Pillot's avatar Tom Pillot
Browse files

Separate ui and code

parent 77b07e55
import sys
from PyQt5 import QtWidgets as qtw
from team import TeamWindow
from team_chooser import TeamWindow
from scoreboard import ScoreWindow
......
import sys
from PyQt5 import QtWidgets as qtw
from PyQt5 import QtCore as qtc
from PyQt5 import QtGui as qtg
from scoreboard_ui import ScoreWindowUi
DURATION = 30
class ScoreWindow(qtw.QMainWindow):
class ScoreWindow(ScoreWindowUi):
def __init__(self):
super().__init__()
self.setWindowTitle("Scores")
widget = qtw.QWidget(self)
self.setCentralWidget(widget)
self.list_widget = qtw.QListWidget()
self.timer_label = qtw.QLabel()
self.timer_label.setFont(qtg.QFont("Arial", 80, qtg.QFont.Bold))
self.timer = qtc.QTimer(self)
self.time_left = DURATION
vlayout = qtw.QVBoxLayout()
vlayout.addWidget(self.timer_label, alignment=qtc.Qt.AlignCenter)
vlayout.addWidget(self.list_widget)
widget.setLayout(vlayout)
def timer_start(self):
self.time_left = DURATION
self.timer.timeout.connect(self.timer_timeout)
......@@ -41,9 +27,3 @@ class ScoreWindow(qtw.QMainWindow):
def update_gui(self):
self.timer_label.setText(str(self.time_left))
if __name__ == '__main__':
app = qtw.QApplication(sys.argv)
w = ScoreWindow()
sys.exit(app.exec_())
from PyQt5 import QtWidgets as qtw
from PyQt5 import QtCore as qtc
from PyQt5 import QtGui as qtg
class ScoreWindowUi(qtw.QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Scores")
widget = qtw.QWidget(self)
self.setCentralWidget(widget)
self.list_widget = qtw.QListWidget()
self.timer_label = qtw.QLabel()
self.timer_label.setFont(qtg.QFont("Arial", 80, qtg.QFont.Bold))
self.timer = qtc.QTimer(self)
vlayout = qtw.QVBoxLayout()
vlayout.addWidget(self.timer_label, alignment=qtc.Qt.AlignCenter)
vlayout.addWidget(self.list_widget)
widget.setLayout(vlayout)
......@@ -3,6 +3,7 @@ from PyQt5 import QtWidgets as qtw
from PyQt5 import QtCore as qtc
from PyQt5 import QtGui as qtg
from detector import Detector
from team_chooser_ui import TeamWindowUi
team_colors = {
1: "#FE3200", 2: "#FE6500", 3: "#FE9800", 4: "#FECB00", 5: "#FEFE00", 6: "#CBFE00",
......@@ -13,102 +14,16 @@ team_colors = {
}
class AlignDelegate(qtw.QStyledItemDelegate):
def initStyleOption(self, option, index):
super(AlignDelegate, self).initStyleOption(option, index)
option.displayAlignment = qtc.Qt.AlignCenter
class TeamWindow(qtw.QMainWindow):
class TeamWindow(TeamWindowUi):
NAME, TAG = range(2)
STATUS_TIME = 5000
def __init__(self, *args, **kargs):
super().__init__(*args, **kargs)
def __init__(self):
super().__init__()
self.detector = Detector()
self.tag_ids = {}
self.setWindowTitle("Liste des équipes")
widget = qtw.QWidget(self)
self.setCentralWidget(widget)
self.status_bar = qtw.QStatusBar()
self.setStatusBar(self.status_bar)
self.table_view = qtw.QTableView()
self.table_view.setEditTriggers(qtw.QAbstractItemView.NoEditTriggers)
self.table_view.horizontalHeader().setSectionResizeMode(qtw.QHeaderView.Stretch)
self.table_view.verticalHeader().setVisible(False)
# Align text to the center
delegate = AlignDelegate(self.table_view)
self.table_view.setItemDelegate(delegate)
self.table_model = qtg.QStandardItemModel(0, 2, self.table_view)
self.table_model.setHeaderData(self.NAME, qtc.Qt.Horizontal, "Nom")
self.table_model.setHeaderData(self.TAG, qtc.Qt.Horizontal, "Tag")
self.table_view.setModel(self.table_model)
self.name_input = qtw.QLineEdit()
self.tag_label = qtw.QLabel("")
self.tag_label.setAlignment(qtc.Qt.AlignCenter)
self.add_button = qtw.QPushButton("Ajouter")
self.edit_button = qtw.QPushButton("Modifier")
self.delete_button = qtw.QPushButton("Supprimer")
self.scan_button = qtw.QPushButton("Scanner le tag")
self.activity_box = qtw.QComboBox()
self.time_edit = qtw.QTimeEdit()
self.start_button = qtw.QPushButton("Démarrer l'activité")
hlayout1 = qtw.QHBoxLayout()
hlayout1.addWidget(qtw.QLabel("Nom de l'équipe :"))
hlayout1.addWidget(self.name_input)
hlayout2 = qtw.QHBoxLayout()
hlayout2.addWidget(qtw.QLabel("Tag ID :"))
hlayout2.addWidget(self.tag_label)
hlayout3 = qtw.QHBoxLayout()
hlayout3.addLayout(hlayout2)
hlayout3.addWidget(self.scan_button)
hlayout4 = qtw.QHBoxLayout()
hlayout4.addWidget(self.add_button)
hlayout4.addWidget(self.edit_button)
hlayout4.addWidget(self.delete_button)
vlayout1 = qtw.QVBoxLayout()
vlayout1.addWidget(self.table_view)
vlayout1.addLayout(hlayout1)
vlayout1.addLayout(hlayout3)
vlayout1.addLayout(hlayout4)
vertical_spacer = qtw.QSpacerItem(20, 40, qtw.QSizePolicy.Minimum, qtw.QSizePolicy.Expanding)
vlayout2 = qtw.QVBoxLayout()
vlayout2.addWidget(qtw.QLabel("Choix de l'activité :"))
vlayout2.addWidget(self.activity_box)
vlayout2.addItem(vertical_spacer)
vlayout2.addWidget(qtw.QLabel("Choix du temps :"))
vlayout2.addWidget(self.time_edit)
vlayout2.addItem(vertical_spacer)
vlayout2.addWidget(self.start_button)
vlayout2.addStretch()
hlayout5 = qtw.QHBoxLayout()
hlayout5.addLayout(vlayout1)
# Add a vertical line
vline = qtw.QFrame()
vline.setFrameShape(qtw.QFrame.VLine)
vline.setMinimumWidth(10)
vline.setFrameShadow(qtw.QFrame.Sunken)
vline.setLineWidth(3)
hlayout5.addWidget(vline)
hlayout5.addLayout(vlayout2)
widget.setLayout(hlayout5)
self.scan_button.clicked.connect(self.detect_tag)
self.add_button.clicked.connect(self.add_team)
self.edit_button.clicked.connect(self.edit_team)
......@@ -186,9 +101,3 @@ class TeamWindow(qtw.QMainWindow):
self.status_bar.showMessage("Une équipe avec ce tag existe déjà.", self.STATUS_TIME)
return False
return True
if __name__ == '__main__':
app = qtw.QApplication(sys.argv)
w = TeamWindow()
sys.exit(app.exec_())
from PyQt5 import QtWidgets as qtw
from PyQt5 import QtCore as qtc
from PyQt5 import QtGui as qtg
class AlignDelegate(qtw.QStyledItemDelegate):
def initStyleOption(self, option, index):
super(AlignDelegate, self).initStyleOption(option, index)
option.displayAlignment = qtc.Qt.AlignCenter
class TeamWindowUi(qtw.QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Liste des équipes")
widget = qtw.QWidget(self)
self.setCentralWidget(widget)
self.status_bar = qtw.QStatusBar()
self.setStatusBar(self.status_bar)
self.table_view = qtw.QTableView()
self.table_view.setEditTriggers(qtw.QAbstractItemView.NoEditTriggers)
self.table_view.horizontalHeader().setSectionResizeMode(qtw.QHeaderView.Stretch)
self.table_view.verticalHeader().setVisible(False)
# Align text to the center
delegate = AlignDelegate(self.table_view)
self.table_view.setItemDelegate(delegate)
self.table_model = qtg.QStandardItemModel(0, 2, self.table_view)
self.table_model.setHeaderData(self.NAME, qtc.Qt.Horizontal, "Nom")
self.table_model.setHeaderData(self.TAG, qtc.Qt.Horizontal, "Tag")
self.table_view.setModel(self.table_model)
self.name_input = qtw.QLineEdit()
self.tag_label = qtw.QLabel("")
self.tag_label.setAlignment(qtc.Qt.AlignCenter)
self.add_button = qtw.QPushButton("Ajouter")
self.edit_button = qtw.QPushButton("Modifier")
self.delete_button = qtw.QPushButton("Supprimer")
self.scan_button = qtw.QPushButton("Scanner le tag")
self.activity_box = qtw.QComboBox()
self.time_edit = qtw.QTimeEdit()
self.start_button = qtw.QPushButton("Démarrer l'activité")
hlayout1 = qtw.QHBoxLayout()
hlayout1.addWidget(qtw.QLabel("Nom de l'équipe :"))
hlayout1.addWidget(self.name_input)
hlayout2 = qtw.QHBoxLayout()
hlayout2.addWidget(qtw.QLabel("Tag ID :"))
hlayout2.addWidget(self.tag_label)
hlayout3 = qtw.QHBoxLayout()
hlayout3.addLayout(hlayout2)
hlayout3.addWidget(self.scan_button)
hlayout4 = qtw.QHBoxLayout()
hlayout4.addWidget(self.add_button)
hlayout4.addWidget(self.edit_button)
hlayout4.addWidget(self.delete_button)
vlayout1 = qtw.QVBoxLayout()
vlayout1.addWidget(self.table_view)
vlayout1.addLayout(hlayout1)
vlayout1.addLayout(hlayout3)
vlayout1.addLayout(hlayout4)
vertical_spacer = qtw.QSpacerItem(20, 40, qtw.QSizePolicy.Minimum, qtw.QSizePolicy.Expanding)
vlayout2 = qtw.QVBoxLayout()
vlayout2.addWidget(qtw.QLabel("Choix de l'activité :"))
vlayout2.addWidget(self.activity_box)
vlayout2.addItem(vertical_spacer)
vlayout2.addWidget(qtw.QLabel("Choix du temps :"))
vlayout2.addWidget(self.time_edit)
vlayout2.addItem(vertical_spacer)
vlayout2.addWidget(self.start_button)
vlayout2.addStretch()
hlayout5 = qtw.QHBoxLayout()
hlayout5.addLayout(vlayout1)
# Add a vertical line
vline = qtw.QFrame()
vline.setFrameShape(qtw.QFrame.VLine)
vline.setMinimumWidth(10)
vline.setFrameShadow(qtw.QFrame.Sunken)
vline.setLineWidth(3)
hlayout5.addWidget(vline)
hlayout5.addLayout(vlayout2)
widget.setLayout(hlayout5)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment