1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-15 16:50:34 +03:00

Open system page after flight log has been sent.

Avoids potential race condition of opening the system page for a new
system before EDSM has created it.
This commit is contained in:
Jonathan Harris 2016-01-05 02:26:15 +00:00
parent 6cda9a067e
commit a3d2ddf6b0
2 changed files with 12 additions and 15 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)

25
edsm.py
View File

@ -3,7 +3,7 @@ import threading
from sys import platform
import time
import urllib
import webbrowser
import Tkinter as tk
from config import applongname, appversion, config
@ -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,24 +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
if (config.EDSM_AUTOOPEN):
webbrowser.open(self.result['url'])
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
if (config.EDSM_AUTOOPEN):
webbrowser.open(self.result['url'])
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()
@ -79,22 +77,19 @@ 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
if (config.EDSM_AUTOOPEN):
webbrowser.open('http://www.edsm.net/show-system?systemName=%s' % urllib.quote(system_name))
elif data.get('coords'):
result['img'] = EDSM._IMG_KNOWN
result['done'] = True
self.syscache.add(system_name)
else:
result['img'] = EDSM._IMG_UNKNOWN
if (config.EDSM_AUTOOPEN):
webbrowser.open('http://www.edsm.net/show-system?systemName=%s' % urllib.quote(system_name))
result['uncharted'] = True
except:
if __debug__: print_exc()
result['img'] = EDSM._IMG_ERROR
result['done'] = True