diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 3ac19880..13c7b201 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -9,7 +9,6 @@ from os.path import expanduser, isdir, join import re import requests from time import time, localtime, strftime -import webbrowser import Tkinter as tk import ttk @@ -512,7 +511,7 @@ class AppWindow: except: pass - def system_change(self, timestamp, system): + def system_change(self, timestamp, system, coordinates): if self.system['text'] != system: self.system['text'] = system @@ -520,7 +519,7 @@ class AppWindow: self.system['image'] = '' self.station['text'] = EDDB.system(system) and self.STATION_UNDOCKED or '' - plug.notify_system_changed(timestamp, system) + plug.notify_system_changed(timestamp, system, coordinates) if config.getint('output') & config.OUT_LOG_FILE: flightlog.writelog(timestamp, system) @@ -528,7 +527,7 @@ class AppWindow: try: self.status['text'] = _('Sending data to EDSM...') self.w.update_idletasks() - edsm.writelog(timestamp, system, lambda:self.edsm.lookup(system, EDDB.system(system))) # Do EDSM lookup during EDSM export + edsm.writelog(timestamp, system, lambda:self.edsm.lookup(system, EDDB.system(system)), coordinates) # Do EDSM lookup during EDSM export self.status['text'] = strftime(_('Last updated at {HH}:{MM}:{SS}').format(HH='%H', MM='%M', SS='%S').encode('utf-8'), localtime(timestamp)).decode('utf-8') except Exception as e: if __debug__: print_exc() @@ -544,8 +543,6 @@ class AppWindow: result = self.edsm.result if result['done']: self.system['image'] = result['img'] - if result['uncharted'] and config.getint('edsm_autoopen'): - webbrowser.open(result['url']) else: self.w.after(int(EDSM_POLL * 1000), self.edsmpoll) diff --git a/L10n/cs.strings b/L10n/cs.strings index 28734e75..5fd2ad3d 100755 --- a/L10n/cs.strings +++ b/L10n/cs.strings @@ -31,9 +31,6 @@ /* Output setting. [prefs.py] */ "Automatically make a log entry on entering a system" = "Automaticky vytvořit záznam při vstoupení do systému"; -/* [prefs.py] */ -"Automatically open uncharted systems’ EDSM pages" = "Automaticky otevřít EDSM stránku nezmapovaných systémů"; - /* Cmdr stats. [stats.py] */ "Balance" = "Zůstatek"; diff --git a/L10n/de.strings b/L10n/de.strings index be842450..186d6a5c 100755 --- a/L10n/de.strings +++ b/L10n/de.strings @@ -31,9 +31,6 @@ /* Output setting. [prefs.py] */ "Automatically make a log entry on entering a system" = "Automatisch Logbucheintrag bei Systemeintritt anlegen"; -/* [prefs.py] */ -"Automatically open uncharted systems’ EDSM pages" = "Automatisch die EDSM Seite unerforschter Systeme öffnen"; - /* Cmdr stats. [stats.py] */ "Balance" = "Kontostand"; diff --git a/L10n/en.template b/L10n/en.template index 799c652d..3b0ec60c 100644 --- a/L10n/en.template +++ b/L10n/en.template @@ -28,9 +28,6 @@ /* Output setting. [prefs.py] */ "Automatically make a log entry on entering a system" = "Automatically make a log entry on entering a system"; -/* [prefs.py] */ -"Automatically open uncharted systems’ EDSM pages" = "Automatically open uncharted systems’ EDSM pages"; - /* Cmdr stats. [stats.py] */ "Balance" = "Balance"; diff --git a/L10n/es.strings b/L10n/es.strings index 675b80e2..42ca1196 100755 --- a/L10n/es.strings +++ b/L10n/es.strings @@ -31,9 +31,6 @@ /* Output setting. [prefs.py] */ "Automatically make a log entry on entering a system" = "Crear automáticamente una entrada en el registro al entrar en un sistema"; -/* [prefs.py] */ -"Automatically open uncharted systems’ EDSM pages" = "Abrir automáticamente sistemas no cartografiados en EDSM"; - /* Cmdr stats. [stats.py] */ "Balance" = "Saldo"; diff --git a/L10n/fr.strings b/L10n/fr.strings index e448dedf..d08b7ad2 100755 --- a/L10n/fr.strings +++ b/L10n/fr.strings @@ -31,9 +31,6 @@ /* Output setting. [prefs.py] */ "Automatically make a log entry on entering a system" = "Ajouter automatiquement une entrée au journal en entrant dans un système"; -/* [prefs.py] */ -"Automatically open uncharted systems’ EDSM pages" = "Ouvrir automatiquement les pages EDSM des systèmes inexplorés"; - /* Cmdr stats. [stats.py] */ "Balance" = "Solde"; diff --git a/L10n/it.strings b/L10n/it.strings index 25ff20a0..9703b29a 100755 --- a/L10n/it.strings +++ b/L10n/it.strings @@ -31,9 +31,6 @@ /* Output setting. [prefs.py] */ "Automatically make a log entry on entering a system" = "Inserisce automaticamente una log entry entrando in un sistema"; -/* [prefs.py] */ -"Automatically open uncharted systems’ EDSM pages" = "Apre automaticamente una pagina su EDSM dei sistemi non esplorati"; - /* Cmdr stats. [stats.py] */ "Balance" = "Saldo"; diff --git a/L10n/ja.strings b/L10n/ja.strings index d6846d25..5ef8a347 100644 --- a/L10n/ja.strings +++ b/L10n/ja.strings @@ -31,9 +31,6 @@ /* Output setting. [prefs.py] */ "Automatically make a log entry on entering a system" = "別の星系に移動したら自動的にフライトログを記録する"; -/* [prefs.py] */ -"Automatically open uncharted systems’ EDSM pages" = "EDSMに座標が登録されていない星系のページを自動的に開く"; - /* Cmdr stats. [stats.py] */ "Balance" = "Balance"; diff --git a/L10n/lv.strings b/L10n/lv.strings index 6f8b9832..03af8896 100755 --- a/L10n/lv.strings +++ b/L10n/lv.strings @@ -31,9 +31,6 @@ /* Output setting. [prefs.py] */ "Automatically make a log entry on entering a system" = "Automātiski veikt ierakstu ierodoties sistēmā"; -/* [prefs.py] */ -"Automatically open uncharted systems’ EDSM pages" = "Automātiski atvērt neatklāto sistēmu EDSM lapas"; - /* Cmdr stats. [stats.py] */ "Balance" = "Bilance"; diff --git a/L10n/nl.strings b/L10n/nl.strings index 2cbf67ff..717ad85e 100755 --- a/L10n/nl.strings +++ b/L10n/nl.strings @@ -31,9 +31,6 @@ /* Output setting. [prefs.py] */ "Automatically make a log entry on entering a system" = "Automatisch een log regel aanmaken bij het binnengaan van een stelsel"; -/* [prefs.py] */ -"Automatically open uncharted systems’ EDSM pages" = "Automatisch openen van nog niet in kaart gebrachte systemen op EDSM website"; - /* Cmdr stats. [stats.py] */ "Balance" = "Balans"; diff --git a/L10n/pl.strings b/L10n/pl.strings index 6896afd5..429dd5cc 100755 --- a/L10n/pl.strings +++ b/L10n/pl.strings @@ -31,9 +31,6 @@ /* Output setting. [prefs.py] */ "Automatically make a log entry on entering a system" = "Stwórz automatycznie wpis w logu po wejściu do systemu"; -/* [prefs.py] */ -"Automatically open uncharted systems’ EDSM pages" = "Automatycznie otwieraj nie skatalogowane systemy w EDSM"; - /* Cmdr stats. [stats.py] */ "Balance" = "Saldo"; diff --git a/L10n/ru.strings b/L10n/ru.strings index d885319c..8d10db1d 100755 --- a/L10n/ru.strings +++ b/L10n/ru.strings @@ -31,9 +31,6 @@ /* Output setting. [prefs.py] */ "Automatically make a log entry on entering a system" = "Автоматически заносить в журнал полета каждую посещённую систему"; -/* [prefs.py] */ -"Automatically open uncharted systems’ EDSM pages" = "Автоматически открывать EDSM для неисследованных систем"; - /* Cmdr stats. [stats.py] */ "Balance" = "Баланс"; diff --git a/L10n/sl.strings b/L10n/sl.strings index 6003451c..66f3e7fb 100755 --- a/L10n/sl.strings +++ b/L10n/sl.strings @@ -31,9 +31,6 @@ /* Output setting. [prefs.py] */ "Automatically make a log entry on entering a system" = "Shrani podatke v dnevnik leta, ko prispeš v sistem"; -/* [prefs.py] */ -"Automatically open uncharted systems’ EDSM pages" = "Automatically open uncharted systems’ EDSM pages"; - /* Cmdr stats. [stats.py] */ "Balance" = "Ravnotežje"; diff --git a/L10n/uk.strings b/L10n/uk.strings index cebcc929..0a6bc465 100755 --- a/L10n/uk.strings +++ b/L10n/uk.strings @@ -31,9 +31,6 @@ /* Output setting. [prefs.py] */ "Automatically make a log entry on entering a system" = "Автоматично робити запис у журналі на вході в систему"; -/* [prefs.py] */ -"Automatically open uncharted systems’ EDSM pages" = "Автоматично відкривати сторінки EDSM, для незвіданих систем"; - /* Cmdr stats. [stats.py] */ "Balance" = "Баланс"; diff --git a/PLUGINS.md b/PLUGINS.md index 52f58935..fe59cf4b 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -73,7 +73,7 @@ Your events all get called on the main tkinter loop so be sure not to block for This gets called when EDMC uses the netlog to notice that you have arrived at a new star system. ``` -def system_changed(timestamp, system): +def system_changed(timestamp, system, coordinates): """ We arrived at a new system! """ diff --git a/edsm.py b/edsm.py index 7176274b..e96bf5b6 100644 --- a/edsm.py +++ b/edsm.py @@ -109,7 +109,7 @@ def export(data, edsmlookupfn): writelog(querytime, data['lastSystem']['name'], edsmlookupfn) -def writelog(timestamp, system, edsmlookupfn): +def writelog(timestamp, system, edsmlookupfn, coordinates=None): try: # Look up the system before adding it to the log, since adding it to the log has the side-effect of creating it @@ -118,7 +118,17 @@ def writelog(timestamp, system, edsmlookupfn): if system in EDSM.FAKE: return - r = requests.get('http://www.edsm.net/api-logs-v1/set-log?commanderName=%s&apiKey=%s&systemName=%s&dateVisited=%s&fromSoftware=%s&fromSoftwareVersion=%s' % (urllib.quote(config.get('edsm_cmdrname').encode('utf-8')), urllib.quote(config.get('edsm_apikey')), urllib.quote(system), urllib.quote(time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(timestamp))), urllib.quote(applongname), urllib.quote(appversion)), timeout=EDSM._TIMEOUT) + url = 'http://www.edsm.net/api-logs-v1/set-log?commanderName=%s&apiKey=%s&systemName=%s&dateVisited=%s&fromSoftware=%s&fromSoftwareVersion=%s' % ( + urllib.quote(config.get('edsm_cmdrname').encode('utf-8')), + urllib.quote(config.get('edsm_apikey')), + urllib.quote(system), + urllib.quote(time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(timestamp))), + urllib.quote(applongname), + urllib.quote(appversion) + ) + if coordinates: + url += '&x=%.3f&y=%.3f&z=%.3f' % coordinates + r = requests.get(url, timeout=EDSM._TIMEOUT) r.raise_for_status() reply = r.json() (msgnum, msg) = reply['msgnum'], reply['msg'] diff --git a/monitor.py b/monitor.py index 5a226eed..789e575a 100644 --- a/monitor.py +++ b/monitor.py @@ -193,9 +193,14 @@ class EDLogs(FileSystemEventHandler): self.logfile = event.src_path def worker(self): - # e.g. "{18:11:44} System:22(Gamma Doradus) Body:3 Pos:(3.69928e+07,1.13173e+09,-1.75892e+08) \r\n" or "... NormalFlight\r\n" or "... Supercruise\r\n" + # e.g.: + # "{18:00:41} System:"Shinrarta Dezhra" StarPos:(55.719,17.594,27.156)ly NormalFlight\r\n" + # or with verboseLogging: + # "{17:20:18} System:"Shinrarta Dezhra" StarPos:(55.719,17.594,27.156)ly Body:69 RelPos:(0.334918,1.20754,1.23625)km NormalFlight\r\n" + # or: + # "... Supercruise\r\n" # Note that system name may contain parantheses, e.g. "Pipe (stem) Sector PI-T c3-5". - regexp = re.compile(r'\{(.+)\} System:\d+\((.+)\) Body:(\d+) .* (\S*)') # (localtime, system, body, context) + regexp = re.compile(r'\{(.+)\} System:"(.+)" StarPos:\((.+),(.+),(.+)\)ly.* (\S+)') # (localtime, system, x, y, z, context) # Seek to the end of the latest log file logfile = self.logfile @@ -215,13 +220,16 @@ class EDLogs(FileSystemEventHandler): loghandle = open(logfile, 'rt') if logfile: - system = visited = None + system = visited = coordinates = None loghandle.seek(0, 1) # reset EOF flag for line in loghandle: match = regexp.match(line) if match: - system, visited = match.group(4) == 'ProvingGround' and 'CQC' or match.group(2), match.group(1) + (visited, system, x, y, z, context) = match.groups() + if system == 'ProvingGround': + system = 'CQC' + coordinates = (float(x), float(y), float(z)) if system: self._restart_required = False # clearly logging is working @@ -233,7 +241,7 @@ class EDLogs(FileSystemEventHandler): now = localtime(time()-12*60*60) # yesterday time_struct = datetime(now.tm_year, now.tm_mon, now.tm_mday, visited_struct.tm_hour, visited_struct.tm_min, visited_struct.tm_sec).timetuple() # still local time # Tk on Windows doesn't like to be called outside of an event handler, so generate an event - self.last_event = (mktime(time_struct), system) + self.last_event = (mktime(time_struct), system, coordinates) self.root.event_generate('<>', when="tail") sleep(10) # New system gets posted to log file before hyperspace ends, so don't need to poll too often diff --git a/plug.py b/plug.py index eeb71d19..6920b90f 100644 --- a/plug.py +++ b/plug.py @@ -87,7 +87,7 @@ def get_plugin_pref(plugname, parent): return None -def notify_system_changed(timestamp, system): +def notify_system_changed(timestamp, system, coordinates): """ Send notification data to each plugin when we arrive at a new system. :param timestamp: @@ -98,7 +98,10 @@ def notify_system_changed(timestamp, system): system_changed = _get_plugin_func(plugname, "system_changed") if system_changed: try: - system_changed(timestamp, system) + if system_changed.func_code.co_argcount == 2: + system_changed(timestamp, system) + else: + system_changed(timestamp, system, coordinates) except Exception as plugerr: print plugerr diff --git a/plugins/About/load.py b/plugins/About/load.py index 7e51eccc..5441f83f 100644 --- a/plugins/About/load.py +++ b/plugins/About/load.py @@ -45,14 +45,18 @@ def plugin_app(parent): return plugin_app.status -def system_changed(timestamp, system): +def system_changed(timestamp, system, coordinates): """ Arrived in a new System :param timestamp: when we arrived :param system: the name of the system + :param coordinates: tuple of (x,y,z) ly relative to Sol, or None if unknown :return: """ - sys.stderr.write("Arrived at {}\n".format(system)) + if coordinates: + sys.stderr.write("Arrived at {} ({},{},{})\n".format(system, *coordinates)) + else: + sys.stderr.write("Arrived at {}\n".format(system)) def cmdr_data(data): diff --git a/prefs.py b/prefs.py index a3a5dbe7..a9669d1f 100644 --- a/prefs.py +++ b/prefs.py @@ -159,9 +159,6 @@ class PreferencesDialog(tk.Toplevel): ttk.Separator(edsmframe, orient=tk.HORIZONTAL).grid(columnspan=2, padx=PADX, pady=PADY, sticky=tk.EW) self.out_log_edsm = tk.IntVar(value = (output & config.OUT_LOG_EDSM) and 1) nb.Checkbutton(edsmframe, text=_('Send flight log to Elite Dangerous Star Map'), variable=self.out_log_edsm, command=self.outvarchanged).grid(columnspan=2, padx=BUTTONX, sticky=tk.W) - self.edsm_autoopen = tk.BooleanVar(value = config.getint('edsm_autoopen')) - self.edsm_autoopen_button = nb.Checkbutton(edsmframe, text=_(u"Automatically open uncharted systems’ EDSM pages"), variable=self.edsm_autoopen) - self.edsm_autoopen_button.grid(columnspan=2, padx=BUTTONX, sticky=tk.W) self.edsm_log_auto_button = nb.Checkbutton(edsmframe, text=_('Automatically make a log entry on entering a system'), variable=self.out_log_auto, command=self.outvarchanged) # Output setting self.edsm_log_auto_button.grid(columnspan=2, padx=BUTTONX, sticky=tk.W) self.edsm_log_auto_text = nb.Label(edsmframe, foreground='firebrick') @@ -294,7 +291,6 @@ class PreferencesDialog(tk.Toplevel): self.outdir['state'] = local and 'readonly' or tk.DISABLED edsm_state = self.out_log_edsm.get() and tk.NORMAL or tk.DISABLED - self.edsm_autoopen_button['state'] = edsm_state self.edsm_label['state'] = edsm_state self.edsm_cmdr_label['state'] = edsm_state self.edsm_apikey_label['state'] = edsm_state @@ -441,7 +437,6 @@ class PreferencesDialog(tk.Toplevel): (self.out_log_auto.get() and config.OUT_LOG_AUTO)) config.set('outdir', self.outdir.get().startswith('~') and join(config.home, self.outdir.get()[2:]) or self.outdir.get()) - config.set('edsm_autoopen', self.edsm_autoopen.get()) config.set('edsm_cmdrname', self.edsm_cmdr.get().strip()) config.set('edsm_apikey', self.edsm_apikey.get().strip())