aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gui/gui.todo18
-rw-r--r--gui/main_window.py38
-rw-r--r--gui/tab_calendar.py13
-rw-r--r--gui/tab_drivers.py16
-rw-r--r--gui/tab_teams.py204
5 files changed, 233 insertions, 56 deletions
diff --git a/gui/gui.todo b/gui/gui.todo
index 7b69d85..537ecfb 100644
--- a/gui/gui.todo
+++ b/gui/gui.todo
@@ -1,19 +1,14 @@
+[ ] {pick} year
[x] login dialog box (like mac system settings with padlock) (username + password)
-[ ] drivers
+[x] drivers
- [x] {show} {set} full name
- [x] {show} {set} nationality (both as text and as flag)
- [x] {show} portrait
- [x] {show} {set} role/function
-[ ] teams
- - [ ] {show} team name
- - [ ] {show} driver names (-> link to driver browser?)
- - [ ] {add/remove} driver
-[ ] calendar
- - [ ] {pick/create} year
- - [ ] {add} race to calendar year
- - [ ] {show} GP name
- - [ ] {show} circuit (-> link)
- - [ ] {show} race (-> link)
+[x] teams
+ - [x] {show} team name
+ - [x] {show} driver names (-> link to driver browser?)
+ - [x] {add/remove} driver
[ ] cirucits
- [ ] {show} circuit name
- [ ] {show} circuit length
@@ -29,4 +24,5 @@
- [ ] {set} driver that got the fastest round
- [ ] {set/order} drivers by finish number
- [ ] {set/radio} driver disqualified/DNF
+ - [ ] {add} race to calendar year
diff --git a/gui/main_window.py b/gui/main_window.py
index c503951..7247e8e 100644
--- a/gui/main_window.py
+++ b/gui/main_window.py
@@ -4,7 +4,6 @@ from PySide6.QtWidgets import *
from tab_drivers import *
from tab_teams import *
-from tab_calendar import *
from tab_circuits import *
from tab_races import *
@@ -15,7 +14,6 @@ class MainWindow(QMainWindow):
_tab_drivers: TabDrivers
_tab_teams: TabTeams
- _tab_calendar: TabCalendar
_tab_circuits: TabCircuits
_tab_races: TabRaces
@@ -59,34 +57,34 @@ class MainWindow(QMainWindow):
self.setMinimumHeight(500)
self._tab_drivers = TabDrivers(self.cursor, self)
- self._tab_teams = TabTeams(self)
- self._tab_calendar = TabCalendar(self)
+ self._tab_teams = TabTeams(self.cursor, self)
self._tab_circuits = TabCircuits(self)
self._tab_races = TabRaces(self)
main_layout = QTabWidget(self);
main_layout.addTab(self._tab_drivers, "drivers")
main_layout.addTab(self._tab_teams, "teams")
- main_layout.addTab(self._tab_calendar, "calendar")
main_layout.addTab(self._tab_circuits, "cirucits")
main_layout.addTab(self._tab_races, "races")
self.menu_bar = QMenuBar(self)
- menu_procedures = self.menu_bar.addMenu("file")
- sp_update_flags = menu_procedures.addAction("Exit (commit changes)")
- sp_update_flags.triggered.connect(self.exit_commit)
- sp_update_flags = menu_procedures.addAction("Exit (don't commit changes)")
- sp_update_flags.triggered.connect(self.exit_no_commit)
- menu_procedures = self.menu_bar.addMenu("procedures")
- sp_update_flags = menu_procedures.addAction("Import/update flags")
- sp_update_flags.triggered.connect(self.call_update_flags)
- sp_update_persons = menu_procedures.addAction("Import/update driver portraits")
- sp_update_persons.triggered.connect(self.call_update_persons)
- sp_delete_flags = menu_procedures.addAction("Delete flags")
- sp_delete_flags.triggered.connect(self.call_delete_flags)
- menu_procedures = self.menu_bar.addMenu("database")
- sp_update_flags = menu_procedures.addAction("Commit changes")
- sp_update_flags.triggered.connect(self.commit)
+ menu = self.menu_bar.addMenu("file")
+ action = menu.addAction("Exit (commit changes)")
+ action.triggered.connect(self.exit_commit)
+ action = menu.addAction("Exit (don't commit changes)")
+ action.triggered.connect(self.exit_no_commit)
+ menu = self.menu_bar.addMenu("procedures")
+ action = menu.addAction("Import/update flags")
+ action.triggered.connect(self.call_update_flags)
+ action = menu.addAction("Import/update driver portraits")
+ action.triggered.connect(self.call_update_persons)
+ action = menu.addAction("Delete flags")
+ action.triggered.connect(self.call_delete_flags)
+ menu = self.menu_bar.addMenu("database")
+ action = menu.addAction("Commit changes")
+ action.triggered.connect(self.commit)
+
+ menu = self.menu_bar.addMenu("seasons")
self.setMenuBar(self.menu_bar)
self.setCentralWidget(main_layout)
diff --git a/gui/tab_calendar.py b/gui/tab_calendar.py
deleted file mode 100644
index 9802143..0000000
--- a/gui/tab_calendar.py
+++ /dev/null
@@ -1,13 +0,0 @@
-import os
-from PySide6.QtGui import *
-from PySide6.QtWidgets import *
-
-class TabCalendar(QWidget):
- def __init__(self, parent=None):
- super(TabCalendar, self).__init__(parent)
-
- layout = QFormLayout()
- layout.addWidget(QLabel("hoi"))
-
- self.setLayout(layout)
-
diff --git a/gui/tab_drivers.py b/gui/tab_drivers.py
index d74e07e..9812ce5 100644
--- a/gui/tab_drivers.py
+++ b/gui/tab_drivers.py
@@ -103,6 +103,7 @@ class DriverBrowser(QTableView):
self.setModel(self.model_proxy)
self.setSortingEnabled(True)
self.selectionModel().selectionChanged.connect(self.on_selection)
+ self.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
@dataclass
class DBNationality():
@@ -118,13 +119,12 @@ class NationalityEditorWidget(QWidget):
button_add: QPushButton
nationalities: [DBNationality]
- def remove_nationality(self, nationality_id):
- print(f"removing nationality id {nationality_id} from driver {self.selected_driver_id}")
+ def remove_nationality(self):
+ nationality_id = self.sender().property("id")
self.cursor.execute("delete from `formula1`.`membernationality` where `memberID` = ? and `nationalityID` = ?", (self.selected_driver_id,nationality_id,))
self.update(False)
def add_nationality(self, nationality_id):
- print(f"adding nationality id {nationality_id} from driver {self.selected_driver_id}")
self.cursor.execute("insert into `formula1`.`membernationality` (`memberID`, `nationalityID`) values (?, ?)", (self.selected_driver_id,nationality_id,))
self.update(False)
@@ -137,7 +137,6 @@ class NationalityEditorWidget(QWidget):
nationalities = list()
self.cursor.execute("select `nationality`.`ID`, `nationality`.`country`, `nationality`.`flag` from nationality join membernationality on membernationality.nationalityID = nationality.ID where membernationality.memberID = ?", (self.selected_driver_id,))
last_row = 0
- buttons = list()
for i, record in enumerate(self.cursor.fetchall()):
nationality = DBNationality(*record)
if nationality.icon != None:
@@ -147,16 +146,17 @@ class NationalityEditorWidget(QWidget):
flag_label.setPixmap(pixmap)
self.layout.addWidget(flag_label, i, 0)
self.layout.addWidget(QLabel(nationality.name), i, 1)
- buttons.insert(i, QPushButton("remove"))
- temp = nationality.id
- buttons[i].clicked.connect(lambda: self.remove_nationality(temp)) # idk this works
- self.layout.addWidget(buttons[i], i, 2)
+ button = QPushButton("remove")
+ button.setProperty("id", nationality.id)
+ button.clicked.connect(self.remove_nationality) # idk this works
+ self.layout.addWidget(button, i, 2)
nationalities.append(nationality)
last_row = i
new_nationality_picker = QComboBox()
for nationality in all_nationalities:
new_nationality_picker.addItem(nationality[1], nationality[0])
new_nationality_picker.setCurrentIndex(-1)
+ new_nationality_picker.setPlaceholderText("Add nationality...")
new_nationality_picker.currentIndexChanged.connect(lambda i: self.add_nationality(new_nationality_picker.itemData(i)))
self.layout.addWidget(new_nationality_picker, last_row + 1, 0, 1, 3)
diff --git a/gui/tab_teams.py b/gui/tab_teams.py
index a96b3e2..0335bab 100644
--- a/gui/tab_teams.py
+++ b/gui/tab_teams.py
@@ -1,13 +1,209 @@
import os
+import mariadb
from PySide6.QtGui import *
from PySide6.QtWidgets import *
+from PySide6.QtCore import *
+from PySide6.QtCore import Qt
+
+from split_view_layout import *
+
+from dataclasses import dataclass
+
+@dataclass
+class DBTeam():
+ id: int = 0
+ name: str = ""
+
+class TeamsModel(QAbstractTableModel):
+ cursor: mariadb.Cursor
+ calendar_id: int = 1
+
+ _header = ["team name"]
+ _data: [DBTeam] = []
+
+ def update(self):
+ self.beginResetModel()
+ self.cursor.execute("select `ID`, `teamName` from `teams` where `calendarID` = ?", (self.calendar_id,))
+ self._data = list()
+ for result in self.cursor.fetchall():
+ self._data.append(DBTeam(*result))
+ self.endResetModel()
+
+ def __init__(self, cursor):
+ super().__init__()
+ self.cursor = cursor
+ self.update()
+
+ def rowCount(self, index=0):
+ return len(self._data)
+
+ def columnCount(self, index=0):
+ return len(self._header)
+
+ def headerData(self, section, orientation, role):
+ if role == Qt.DisplayRole:
+ if orientation == Qt.Horizontal:
+ return self._header[section]
+ else:
+ return self._data[section].id
+
+ def data(self, index, role):
+ if role == Qt.DisplayRole:
+ team = self._data[index.row()]
+ return (
+ team.name,
+ )[index.column()]
+
+class TeamBrowser(QTableView):
+ model_table: TeamsModel
+ model_proxy: QSortFilterProxyModel
+ parent_update_fn: callable
+ selected_team_id: int = 1
+ ignore_update: bool = False
+ temp_selection_index: int = 0
+
+ def update(self, cascade=True):
+ self.model_table.update()
+ self.ignore_update = True
+ self.selectRow(self.temp_selection_index)
+ self.ignore_update = False
+
+ def parent_update(self):
+ if self.parent_update_fn != None:
+ self.parent_update_fn()
+
+ def set_parent_update(self, fn):
+ self.parent_update_fn = fn
+
+ def on_selection(self):
+ if self.ignore_update: return
+ rows = self.selectionModel().selectedRows()
+ if len(rows) == 0: return
+ row = rows[0].row()
+ self.temp_selection_index = row
+ index = self.model_proxy.mapToSource(self.model_proxy.index(row, 0))
+ new_team_id = self.model_table.headerData(index.row(), Qt.Vertical, Qt.DisplayRole)
+ if self.selected_team_id == new_team_id: return
+ self.selected_team_id = new_team_id
+ self.parent_update()
+
+ def __init__(self, cursor: mariadb.Cursor, parent=None):
+ super(TeamBrowser, self).__init__(parent)
+
+ self.cursor = cursor
+
+ self.setSelectionBehavior(QAbstractItemView.SelectRows)
+ self.model_table = TeamsModel(self.cursor)
+ self.model_proxy = QSortFilterProxyModel()
+ self.model_proxy.setSourceModel(self.model_table)
+ self.setModel(self.model_proxy)
+ self.setSortingEnabled(True)
+ self.selectionModel().selectionChanged.connect(self.on_selection)
+ self.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
+
+class TeamDetailsWidget(QWidget):
+ cursor: mariadb.Cursor
+ parent_update_fn: callable
+ selected_team_id: int = 1
+
+ team_members: QFormLayout
+ buttons: [QPushButton]
+ layout: QVBoxLayout
+ new_member_picker: QComboBox
+
+ def member_remove(self):
+ id = self.sender().property("id")
+ self.cursor.execute("delete from `formula1`.`teamsmember` where `memberID` = ? and `teamsID` = ?", (id,self.selected_team_id,))
+ self.update(False)
+
+ def member_add(self, id):
+ self.cursor.execute("insert into `formula1`.`teamsmember` (`memberID`, `teamsID`) values (?, ?)", (id,self.selected_team_id,))
+ self.update(False)
+
+ def update(self, cascade=True):
+ self.buttons = list()
+ for x in range(self.team_members.rowCount()):
+ self.team_members.removeRow(0)
+ self.cursor.execute("select member.ID, firstName, middleName, lastName from member join teamsmember on teamsmember.memberID = member.ID where teamsmember.teamsID = ?", (self.selected_team_id,))
+ for member in self.cursor.fetchall():
+ id = member[0]
+ name = " ".join(member[1:4])
+ remove_button = QPushButton("remove")
+ remove_button.setProperty("id", id)
+ remove_button.clicked.connect(self.member_remove)
+ self.team_members.addRow(QLabel(name), remove_button)
+
+ self.cursor.execute("select member.ID, firstName, middleName, lastName from member")
+ self.new_member_picker.clear()
+ for member in self.cursor.fetchall():
+ self.new_member_picker.addItem(" ".join(member[1:4]), member[0])
+
+ if cascade == False: return
+ self.nationality_editor.update()
+
+ def parent_update(self):
+ if self.parent_update_fn != None:
+ self.parent_update_fn()
+
+ def set_team_id(self, id):
+ self.selected_team_id = id
+ self.update(False)
+
+ def set_parent_update(self, fn):
+ self.parent_update_fn = fn
+
+ def __init__(self, cursor: mariadb.Cursor, parent=None):
+ super(TeamDetailsWidget, self).__init__(parent)
+ self.cursor = cursor
+
+ self.layout = QVBoxLayout(self)
+ self.layout.setAlignment(Qt.AlignmentFlag.AlignTop)
+
+ self.layout.addWidget(QLabel("Team members"))
+
+ self.team_members = QFormLayout(self)
+ self.team_members.addRow("bernard", QPushButton("remove"))
+ self.layout.addLayout(self.team_members)
+
+ self.new_member_picker = QComboBox()
+ self.new_member_picker.setCurrentIndex(-1)
+ self.new_member_picker.setPlaceholderText("Add member...")
+ self.new_member_picker.currentIndexChanged.connect(lambda i: self.member_add(self.new_member_picker.itemData(i)))
+ self.layout.addWidget(self.new_member_picker)
+
+ self.setLayout(self.layout)
class TabTeams(QWidget):
- def __init__(self, parent=None):
+ layout: SplitViewLayout
+ cursor: mariadb.Cursor
+ selected_team_id: int = 1
+
+ team_browser: TeamBrowser
+ team_details: TeamDetailsWidget
+
+ def update(self, cascade=True):
+ print("update TabTeams")
+
+ if not cascade: return
+ self.team_browser.update(True)
+
+ def child_update(self):
+ self.selected_team_id = self.team_browser.selected_team_id
+ self.team_browser.update(False)
+ self.team_details.set_team_id(self.selected_team_id)
+
+ def __init__(self, cursor, parent=None):
super(TabTeams, self).__init__(parent)
+ self.layout = SplitViewLayout(self)
+ self.cursor = cursor
+
+ self.team_browser = TeamBrowser(self.cursor, self)
+ self.team_browser.set_parent_update(self.child_update)
+ self.layout.leftWidget(self.team_browser)
- layout = QFormLayout()
- layout.addWidget(QLabel("hoi"))
+ self.team_details = TeamDetailsWidget(self.cursor, self)
+ self.team_details.set_parent_update(self.child_update)
+ self.layout.rightWidget(self.team_details)
- self.setLayout(layout)
+ self.setLayout(self.layout)