diff --git a/EDMarketConnector.py b/EDMarketConnector.py index b3e1e1cf..6ca1c966 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -604,6 +604,19 @@ class AppWindow(object): self.postprefs(False) # Companion login happens in callback from monitor self.toggle_suit_row(visible=False) + def update_suit_text(self) -> None: + """Update the suit text for current type and loadout.""" + if (suit := monitor.state.get('SuitCurrent')) is None: + return + + suitname = suit['locName'] + + if (suitloadout := monitor.state.get('SuitLoadoutCurrent')) is None: + return + + loadout_name = suitloadout['name'] + self.suit['text'] = f'{suitname} ({loadout_name})' + def toggle_suit_row(self, visible: Optional[bool] = None) -> None: """ Toggle the visibility of the 'Suit' row. @@ -1035,6 +1048,8 @@ class AppWindow(object): self.ship_label['text'] = _('Ship') + ':' # Main window self.ship['text'] = '' + self.update_suit_text() + self.edit_menu.entryconfigure(0, state=monitor.system and tk.NORMAL or tk.DISABLED) # Copy if entry['event'] in ( diff --git a/monitor.py b/monitor.py index 7d2e14b3..cc27865d 100644 --- a/monitor.py +++ b/monitor.py @@ -827,6 +827,33 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below if self.state['BackPack'][c][m] < 0: self.state['BackPack'][c][m] = 0 + elif event_type == 'SwitchSuitLoadout': + loadoutid = entry['LoadoutID'] + # Observed LoadoutID in SwitchSuitLoadout events are, e.g. + # 4293000005 for CAPI slot 5. + # This *might* actually be "lower 6 bits", but maybe it's not. + new_slot = loadoutid - 4293000000 + try: + self.state['SuitLoadoutCurrent'] = self.state['SuitLoadouts'][f'{new_slot}'] + + except KeyError: + logger.exception(f"Getting suit loadout after switch, bad slot: {new_slot} ({loadoutid})") + # Might mean that a new suit loadout was created and we need a new CAPI fetch ? + + else: + try: + new_suitid = self.state['SuitLoadoutCurrent']['suit']['suitId'] + + except KeyError: + logger.exception(f"Getting switched-to suit ID from slot {new_slot} ({loadoutid})") + + else: + try: + self.state['SuitCurrent'] = self.state['Suits'][f'{new_suitid}'] + + except KeyError: + logger.exception(f"Getting switched-to suit from slot {new_slot} ({loadoutid}") + elif event_type == 'NavRoute': # Added in ED 3.7 - multi-hop route details in NavRoute.json with open(join(self.currentdir, 'NavRoute.json'), 'rb') as rf: # type: ignore