mirror of
https://github.com/norohind/HabZone.git
synced 2025-04-21 00:47:36 +03:00
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
2a90980b03 | |||
|
2c4646a6bc | ||
|
ad6fe7a82d | ||
|
0c05e5efcd | ||
|
d0082b3333 | ||
|
e951f2239e | ||
|
3c41cd41d5 | ||
|
8f9d4cc6a4 | ||
|
12d89a6233 | ||
|
5edfc79558 | ||
|
5e5a60f969 |
@ -24,4 +24,6 @@ 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
52
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)
|
# 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
|
||||||
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
|
from ttkHyperlinkLabel import HyperlinkLabel
|
||||||
import myNotebook as nb
|
import myNotebook as nb
|
||||||
|
|
||||||
@ -19,18 +27,19 @@ if __debug__:
|
|||||||
from config import config
|
from config import config
|
||||||
from l10n import Locale
|
from l10n import Locale
|
||||||
|
|
||||||
VERSION = '1.11'
|
VERSION = '1.20'
|
||||||
|
|
||||||
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, 'Earth-like world'),
|
('Earth Like', 278.0, 227.0, 'Earthlike body'),
|
||||||
('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)
|
||||||
@ -46,6 +55,9 @@ 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'
|
||||||
@ -57,14 +69,12 @@ 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), # edsm
|
HyperlinkLabel(this.frame, wraplength=100), # 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
|
||||||
@ -172,9 +182,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' % urllib2.quote(systemName), timeout=10)
|
r = this.edsm_session.get('https://www.edsm.net/api-system-v1/bodies?systemName=%s' % quote(systemName), timeout=10)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
this.edsm_data = r.json()
|
this.edsm_data = r.json() or {} # Unknown system represented as empty list
|
||||||
except:
|
except:
|
||||||
this.edsm_data = None
|
this.edsm_data = None
|
||||||
|
|
||||||
@ -191,8 +201,6 @@ 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
|
||||||
@ -205,18 +213,16 @@ 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' % urllib2.quote(systemName)
|
url = 'https://www.edsm.net/show-system?systemName=%s&bodyName=ALL' % 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' % (urllib2.quote(systemName), urllib2.quote(bodies[subType][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
|
||||||
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.getint('habzone')
|
setting = config.get_int('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:
|
||||||
@ -243,12 +249,6 @@ 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:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user