From ab58aa6355fafe75e188864ef0af51f09843d992 Mon Sep 17 00:00:00 2001 From: A_D Date: Sun, 26 Jul 2020 19:41:51 +0200 Subject: [PATCH 1/8] autoformatted file --- plugins/eddb.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/plugins/eddb.py b/plugins/eddb.py index 17e72bf4..09f84710 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -29,9 +29,9 @@ import requests from config import config -STATION_UNDOCKED: str = u'×' # "Station" name to display when not docked = U+00D7 +STATION_UNDOCKED: str = u'×' # "Station" name to display when not docked = U+00D7 -this = sys.modules[__name__] # For holding module globals +this = sys.modules[__name__] # For holding module globals # Main window clicks this.system_link = None @@ -51,23 +51,27 @@ def system_url(system_name: str) -> str: else: return '' + def station_url(system_name: str, station_name: str) -> str: if this.station_marketid: return requests.utils.requote_uri(f'https://eddb.io/station/market-id/{this.station_marketid}') else: return system_url('') + def plugin_start3(plugin_dir): return 'eddb' + def plugin_app(parent): - this.system_link = parent.children['system'] # system label in main window + this.system_link = parent.children['system'] # system label in main window this.system = None this.system_address = None this.station = None this.station_marketid = None # Frontier MarketID this.station_link = parent.children['station'] # station label in main window - this.station_link.configure(popup_copy = lambda x: x != STATION_UNDOCKED) + this.station_link.configure(popup_copy=lambda x: x != STATION_UNDOCKED) + def prefs_changed(cmdr, is_beta): # Override standard URL functions @@ -103,7 +107,8 @@ def journal_entry(cmdr, is_beta, system, station, entry, state): # But only actually change the URL if we are current station provider. if config.get('station_provider') == 'eddb': - this.station_link['text'] = this.station or (this.system_population and this.system_population > 0 and STATION_UNDOCKED or '') + this.station_link['text'] = this.station or ( + this.system_population and this.system_population > 0 and STATION_UNDOCKED or '') this.station_link['url'] = station_url(this.system, this.station) # Override standard URL function this.station_link.update_idletasks() @@ -131,4 +136,3 @@ def cmdr_data(data, is_beta): this.station_link['url'] = station_url(this.system, this.station) this.station_link.update_idletasks() - From 4eed4404c62b25566fbcbc507c154f0c9e1e70a2 Mon Sep 17 00:00:00 2001 From: A_D Date: Sun, 26 Jul 2020 19:42:34 +0200 Subject: [PATCH 2/8] Added Any type hint to `this` Resolves most type warnings --- plugins/eddb.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/eddb.py b/plugins/eddb.py index 09f84710..7eb134d6 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -24,6 +24,7 @@ import sys +from typing import Any import requests from config import config @@ -31,7 +32,7 @@ from config import config STATION_UNDOCKED: str = u'×' # "Station" name to display when not docked = U+00D7 -this = sys.modules[__name__] # For holding module globals +this: Any = sys.modules[__name__] # For holding module globals # Main window clicks this.system_link = None From 37181264c9a483c3dd9cb77e6465b4fc988bc6f7 Mon Sep 17 00:00:00 2001 From: A_D Date: Sun, 26 Jul 2020 19:46:27 +0200 Subject: [PATCH 3/8] Added newline after scope changes --- plugins/eddb.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/eddb.py b/plugins/eddb.py index 7eb134d6..db49c66a 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -47,8 +47,10 @@ this.station_marketid = None def system_url(system_name: str) -> str: if this.system_address: return requests.utils.requote_uri(f'https://eddb.io/system/ed-address/{this.system_address}') + elif system_name: return requests.utils.requote_uri(f'https://eddb.io/system/name/{system_name}') + else: return '' @@ -56,6 +58,7 @@ def system_url(system_name: str) -> str: def station_url(system_name: str, station_name: str) -> str: if this.station_marketid: return requests.utils.requote_uri(f'https://eddb.io/station/market-id/{this.station_marketid}') + else: return system_url('') @@ -78,6 +81,7 @@ def prefs_changed(cmdr, is_beta): # Override standard URL functions if config.get('system_provider') == 'eddb': this.system_link['url'] = system_url(this.system) + if config.get('station_provider') == 'eddb': this.station_link['url'] = station_url(this.system, this.station) @@ -118,6 +122,7 @@ def cmdr_data(data, is_beta): # Always store initially, even if we're not the *current* system provider. if not this.station_marketid: this.station_marketid = data['commander']['docked'] and data['lastStarport']['id'] + # Only trust CAPI if these aren't yet set this.system = this.system or data['lastSystem']['name'] this.station = this.station or data['commander']['docked'] and data['lastStarport']['name'] @@ -127,11 +132,14 @@ def cmdr_data(data, is_beta): this.system_link['text'] = this.system this.system_link['url'] = system_url(this.system) this.system_link.update_idletasks() + if config.get('station_provider') == 'eddb': if data['commander']['docked']: this.station_link['text'] = this.station + elif data['lastStarport']['name'] and data['lastStarport']['name'] != "": this.station_link['text'] = STATION_UNDOCKED + else: this.station_link['text'] = '' From e0462d87194c1e4f3831e1e89ce497e7c76777a1 Mon Sep 17 00:00:00 2001 From: A_D Date: Sun, 26 Jul 2020 20:08:56 +0200 Subject: [PATCH 4/8] Replaced complex oneliner with multiline if --- plugins/eddb.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/plugins/eddb.py b/plugins/eddb.py index db49c66a..48d63d7a 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -112,20 +112,30 @@ def journal_entry(cmdr, is_beta, system, station, entry, state): # But only actually change the URL if we are current station provider. if config.get('station_provider') == 'eddb': - this.station_link['text'] = this.station or ( - this.system_population and this.system_population > 0 and STATION_UNDOCKED or '') + text = this.station + if not text: + if this.system_population is not None and this.system_population > 0: + text = STATION_UNDOCKED + + else: + text = '' + + this.station_link['text'] = text this.station_link['url'] = station_url(this.system, this.station) # Override standard URL function this.station_link.update_idletasks() def cmdr_data(data, is_beta): # Always store initially, even if we're not the *current* system provider. - if not this.station_marketid: - this.station_marketid = data['commander']['docked'] and data['lastStarport']['id'] + if not this.station_marketid and data['commander']['docked']: + this.station_marketid = data['lastStarport']['id'] # Only trust CAPI if these aren't yet set - this.system = this.system or data['lastSystem']['name'] - this.station = this.station or data['commander']['docked'] and data['lastStarport']['name'] + if not this.system: + this.system = data['lastSystem']['name'] + + if not this.station and data['commander']['docked']: + this.station = data['lastStarport']['name'] # Override standard URL functions if config.get('system_provider') == 'eddb': From 07c43d30574e74577a9a38381164592c9510ef1e Mon Sep 17 00:00:00 2001 From: A_D Date: Sun, 26 Jul 2020 20:12:56 +0200 Subject: [PATCH 5/8] added type annotations to globals --- plugins/eddb.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/eddb.py b/plugins/eddb.py index 48d63d7a..b8c9c9d1 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -24,7 +24,7 @@ import sys -from typing import Any +from typing import Any, Optional import requests from config import config @@ -35,13 +35,13 @@ STATION_UNDOCKED: str = u'×' # "Station" name to display when not docked = U+0 this: Any = sys.modules[__name__] # For holding module globals # Main window clicks -this.system_link = None -this.system = None -this.system_address = None -this.system_population = None -this.station_link = None -this.station = None -this.station_marketid = None +this.system_link: Optional[str] = None +this.system: Optional[str] = None +this.system_address: Optional[str] = None +this.system_population: Optional[int] = None +this.station_link = None # tk thing, not annotated +this.station: Optional[str] = None +this.station_marketid: Optional[int] = None def system_url(system_name: str) -> str: From 7b231fb244429dc5c2dfc720bc2faf4892d63e0e Mon Sep 17 00:00:00 2001 From: A_D Date: Sun, 26 Jul 2020 20:14:08 +0200 Subject: [PATCH 6/8] removed unicode specifier from string python3 strings are always unicode --- plugins/eddb.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/eddb.py b/plugins/eddb.py index b8c9c9d1..83f4be59 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -30,7 +30,7 @@ import requests from config import config -STATION_UNDOCKED: str = u'×' # "Station" name to display when not docked = U+00D7 +STATION_UNDOCKED: str = '×' # "Station" name to display when not docked = U+00D7 this: Any = sys.modules[__name__] # For holding module globals @@ -39,7 +39,7 @@ this.system_link: Optional[str] = None this.system: Optional[str] = None this.system_address: Optional[str] = None this.system_population: Optional[int] = None -this.station_link = None # tk thing, not annotated +this.station_link = None # tk thing, not annotated this.station: Optional[str] = None this.station_marketid: Optional[int] = None From cad5f72b0ac4cfbdee09c05aab5962fc2763a777 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 27 Jul 2020 11:26:31 +0200 Subject: [PATCH 7/8] updated type annotation --- plugins/eddb.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/eddb.py b/plugins/eddb.py index 83f4be59..43a5b09f 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -24,11 +24,15 @@ import sys -from typing import Any, Optional +import tkinter +from typing import Any, Optional, TYPE_CHECKING import requests from config import config +if TYPE_CHECKING: + from tkinter import Tk + STATION_UNDOCKED: str = '×' # "Station" name to display when not docked = U+00D7 @@ -39,7 +43,7 @@ this.system_link: Optional[str] = None this.system: Optional[str] = None this.system_address: Optional[str] = None this.system_population: Optional[int] = None -this.station_link = None # tk thing, not annotated +this.station_link: 'Optional[tkinter.Tk]' = None this.station: Optional[str] = None this.station_marketid: Optional[int] = None @@ -67,7 +71,7 @@ def plugin_start3(plugin_dir): return 'eddb' -def plugin_app(parent): +def plugin_app(parent: 'tkinter.Tk'): this.system_link = parent.children['system'] # system label in main window this.system = None this.system_address = None From b27e4a362818b9e828ed96e13c13a1c32fbfc4f5 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 27 Jul 2020 15:15:48 +0200 Subject: [PATCH 8/8] fixed tk import and type annotations --- plugins/eddb.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/eddb.py b/plugins/eddb.py index 43a5b09f..1613ba5b 100644 --- a/plugins/eddb.py +++ b/plugins/eddb.py @@ -24,7 +24,6 @@ import sys -import tkinter from typing import Any, Optional, TYPE_CHECKING import requests @@ -43,7 +42,7 @@ this.system_link: Optional[str] = None this.system: Optional[str] = None this.system_address: Optional[str] = None this.system_population: Optional[int] = None -this.station_link: 'Optional[tkinter.Tk]' = None +this.station_link: 'Optional[Tk]' = None this.station: Optional[str] = None this.station_marketid: Optional[int] = None @@ -71,7 +70,7 @@ def plugin_start3(plugin_dir): return 'eddb' -def plugin_app(parent: 'tkinter.Tk'): +def plugin_app(parent: 'Tk'): this.system_link = parent.children['system'] # system label in main window this.system = None this.system_address = None