From 9ca55e7af75c1c14e8da6cf8cb907151acd345b7 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 13 Apr 2021 14:15:45 +0100 Subject: [PATCH] Suit: Implement auto-toggle of Suit line based on CAPI data * There's a 'visible' argument to force it, default None to ignore. That flag is checked first in the function, and then it sets the 'current' state to the opposite so the following conditional will do the right thing. * Toggling is triggered in AppWindow.getandsend(). --- EDMarketConnector.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 0a3beee7..b695545a 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -599,22 +599,28 @@ class AppWindow(object): self.postprefs(False) # Companion login happens in callback from monitor - def toggle_suit_row(self, visible=True) -> None: + def toggle_suit_row(self, visible: Optional[bool] = None) -> None: """ Toggle the visibility of the 'Suit' row. - :param visible: UNIMPLEMENTED + :param visible: Force visibility to this. """ + if visible is True: + self.suit_shown = False + + elif visible is False: + self.suit_shown = True + if not self.suit_shown: self.suit_label.grid(row=self.suit_grid_row, column=0, sticky=tk.W) self.suit.grid(row=self.suit_grid_row, column=1, sticky=tk.EW) + self.suit_shown = True else: # Hide the Suit row self.suit_label.grid_forget() self.suit.grid_forget() - - self.suit_shown = not self.suit_shown + self.suit_shown = False def postprefs(self, dologin: bool = True): """Perform necessary actions after the Preferences dialog is applied.""" @@ -883,6 +889,12 @@ class AppWindow(object): if monitor.state['Modules']: self.ship.configure(state=True) + if monitor.state.get('SuitCurrent') is not None: + self.toggle_suit_row(visible=True) + + else: + self.toggle_suit_row(visible=False) + if data['commander'].get('credits') is not None: monitor.state['Credits'] = data['commander']['credits'] monitor.state['Loan'] = data['commander'].get('debt', 0)