diff --git a/qt_ui/widgets/map/QLiberationMap.py b/qt_ui/widgets/map/QLiberationMap.py index dde0893e..2c83996c 100644 --- a/qt_ui/widgets/map/QLiberationMap.py +++ b/qt_ui/widgets/map/QLiberationMap.py @@ -62,18 +62,36 @@ class QLiberationMap(QGraphicsView): lambda: self.draw_flight_plans(self.scene()) ) - def update_package_selection(index: Optional[int]) -> None: - self.selected_flight = index, 0 + def update_package_selection(index: int) -> None: + # Optional[int] isn't a valid type for a Qt signal. None will be + # converted to zero automatically. We use -1 to indicate no + # selection. + if index == -1: + self.selected_flight = None + else: + self.selected_flight = index, 0 self.draw_flight_plans(self.scene()) GameUpdateSignal.get_instance().package_selection_changed.connect( update_package_selection ) - def update_flight_selection(index: Optional[int]) -> None: + def update_flight_selection(index: int) -> None: if self.selected_flight is None: - logging.error("Flight was selected with no package selected") + if index != -1: + # We don't know what order update_package_selection and + # update_flight_selection will be called in when the last + # package is removed. If no flight is selected, it's not a + # problem to also have no package selected. + logging.error( + "Flight was selected with no package selected") return + + # Optional[int] isn't a valid type for a Qt signal. None will be + # converted to zero automatically. We use -1 to indicate no + # selection. + if index == -1: + self.selected_flight = self.selected_flight[0], None self.selected_flight = self.selected_flight[0], index self.draw_flight_plans(self.scene()) @@ -259,7 +277,10 @@ class QLiberationMap(QGraphicsView): packages.extend(self.game_model.red_ato_model.packages) for p_idx, package_model in enumerate(packages): for f_idx, flight in enumerate(package_model.flights): - selected = (p_idx, f_idx) == self.selected_flight + if self.selected_flight is None: + selected = False + else: + selected = (p_idx, f_idx) == self.selected_flight if DisplayOptions.flight_paths.only_selected and not selected: continue self.draw_flight_plan(scene, package_model.package, flight, diff --git a/qt_ui/windows/GameUpdateSignal.py b/qt_ui/windows/GameUpdateSignal.py index 3c112952..529a7498 100644 --- a/qt_ui/windows/GameUpdateSignal.py +++ b/qt_ui/windows/GameUpdateSignal.py @@ -24,8 +24,8 @@ class GameUpdateSignal(QObject): debriefingReceived = Signal(DebriefingSignal) flight_paths_changed = Signal() - package_selection_changed = Signal(int) # Optional[int] - flight_selection_changed = Signal(int) # Optional[int] + package_selection_changed = Signal(int) # -1 indicates no selection. + flight_selection_changed = Signal(int) # -1 indicates no selection. def __init__(self): super(GameUpdateSignal, self).__init__() @@ -33,11 +33,11 @@ class GameUpdateSignal(QObject): def select_package(self, index: Optional[int]) -> None: # noinspection PyUnresolvedReferences - self.package_selection_changed.emit(index) + self.package_selection_changed.emit(-1 if index is None else index) def select_flight(self, index: Optional[int]) -> None: # noinspection PyUnresolvedReferences - self.flight_selection_changed.emit(index) + self.flight_selection_changed.emit(-1 if index is None else index) def redraw_flight_paths(self) -> None: # noinspection PyUnresolvedReferences