rename app ; add new,open,save actions
0
src/warchron/controller/__ini__.py
Normal file
119
src/warchron/controller/controller.py
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
from pathlib import Path
|
||||
|
||||
from PyQt6.QtWidgets import QMessageBox, QDialog
|
||||
|
||||
from warchron.view.view import PlayerDialog
|
||||
|
||||
class Controller:
|
||||
def __init__(self, model, view):
|
||||
self.model = model
|
||||
self.view = view
|
||||
self.current_file: Path | None = None
|
||||
self.view.on_close_callback = self.on_app_close
|
||||
self.is_dirty = False
|
||||
self.__connect()
|
||||
self.refresh_players_view()
|
||||
|
||||
def __connect(self):
|
||||
self.view.addPlayerBtn.clicked.connect(self.add_player)
|
||||
self.view.actionExit.triggered.connect(self.view.close)
|
||||
self.view.actionNew.triggered.connect(self.new)
|
||||
self.view.actionOpen.triggered.connect(self.open_file)
|
||||
self.view.actionSave.triggered.connect(self.save)
|
||||
self.view.actionSave_as.triggered.connect(self.save_as)
|
||||
|
||||
def refresh_players_view(self):
|
||||
players = self.model.get_all_players()
|
||||
self.view.display_players(players)
|
||||
|
||||
def new(self):
|
||||
if self.is_dirty:
|
||||
reply = QMessageBox.question(
|
||||
self.view,
|
||||
"Unsaved changes",
|
||||
"Discard current campaign?",
|
||||
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
|
||||
)
|
||||
if reply != QMessageBox.StandardButton.Yes:
|
||||
return
|
||||
self.model.new()
|
||||
self.current_file = None
|
||||
self.is_dirty = False
|
||||
self.refresh_players_view()
|
||||
self.update_window_title()
|
||||
|
||||
def open_file(self):
|
||||
if self.is_dirty:
|
||||
reply = QMessageBox.question(
|
||||
self.view,
|
||||
"Unsaved changes",
|
||||
"Discard current campaign?",
|
||||
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
|
||||
)
|
||||
if reply != QMessageBox.StandardButton.Yes:
|
||||
return
|
||||
path = self.view.ask_open_file()
|
||||
if not path:
|
||||
return
|
||||
self.model.load(path)
|
||||
self.current_file = path
|
||||
self.is_dirty = False
|
||||
self.refresh_players_view()
|
||||
self.update_window_title()
|
||||
|
||||
def on_app_close(self) -> bool:
|
||||
if self.is_dirty:
|
||||
reply = QMessageBox.question(
|
||||
self.view,
|
||||
"Unsaved changes",
|
||||
"You have unsaved changes. Do you want to save before quitting?",
|
||||
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No | QMessageBox.StandardButton.Cancel
|
||||
)
|
||||
if reply == QMessageBox.StandardButton.Yes:
|
||||
self.save()
|
||||
elif reply == QMessageBox.StandardButton.Cancel:
|
||||
return False
|
||||
return True
|
||||
|
||||
def save(self):
|
||||
if not self.current_file:
|
||||
self.save_as()
|
||||
return
|
||||
self.model.save(self.current_file)
|
||||
self.is_dirty = False
|
||||
self.update_window_title()
|
||||
|
||||
def save_as(self):
|
||||
path = self.view.ask_save_file()
|
||||
if not path:
|
||||
return
|
||||
self.current_file = path
|
||||
self.model.save(path)
|
||||
self.is_dirty = False
|
||||
self.update_window_title()
|
||||
|
||||
def update_window_title(self):
|
||||
base = "WarChron"
|
||||
if self.current_file:
|
||||
base += f" - {self.current_file.name}"
|
||||
if self.is_dirty:
|
||||
base = "*" + base
|
||||
self.view.setWindowTitle(base)
|
||||
|
||||
|
||||
def add_player(self):
|
||||
dialog = PlayerDialog(self.view)
|
||||
result = dialog.exec() # modal blocking dialog
|
||||
if result == QDialog.DialogCode.Accepted:
|
||||
name = dialog.get_player_name()
|
||||
if not name:
|
||||
QMessageBox.warning(
|
||||
self.view,
|
||||
"Invalid name",
|
||||
"Player name cannot be empty."
|
||||
)
|
||||
return
|
||||
self.model.add_player(name)
|
||||
self.is_dirty = True
|
||||
self.refresh_players_view()
|
||||
self.update_window_title()
|
||||
0
src/warchron/model/__ini__.py
Normal file
68
src/warchron/model/model.py
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
from pathlib import Path
|
||||
import json
|
||||
import shutil
|
||||
|
||||
from warchron.model.player import Player
|
||||
|
||||
class Model:
|
||||
def __init__(self):
|
||||
self.players = {}
|
||||
|
||||
def new(self):
|
||||
self.players.clear()
|
||||
# self.wars.clear()
|
||||
# self.campaigns.clear()
|
||||
# self.rounds.clear()
|
||||
|
||||
def load(self, path: Path):
|
||||
self.players.clear()
|
||||
self._load_data(path)
|
||||
|
||||
def save(self, path: Path):
|
||||
self._save_data(path)
|
||||
|
||||
def _load_data(self, path: Path):
|
||||
if not path.exists() or path.stat().st_size == 0:
|
||||
return # Start empty
|
||||
try:
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
for player in data["players"] :
|
||||
saved_player = Player.fromDict(player["id"], player['name'])
|
||||
self.players[saved_player.id] = saved_player
|
||||
for war in data["wars"]:
|
||||
# placeholder
|
||||
pass
|
||||
except json.JSONDecodeError:
|
||||
raise RuntimeError("Data file is corrupted")
|
||||
|
||||
def _save_data(self, path: Path):
|
||||
if path.exists():
|
||||
shutil.copy(path, path.with_suffix(".json.bak"))
|
||||
data = {}
|
||||
data['version'] = "1.0"
|
||||
data['players'] = []
|
||||
data['wars'] = []
|
||||
for player in self.players.values():
|
||||
data['players'].append(player.toDict())
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
json.dump(data, f, indent=2)
|
||||
|
||||
def add_player(self, name):
|
||||
player = Player(name)
|
||||
self.players[player.id] = player
|
||||
return player
|
||||
|
||||
def get_player(self, id):
|
||||
return self.players[id]
|
||||
|
||||
def update_player(self, id, name):
|
||||
player = self.get_player(id)
|
||||
player.set_name(name)
|
||||
|
||||
def delete_player(self, id):
|
||||
del self.players[id]
|
||||
|
||||
def get_all_players(self) -> list[Player]:
|
||||
return list(self.players.values())
|
||||
|
||||
24
src/warchron/model/player.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
from uuid import uuid4
|
||||
|
||||
class Player:
|
||||
def __init__(self, name ):
|
||||
self.id = str(uuid4())
|
||||
self.name = name
|
||||
|
||||
def set_id(self, new_id):
|
||||
self.id = new_id
|
||||
|
||||
def set_name(self, name):
|
||||
self.name = name
|
||||
|
||||
def toDict(self):
|
||||
return {
|
||||
"id" : self.id,
|
||||
"name" : self.name
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def fromDict(id, name):
|
||||
tmp = Player(name=name)
|
||||
tmp.set_id(id)
|
||||
return tmp
|
||||
22
src/warchron/model/repository.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import json
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
DATA_FILE = Path("data/warmachron.json")
|
||||
|
||||
def load_data():
|
||||
if not DATA_FILE.exists() or DATA_FILE.stat().st_size == 0:
|
||||
return {"version": 1, "players": {}, "wars": []}
|
||||
|
||||
try:
|
||||
with open(DATA_FILE, "r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
except json.JSONDecodeError:
|
||||
raise RuntimeError("Data file is corrupted")
|
||||
|
||||
def save_data(data):
|
||||
if DATA_FILE.exists():
|
||||
shutil.copy(DATA_FILE, DATA_FILE.with_suffix(".json.bak"))
|
||||
|
||||
with open(DATA_FILE, "w", encoding="utf-8") as f:
|
||||
json.dump(data, f, indent=2)
|
||||
0
src/warchron/view/__ini__.py
Normal file
BIN
src/warchron/view/resources/arrow-curve-180-left.png
Normal file
|
After Width: | Height: | Size: 631 B |
BIN
src/warchron/view/resources/arrow-curve.png
Normal file
|
After Width: | Height: | Size: 613 B |
BIN
src/warchron/view/resources/cross.png
Normal file
|
After Width: | Height: | Size: 544 B |
BIN
src/warchron/view/resources/disk--pencil.png
Normal file
|
After Width: | Height: | Size: 677 B |
BIN
src/warchron/view/resources/disk.png
Normal file
|
After Width: | Height: | Size: 507 B |
BIN
src/warchron/view/resources/document.png
Normal file
|
After Width: | Height: | Size: 485 B |
BIN
src/warchron/view/resources/door--arrow.png
Normal file
|
After Width: | Height: | Size: 618 B |
BIN
src/warchron/view/resources/folder.png
Normal file
|
After Width: | Height: | Size: 476 B |
BIN
src/warchron/view/resources/notebook--arrow.png
Normal file
|
After Width: | Height: | Size: 692 B |
BIN
src/warchron/view/resources/pencil.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
src/warchron/view/resources/plus.png
Normal file
|
After Width: | Height: | Size: 521 B |
BIN
src/warchron/view/resources/question.png
Normal file
|
After Width: | Height: | Size: 766 B |
BIN
src/warchron/view/resources/swords-small.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
src/warchron/view/resources/swords.png
Normal file
|
After Width: | Height: | Size: 26 KiB |
BIN
src/warchron/view/resources/users.png
Normal file
|
After Width: | Height: | Size: 870 B |
BIN
src/warchron/view/resources/warchron_logo.png
Normal file
|
After Width: | Height: | Size: 9.4 KiB |
173
src/warchron/view/ui/ui_main_window.py
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
# Form implementation generated from reading ui file '.\src\warchron\view\ui\ui_main_window.ui'
|
||||
#
|
||||
# Created by: PyQt6 UI code generator 6.7.1
|
||||
#
|
||||
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
|
||||
# run again. Do not edit this file unless you know what you are doing.
|
||||
|
||||
|
||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||
|
||||
|
||||
class Ui_MainWindow(object):
|
||||
def setupUi(self, MainWindow):
|
||||
MainWindow.setObjectName("MainWindow")
|
||||
MainWindow.resize(800, 600)
|
||||
icon = QtGui.QIcon()
|
||||
icon.addPixmap(QtGui.QPixmap(".\\src\\warchron\\view\\ui\\../resources/warchron_logo.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
|
||||
MainWindow.setWindowIcon(icon)
|
||||
self.centralwidget = QtWidgets.QWidget(parent=MainWindow)
|
||||
self.centralwidget.setObjectName("centralwidget")
|
||||
self.tabWidget = QtWidgets.QTabWidget(parent=self.centralwidget)
|
||||
self.tabWidget.setGeometry(QtCore.QRect(16, 9, 771, 531))
|
||||
self.tabWidget.setObjectName("tabWidget")
|
||||
self.playersTab = QtWidgets.QWidget()
|
||||
self.playersTab.setObjectName("playersTab")
|
||||
self.playersTable = QtWidgets.QTableWidget(parent=self.playersTab)
|
||||
self.playersTable.setGeometry(QtCore.QRect(10, 60, 741, 431))
|
||||
self.playersTable.setObjectName("playersTable")
|
||||
self.playersTable.setColumnCount(2)
|
||||
self.playersTable.setRowCount(0)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
self.playersTable.setHorizontalHeaderItem(0, item)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
self.playersTable.setHorizontalHeaderItem(1, item)
|
||||
self.addPlayerBtn = QtWidgets.QPushButton(parent=self.playersTab)
|
||||
self.addPlayerBtn.setGeometry(QtCore.QRect(20, 20, 75, 23))
|
||||
self.addPlayerBtn.setObjectName("addPlayerBtn")
|
||||
icon1 = QtGui.QIcon()
|
||||
icon1.addPixmap(QtGui.QPixmap(".\\src\\warchron\\view\\ui\\../resources/users.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
|
||||
self.tabWidget.addTab(self.playersTab, icon1, "")
|
||||
self.warsTab = QtWidgets.QWidget()
|
||||
self.warsTab.setObjectName("warsTab")
|
||||
self.warsTree = QtWidgets.QTreeWidget(parent=self.warsTab)
|
||||
self.warsTree.setGeometry(QtCore.QRect(10, 60, 211, 431))
|
||||
self.warsTree.setObjectName("warsTree")
|
||||
self.warsTree.headerItem().setText(0, "1")
|
||||
self.addWarBtn = QtWidgets.QPushButton(parent=self.warsTab)
|
||||
self.addWarBtn.setGeometry(QtCore.QRect(20, 20, 75, 23))
|
||||
self.addWarBtn.setObjectName("addWarBtn")
|
||||
self.addCampaignBtn = QtWidgets.QPushButton(parent=self.warsTab)
|
||||
self.addCampaignBtn.setEnabled(False)
|
||||
self.addCampaignBtn.setGeometry(QtCore.QRect(110, 20, 91, 23))
|
||||
self.addCampaignBtn.setObjectName("addCampaignBtn")
|
||||
icon2 = QtGui.QIcon()
|
||||
icon2.addPixmap(QtGui.QPixmap(".\\src\\warchron\\view\\ui\\../resources/swords-small.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
|
||||
self.tabWidget.addTab(self.warsTab, icon2, "")
|
||||
MainWindow.setCentralWidget(self.centralwidget)
|
||||
self.menubar = QtWidgets.QMenuBar(parent=MainWindow)
|
||||
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 22))
|
||||
self.menubar.setObjectName("menubar")
|
||||
self.menuFile = QtWidgets.QMenu(parent=self.menubar)
|
||||
self.menuFile.setObjectName("menuFile")
|
||||
self.menuEdit = QtWidgets.QMenu(parent=self.menubar)
|
||||
self.menuEdit.setObjectName("menuEdit")
|
||||
self.menuHelp = QtWidgets.QMenu(parent=self.menubar)
|
||||
self.menuHelp.setObjectName("menuHelp")
|
||||
MainWindow.setMenuBar(self.menubar)
|
||||
self.statusbar = QtWidgets.QStatusBar(parent=MainWindow)
|
||||
self.statusbar.setObjectName("statusbar")
|
||||
MainWindow.setStatusBar(self.statusbar)
|
||||
self.actionNew = QtGui.QAction(parent=MainWindow)
|
||||
icon3 = QtGui.QIcon()
|
||||
icon3.addPixmap(QtGui.QPixmap(".\\src\\warchron\\view\\ui\\../resources/document.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
|
||||
self.actionNew.setIcon(icon3)
|
||||
self.actionNew.setObjectName("actionNew")
|
||||
self.actionOpen = QtGui.QAction(parent=MainWindow)
|
||||
icon4 = QtGui.QIcon()
|
||||
icon4.addPixmap(QtGui.QPixmap(".\\src\\warchron\\view\\ui\\../resources/folder.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
|
||||
self.actionOpen.setIcon(icon4)
|
||||
self.actionOpen.setObjectName("actionOpen")
|
||||
self.actionSave = QtGui.QAction(parent=MainWindow)
|
||||
icon5 = QtGui.QIcon()
|
||||
icon5.addPixmap(QtGui.QPixmap(".\\src\\warchron\\view\\ui\\../resources/disk.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
|
||||
self.actionSave.setIcon(icon5)
|
||||
self.actionSave.setObjectName("actionSave")
|
||||
self.actionExit = QtGui.QAction(parent=MainWindow)
|
||||
icon6 = QtGui.QIcon()
|
||||
icon6.addPixmap(QtGui.QPixmap(".\\src\\warchron\\view\\ui\\../resources/door--arrow.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
|
||||
self.actionExit.setIcon(icon6)
|
||||
self.actionExit.setObjectName("actionExit")
|
||||
self.actionUndo = QtGui.QAction(parent=MainWindow)
|
||||
icon7 = QtGui.QIcon()
|
||||
icon7.addPixmap(QtGui.QPixmap(".\\src\\warchron\\view\\ui\\../resources/arrow-curve-180-left.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
|
||||
self.actionUndo.setIcon(icon7)
|
||||
self.actionUndo.setObjectName("actionUndo")
|
||||
self.actionRedo = QtGui.QAction(parent=MainWindow)
|
||||
icon8 = QtGui.QIcon()
|
||||
icon8.addPixmap(QtGui.QPixmap(".\\src\\warchron\\view\\ui\\../resources/arrow-curve.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
|
||||
self.actionRedo.setIcon(icon8)
|
||||
self.actionRedo.setObjectName("actionRedo")
|
||||
self.actionAbout = QtGui.QAction(parent=MainWindow)
|
||||
icon9 = QtGui.QIcon()
|
||||
icon9.addPixmap(QtGui.QPixmap(".\\src\\warchron\\view\\ui\\../resources/question.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
|
||||
self.actionAbout.setIcon(icon9)
|
||||
self.actionAbout.setObjectName("actionAbout")
|
||||
self.actionExport = QtGui.QAction(parent=MainWindow)
|
||||
self.actionExport.setEnabled(False)
|
||||
icon10 = QtGui.QIcon()
|
||||
icon10.addPixmap(QtGui.QPixmap(".\\src\\warchron\\view\\ui\\../resources/notebook--arrow.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
|
||||
self.actionExport.setIcon(icon10)
|
||||
self.actionExport.setObjectName("actionExport")
|
||||
self.actionSave_as = QtGui.QAction(parent=MainWindow)
|
||||
icon11 = QtGui.QIcon()
|
||||
icon11.addPixmap(QtGui.QPixmap(".\\src\\warchron\\view\\ui\\../resources/disk--pencil.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
|
||||
self.actionSave_as.setIcon(icon11)
|
||||
self.actionSave_as.setObjectName("actionSave_as")
|
||||
self.menuFile.addAction(self.actionNew)
|
||||
self.menuFile.addAction(self.actionOpen)
|
||||
self.menuFile.addAction(self.actionSave)
|
||||
self.menuFile.addAction(self.actionSave_as)
|
||||
self.menuFile.addSeparator()
|
||||
self.menuFile.addAction(self.actionExport)
|
||||
self.menuFile.addSeparator()
|
||||
self.menuFile.addAction(self.actionExit)
|
||||
self.menuEdit.addAction(self.actionUndo)
|
||||
self.menuEdit.addAction(self.actionRedo)
|
||||
self.menuHelp.addAction(self.actionAbout)
|
||||
self.menubar.addAction(self.menuFile.menuAction())
|
||||
self.menubar.addAction(self.menuEdit.menuAction())
|
||||
self.menubar.addAction(self.menuHelp.menuAction())
|
||||
|
||||
self.retranslateUi(MainWindow)
|
||||
self.tabWidget.setCurrentIndex(1)
|
||||
QtCore.QMetaObject.connectSlotsByName(MainWindow)
|
||||
|
||||
def retranslateUi(self, MainWindow):
|
||||
_translate = QtCore.QCoreApplication.translate
|
||||
MainWindow.setWindowTitle(_translate("MainWindow", "WarChron"))
|
||||
item = self.playersTable.horizontalHeaderItem(0)
|
||||
item.setText(_translate("MainWindow", "Name"))
|
||||
item = self.playersTable.horizontalHeaderItem(1)
|
||||
item.setText(_translate("MainWindow", "ID"))
|
||||
self.addPlayerBtn.setText(_translate("MainWindow", "Add player"))
|
||||
self.tabWidget.setTabText(self.tabWidget.indexOf(self.playersTab), _translate("MainWindow", "Players"))
|
||||
self.addWarBtn.setText(_translate("MainWindow", "Add war"))
|
||||
self.addCampaignBtn.setText(_translate("MainWindow", "Add Campaign"))
|
||||
self.tabWidget.setTabText(self.tabWidget.indexOf(self.warsTab), _translate("MainWindow", "Wars"))
|
||||
self.menuFile.setTitle(_translate("MainWindow", "File"))
|
||||
self.menuEdit.setTitle(_translate("MainWindow", "Edit"))
|
||||
self.menuHelp.setTitle(_translate("MainWindow", "Help"))
|
||||
self.actionNew.setText(_translate("MainWindow", "New"))
|
||||
self.actionNew.setShortcut(_translate("MainWindow", "Ctrl+N"))
|
||||
self.actionOpen.setText(_translate("MainWindow", "Open"))
|
||||
self.actionOpen.setShortcut(_translate("MainWindow", "Ctrl+O"))
|
||||
self.actionSave.setText(_translate("MainWindow", "Save"))
|
||||
self.actionSave.setShortcut(_translate("MainWindow", "Ctrl+S"))
|
||||
self.actionExit.setText(_translate("MainWindow", "Exit"))
|
||||
self.actionExit.setShortcut(_translate("MainWindow", "Ctrl+Shift+Q"))
|
||||
self.actionUndo.setText(_translate("MainWindow", "Undo"))
|
||||
self.actionRedo.setText(_translate("MainWindow", "Redo"))
|
||||
self.actionAbout.setText(_translate("MainWindow", "About"))
|
||||
self.actionExport.setText(_translate("MainWindow", "Export"))
|
||||
self.actionSave_as.setText(_translate("MainWindow", "Save as..."))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
MainWindow = QtWidgets.QMainWindow()
|
||||
ui = Ui_MainWindow()
|
||||
ui.setupUi(MainWindow)
|
||||
MainWindow.show()
|
||||
sys.exit(app.exec())
|
||||
269
src/warchron/view/ui/ui_main_window.ui
Normal file
|
|
@ -0,0 +1,269 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>WarChron</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset>
|
||||
<normaloff>../resources/warchron_logo.png</normaloff>../resources/warchron_logo.png</iconset>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>16</x>
|
||||
<y>9</y>
|
||||
<width>771</width>
|
||||
<height>531</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="playersTab">
|
||||
<attribute name="icon">
|
||||
<iconset>
|
||||
<normaloff>../resources/users.png</normaloff>../resources/users.png</iconset>
|
||||
</attribute>
|
||||
<attribute name="title">
|
||||
<string>Players</string>
|
||||
</attribute>
|
||||
<widget class="QTableWidget" name="playersTable">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>60</y>
|
||||
<width>741</width>
|
||||
<height>431</height>
|
||||
</rect>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>ID</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="addPlayerBtn">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
<width>75</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Add player</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QWidget" name="warsTab">
|
||||
<attribute name="icon">
|
||||
<iconset>
|
||||
<normaloff>../resources/swords-small.png</normaloff>../resources/swords-small.png</iconset>
|
||||
</attribute>
|
||||
<attribute name="title">
|
||||
<string>Wars</string>
|
||||
</attribute>
|
||||
<widget class="QTreeWidget" name="warsTree">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>60</y>
|
||||
<width>211</width>
|
||||
<height>431</height>
|
||||
</rect>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">1</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="addWarBtn">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
<width>75</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Add war</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="addCampaignBtn">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>110</x>
|
||||
<y>20</y>
|
||||
<width>91</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Add Campaign</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
<property name="title">
|
||||
<string>File</string>
|
||||
</property>
|
||||
<addaction name="actionNew"/>
|
||||
<addaction name="actionOpen"/>
|
||||
<addaction name="actionSave"/>
|
||||
<addaction name="actionSave_as"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionExport"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionExit"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuEdit">
|
||||
<property name="title">
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
<addaction name="actionUndo"/>
|
||||
<addaction name="actionRedo"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuHelp">
|
||||
<property name="title">
|
||||
<string>Help</string>
|
||||
</property>
|
||||
<addaction name="actionAbout"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
<addaction name="menuEdit"/>
|
||||
<addaction name="menuHelp"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
<action name="actionNew">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>../resources/document.png</normaloff>../resources/document.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>New</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+N</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionOpen">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>../resources/folder.png</normaloff>../resources/folder.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Open</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+O</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSave">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>../resources/disk.png</normaloff>../resources/disk.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+S</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionExit">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>../resources/door--arrow.png</normaloff>../resources/door--arrow.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Exit</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+Shift+Q</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionUndo">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>../resources/arrow-curve-180-left.png</normaloff>../resources/arrow-curve-180-left.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Undo</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionRedo">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>../resources/arrow-curve.png</normaloff>../resources/arrow-curve.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Redo</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionAbout">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>../resources/question.png</normaloff>../resources/question.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>About</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionExport">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>../resources/notebook--arrow.png</normaloff>../resources/notebook--arrow.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Export</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSave_as">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>../resources/disk--pencil.png</normaloff>../resources/disk--pencil.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save as...</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
50
src/warchron/view/ui/ui_player_dialog.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
# Form implementation generated from reading ui file '.\src\warchron\view\ui\ui_player_dialog.ui'
|
||||
#
|
||||
# Created by: PyQt6 UI code generator 6.7.1
|
||||
#
|
||||
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
|
||||
# run again. Do not edit this file unless you know what you are doing.
|
||||
|
||||
|
||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||
|
||||
|
||||
class Ui_playerDialog(object):
|
||||
def setupUi(self, playerDialog):
|
||||
playerDialog.setObjectName("playerDialog")
|
||||
playerDialog.setWindowModality(QtCore.Qt.WindowModality.ApplicationModal)
|
||||
playerDialog.resize(378, 98)
|
||||
icon = QtGui.QIcon()
|
||||
icon.addPixmap(QtGui.QPixmap(".\\src\\warchron\\view\\ui\\../resources/warchron_logo.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
|
||||
playerDialog.setWindowIcon(icon)
|
||||
self.buttonBox = QtWidgets.QDialogButtonBox(parent=playerDialog)
|
||||
self.buttonBox.setGeometry(QtCore.QRect(10, 60, 341, 32))
|
||||
self.buttonBox.setOrientation(QtCore.Qt.Orientation.Horizontal)
|
||||
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.StandardButton.Cancel|QtWidgets.QDialogButtonBox.StandardButton.Ok)
|
||||
self.buttonBox.setObjectName("buttonBox")
|
||||
self.label = QtWidgets.QLabel(parent=playerDialog)
|
||||
self.label.setGeometry(QtCore.QRect(10, 20, 47, 14))
|
||||
self.label.setObjectName("label")
|
||||
self.playerName = QtWidgets.QLineEdit(parent=playerDialog)
|
||||
self.playerName.setGeometry(QtCore.QRect(60, 20, 113, 20))
|
||||
self.playerName.setObjectName("playerName")
|
||||
|
||||
self.retranslateUi(playerDialog)
|
||||
self.buttonBox.accepted.connect(playerDialog.accept) # type: ignore
|
||||
self.buttonBox.rejected.connect(playerDialog.reject) # type: ignore
|
||||
QtCore.QMetaObject.connectSlotsByName(playerDialog)
|
||||
|
||||
def retranslateUi(self, playerDialog):
|
||||
_translate = QtCore.QCoreApplication.translate
|
||||
playerDialog.setWindowTitle(_translate("playerDialog", "Player"))
|
||||
self.label.setText(_translate("playerDialog", "Name:"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
playerDialog = QtWidgets.QDialog()
|
||||
ui = Ui_playerDialog()
|
||||
ui.setupUi(playerDialog)
|
||||
playerDialog.show()
|
||||
sys.exit(app.exec())
|
||||
98
src/warchron/view/ui/ui_player_dialog.ui
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>playerDialog</class>
|
||||
<widget class="QDialog" name="playerDialog">
|
||||
<property name="windowModality">
|
||||
<enum>Qt::ApplicationModal</enum>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>378</width>
|
||||
<height>98</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Player</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset>
|
||||
<normaloff>../resources/warchron_logo.png</normaloff>../resources/warchron_logo.png</iconset>
|
||||
</property>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>60</y>
|
||||
<width>341</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>20</y>
|
||||
<width>47</width>
|
||||
<height>14</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Name:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="playerName">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>60</x>
|
||||
<y>20</y>
|
||||
<width>113</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>playerDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>playerDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
57
src/warchron/view/view.py
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
from pathlib import Path
|
||||
|
||||
from PyQt6 import QtWidgets
|
||||
from PyQt6.QtWidgets import QDialog, QFileDialog
|
||||
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
|
||||
|
||||
class View(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
def __init__(self, parent=None):
|
||||
super(View, self).__init__(parent)
|
||||
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()
|
||||
if not proceed:
|
||||
event.ignore()
|
||||
return
|
||||
event.accept()
|
||||
|
||||
def ask_open_file(self) -> Path | None:
|
||||
filename, _ = QFileDialog.getOpenFileName(
|
||||
self,
|
||||
"Open war history",
|
||||
"",
|
||||
"WarChron files (*.json)"
|
||||
)
|
||||
return Path(filename) if filename else None
|
||||
|
||||
def ask_save_file(self) -> Path | None:
|
||||
filename, _ = QFileDialog.getSaveFileName(
|
||||
self,
|
||||
"Save war history",
|
||||
"",
|
||||
"WarChron files (*.json)"
|
||||
)
|
||||
return Path(filename) if filename else None
|
||||
|
||||
class PlayerDialog(QDialog):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.ui = Ui_playerDialog()
|
||||
self.ui.setupUi(self)
|
||||
|
||||
def get_player_name(self) -> str:
|
||||
return self.ui.playerName.text().strip()
|
||||