war add & display
This commit is contained in:
parent
cfa65a41f0
commit
9e966baf9b
4 changed files with 223 additions and 30 deletions
|
|
@ -1,11 +1,12 @@
|
|||
from pathlib import Path
|
||||
|
||||
from PyQt6 import QtWidgets
|
||||
from PyQt6.QtWidgets import QDialog, QFileDialog
|
||||
from PyQt6.QtWidgets import QDialog, QFileDialog, QTreeWidgetItem
|
||||
from PyQt6.QtGui import QCloseEvent
|
||||
|
||||
from warchron.view.ui.ui_main_window import Ui_MainWindow
|
||||
from warchron.view.ui.ui_player_dialog import Ui_playerDialog
|
||||
from warchron.view.ui.ui_war_dialog import Ui_warDialog
|
||||
|
||||
class View(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
def __init__(self, parent=None):
|
||||
|
|
@ -13,14 +14,6 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||
self.setupUi(self)
|
||||
self.on_close_callback = None
|
||||
|
||||
def display_players(self, players: list):
|
||||
table = self.playersTable
|
||||
table.setRowCount(len(players))
|
||||
for row, player in enumerate(players):
|
||||
table.setItem(row, 0, QtWidgets.QTableWidgetItem(player.name))
|
||||
table.setItem(row, 1, QtWidgets.QTableWidgetItem(player.id))
|
||||
table.resizeColumnsToContents()
|
||||
|
||||
def closeEvent(self, event: QCloseEvent):
|
||||
if self.on_close_callback:
|
||||
proceed = self.on_close_callback()
|
||||
|
|
@ -47,6 +40,25 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
|
|||
)
|
||||
return Path(filename) if filename else None
|
||||
|
||||
def display_players(self, players: list):
|
||||
table = self.playersTable
|
||||
table.setRowCount(len(players))
|
||||
for row, player in enumerate(players):
|
||||
table.setItem(row, 0, QtWidgets.QTableWidgetItem(player.name))
|
||||
table.setItem(row, 1, QtWidgets.QTableWidgetItem(player.id))
|
||||
table.resizeColumnsToContents()
|
||||
|
||||
def display_wars(self, wars: list):
|
||||
tree = self.warsTree
|
||||
tree.clear()
|
||||
tree.setColumnCount(1)
|
||||
tree.setHeaderLabels(["Wars"])
|
||||
for war in wars:
|
||||
war_item = QTreeWidgetItem([f"{war.name} ({war.year})"])
|
||||
war_item.setData(0, 1, war.id) # role=1 to store id
|
||||
tree.addTopLevelItem(war_item)
|
||||
tree.expandAll()
|
||||
|
||||
class PlayerDialog(QDialog):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
|
@ -55,3 +67,12 @@ class PlayerDialog(QDialog):
|
|||
|
||||
def get_player_name(self) -> str:
|
||||
return self.ui.playerName.text().strip()
|
||||
|
||||
class WarDialog(QDialog):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.ui = Ui_warDialog()
|
||||
self.ui.setupUi(self)
|
||||
|
||||
def get_war_name(self) -> str:
|
||||
return self.ui.warName.text().strip()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue