Compare commits

...

8 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
2 changed files with 22 additions and 9 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.

29
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
@ -27,8 +35,8 @@ 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'),
('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'),
@ -47,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'
@ -58,7 +69,7 @@ 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
@ -171,7 +182,7 @@ 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() or {} # Unknown system represented as empty list
except:
@ -202,16 +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
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: