Compare commits

...

11 Commits

Author SHA1 Message Date
2a90980b03
Fix deprecated config.getint() method
config.getint() is deprecated since EDMC 5.0.0 (ref: https://github.com/EDCD/EDMarketConnector/releases/tag/Release%2F5.0.0), now plugins should use config.get_int() instead
2021-08-03 21:01:45 +05:00
Asrothear
2c4646a6bc
Update load.py 2021-07-11 21:47:57 +02:00
Asrothear
ad6fe7a82d
Update README.md 2021-07-11 21:45:27 +02:00
Asrothear
0c05e5efcd
Update README.md 2021-07-11 21:45:02 +02:00
Asrothear
d0082b3333
Update README.md 2021-07-11 21:44:05 +02:00
Asrothear
e951f2239e
Update load.py 2021-07-11 21:42:39 +02:00
Jonathan Harris
3c41cd41d5 Python 2/3 compatibility 2019-10-02 02:13:24 +01:00
Jonathan Harris
8f9d4cc6a4 Wrap EDSM fields 2017-11-16 00:16:39 +00:00
Jonathan Harris
12d89a6233 Release 1.20 2017-10-21 14:40:20 +01:00
Jonathan Harris
5edfc79558 Display Terraformable range
Fixes #1
2017-10-21 14:38:55 +01:00
Jonathan Harris
5e5a60f969 Fix error in log for unknown systems 2017-08-20 15:47:01 +01:00
2 changed files with 28 additions and 26 deletions

View File

@ -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.

52
load.py
View File

@ -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.11'
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
@ -172,9 +182,9 @@ def edsm_worker(systemName):
this.edsm_session = requests.Session()
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()
this.edsm_data = r.json()
this.edsm_data = r.json() or {} # Unknown system represented as empty list
except:
this.edsm_data = None
@ -191,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
@ -205,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:
@ -243,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: