From 3a3827f168d656e008663ce515d5ed1a8cc5a75d Mon Sep 17 00:00:00 2001 From: Jonathan Harris Date: Wed, 4 Apr 2018 13:45:49 +0100 Subject: [PATCH] Make system and station links unclickable if URL not available --- EDMarketConnector.py | 5 +++++ plugins/eddb.py | 23 +++++++++++++++-------- plugins/edsm.py | 6 ++++-- plugins/inara.py | 31 ++++++++++++++++++++++++++++++- prefs.py | 5 +++-- 5 files changed, 57 insertions(+), 13 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 76a7620f..307887de 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -330,6 +330,11 @@ class AppWindow: self.prefsdialog = None self.set_labels() # in case language has changed + # Reset links in case plugins changed them + self.ship.configure(url = self.shipyard_url) + self.system.configure(url = self.system_url) + self.station.configure(url = self.station_url) + # (Re-)install hotkey monitoring hotkeymgr.register(self.w, config.getint('hotkey_code'), config.getint('hotkey_mods')) diff --git a/plugins/eddb.py b/plugins/eddb.py index 4a654b69..3fed0563 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -55,15 +55,22 @@ def plugin_start(): return 'eddb' def plugin_app(parent): - this.station = parent.children['station'] # station label in main window - this.station.configure(popup_copy = lambda x: x != STATION_UNDOCKED) + this.system_link = parent.children['system'] # system label in main window + this.station_link = parent.children['station'] # station label in main window + this.station_link.configure(popup_copy = lambda x: x != STATION_UNDOCKED) + +def prefs_changed(cmdr, is_beta): + if config.get('system_provider') == 'eddb': + this.system_link['url'] = system_url(system_link['text']) # Override standard URL function def journal_entry(cmdr, is_beta, system, station, entry, state): - this.system = system - this.station['text'] = station or (system_populated(system) and STATION_UNDOCKED or '') - this.station.update_idletasks() + if config.get('system_provider') == 'eddb': + this.system_link['url'] = system_url(system) # Override standard URL function + this.station_link['text'] = station or (system_populated(system) and STATION_UNDOCKED or '') + this.station_link.update_idletasks() def cmdr_data(data, is_beta): - this.system = data['lastSystem']['name'] - this.station['text'] = data['commander']['docked'] and data['lastStarport']['name'] or (system_populated(data['lastSystem']['name']) and STATION_UNDOCKED or '') - this.station.update_idletasks() + if config.get('system_provider') == 'eddb': + this.system_link['url'] = system_url(data['lastSystem']['name']) # Override standard URL function + this.station_link['text'] = data['commander']['docked'] and data['lastStarport']['name'] or (system_populated(data['lastSystem']['name']) and STATION_UNDOCKED or '') + this.station_link.update_idletasks() diff --git a/plugins/edsm.py b/plugins/edsm.py index ec760dad..20236305 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -47,8 +47,10 @@ def system_url(system_name): return 'https://www.edsm.net/en/system?systemName=%s' % urllib2.quote(system_name) def station_url(system_name, station_name): - return 'https://www.edsm.net/en/system?systemName=%s&stationName=%s' % (urllib2.quote(system_name), urllib2.quote(station_name)) - + if station_name: + return 'https://www.edsm.net/en/system?systemName=%s&stationName=%s' % (urllib2.quote(system_name), urllib2.quote(station_name)) + else: + return system_url(system_name) def plugin_start(): # Can't be earlier since can only call PhotoImage after window is created diff --git a/plugins/inara.py b/plugins/inara.py index 3d97c486..b1c69be9 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -48,7 +48,9 @@ this.shipswap = False # just swapped ship # Main window clicks +this.system_link = None this.system = None +this.station_link = None this.station = None def system_url(system_name): @@ -64,6 +66,10 @@ def plugin_start(): this.thread.start() return 'Inara' +def plugin_app(parent): + this.system_link = parent.children['system'] # system label in main window + this.station_link = parent.children['station'] # station label in main window + def plugin_stop(): # Send any unsent events call() @@ -116,6 +122,12 @@ def prefs_changed(cmdr, is_beta): changed = config.getint('inara_out') != this.log.get() config.set('inara_out', this.log.get()) + # Override standard URL functions + if config.get('system_provider') == 'Inara': + this.system_link['url'] = this.system + if config.get('station_provider') == 'Inara': + this.station_link['url'] = this.station or this.system + if cmdr and not is_beta: this.cmdr = cmdr cmdrs = config.get('inara_cmdrs') or [] @@ -325,8 +337,15 @@ def journal_entry(cmdr, is_beta, system, station, entry, state): ])) + # Override standard URL functions + if config.get('system_provider') == 'Inara': + this.system_link['url'] = this.system + if config.get('station_provider') == 'Inara': + this.station_link['url'] = this.station or this.system + + + # Send event(s) to Inara if entry['event'] == 'ShutDown' or len(this.events) > old_events: - # We have new event(s) so send to Inara # Send cargo and materials if changed cargo = [ OrderedDict([('itemName', k), ('itemCount', state['Cargo'][k])]) for k in sorted(state['Cargo']) ] @@ -616,6 +635,12 @@ def cmdr_data(data, is_beta): this.cmdr = data['commander']['name'] + # Override standard URL functions + if config.get('system_provider') == 'Inara': + this.system_link['url'] = this.system + if config.get('station_provider') == 'Inara': + this.station_link['url'] = this.station or this.system + if config.getint('inara_out') and not is_beta and not this.multicrew and credentials(this.cmdr): if not (CREDIT_RATIO > this.lastcredits / data['commander']['credits'] > 1/CREDIT_RATIO): this.events = [x for x in this.events if x['eventName'] != 'setCommanderCredits'] # Remove any unsent @@ -731,7 +756,11 @@ def worker(): if data_event['eventName'] in ['addCommanderTravelDock', 'addCommanderTravelFSDJump', 'setCommanderTravelLocation']: eventData = reply_event.get('eventData', {}) this.system = eventData.get('starsystemInaraURL') + if config.get('system_provider') == 'Inara': + this.system_link['url'] = this.system # Override standard URL function this.station = eventData.get('stationInaraURL') + if config.get('station_provider') == 'Inara': + this.station_link['url'] = this.station or this.system # Override standard URL function break except: if __debug__: print_exc() diff --git a/prefs.py b/prefs.py index 391eccae..4ef506b0 100644 --- a/prefs.py +++ b/prefs.py @@ -600,11 +600,12 @@ class PreferencesDialog(tk.Toplevel): config.set('anonymous', self.out_anon.get()) + # Notify + if self.callback: + self.callback() plug.notify_prefs_changed(monitor.cmdr, monitor.is_beta) self._destroy() - if self.callback: - self.callback() def _destroy(self): if self.cmdrchanged_alarm is not None: