1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-17 17:42:20 +03:00

Merge branch 'edsm_autoopen'

This commit is contained in:
Jonathan Harris 2016-01-05 17:59:05 +00:00
commit c964b310c1
5 changed files with 21 additions and 6 deletions

View File

@ -449,6 +449,8 @@ class AppWindow:
result = self.edsm.result
if result['done']:
self.system['image'] = result['img']
if result['uncharted'] and (config.getint('output') & config.EDSM_AUTOOPEN):
webbrowser.open(result['url'])
else:
self.w.after(int(EDSM_POLL * 1000), self.edsmpoll)

View File

@ -19,6 +19,9 @@
/* 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 page" = "Automatically open uncharted systems' EDSM page";
/* Cmdr stats. [stats.py] */
"Balance" = "Balance";

View File

@ -80,6 +80,7 @@ class Config:
OUT_SHIP_CORIOLIS = 128
OUT_LOG_EDSM = 256
OUT_LOG_AUTO = 512
EDSM_AUTOOPEN = 1024
if platform=='darwin':

14
edsm.py
View File

@ -28,15 +28,15 @@ class EDSM:
# Just set link without doing a lookup
def link(self, system_name):
self.cancel_lookup()
self.result = { 'img': '', 'url': 'http://www.edsm.net/show-system?systemName=%s' % urllib.quote(system_name), 'done': True }
self.result = { 'img': '', 'url': 'http://www.edsm.net/show-system?systemName=%s' % urllib.quote(system_name), 'done': True, 'uncharted': False }
def lookup(self, system_name, known=0):
self.cancel_lookup()
if known or system_name in self.syscache:
self.result = { 'img': EDSM._IMG_KNOWN, 'url': 'http://www.edsm.net/show-system?systemName=%s' % urllib.quote(system_name), 'done': True }
self.result = { 'img': EDSM._IMG_KNOWN, 'url': 'http://www.edsm.net/show-system?systemName=%s' % urllib.quote(system_name), 'done': True, 'uncharted': False }
else:
self.result = { 'img': EDSM._IMG_ERROR, 'url': 'http://www.edsm.net/show-system?systemName=%s' % urllib.quote(system_name), 'done': True }
self.result = { 'img': EDSM._IMG_ERROR, 'url': 'http://www.edsm.net/show-system?systemName=%s' % urllib.quote(system_name), 'done': True, 'uncharted': False }
r = requests.get('http://www.edsm.net/api-v1/system?sysname=%s&coords=1&fromSoftware=%s&fromSoftwareVersion=%s' % (urllib.quote(system_name), urllib.quote(applongname), urllib.quote(appversion)), timeout=EDSM._TIMEOUT)
r.raise_for_status()
data = r.json()
@ -44,20 +44,22 @@ class EDSM:
if data == -1:
# System not present - but don't create it on the assumption that the caller will
self.result['img'] = EDSM._IMG_NEW
self.result['uncharted'] = True
elif data.get('coords'):
self.result['img'] = EDSM._IMG_KNOWN
self.syscache.add(system_name)
else:
self.result['img'] = EDSM._IMG_UNKNOWN
self.result['uncharted'] = True
# Asynchronous version of the above
def start_lookup(self, system_name, known=0):
self.cancel_lookup()
if known or system_name in self.syscache: # Cache URLs of systems with known coordinates
self.result = { 'img': EDSM._IMG_KNOWN, 'url': 'http://www.edsm.net/show-system?systemName=%s' % urllib.quote(system_name), 'done': True }
self.result = { 'img': EDSM._IMG_KNOWN, 'url': 'http://www.edsm.net/show-system?systemName=%s' % urllib.quote(system_name), 'done': True, 'uncharted': False }
else:
self.result = { 'img': '', 'url': 'http://www.edsm.net/show-system?systemName=%s' % urllib.quote(system_name), 'done': False }
self.result = { 'img': '', 'url': 'http://www.edsm.net/show-system?systemName=%s' % urllib.quote(system_name), 'done': False, 'uncharted': False }
self.thread = threading.Thread(target = self.worker, name = 'EDSM worker', args = (system_name, self.result))
self.thread.daemon = True
self.thread.start()
@ -75,6 +77,7 @@ class EDSM:
if data == -1:
# System not present - create it
result['img'] = EDSM._IMG_NEW
result['uncharted'] = True
result['done'] = True # give feedback immediately
requests.get('http://www.edsm.net/api-v1/url?sysname=%s&fromSoftware=%s&fromSoftwareVersion=%s' % (urllib.quote(system_name), urllib.quote(applongname), urllib.quote(appversion)), timeout=EDSM._TIMEOUT) # creates system
elif data.get('coords'):
@ -83,6 +86,7 @@ class EDSM:
self.syscache.add(system_name)
else:
result['img'] = EDSM._IMG_UNKNOWN
result['uncharted'] = True
except:
if __debug__: print_exc()
result['img'] = EDSM._IMG_ERROR

View File

@ -156,6 +156,9 @@ 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.IntVar(value = (output & config.EDSM_AUTOOPEN) and 1)
self.edsm_autoopen_button = nb.Checkbutton(edsmframe, text=_("Automatically open uncharted systems' EDSM page"), variable=self.edsm_autoopen)
self.edsm_autoopen_button.grid(columnspan=2, padx=BUTTONX, sticky=tk.W)
if monitor.logdir:
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)
@ -245,6 +248,7 @@ 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
@ -361,7 +365,8 @@ class PreferencesDialog(tk.Toplevel):
(self.out_log_file.get() and config.OUT_LOG_FILE) +
(self.out_ship_coriolis.get() and config.OUT_SHIP_CORIOLIS) +
(self.out_log_edsm.get() and config.OUT_LOG_EDSM) +
(self.out_log_auto.get() and config.OUT_LOG_AUTO))
(self.out_log_auto.get() and config.OUT_LOG_AUTO) +
(self.edsm_autoopen.get() and config.EDSM_AUTOOPEN))
config.set('outdir', self.outdir.get().startswith('~') and join(config.home, self.outdir.get()[2:]) or self.outdir.get())
config.set('edsm_cmdrname', self.edsm_cmdr.get().strip())