From 86624d6dba258197e890e0d68975cbfb3ceb0fa4 Mon Sep 17 00:00:00 2001 From: Sileo35 <33731447+Sileo35@users.noreply.github.com> Date: Tue, 11 Sep 2018 01:09:11 +0200 Subject: [PATCH 1/4] Update load.py Add organic POI range in the list Add the possibility to change the star used for the range calculation in the system --- load.py | 191 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 135 insertions(+), 56 deletions(-) diff --git a/load.py b/load.py index a294a58..6852964 100644 --- a/load.py +++ b/load.py @@ -26,12 +26,13 @@ SETTING_NONE = 0xffff WORLDS = [ - # Type Black-body temp range EDSM description - ('Metal-Rich', 0, 1103.0, 'Metal-rich body'), - ('Earth-Like', 278.0, 227.0, 'Earth-like world'), - ('Water', 307.0, 156.0, 'Water world'), - ('Ammonia', 193.0, 117.0, 'Ammonia world'), - ('Terraformable', 315.0, 223.0, 'terraformable'), + # Type Black-body temp range EDSM description + ('Metal-Rich', 0, 1103.0, 'Metal-rich body'), + ('Earth-Like', 278.0, 227.0, 'Earth-like world'), + ('Water', 307.0, 156.0, 'Water world'), + ('Ammonia', 193.0, 117.0, 'Ammonia world'), + ('Terraformable', 315.0, 223.0, 'Terraformable'), + ('Organic', 500.0, 200.0, 'Organic POI'), ] LS = 300000000.0 # 1 ls in m (approx) @@ -46,6 +47,9 @@ this.settings = None this.edsm_setting = None +this.istar = 0 +this.stars = defaultdict(list) +this.bodies = defaultdict(list) def plugin_start(): # App isn't initialised at this point so can't do anything interesting @@ -56,6 +60,16 @@ def plugin_app(parent): this.frame = tk.Frame(parent) this.frame.columnconfigure(3, weight=1) this.frame.bind('<>', edsm_data) # callback when EDSM data received + this.starused_label = tk.Label(this.frame, text = 'Star used: [0]') + this.starused = HyperlinkLabel(this.frame) + this.starused_next = HyperlinkLabel(this.frame) + this.starused_next['text'] = '>' + this.starused_next['url'] = '>' + this.starused_next.bind("", next_star) + this.starused_prev = HyperlinkLabel(this.frame) + this.starused_prev['text'] = '<' + this.starused_prev['url'] = '<' + this.starused_prev.bind("", prev_star) for (name, high, low, subType) in WORLDS: this.worlds.append((tk.Label(this.frame, text = name + ':'), HyperlinkLabel(this.frame, wraplength=100), # edsm @@ -106,51 +120,69 @@ def prefs_changed(cmdr, is_beta): def journal_entry(cmdr, is_beta, system, station, entry, state): if entry['event'] == 'Scan': - try: - if not float(entry['DistanceFromArrivalLS']): # Only calculate for arrival star - r = float(entry['Radius']) - t = float(entry['SurfaceTemperature']) - for i in range(len(WORLDS)): - (name, high, low, subType) = WORLDS[i] - (label, edsm, near, dash, far, ls) = this.worlds[i] - far_dist = int(0.5 + dfort(r, t, low)) - radius = int(0.5 + r / LS) - if far_dist <= radius: - near['text'] = '' - dash['text'] = u'×' - far['text'] = '' - ls['text'] = '' - else: - if not high: - near['text'] = Locale.stringFromNumber(radius) - else: - near['text'] = Locale.stringFromNumber(int(0.5 + dfort(r, t, high))) - dash['text'] = '-' - far['text'] = Locale.stringFromNumber(far_dist) - ls['text'] = 'ls' - except: - for (label, edsm, near, dash, far, ls) in this.worlds: - near['text'] = '' - dash['text'] = '' - far['text'] = '' - ls['text'] = '?' - - elif entry['event'] == 'FSDJump': + if 'StarType' in entry: + r = float(entry['Radius']) + t = float(entry['SurfaceTemperature']) + if not entry['BodyName'] in this.stars['name']: + this.stars['name'].append(entry['BodyName']) + this.stars['surfaceTemperature'].append(t) + this.stars['solarRadius'].append(r) + this.starused_label['text'] = 'Star used: ['+str(this.istar+1)+'/'+str(len(this.stars['name']))+']' + updateValues(r,t,entry['BodyName']) + + if 'PlanetClass' in entry: + url = 'https://www.edsm.net/show-system?systemName=%s&bodyName=ALL' % urllib2.quote(this.systemName) + if entry['TerraformState'] == 'Terraformable': + if not entry['BodyName'] in this.bodies['Terraformable']: + this.bodies['Terraformable'].append(entry['BodyName']) + for i in range(len(WORLDS)): + (name, high, low, subType) = WORLDS[i] + (label, edsm, near, dash, far, ls) = this.worlds[i] + if entry['PlanetClass'][0:5] == subType[0:5]: + if not entry['BodyName'] in this.bodies[subType]: + this.bodies[subType].append(entry['BodyName']) + edsm['text'] = ' '.join([x[len(this.systemName):].replace(' ', '') if x.startswith(this.systemName) else x for x in this.bodies[subType]]) + edsm['url'] = len(this.bodies[subType]) == 1 and 'https://www.edsm.net/show-system?systemName=%s&bodyName=%s' % (urllib2.quote(this.systemName), urllib2.quote(this.bodies[subType][0])) or url + + if entry['event'] in ['Location', 'FSDJump', 'StartUp']: + this.istar = 0 + this.stars = defaultdict(list) + this.bodies = defaultdict(list) + this.starused_label['text'] = 'Star used: [0]' + this.starused['text'] = '' + this.starused['url'] = '' for (label, edsm, near, dash, far, ls) in this.worlds: - edsm['text'] = '' - edsm['url'] = '' - near['text'] = '' - dash['text'] = '' - far['text'] = '' - ls['text'] = '' - - if entry['event'] in ['Location', 'FSDJump'] and get_setting() & SETTING_EDSM: - thread = threading.Thread(target = edsm_worker, name = 'EDSM worker', args = (entry['StarSystem'],)) + edsm['text'] = ' ' + edsm['url'] = ' ' + near['text'] = ' ' + dash['text'] = ' ' + far['text'] = ' ' + ls['text'] = ' ' + this.systemName = entry['StarSystem'] + + if entry['event'] in ['Location', 'FSDJump', 'StartUp'] and get_setting() & SETTING_EDSM: + thread = threading.Thread(target = edsm_worker, name = 'EDSM worker', args = (this.systemName,)) thread.daemon = True thread.start() def cmdr_data(data, is_beta): + + this.istar = 0 + this.stars = defaultdict(list) + this.bodies = defaultdict(list) + this.starused_label['text'] = 'Star used: [0]' + this.starused['text'] = ' ' + this.starused['url'] = ' ' + + for (label, edsm, near, dash, far, ls) in this.worlds: + edsm['text'] = ' ' + edsm['url'] = ' ' + near['text'] = ' ' + dash['text'] = ' ' + far['text'] = ' ' + ls['text'] = ' ' + # Manual Update if get_setting() & SETTING_EDSM and not data['commander']['docked']: thread = threading.Thread(target = edsm_worker, name = 'EDSM worker', args = (data['lastSystem']['name'],)) @@ -163,6 +195,28 @@ def cmdr_data(data, is_beta): def dfort(r, t, target): return (((r ** 2) * (t ** 4) / (4 * (target ** 4))) ** 0.5) / LS +def updateValues(r,t,name): + this.starused['text'] = name + this.starused['url'] = 'https://www.edsm.net/show-system?systemName=%s&bodyName=%s' % (urllib2.quote(this.systemName), urllib2.quote(name)) + for i in range(len(WORLDS)): + (name, high, low, subType) = WORLDS[i] + (label, edsm, near, dash, far, ls) = this.worlds[i] + far_dist = int(0.5 + dfort(r, t, low)) + radius = int(0.5 + r / LS) + if far_dist <= radius: + near['text'] = '' + dash['text'] = u'×' + far['text'] = '' + ls['text'] = '' + else: + if not high: + near['text'] = Locale.stringFromNumber(radius) + else: + near['text'] = Locale.stringFromNumber(int(0.5 + dfort(r, t, high))) + dash['text'] = '-' + far['text'] = Locale.stringFromNumber(far_dist) + ls['text'] = 'ls' + return 0 # EDSM lookup def edsm_worker(systemName): @@ -184,7 +238,7 @@ def edsm_worker(systemName): # EDSM data received def edsm_data(event): - + if this.edsm_data is None: # error for (label, edsm, near, dash, far, ls) in this.worlds: @@ -193,12 +247,20 @@ def edsm_data(event): return # Collate - bodies = defaultdict(list) for body in this.edsm_data.get('bodies', []): + if body['type'] == 'Star': + this.stars['name'].append(body['name']) + this.stars['surfaceTemperature'].append(body['surfaceTemperature']) + this.stars['solarRadius'].append(body['solarRadius']*695500000) + + this.bodies[body['subType']].append(body['name']) if body.get('terraformingState') == 'Candidate for terraforming': - bodies['terraformable'].append(body['name']) - else: - bodies[body['subType']].append(body['name']) + this.bodies['Terraformable'].append(body['name']) + + + if len(this.stars['name']) > 0: + this.starused_label['text'] = 'Star used: ['+str(this.istar+1)+'/'+str(len(this.stars['name']))+']' + updateValues(this.stars['solarRadius'][this.istar],this.stars['surfaceTemperature'][this.istar],this.stars['name'][this.istar]) # Display systemName = this.edsm_data.get('name', '') @@ -206,9 +268,8 @@ def edsm_data(event): for i in range(len(WORLDS)): (name, high, low, subType) = WORLDS[i] (label, edsm, near, dash, far, ls) = this.worlds[i] - edsm['text'] = ' '.join([x[len(systemName):].replace(' ', '') if x.startswith(systemName) else x for x in bodies[subType]]) - edsm['url'] = len(bodies[subType]) == 1 and 'https://www.edsm.net/show-system?systemName=%s&bodyName=%s' % (urllib2.quote(systemName), urllib2.quote(bodies[subType][0])) or url - + edsm['text'] = ' '.join([x[len(systemName):].replace(' ', '') if x.startswith(systemName) else x for x in this.bodies[subType]]) + edsm['url'] = len(this.bodies[subType]) == 1 and 'https://www.edsm.net/show-system?systemName=%s&bodyName=%s' % (urllib2.quote(systemName), urllib2.quote(this.bodies[subType][0])) or url def get_setting(): setting = config.getint('habzone') @@ -222,14 +283,19 @@ def get_setting(): def update_visibility(): setting = get_setting() row = 1 + this.starused_label.grid(row = row, column = 0, sticky=tk.W) + this.starused.grid(row = row, column = 1, columnspan=3, sticky=tk.W) + this.starused_prev.grid(row = row, column = 4, sticky=tk.E) + this.starused_next.grid(row = row, column = 5, sticky=tk.E) + row += 1 for (label, edsm, near, dash, far, ls) in this.worlds: if setting & row: label.grid(row = row, column = 0, sticky=tk.W) - edsm.grid(row = row, column = 1, sticky=tk.W, padx = (0,10)) + edsm.grid(row = row, column = 1, sticky=tk.E) near.grid(row = row, column = 2, sticky=tk.E) dash.grid(row = row, column = 3, sticky=tk.E) far.grid(row = row, column = 4, sticky=tk.E) - ls.grid(row = row, column = 5, sticky=tk.W) + ls.grid(row = row, column = 5, sticky=tk.E) else: label.grid_remove() edsm.grid_remove() @@ -237,9 +303,22 @@ def update_visibility(): dash.grid_remove() far.grid_remove() ls.grid_remove() - row *= 2 + row += 1 if setting: this.spacer.grid_remove() else: this.spacer.grid(row = 0) +def next_star(event): + this.istar+=1 + if this.istar >= len(this.stars['name']): + this.istar=0 + this.starused_label['text'] = 'Star used: ['+str(this.istar+1)+'/'+str(len(this.stars['name']))+']' + updateValues(this.stars['solarRadius'][this.istar],this.stars['surfaceTemperature'][this.istar],this.stars['name'][this.istar]) + +def prev_star(event): + this.istar-=1 + if this.istar < 0: + this.istar=len(this.stars['name'])-1 + this.starused_label['text'] = 'Star used: ['+str(this.istar+1)+'/'+str(len(this.stars['name']))+']' + updateValues(this.stars['solarRadius'][this.istar],this.stars['surfaceTemperature'][this.istar],this.stars['name'][this.istar]) From 1e98c23779990b9999b3dd952cee4643303697e7 Mon Sep 17 00:00:00 2001 From: Sileo35 <33731447+Sileo35@users.noreply.github.com> Date: Tue, 11 Sep 2018 15:07:44 +0200 Subject: [PATCH 2/4] Update load.py Debug settings --- load.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/load.py b/load.py index 6852964..5a19979 100644 --- a/load.py +++ b/load.py @@ -287,15 +287,14 @@ def update_visibility(): this.starused.grid(row = row, column = 1, columnspan=3, sticky=tk.W) this.starused_prev.grid(row = row, column = 4, sticky=tk.E) this.starused_next.grid(row = row, column = 5, sticky=tk.E) - row += 1 for (label, edsm, near, dash, far, ls) in this.worlds: if setting & row: - label.grid(row = row, column = 0, sticky=tk.W) - edsm.grid(row = row, column = 1, sticky=tk.E) - near.grid(row = row, column = 2, sticky=tk.E) - dash.grid(row = row, column = 3, sticky=tk.E) - far.grid(row = row, column = 4, sticky=tk.E) - ls.grid(row = row, column = 5, sticky=tk.E) + label.grid(row = row+1, column = 0, sticky=tk.W) + edsm.grid(row = row+1, column = 1, sticky=tk.E) + near.grid(row = row+1, column = 2, sticky=tk.E) + dash.grid(row = row+1, column = 3, sticky=tk.E) + far.grid(row = row+1, column = 4, sticky=tk.E) + ls.grid(row = row+1, column = 5, sticky=tk.E) else: label.grid_remove() edsm.grid_remove() @@ -303,7 +302,7 @@ def update_visibility(): dash.grid_remove() far.grid_remove() ls.grid_remove() - row += 1 + row *= 2 if setting: this.spacer.grid_remove() else: From 1f7995a0c0ed2d86fbb9219c69c0acf5124838df Mon Sep 17 00:00:00 2001 From: Sileo35 <33731447+Sileo35@users.noreply.github.com> Date: Tue, 11 Sep 2018 15:10:53 +0200 Subject: [PATCH 3/4] Update load.py --- load.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/load.py b/load.py index 5a19979..e7428eb 100644 --- a/load.py +++ b/load.py @@ -152,12 +152,12 @@ def journal_entry(cmdr, is_beta, system, station, entry, state): this.starused['text'] = '' this.starused['url'] = '' for (label, edsm, near, dash, far, ls) in this.worlds: - edsm['text'] = ' ' - edsm['url'] = ' ' - near['text'] = ' ' - dash['text'] = ' ' - far['text'] = ' ' - ls['text'] = ' ' + edsm['text'] = '' + edsm['url'] = '' + near['text'] = '' + dash['text'] = '' + far['text'] = '' + ls['text'] = '' this.systemName = entry['StarSystem'] if entry['event'] in ['Location', 'FSDJump', 'StartUp'] and get_setting() & SETTING_EDSM: @@ -172,16 +172,16 @@ def cmdr_data(data, is_beta): this.stars = defaultdict(list) this.bodies = defaultdict(list) this.starused_label['text'] = 'Star used: [0]' - this.starused['text'] = ' ' - this.starused['url'] = ' ' + this.starused['text'] = '' + this.starused['url'] = '' for (label, edsm, near, dash, far, ls) in this.worlds: - edsm['text'] = ' ' - edsm['url'] = ' ' - near['text'] = ' ' - dash['text'] = ' ' - far['text'] = ' ' - ls['text'] = ' ' + edsm['text'] = '' + edsm['url'] = '' + near['text'] = '' + dash['text'] = '' + far['text'] = '' + ls['text'] = '' # Manual Update if get_setting() & SETTING_EDSM and not data['commander']['docked']: From 46aa1215a1864bf2c60e0b69c1597cd049f588be Mon Sep 17 00:00:00 2001 From: Sileo35 <33731447+Sileo35@users.noreply.github.com> Date: Tue, 11 Sep 2018 15:18:41 +0200 Subject: [PATCH 4/4] Update load.py --- load.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/load.py b/load.py index e7428eb..b147645 100644 --- a/load.py +++ b/load.py @@ -58,7 +58,7 @@ def plugin_start(): def plugin_app(parent): # Create and display widgets this.frame = tk.Frame(parent) - this.frame.columnconfigure(3, weight=1) + this.frame.columnconfigure(6, weight=1) this.frame.bind('<>', edsm_data) # callback when EDSM data received this.starused_label = tk.Label(this.frame, text = 'Star used: [0]') this.starused = HyperlinkLabel(this.frame)