mirror of
https://github.com/norohind/HabZone.git
synced 2025-04-20 16:37:38 +03:00
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
2a90980b03 | |||
|
2c4646a6bc | ||
|
ad6fe7a82d | ||
|
0c05e5efcd | ||
|
d0082b3333 | ||
|
e951f2239e | ||
|
3c41cd41d5 | ||
|
8f9d4cc6a4 | ||
|
12d89a6233 | ||
|
5edfc79558 | ||
|
5e5a60f969 | ||
|
8bced3b73a | ||
|
665cc9fb25 |
@ -24,4 +24,6 @@ Calculations taken from Jackie Silver's [Hab-Zone Calculator](https://forums.fro
|
||||
|
||||
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.
|
||||
|
60
load.py
60
load.py
@ -3,13 +3,21 @@
|
||||
# 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
|
||||
import requests
|
||||
import sys
|
||||
import threading
|
||||
import urllib2
|
||||
try:
|
||||
# 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
|
||||
import myNotebook as nb
|
||||
|
||||
@ -19,18 +27,19 @@ if __debug__:
|
||||
from config import config
|
||||
from l10n import Locale
|
||||
|
||||
VERSION = '1.10'
|
||||
VERSION = '1.20'
|
||||
|
||||
SETTING_DEFAULT = 0x0002 # Earth-like
|
||||
SETTING_EDSM = 0x1000
|
||||
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'),
|
||||
# Type Black-body temp range EDSM description
|
||||
('Metal Rich', 0, 1103.0, 'Metal rich body'),
|
||||
('Earth Like', 278.0, 227.0, 'Earthlike body'),
|
||||
('Water', 307.0, 156.0, 'Water world'),
|
||||
('Ammonia', 193.0, 117.0, 'Ammonia world'),
|
||||
('Terraformable', 315.0, 223.0, 'terraformable'),
|
||||
]
|
||||
|
||||
LS = 300000000.0 # 1 ls in m (approx)
|
||||
@ -46,6 +55,9 @@ this.settings = None
|
||||
this.edsm_setting = None
|
||||
|
||||
|
||||
def plugin_start3(plugin_dir):
|
||||
return plugin_start()
|
||||
|
||||
def plugin_start():
|
||||
# App isn't initialised at this point so can't do anything interesting
|
||||
return 'HabZone'
|
||||
@ -57,14 +69,12 @@ def plugin_app(parent):
|
||||
this.frame.bind('<<HabZoneData>>', edsm_data) # callback when EDSM data received
|
||||
for (name, high, low, subType) in WORLDS:
|
||||
this.worlds.append((tk.Label(this.frame, text = name + ':'),
|
||||
HyperlinkLabel(this.frame), # edsm
|
||||
HyperlinkLabel(this.frame, wraplength=100), # edsm
|
||||
tk.Label(this.frame), # near
|
||||
tk.Label(this.frame), # dash
|
||||
tk.Label(this.frame), # far
|
||||
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
|
||||
update_visibility()
|
||||
return this.frame
|
||||
@ -171,14 +181,12 @@ def edsm_worker(systemName):
|
||||
if not this.edsm_session:
|
||||
this.edsm_session = requests.Session()
|
||||
|
||||
r = this.edsm_session.get('https://www.edsm.net/api-system-v1/bodies?systemName=%s' % urllib2.quote(systemName), timeout=10)
|
||||
if r.status_code != requests.codes.ok:
|
||||
try:
|
||||
r = this.edsm_session.get('https://www.edsm.net/api-system-v1/bodies?systemName=%s' % quote(systemName), timeout=10)
|
||||
r.raise_for_status()
|
||||
this.edsm_data = r.json() or {} # Unknown system represented as empty list
|
||||
except:
|
||||
this.edsm_data = None
|
||||
else:
|
||||
try:
|
||||
this.edsm_data = r.json()
|
||||
except:
|
||||
this.edsm_data = None
|
||||
|
||||
# Tk is not thread-safe, so can't access widgets in this thread.
|
||||
# event_generate() is the only safe way to poke the main thread from this thread.
|
||||
@ -193,8 +201,6 @@ def edsm_data(event):
|
||||
for (label, edsm, near, dash, far, ls) in this.worlds:
|
||||
edsm['text'] = '?'
|
||||
edsm['url'] = None
|
||||
this.terraformable['text'] = '?'
|
||||
this.terraformable['url'] = None
|
||||
return
|
||||
|
||||
# Collate
|
||||
@ -207,18 +213,16 @@ def edsm_data(event):
|
||||
|
||||
# Display
|
||||
systemName = this.edsm_data.get('name', '')
|
||||
url = 'https://www.edsm.net/show-system?systemName=%s&bodyName=ALL' % urllib2.quote(systemName)
|
||||
url = 'https://www.edsm.net/show-system?systemName=%s&bodyName=ALL' % quote(systemName)
|
||||
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
|
||||
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
|
||||
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
|
||||
|
||||
|
||||
def get_setting():
|
||||
setting = config.getint('habzone')
|
||||
setting = config.get_int('habzone')
|
||||
if setting == 0:
|
||||
return SETTING_DEFAULT # Default to Earth-Like
|
||||
elif setting == SETTING_NONE:
|
||||
@ -245,12 +249,6 @@ def update_visibility():
|
||||
far.grid_remove()
|
||||
ls.grid_remove()
|
||||
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:
|
||||
this.spacer.grid_remove()
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user