Compare commits

..

No commits in common. "master" and "rel-111" have entirely different histories.

2 changed files with 26 additions and 28 deletions

View File

@ -24,6 +24,4 @@ Calculations taken from Jackie Silver's [Hab-Zone Calculator](https://forums.fro
Copyright © 2017 Jonathan Harris. Copyright © 2017 Jonathan Harris.
Continued by [asrothear](https://github.com/asrothear) Copyright for all Changes © 2021
Licensed under the [GNU Public License (GPL)](http://www.gnu.org/licenses/gpl-2.0.html) version 2 or later. Licensed under the [GNU Public License (GPL)](http://www.gnu.org/licenses/gpl-2.0.html) version 2 or later.

52
load.py
View File

@ -3,21 +3,13 @@
# Display the "habitable-zone" (i.e. the range of distances in which you might find an Earth-Like World) # Display the "habitable-zone" (i.e. the range of distances in which you might find an Earth-Like World)
# #
from __future__ import print_function
from collections import defaultdict from collections import defaultdict
import requests import requests
import sys import sys
import threading import threading
try: import urllib2
# Python 2
from urllib2 import quote
import Tkinter as tk
except ModuleNotFoundError:
# Python 3
from urllib.parse import quote
import tkinter as tk
import Tkinter as tk
from ttkHyperlinkLabel import HyperlinkLabel from ttkHyperlinkLabel import HyperlinkLabel
import myNotebook as nb import myNotebook as nb
@ -27,19 +19,18 @@ if __debug__:
from config import config from config import config
from l10n import Locale from l10n import Locale
VERSION = '1.20' VERSION = '1.11'
SETTING_DEFAULT = 0x0002 # Earth-like SETTING_DEFAULT = 0x0002 # Earth-like
SETTING_EDSM = 0x1000 SETTING_EDSM = 0x1000
SETTING_NONE = 0xffff SETTING_NONE = 0xffff
WORLDS = [ WORLDS = [
# Type Black-body temp range EDSM description # Type Black-body temp range EDSM description
('Metal Rich', 0, 1103.0, 'Metal rich body'), ('Metal-Rich', 0, 1103.0, 'Metal-rich body'),
('Earth Like', 278.0, 227.0, 'Earthlike body'), ('Earth-Like', 278.0, 227.0, 'Earth-like world'),
('Water', 307.0, 156.0, 'Water world'), ('Water', 307.0, 156.0, 'Water world'),
('Ammonia', 193.0, 117.0, 'Ammonia world'), ('Ammonia', 193.0, 117.0, 'Ammonia world'),
('Terraformable', 315.0, 223.0, 'terraformable'),
] ]
LS = 300000000.0 # 1 ls in m (approx) LS = 300000000.0 # 1 ls in m (approx)
@ -55,9 +46,6 @@ this.settings = None
this.edsm_setting = None this.edsm_setting = None
def plugin_start3(plugin_dir):
return plugin_start()
def plugin_start(): def plugin_start():
# App isn't initialised at this point so can't do anything interesting # App isn't initialised at this point so can't do anything interesting
return 'HabZone' return 'HabZone'
@ -69,12 +57,14 @@ def plugin_app(parent):
this.frame.bind('<<HabZoneData>>', edsm_data) # callback when EDSM data received this.frame.bind('<<HabZoneData>>', edsm_data) # callback when EDSM data received
for (name, high, low, subType) in WORLDS: for (name, high, low, subType) in WORLDS:
this.worlds.append((tk.Label(this.frame, text = name + ':'), this.worlds.append((tk.Label(this.frame, text = name + ':'),
HyperlinkLabel(this.frame, wraplength=100), # edsm HyperlinkLabel(this.frame), # edsm
tk.Label(this.frame), # near tk.Label(this.frame), # near
tk.Label(this.frame), # dash tk.Label(this.frame), # dash
tk.Label(this.frame), # far tk.Label(this.frame), # far
tk.Label(this.frame), # ls tk.Label(this.frame), # ls
)) ))
this.terraformable_label = tk.Label(this.frame, text = 'Terraformable:')
this.terraformable = HyperlinkLabel(this.frame)
this.spacer = tk.Frame(this.frame) # Main frame can't be empty or it doesn't resize this.spacer = tk.Frame(this.frame) # Main frame can't be empty or it doesn't resize
update_visibility() update_visibility()
return this.frame return this.frame
@ -182,9 +172,9 @@ def edsm_worker(systemName):
this.edsm_session = requests.Session() this.edsm_session = requests.Session()
try: try:
r = this.edsm_session.get('https://www.edsm.net/api-system-v1/bodies?systemName=%s' % quote(systemName), timeout=10) r = this.edsm_session.get('https://www.edsm.net/api-system-v1/bodies?systemName=%s' % urllib2.quote(systemName), timeout=10)
r.raise_for_status() r.raise_for_status()
this.edsm_data = r.json() or {} # Unknown system represented as empty list this.edsm_data = r.json()
except: except:
this.edsm_data = None this.edsm_data = None
@ -201,6 +191,8 @@ def edsm_data(event):
for (label, edsm, near, dash, far, ls) in this.worlds: for (label, edsm, near, dash, far, ls) in this.worlds:
edsm['text'] = '?' edsm['text'] = '?'
edsm['url'] = None edsm['url'] = None
this.terraformable['text'] = '?'
this.terraformable['url'] = None
return return
# Collate # Collate
@ -213,16 +205,18 @@ def edsm_data(event):
# Display # Display
systemName = this.edsm_data.get('name', '') systemName = this.edsm_data.get('name', '')
url = 'https://www.edsm.net/show-system?systemName=%s&bodyName=ALL' % quote(systemName) url = 'https://www.edsm.net/show-system?systemName=%s&bodyName=ALL' % urllib2.quote(systemName)
for i in range(len(WORLDS)): for i in range(len(WORLDS)):
(name, high, low, subType) = WORLDS[i] (name, high, low, subType) = WORLDS[i]
(label, edsm, near, dash, far, ls) = this.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['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' % (quote(systemName), quote(bodies[subType][0])) or url 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
this.terraformable['text'] = ' '.join([x[len(systemName):].replace(' ', '') if x.startswith(systemName) else x for x in bodies['terraformable']])
this.terraformable['url'] = len(bodies['terraformable']) == 1 and 'https://www.edsm.net/show-system?systemName=%s&bodyName=%s' % (urllib2.quote(systemName), urllib2.quote(bodies['terraformable'][0])) or url
def get_setting(): def get_setting():
setting = config.get_int('habzone') setting = config.getint('habzone')
if setting == 0: if setting == 0:
return SETTING_DEFAULT # Default to Earth-Like return SETTING_DEFAULT # Default to Earth-Like
elif setting == SETTING_NONE: elif setting == SETTING_NONE:
@ -249,6 +243,12 @@ def update_visibility():
far.grid_remove() far.grid_remove()
ls.grid_remove() ls.grid_remove()
row *= 2 row *= 2
if setting & SETTING_EDSM:
this.terraformable_label.grid(row = row, column = 0, sticky=tk.W)
this.terraformable.grid(row = row, column = 1, sticky=tk.W)
else:
this.terraformable_label.grid_remove()
this.terraformable.grid_remove()
if setting: if setting:
this.spacer.grid_remove() this.spacer.grid_remove()
else: else: