mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-15 14:52:15 +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:
parent
6cda9a067e
commit
a3d2ddf6b0
@ -449,6 +449,8 @@ class AppWindow:
|
|||||||
result = self.edsm.result
|
result = self.edsm.result
|
||||||
if result['done']:
|
if result['done']:
|
||||||
self.system['image'] = result['img']
|
self.system['image'] = result['img']
|
||||||
|
if result['uncharted'] and (config.getint('output') & config.EDSM_AUTOOPEN):
|
||||||
|
webbrowser.open(result['url'])
|
||||||
else:
|
else:
|
||||||
self.w.after(int(EDSM_POLL * 1000), self.edsmpoll)
|
self.w.after(int(EDSM_POLL * 1000), self.edsmpoll)
|
||||||
|
|
||||||
|
25
edsm.py
25
edsm.py
@ -3,7 +3,7 @@ import threading
|
|||||||
from sys import platform
|
from sys import platform
|
||||||
import time
|
import time
|
||||||
import urllib
|
import urllib
|
||||||
import webbrowser
|
|
||||||
import Tkinter as tk
|
import Tkinter as tk
|
||||||
|
|
||||||
from config import applongname, appversion, config
|
from config import applongname, appversion, config
|
||||||
@ -28,15 +28,15 @@ class EDSM:
|
|||||||
# Just set link without doing a lookup
|
# Just set link without doing a lookup
|
||||||
def link(self, system_name):
|
def link(self, system_name):
|
||||||
self.cancel_lookup()
|
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):
|
def lookup(self, system_name, known=0):
|
||||||
self.cancel_lookup()
|
self.cancel_lookup()
|
||||||
|
|
||||||
if known or system_name in self.syscache:
|
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:
|
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 = 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()
|
r.raise_for_status()
|
||||||
data = r.json()
|
data = r.json()
|
||||||
@ -44,24 +44,22 @@ class EDSM:
|
|||||||
if data == -1:
|
if data == -1:
|
||||||
# System not present - but don't create it on the assumption that the caller will
|
# System not present - but don't create it on the assumption that the caller will
|
||||||
self.result['img'] = EDSM._IMG_NEW
|
self.result['img'] = EDSM._IMG_NEW
|
||||||
if (config.EDSM_AUTOOPEN):
|
self.result['uncharted'] = True
|
||||||
webbrowser.open(self.result['url'])
|
|
||||||
elif data.get('coords'):
|
elif data.get('coords'):
|
||||||
self.result['img'] = EDSM._IMG_KNOWN
|
self.result['img'] = EDSM._IMG_KNOWN
|
||||||
self.syscache.add(system_name)
|
self.syscache.add(system_name)
|
||||||
else:
|
else:
|
||||||
self.result['img'] = EDSM._IMG_UNKNOWN
|
self.result['img'] = EDSM._IMG_UNKNOWN
|
||||||
if (config.EDSM_AUTOOPEN):
|
self.result['uncharted'] = True
|
||||||
webbrowser.open(self.result['url'])
|
|
||||||
|
|
||||||
# Asynchronous version of the above
|
# Asynchronous version of the above
|
||||||
def start_lookup(self, system_name, known=0):
|
def start_lookup(self, system_name, known=0):
|
||||||
self.cancel_lookup()
|
self.cancel_lookup()
|
||||||
|
|
||||||
if known or system_name in self.syscache: # Cache URLs of systems with known coordinates
|
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:
|
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 = threading.Thread(target = self.worker, name = 'EDSM worker', args = (system_name, self.result))
|
||||||
self.thread.daemon = True
|
self.thread.daemon = True
|
||||||
self.thread.start()
|
self.thread.start()
|
||||||
@ -79,22 +77,19 @@ class EDSM:
|
|||||||
if data == -1:
|
if data == -1:
|
||||||
# System not present - create it
|
# System not present - create it
|
||||||
result['img'] = EDSM._IMG_NEW
|
result['img'] = EDSM._IMG_NEW
|
||||||
|
result['uncharted'] = True
|
||||||
result['done'] = True # give feedback immediately
|
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
|
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'):
|
elif data.get('coords'):
|
||||||
result['img'] = EDSM._IMG_KNOWN
|
result['img'] = EDSM._IMG_KNOWN
|
||||||
result['done'] = True
|
result['done'] = True
|
||||||
self.syscache.add(system_name)
|
self.syscache.add(system_name)
|
||||||
else:
|
else:
|
||||||
result['img'] = EDSM._IMG_UNKNOWN
|
result['img'] = EDSM._IMG_UNKNOWN
|
||||||
if (config.EDSM_AUTOOPEN):
|
result['uncharted'] = True
|
||||||
webbrowser.open('http://www.edsm.net/show-system?systemName=%s' % urllib.quote(system_name))
|
|
||||||
except:
|
except:
|
||||||
if __debug__: print_exc()
|
if __debug__: print_exc()
|
||||||
result['img'] = EDSM._IMG_ERROR
|
result['img'] = EDSM._IMG_ERROR
|
||||||
|
|
||||||
result['done'] = True
|
result['done'] = True
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user