55 lines
2.1 KiB
Python
55 lines
2.1 KiB
Python
|
|
from typing import cast, List
|
||
|
|
|
||
|
|
from PyQt6.QtWidgets import QWidget, QDialog
|
||
|
|
|
||
|
|
from warchron.controller.dtos import ObjectiveDTO, RoundDTO
|
||
|
|
from warchron.view.helpers import select_if_exists, format_round_label
|
||
|
|
from warchron.view.ui.ui_sector_dialog import Ui_sectorDialog
|
||
|
|
|
||
|
|
|
||
|
|
class SectorDialog(QDialog):
|
||
|
|
def __init__(
|
||
|
|
self,
|
||
|
|
parent: QWidget | None = 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 = 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(index), rnd.id)
|
||
|
|
select_if_exists(self.ui.roundComboBox, default_round_id)
|
||
|
|
for obj in objectives:
|
||
|
|
self.ui.majorComboBox.addItem(obj.name, obj.id)
|
||
|
|
self.ui.minorComboBox.addItem(obj.name, obj.id)
|
||
|
|
self.ui.influenceComboBox.addItem(obj.name, obj.id)
|
||
|
|
select_if_exists(self.ui.majorComboBox, default_major_id)
|
||
|
|
select_if_exists(self.ui.minorComboBox, default_minor_id)
|
||
|
|
select_if_exists(self.ui.influenceComboBox, default_influence_id)
|
||
|
|
|
||
|
|
def get_sector_name(self) -> str:
|
||
|
|
return self.ui.sectorName.text().strip()
|
||
|
|
|
||
|
|
def get_round_id(self) -> str:
|
||
|
|
return cast(str, self.ui.roundComboBox.currentData())
|
||
|
|
|
||
|
|
def get_major_id(self) -> str:
|
||
|
|
return cast(str, self.ui.majorComboBox.currentData())
|
||
|
|
|
||
|
|
def get_minor_id(self) -> str:
|
||
|
|
return cast(str, self.ui.minorComboBox.currentData())
|
||
|
|
|
||
|
|
def get_influence_id(self) -> str:
|
||
|
|
return cast(str, self.ui.influenceComboBox.currentData())
|