code quality (mypy+flake8)

This commit is contained in:
Maxime Réaux 2026-02-04 16:10:53 +01:00
parent 7210ddc927
commit 55abdccc64
19 changed files with 778 additions and 497 deletions

View file

@ -1,20 +1,42 @@
from typing import cast, Callable, List
from pathlib import Path
import calendar
from PyQt6 import QtWidgets
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QDialog, QFileDialog, QTreeWidgetItem, QMenu
from PyQt6.QtCore import Qt, QPoint
from PyQt6.QtWidgets import (
QWidget,
QDialog,
QFileDialog,
QTreeWidgetItem,
QMenu,
QComboBox,
)
from PyQt6.QtGui import QCloseEvent
from warchron.constants import ROLE_TYPE, ROLE_ID, ItemType
from warchron.controller.dtos import ParticipantOption
from warchron.controller.dtos import (
ParticipantOption,
TreeSelection,
WarDTO,
WarParticipantDTO,
ObjectiveDTO,
CampaignDTO,
CampaignParticipantDTO,
SectorDTO,
RoundDTO,
ChoiceDTO,
BattleDTO,
)
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
from warchron.view.ui.ui_campaign_dialog import Ui_campaignDialog
from warchron.view.ui.ui_objective_dialog import Ui_objectiveDialog
from warchron.view.ui.ui_war_participant_dialog import Ui_warParticipantDialog
from warchron.view.ui.ui_campaign_participant_dialog import Ui_campaignParticipantDialog
from warchron.view.ui.ui_campaign_participant_dialog import (
Ui_campaignParticipantDialog,
)
from warchron.view.ui.ui_sector_dialog import Ui_sectorDialog
from warchron.view.ui.ui_choices_dialog import Ui_choicesDialog
from warchron.view.ui.ui_battle_result_dialog import Ui_battleResultDialog
@ -22,7 +44,7 @@ from warchron.view.ui.ui_battle_result_dialog import Ui_battleResultDialog
# utils...
def select_if_exists(combo, value):
def select_if_exists(combo: QComboBox, value: str | None) -> None:
if value is None:
return
idx = combo.findData(value)
@ -30,30 +52,32 @@ def select_if_exists(combo, value):
combo.setCurrentIndex(idx)
def format_war_label(war) -> str:
def format_war_label(war: WarDTO) -> str:
return f"{war.name} ({war.year})"
def format_campaign_label(camp) -> str:
def format_campaign_label(camp: CampaignDTO) -> str:
return f"{camp.name} ({calendar.month_name[camp.month]})"
def format_round_label(round, index: int) -> str:
def format_round_label(index: int) -> str:
if index is None:
return ""
return f"Round {index}"
class View(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
def __init__(self, parent: QWidget | None = None) -> None:
super(View, self).__init__(parent)
self.setupUi(self)
self.on_close_callback = None
self.on_selection_changed = None
self.on_add_campaign = None
self.on_add_round = None
self.on_edit_item = None
self.on_delete_item = None
self.setupUi(self) # type: ignore
self.on_close_callback: Callable[[], bool] | None = None
self.on_tree_selection_changed: (
Callable[[TreeSelection | None], None] | None
) = None
self.on_add_campaign: Callable[[], None] | None = None
self.on_add_round: Callable[[], None] | None = None
self.on_edit_item: Callable[[str, str], None] | None = None
self.on_delete_item: Callable[[str, str], None] | None = None
self.splitter.setSizes([200, 800])
self.show_details(None)
self.playersTable.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
@ -98,17 +122,17 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
self._on_battles_table_context_menu
)
def _emit_selection_changed(self, current, previous):
def _emit_selection_changed(self, current: QTreeWidgetItem | None) -> None:
if not self.on_tree_selection_changed:
return
if not current:
self.on_tree_selection_changed(None)
return
self.on_tree_selection_changed(
{
"type": current.data(0, ROLE_TYPE),
"id": current.data(0, ROLE_ID),
}
TreeSelection(
type=current.data(0, ROLE_TYPE),
id=current.data(0, ROLE_ID),
)
)
def get_current_tab(self) -> str:
@ -121,7 +145,9 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
# General popups
def closeEvent(self, event: QCloseEvent):
def closeEvent(self, event: QCloseEvent | None = None) -> None:
if event is None:
return
if self.on_close_callback:
proceed = self.on_close_callback()
if not proceed:
@ -143,7 +169,7 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
# Players view
def _on_players_table_context_menu(self, pos):
def _on_players_table_context_menu(self, pos: QPoint) -> None:
item = self.playersTable.itemAt(pos)
if not item:
return
@ -155,13 +181,15 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
menu = QMenu(self)
edit_action = menu.addAction("Edit")
delete_action = menu.addAction("Delete")
action = menu.exec(self.playersTable.viewport().mapToGlobal(pos))
viewport = self.playersTable.viewport()
assert viewport is not None
action = menu.exec(viewport.mapToGlobal(pos))
if action == edit_action and self.on_edit_item:
self.on_edit_item(ItemType.PLAYER, player_id)
elif action == delete_action and self.on_delete_item:
self.on_delete_item(ItemType.PLAYER, player_id)
def display_players(self, players: list):
def display_players(self, players: List[ParticipantOption]) -> None:
table = self.playersTable
table.setRowCount(len(players))
for row, player in enumerate(players):
@ -172,21 +200,21 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
# Wars view
def _on_add_campaign_clicked(self):
def _on_add_campaign_clicked(self) -> None:
if self.on_add_campaign:
self.on_add_campaign()
def _on_add_round_clicked(self):
def _on_add_round_clicked(self) -> None:
if self.on_add_round:
self.on_add_round()
def set_add_campaign_enabled(self, enabled: bool):
def set_add_campaign_enabled(self, enabled: bool) -> None:
self.addCampaignBtn.setEnabled(enabled)
def set_add_round_enabled(self, enabled: bool):
def set_add_round_enabled(self, enabled: bool) -> None:
self.addRoundBtn.setEnabled(enabled)
def _on_wars_tree_context_menu(self, pos):
def _on_wars_tree_context_menu(self, pos: QPoint) -> None:
item = self.warsTree.itemAt(pos)
if not item:
return
@ -197,7 +225,9 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
if item_type != ItemType.ROUND:
edit_action = menu.addAction("Edit")
delete_action = menu.addAction("Delete")
action = menu.exec(self.warsTree.viewport().mapToGlobal(pos))
viewport = self.warsTree.viewport()
assert viewport is not None
action = menu.exec(viewport.mapToGlobal(pos))
if action == edit_action:
if self.on_edit_item:
self.on_edit_item(item_type, item_id)
@ -205,7 +235,7 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
if self.on_delete_item:
self.on_delete_item(item_type, item_id)
def display_wars_tree(self, wars: list):
def display_wars_tree(self, wars: List[WarDTO]) -> None:
tree = self.warsTree
tree.clear()
tree.setColumnCount(1)
@ -221,15 +251,15 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
camp_item.setData(0, ROLE_ID, camp.id)
war_item.addChild(camp_item)
for index, rnd in enumerate(camp.get_all_rounds(), start=1):
rnd_item = QTreeWidgetItem([format_round_label(rnd, index)])
rnd_item = QTreeWidgetItem([format_round_label(index)])
rnd_item.setData(0, ROLE_TYPE, ItemType.ROUND)
rnd_item.setData(0, ROLE_ID, rnd.id)
camp_item.addChild(rnd_item)
tree.currentItemChanged.connect(self._emit_selection_changed)
tree.expandAll()
def select_tree_item(self, *, item_type: ItemType, item_id: str):
def walk(item: QTreeWidgetItem):
def select_tree_item(self, *, item_type: ItemType, item_id: str) -> None:
def walk(item: QTreeWidgetItem) -> bool:
if (
item.data(0, ROLE_TYPE) == item_type
and item.data(0, ROLE_ID) == item_id
@ -237,21 +267,25 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
self.warsTree.setCurrentItem(item)
return True
for i in range(item.childCount()):
if walk(item.child(i)):
# if walk(item.child(i)):
ytem = item.child(i)
if ytem is not None and walk(ytem):
return True
return False
for i in range(self.warsTree.topLevelItemCount()):
if walk(self.warsTree.topLevelItem(i)):
# if walk(self.warsTree.topLevelItem(i)):
item = self.warsTree.topLevelItem(i)
if item is not None and walk(item):
return
def get_selected_tree_item(self):
def get_selected_tree_item(self) -> dict[str, str] | None:
item = self.warsTree.currentItem()
if not item:
return None
return {"type": item.data(0, ROLE_TYPE), "id": item.data(0, ROLE_ID)}
def show_details(self, item_type: str | None):
def show_details(self, item_type: str | None) -> None:
if item_type == ItemType.WAR:
self.selectedDetailsStack.setCurrentWidget(self.pageWar)
elif item_type == ItemType.CAMPAIGN:
@ -263,7 +297,7 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
# War page
def _on_objectives_table_context_menu(self, pos):
def _on_objectives_table_context_menu(self, pos: QPoint) -> None:
item = self.objectivesTable.itemAt(pos)
if not item:
return
@ -275,13 +309,15 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
menu = QMenu(self)
edit_action = menu.addAction("Edit")
delete_action = menu.addAction("Delete")
action = menu.exec(self.objectivesTable.viewport().mapToGlobal(pos))
viewport = self.objectivesTable.viewport()
assert viewport is not None
action = menu.exec(viewport.mapToGlobal(pos))
if action == edit_action and self.on_edit_item:
self.on_edit_item(ItemType.OBJECTIVE, objective_id)
elif action == delete_action and self.on_delete_item:
self.on_delete_item(ItemType.OBJECTIVE, objective_id)
def _on_war_participants_table_context_menu(self, pos):
def _on_war_participants_table_context_menu(self, pos: QPoint) -> None:
item = self.warParticipantsTable.itemAt(pos)
if not item:
return
@ -293,17 +329,19 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
menu = QMenu(self)
edit_action = menu.addAction("Edit")
delete_action = menu.addAction("Delete")
action = menu.exec(self.warParticipantsTable.viewport().mapToGlobal(pos))
viewport = self.warParticipantsTable.viewport()
assert viewport is not None
action = menu.exec(viewport.mapToGlobal(pos))
if action == edit_action and self.on_edit_item:
self.on_edit_item(ItemType.WAR_PARTICIPANT, participant_id)
elif action == delete_action and self.on_delete_item:
self.on_delete_item(ItemType.WAR_PARTICIPANT, participant_id)
def show_war_details(self, *, name: str, year: int):
def show_war_details(self, *, name: str, year: int) -> None:
self.warName.setText(name)
self.warYear.setText(str(year))
def display_war_objectives(self, objectives: list):
def display_war_objectives(self, objectives: List[ObjectiveDTO]) -> None:
table = self.objectivesTable
table.clearContents()
table.setRowCount(len(objectives))
@ -315,21 +353,21 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
table.setItem(row, 1, desc_item)
table.resizeColumnsToContents()
def display_war_participants(self, participants: list[tuple[str, str, str]]):
def display_war_participants(self, participants: List[WarParticipantDTO]) -> None:
table = self.warParticipantsTable
table.clearContents()
table.setRowCount(len(participants))
for row, (name, faction, pid) in enumerate(participants):
name_item = QtWidgets.QTableWidgetItem(name)
fact_item = QtWidgets.QTableWidgetItem(faction)
name_item.setData(Qt.ItemDataRole.UserRole, pid)
for row, part in enumerate(participants):
name_item = QtWidgets.QTableWidgetItem(part.player_name)
fact_item = QtWidgets.QTableWidgetItem(part.faction)
name_item.setData(Qt.ItemDataRole.UserRole, part.id)
table.setItem(row, 0, name_item)
table.setItem(row, 1, fact_item)
table.resizeColumnsToContents()
# Campaign page
def _on_sectors_table_context_menu(self, pos):
def _on_sectors_table_context_menu(self, pos: QPoint) -> None:
item = self.sectorsTable.itemAt(pos)
if not item:
return
@ -341,13 +379,15 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
menu = QMenu(self)
edit_action = menu.addAction("Edit")
delete_action = menu.addAction("Delete")
action = menu.exec(self.sectorsTable.viewport().mapToGlobal(pos))
viewport = self.sectorsTable.viewport()
assert viewport is not None
action = menu.exec(viewport.mapToGlobal(pos))
if action == edit_action and self.on_edit_item:
self.on_edit_item(ItemType.SECTOR, sector_id)
elif action == delete_action and self.on_delete_item:
self.on_delete_item(ItemType.SECTOR, sector_id)
def _on_campaign_participants_table_context_menu(self, pos):
def _on_campaign_participants_table_context_menu(self, pos: QPoint) -> None:
item = self.campaignParticipantsTable.itemAt(pos)
if not item:
return
@ -359,33 +399,31 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
menu = QMenu(self)
edit_action = menu.addAction("Edit")
delete_action = menu.addAction("Delete")
action = menu.exec(self.campaignParticipantsTable.viewport().mapToGlobal(pos))
viewport = self.campaignParticipantsTable.viewport()
assert viewport is not None
action = menu.exec(viewport.mapToGlobal(pos))
if action == edit_action and self.on_edit_item:
self.on_edit_item(ItemType.CAMPAIGN_PARTICIPANT, participant_id)
elif action == delete_action and self.on_delete_item:
self.on_delete_item(ItemType.CAMPAIGN_PARTICIPANT, participant_id)
def show_campaign_details(self, *, name: str, month: int):
def show_campaign_details(self, *, name: str, month: int) -> None:
self.campaignName.setText(name)
self.campaignMonth.setText(calendar.month_name[month])
def display_campaign_sectors(
self, sectors: list[tuple[str, str, str, str, str, str]]
):
def display_campaign_sectors(self, sectors: List[SectorDTO]) -> None:
table = self.sectorsTable
table.clearContents()
table.setRowCount(len(sectors))
for row, (name, round_index, major, minor, influence, pid) in enumerate(
sectors
):
name_item = QtWidgets.QTableWidgetItem(name)
for row, sect in enumerate(sectors):
name_item = QtWidgets.QTableWidgetItem(sect.name)
round_item = QtWidgets.QTableWidgetItem(
format_round_label(None, round_index)
format_round_label(sect.round_index)
)
major_item = QtWidgets.QTableWidgetItem(major)
minor_item = QtWidgets.QTableWidgetItem(minor)
influence_item = QtWidgets.QTableWidgetItem(influence)
name_item.setData(Qt.ItemDataRole.UserRole, pid)
major_item = QtWidgets.QTableWidgetItem(sect.major)
minor_item = QtWidgets.QTableWidgetItem(sect.minor)
influence_item = QtWidgets.QTableWidgetItem(sect.influence)
name_item.setData(Qt.ItemDataRole.UserRole, sect.id)
table.setItem(row, 0, name_item)
table.setItem(row, 1, round_item)
table.setItem(row, 2, major_item)
@ -394,16 +432,16 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
table.resizeColumnsToContents()
def display_campaign_participants(
self, participants: list[tuple[str, str, str, str]]
):
self, participants: List[CampaignParticipantDTO]
) -> None:
table = self.campaignParticipantsTable
table.clearContents()
table.setRowCount(len(participants))
for row, (name, leader, theme, pid) in enumerate(participants):
name_item = QtWidgets.QTableWidgetItem(name)
lead_item = QtWidgets.QTableWidgetItem(leader)
theme_item = QtWidgets.QTableWidgetItem(theme)
name_item.setData(Qt.ItemDataRole.UserRole, pid)
for row, part in enumerate(participants):
name_item = QtWidgets.QTableWidgetItem(part.player_name)
lead_item = QtWidgets.QTableWidgetItem(part.leader)
theme_item = QtWidgets.QTableWidgetItem(part.theme)
name_item.setData(Qt.ItemDataRole.UserRole, part.id)
table.setItem(row, 0, name_item)
table.setItem(row, 1, lead_item)
table.setItem(row, 2, theme_item)
@ -411,7 +449,7 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
# Round page
def _on_choices_table_context_menu(self, pos):
def _on_choices_table_context_menu(self, pos: QPoint) -> None:
item = self.choicesTable.itemAt(pos)
if not item:
return
@ -424,11 +462,13 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
return
menu = QMenu(self)
edit_action = menu.addAction("Edit")
action = menu.exec(self.choicesTable.viewport().mapToGlobal(pos))
viewport = self.choicesTable.viewport()
assert viewport is not None
action = menu.exec(viewport.mapToGlobal(pos))
if action == edit_action and self.on_edit_item:
self.on_edit_item(ItemType.CHOICE, choice_id)
def _on_battles_table_context_menu(self, pos):
def _on_battles_table_context_menu(self, pos: QPoint) -> None:
item = self.battlesTable.itemAt(pos)
if not item:
return
@ -441,38 +481,38 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
return
menu = QMenu(self)
edit_action = menu.addAction("Edit")
action = menu.exec(self.battlesTable.viewport().mapToGlobal(pos))
viewport = self.battlesTable.viewport()
assert viewport is not None
action = menu.exec(viewport.mapToGlobal(pos))
if action == edit_action and self.on_edit_item:
self.on_edit_item(ItemType.BATTLE, battle_id)
def show_round_details(self, *, index: int):
def show_round_details(self, *, index: int) -> None:
self.roundNb.setText(f"Round {index}")
def display_round_choices(self, participants: list[tuple[str, str, str, str]]):
def display_round_choices(self, participants: List[ChoiceDTO]) -> None:
table = self.choicesTable
table.clearContents()
table.setRowCount(len(participants))
for row, (participant, priority, secondary, choice_id) in enumerate(
participants
):
participant_item = QtWidgets.QTableWidgetItem(participant)
priority_item = QtWidgets.QTableWidgetItem(priority)
secondary_item = QtWidgets.QTableWidgetItem(secondary)
participant_item.setData(Qt.ItemDataRole.UserRole, choice_id)
for row, choice in enumerate(participants):
participant_item = QtWidgets.QTableWidgetItem(choice.participant_name)
priority_item = QtWidgets.QTableWidgetItem(choice.priority_sector)
secondary_item = QtWidgets.QTableWidgetItem(choice.secondary_sector)
participant_item.setData(Qt.ItemDataRole.UserRole, choice.id)
table.setItem(row, 0, participant_item)
table.setItem(row, 1, priority_item)
table.setItem(row, 2, secondary_item)
table.resizeColumnsToContents()
def display_round_battles(self, sectors: list[tuple[str, str, str, str]]):
def display_round_battles(self, sectors: List[BattleDTO]) -> None:
table = self.battlesTable
table.clearContents()
table.setRowCount(len(sectors))
for row, (sector, player_1, player_2, battle_id) in enumerate(sectors):
sector_item = QtWidgets.QTableWidgetItem(sector)
player_1_item = QtWidgets.QTableWidgetItem(player_1)
player_2_item = QtWidgets.QTableWidgetItem(player_2)
sector_item.setData(Qt.ItemDataRole.UserRole, battle_id)
for row, battle in enumerate(sectors):
sector_item = QtWidgets.QTableWidgetItem(battle.sector_name)
player_1_item = QtWidgets.QTableWidgetItem(battle.player_1)
player_2_item = QtWidgets.QTableWidgetItem(battle.player_2)
sector_item.setData(Qt.ItemDataRole.UserRole, battle.id)
table.setItem(row, 0, sector_item)
table.setItem(row, 1, player_1_item)
table.setItem(row, 2, player_2_item)
@ -480,10 +520,12 @@ class View(QtWidgets.QMainWindow, Ui_MainWindow):
class PlayerDialog(QDialog):
def __init__(self, parent=None, *, default_name: str = ""):
def __init__(
self, parent: QWidget | None = None, *, default_name: str = ""
) -> None:
super().__init__(parent)
self.ui = Ui_playerDialog()
self.ui.setupUi(self)
self.ui: Ui_playerDialog = Ui_playerDialog()
self.ui.setupUi(self) # type: ignore
self.ui.playerName.setText(default_name)
def get_player_name(self) -> str:
@ -492,11 +534,14 @@ class PlayerDialog(QDialog):
class WarDialog(QDialog):
def __init__(
self, parent=None, default_name: str = "", default_year: int | None = None
):
self,
parent: QWidget | None = None,
default_name: str = "",
default_year: int | None = None,
) -> None:
super().__init__(parent)
self.ui = Ui_warDialog()
self.ui.setupUi(self)
self.ui: Ui_warDialog = Ui_warDialog()
self.ui.setupUi(self) # type: ignore
self.ui.warName.setText(default_name)
if default_year is not None:
self.ui.warYear.setValue(default_year)
@ -510,11 +555,14 @@ class WarDialog(QDialog):
class CampaignDialog(QDialog):
def __init__(
self, parent=None, default_name: str = "", default_month: int | None = None
):
self,
parent: QWidget | None = None,
default_name: str = "",
default_month: int | None = None,
) -> None:
super().__init__(parent)
self.ui = Ui_campaignDialog()
self.ui.setupUi(self)
self.ui: Ui_campaignDialog = Ui_campaignDialog()
self.ui.setupUi(self) # type: ignore
self.ui.campaignName.setText(default_name)
if default_month is not None:
self.ui.campaignMonth.setValue(default_month)
@ -527,10 +575,16 @@ class CampaignDialog(QDialog):
class ObjectiveDialog(QDialog):
def __init__(self, parent=None, *, default_name="", default_description=""):
def __init__(
self,
parent: QWidget | None = None,
*,
default_name: str = "",
default_description: str | None = "",
) -> None:
super().__init__(parent)
self.ui = Ui_objectiveDialog()
self.ui.setupUi(self)
self.ui: Ui_objectiveDialog = Ui_objectiveDialog()
self.ui.setupUi(self) # type: ignore
self.ui.objectiveName.setText(default_name)
self.ui.objectiveDescription.setPlainText(default_description)
@ -544,16 +598,16 @@ class ObjectiveDialog(QDialog):
class WarParticipantDialog(QDialog):
def __init__(
self,
parent=None,
parent: QWidget | None = None,
*,
players: list,
default_player_id=None,
default_faction="",
editable_player=True,
players: List[ParticipantOption],
default_player_id: str | None = None,
default_faction: str | None = "",
editable_player: bool = True,
):
super().__init__(parent)
self.ui = Ui_warParticipantDialog()
self.ui.setupUi(self)
self.ui: Ui_warParticipantDialog = Ui_warParticipantDialog()
self.ui.setupUi(self) # type: ignore
for player in players:
self.ui.playerComboBox.addItem(player.name, player.id)
select_if_exists(self.ui.playerComboBox, default_player_id)
@ -561,7 +615,7 @@ class WarParticipantDialog(QDialog):
self.ui.faction.setText(default_faction)
def get_player_id(self) -> str:
return self.ui.playerComboBox.currentData()
return cast(str, self.ui.playerComboBox.currentData())
def get_participant_faction(self) -> str:
return self.ui.faction.text().strip()
@ -570,17 +624,17 @@ class WarParticipantDialog(QDialog):
class CampaignParticipantDialog(QDialog):
def __init__(
self,
parent=None,
parent: QWidget | None = None,
*,
participants: list[ParticipantOption],
default_participant_id=None,
default_leader="",
default_theme="",
editable_player=True,
):
participants: List[ParticipantOption],
default_participant_id: str | None = None,
default_leader: str | None = "",
default_theme: str | None = "",
editable_player: bool = True,
) -> None:
super().__init__(parent)
self.ui = Ui_campaignParticipantDialog()
self.ui.setupUi(self)
self.ui: Ui_campaignParticipantDialog = Ui_campaignParticipantDialog()
self.ui.setupUi(self) # type: ignore
for part in participants:
self.ui.playerComboBox.addItem(part.name, part.id)
select_if_exists(self.ui.playerComboBox, default_participant_id)
@ -589,7 +643,7 @@ class CampaignParticipantDialog(QDialog):
self.ui.theme.setText(default_theme)
def get_player_id(self) -> str:
return self.ui.playerComboBox.currentData()
return cast(str, self.ui.playerComboBox.currentData())
def get_participant_leader(self) -> str:
return self.ui.leader.text().strip()
@ -601,25 +655,25 @@ class CampaignParticipantDialog(QDialog):
class SectorDialog(QDialog):
def __init__(
self,
parent=None,
parent: QWidget | None = None,
*,
default_name="",
rounds: list,
default_round_id=None,
objectives: list,
default_major_id=None,
default_minor_id=None,
default_influence_id=None,
):
default_name: str = "",
rounds: List[RoundDTO],
default_round_id: str | None = None,
objectives: List[ObjectiveDTO],
default_major_id: str | None = None,
default_minor_id: str | None = None,
default_influence_id: str | None = None,
) -> None:
super().__init__(parent)
self.ui = Ui_sectorDialog()
self.ui.setupUi(self)
self.ui: Ui_sectorDialog = Ui_sectorDialog()
self.ui.setupUi(self) # type: ignore
self.ui.majorComboBox.addItem("(none)", None)
self.ui.minorComboBox.addItem("(none)", None)
self.ui.influenceComboBox.addItem("(none)", None)
self.ui.sectorName.setText(default_name)
for index, rnd in enumerate(rounds, start=1):
self.ui.roundComboBox.addItem(format_round_label(rnd, index), rnd.id)
self.ui.roundComboBox.addItem(format_round_label(index), rnd.id)
select_if_exists(self.ui.roundComboBox, default_round_id)
for obj in objectives:
self.ui.majorComboBox.addItem(obj.name, obj.id)
@ -633,33 +687,33 @@ class SectorDialog(QDialog):
return self.ui.sectorName.text().strip()
def get_round_id(self) -> str:
return self.ui.roundComboBox.currentData()
return cast(str, self.ui.roundComboBox.currentData())
def get_major_id(self) -> str:
return self.ui.majorComboBox.currentData()
return cast(str, self.ui.majorComboBox.currentData())
def get_minor_id(self) -> str:
return self.ui.minorComboBox.currentData()
return cast(str, self.ui.minorComboBox.currentData())
def get_influence_id(self) -> str:
return self.ui.influenceComboBox.currentData()
return cast(str, self.ui.influenceComboBox.currentData())
class ChoicesDialog(QDialog):
def __init__(
self,
parent=None,
parent: QWidget | None = None,
*,
participants: list,
default_participant_id=None,
sectors: list,
default_priority_id=None,
default_secondary_id=None,
default_comment=None,
):
participants: List[ParticipantOption],
default_participant_id: str | None = None,
sectors: List[SectorDTO],
default_priority_id: str | None = None,
default_secondary_id: str | None = None,
default_comment: str | None = None,
) -> None:
super().__init__(parent)
self.ui = Ui_choicesDialog()
self.ui.setupUi(self)
self.ui: Ui_choicesDialog = Ui_choicesDialog()
self.ui.setupUi(self) # type: ignore
for part in participants:
self.ui.playerComboBox.addItem(part.name, part.id)
select_if_exists(self.ui.playerComboBox, default_participant_id)
@ -674,13 +728,13 @@ class ChoicesDialog(QDialog):
self.ui.choiceComment.setPlainText(default_comment)
def get_participant_id(self) -> str:
return self.ui.playerComboBox.currentData()
return cast(str, self.ui.playerComboBox.currentData())
def get_priority_id(self) -> str:
return self.ui.priorityComboBox.currentData()
return cast(str, self.ui.priorityComboBox.currentData())
def get_secondary_id(self) -> str:
return self.ui.secondaryComboBox.currentData()
return cast(str, self.ui.secondaryComboBox.currentData())
def get_comment(self) -> str:
return self.ui.choiceComment.toPlainText().strip()
@ -689,21 +743,21 @@ class ChoicesDialog(QDialog):
class BattlesDialog(QDialog):
def __init__(
self,
parent=None,
parent: QWidget | None = None,
*,
sectors: list,
default_sector_id=None,
players: list,
default_player_1_id=None,
default_player_2_id=None,
default_winner_id=None,
default_score=None,
default_victory_condition=None,
default_comment=None,
):
sectors: List[SectorDTO],
default_sector_id: str | None = None,
players: List[ParticipantOption],
default_player_1_id: str | None = None,
default_player_2_id: str | None = None,
default_winner_id: str | None = None,
default_score: str | None = None,
default_victory_condition: str | None = None,
default_comment: str | None = None,
) -> None:
super().__init__(parent)
self.ui = Ui_battleResultDialog()
self.ui.setupUi(self)
self.ui: Ui_battleResultDialog = Ui_battleResultDialog()
self.ui.setupUi(self) # type: ignore
for sect in sectors:
self.ui.sectorComboBox.addItem(sect.name, sect.id)
select_if_exists(self.ui.sectorComboBox, default_sector_id)
@ -726,16 +780,16 @@ class BattlesDialog(QDialog):
self.ui.battleComment.setPlainText(default_comment)
def get_sector_id(self) -> str:
return self.ui.sectorComboBox.currentData()
return cast(str, self.ui.sectorComboBox.currentData())
def get_player_1_id(self) -> str:
return self.ui.player1ComboBox.currentData()
return cast(str, self.ui.player1ComboBox.currentData())
def get_player_2_id(self) -> str:
return self.ui.player2ComboBox.currentData()
return cast(str, self.ui.player2ComboBox.currentData())
def get_winner_id(self) -> str:
return self.ui.winnerComboBox.currentData()
return cast(str, self.ui.winnerComboBox.currentData())
def get_score(self) -> str:
return self.ui.score.text().strip()