mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-05-02 16:31:32 +03:00
[#2406] Consolidate Modules
This commit is contained in:
parent
2c4e409ca3
commit
26f06b7bf0
1
build.py
1
build.py
@ -121,6 +121,7 @@ def build() -> None:
|
||||
"plugins/edsy.py",
|
||||
"plugins/inara.py",
|
||||
"plugins/spansh_core.py",
|
||||
"plugins/common_coreutils.py"
|
||||
]
|
||||
options: dict = {
|
||||
"py2exe": {
|
||||
|
190
plugins/common_coreutils.py
Normal file
190
plugins/common_coreutils.py
Normal file
@ -0,0 +1,190 @@
|
||||
"""
|
||||
common_coreutils.py - Common Plugin Functions.
|
||||
|
||||
Copyright (c) EDCD, All Rights Reserved
|
||||
Licensed under the GNU General Public License.
|
||||
See LICENSE file.
|
||||
|
||||
This is an EDMC 'core' plugin.
|
||||
|
||||
All EDMC plugins are *dynamically* loaded at run-time.
|
||||
|
||||
We build for Windows using `py2exe`.
|
||||
`py2exe` can't possibly know about anything in the dynamically loaded core plugins.
|
||||
|
||||
Thus, you **MUST** check if any imports you add in this file are only
|
||||
referenced in this file (or only in any other core plugin), and if so...
|
||||
|
||||
YOU MUST ENSURE THAT PERTINENT ADJUSTMENTS ARE MADE IN
|
||||
`build.py` TO ENSURE THE FILES ARE ACTUALLY PRESENT
|
||||
IN AN END-USER INSTALLATION ON WINDOWS.
|
||||
"""
|
||||
# pylint: disable=import-error
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Mapping, cast
|
||||
import tkinter as tk
|
||||
import base64
|
||||
import gzip
|
||||
import io
|
||||
import json
|
||||
import myNotebook as nb # noqa: N813
|
||||
from EDMCLogging import get_main_logger
|
||||
from companion import CAPIData
|
||||
from l10n import translations as tr
|
||||
|
||||
logger = get_main_logger()
|
||||
|
||||
# Global Padding Preferences
|
||||
PADX = 10
|
||||
BUTTONX = 12 # indent Checkbuttons and Radiobuttons
|
||||
PADY = 1 # close spacing
|
||||
BOXY = 2 # box spacing
|
||||
SEPY = 10 # seperator line spacing
|
||||
STATION_UNDOCKED = '×' # "Station" name to display when not docked = U+00D7
|
||||
|
||||
|
||||
def plugin_start3(plugin_dir: str) -> str:
|
||||
"""
|
||||
Start the plugin.
|
||||
|
||||
:param plugin_dir: NAme of directory this was loaded from.
|
||||
:return: Identifier string for this plugin.
|
||||
"""
|
||||
return 'CommonCoreUtils'
|
||||
|
||||
|
||||
def api_keys_label_common(this, cur_row: int, frame: nb.Frame):
|
||||
"""
|
||||
Prepare the box for API Key Loading. This is an EDMC Common Function.
|
||||
|
||||
:param this: The module global from the calling module.
|
||||
:param cur_row: The current row in the calling module's config page.
|
||||
:param frame: The current frame in the calling module's config page.
|
||||
:return: The updated module global from the calling module.
|
||||
"""
|
||||
# LANG: EDSM API key label
|
||||
this.apikey_label = nb.Label(frame, text=tr.tl('API Key'))
|
||||
this.apikey_label.grid(row=cur_row, padx=PADX, pady=PADY, sticky=tk.W)
|
||||
this.apikey = nb.EntryMenu(frame, show="*", width=50)
|
||||
this.apikey.grid(row=cur_row, column=1, padx=PADX, pady=BOXY, sticky=tk.EW)
|
||||
return this
|
||||
|
||||
|
||||
def show_pwd_var_common(frame: nb.Frame, cur_row: int, this):
|
||||
"""
|
||||
Allow unmasking of the API Key. This is an EDMC Common Function.
|
||||
|
||||
:param cur_row: The current row in the calling module's config page.
|
||||
:param frame: The current frame in the calling module's config page.
|
||||
"""
|
||||
show_password_var.set(False) # Password is initially masked
|
||||
|
||||
show_password_checkbox = nb.Checkbutton(
|
||||
frame,
|
||||
text=tr.tl('Show API Key'), # LANG: Text EDSM Show API Key
|
||||
variable=show_password_var,
|
||||
command=lambda: toggle_password_visibility_common(this)
|
||||
)
|
||||
show_password_checkbox.grid(row=cur_row, columnspan=2, padx=BUTTONX, pady=PADY, sticky=tk.W)
|
||||
|
||||
|
||||
# Return a URL for the current ship
|
||||
def shipyard_url_common(loadout: Mapping[str, Any]) -> str:
|
||||
"""
|
||||
Construct a URL for ship loadout. This is an EDMC Common Function.
|
||||
|
||||
:param loadout: The ship loadout data.
|
||||
:return: The constructed URL for the ship loadout.
|
||||
"""
|
||||
# Convert loadout to JSON and gzip compress it
|
||||
string = json.dumps(loadout, ensure_ascii=False, sort_keys=True, separators=(',', ':')).encode('utf-8')
|
||||
if not string:
|
||||
return ''
|
||||
|
||||
out = io.BytesIO()
|
||||
with gzip.GzipFile(fileobj=out, mode='w') as f:
|
||||
f.write(string)
|
||||
|
||||
encoded_data = base64.urlsafe_b64encode(out.getvalue()).decode().replace('=', '%3D')
|
||||
return encoded_data
|
||||
|
||||
|
||||
def station_link_common(data: CAPIData, this):
|
||||
"""
|
||||
Set the Staion Name. This is an EDMC Common Function.
|
||||
|
||||
:param data: A CAPI Data Entry.
|
||||
:param this: The module global from the calling module.
|
||||
"""
|
||||
if data['commander']['docked'] or this.on_foot and this.station_name:
|
||||
this.station_link['text'] = this.station_name
|
||||
elif data['lastStarport']['name'] and data['lastStarport']['name'] != "":
|
||||
this.station_link['text'] = STATION_UNDOCKED
|
||||
else:
|
||||
this.station_link['text'] = ''
|
||||
|
||||
|
||||
def this_format_common(this, state: Mapping[str, Any]):
|
||||
"""
|
||||
Gather Common 'This' Elements. This is an EDMC Common Function.
|
||||
|
||||
:param this: The module global from the calling module.
|
||||
:param state: `monitor.state`.
|
||||
"""
|
||||
this.system_address = state['SystemAddress']
|
||||
this.system_name = state['SystemName']
|
||||
this.system_population = state['SystemPopulation']
|
||||
this.station_name = state['StationName']
|
||||
this.station_marketid = state['MarketID']
|
||||
this.station_type = state['StationType']
|
||||
this.on_foot = state['OnFoot']
|
||||
|
||||
|
||||
def toggle_password_visibility_common(this):
|
||||
"""
|
||||
Toggle if the API Key is visible or not. This is an EDMC Common Function.
|
||||
|
||||
:param this: The module global from the calling module.
|
||||
"""
|
||||
if show_password_var.get():
|
||||
this.apikey.config(show="") # type: ignore
|
||||
else:
|
||||
this.apikey.config(show="*") # type: ignore
|
||||
|
||||
|
||||
def station_name_setter_common(this):
|
||||
"""
|
||||
Set the Station Name. This is an EDMC Common Function.
|
||||
|
||||
:param this: The module global from the calling module.
|
||||
"""
|
||||
to_set: str = cast(str, this.station_name)
|
||||
if not to_set:
|
||||
if this.system_population is not None and this.system_population > 0:
|
||||
to_set = STATION_UNDOCKED
|
||||
else:
|
||||
to_set = ''
|
||||
|
||||
this.station_link['text'] = to_set
|
||||
|
||||
|
||||
def cmdr_data_initial_common(this, data: CAPIData):
|
||||
"""
|
||||
Set the common CMDR Data. This is an EDMC Common Function.
|
||||
|
||||
:param this: The module global from the calling module.
|
||||
:param data: The latest merged CAPI data.
|
||||
"""
|
||||
# Always store initially, even if we're not the *current* system provider.
|
||||
if not this.station_marketid and data['commander']['docked']:
|
||||
this.station_marketid = data['lastStarport']['id']
|
||||
|
||||
# Only trust CAPI if these aren't yet set
|
||||
if not this.system_name:
|
||||
this.system_name = data['lastSystem']['name']
|
||||
if not this.station_name and data['commander']['docked']:
|
||||
this.station_name = data['lastStarport']['name']
|
||||
|
||||
|
||||
show_password_var = tk.BooleanVar()
|
@ -19,12 +19,10 @@ referenced in this file (or only in any other core plugin), and if so...
|
||||
`build.py` TO ENSURE THE FILES ARE ACTUALLY PRESENT
|
||||
IN AN END-USER INSTALLATION ON WINDOWS.
|
||||
"""
|
||||
# pylint: disable=import-error
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import gzip
|
||||
import io
|
||||
import json
|
||||
from typing import Any, Mapping
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
import myNotebook as nb # noqa: N813 # its not my fault.
|
||||
@ -32,6 +30,7 @@ from EDMCLogging import get_main_logger
|
||||
from plug import show_error
|
||||
from config import config
|
||||
from l10n import translations as tr
|
||||
from plugins.common_coreutils import PADX, PADY, BOXY, shipyard_url_common
|
||||
|
||||
|
||||
class CoriolisConfig:
|
||||
@ -82,10 +81,6 @@ def plugin_start3(path: str) -> str:
|
||||
|
||||
def plugin_prefs(parent: ttk.Notebook, cmdr: str | None, is_beta: bool) -> nb.Frame:
|
||||
"""Set up plugin preferences."""
|
||||
PADX = 10 # noqa: N806
|
||||
PADY = 1 # noqa: N806
|
||||
BOXY = 2 # noqa: N806 # box spacing
|
||||
|
||||
# Save the old text values for the override mode, so we can update them if the language is changed
|
||||
coriolis_config.override_text_old_auto = tr.tl('Auto') # LANG: Coriolis normal/beta selection - auto
|
||||
coriolis_config.override_text_old_normal = tr.tl('Normal') # LANG: Coriolis normal/beta selection - normal
|
||||
@ -207,14 +202,14 @@ def _get_target_url(is_beta: bool) -> str:
|
||||
return coriolis_config.normal_url
|
||||
|
||||
|
||||
def shipyard_url(loadout, is_beta) -> str | bool:
|
||||
"""Return a URL for the current ship."""
|
||||
# most compact representation
|
||||
string = json.dumps(loadout, ensure_ascii=False, sort_keys=True, separators=(',', ':')).encode('utf-8')
|
||||
if not string:
|
||||
return False
|
||||
out = io.BytesIO()
|
||||
with gzip.GzipFile(fileobj=out, mode='w') as f:
|
||||
f.write(string)
|
||||
encoded = base64.urlsafe_b64encode(out.getvalue()).decode().replace('=', '%3D')
|
||||
return _get_target_url(is_beta) + encoded
|
||||
# Return a URL for the current ship
|
||||
def shipyard_url(loadout: Mapping[str, Any], is_beta: bool) -> bool | str:
|
||||
"""
|
||||
Construct a URL for ship loadout.
|
||||
|
||||
:param loadout: The ship loadout data.
|
||||
:param is_beta: Whether the game is in beta.
|
||||
:return: The constructed URL for the ship loadout.
|
||||
"""
|
||||
encoded_data = shipyard_url_common(loadout)
|
||||
return _get_target_url(is_beta) + encoded_data if encoded_data else False
|
||||
|
@ -18,6 +18,7 @@ referenced in this file (or only in any other core plugin), and if so...
|
||||
`build.py` TO ENSURE THE FILES ARE ACTUALLY PRESENT
|
||||
IN AN END-USER INSTALLATION ON WINDOWS.
|
||||
"""
|
||||
# pylint: disable=import-error
|
||||
from __future__ import annotations
|
||||
|
||||
import http
|
||||
@ -47,6 +48,7 @@ from prefs import prefsVersion
|
||||
from ttkHyperlinkLabel import HyperlinkLabel
|
||||
from util import text
|
||||
from l10n import translations as tr
|
||||
from plugins.common_coreutils import PADX, PADY, BUTTONX, this_format_common
|
||||
|
||||
logger = get_main_logger()
|
||||
|
||||
@ -2145,10 +2147,6 @@ def plugin_prefs(parent, cmdr: str, is_beta: bool) -> Frame:
|
||||
:param is_beta: `bool` - True if this is a beta version of the Game.
|
||||
:return: The tkinter frame we created.
|
||||
"""
|
||||
PADX = 10 # noqa: N806
|
||||
BUTTONX = 12 # noqa: N806 # indent Checkbuttons and Radiobuttons
|
||||
PADY = 1 # noqa: N806
|
||||
|
||||
if prefsVersion.shouldSetDefaults('0.0.0.0', not bool(config.get_int('output'))):
|
||||
output: int = config.OUT_EDDN_SEND_STATION_DATA | config.OUT_EDDN_SEND_NON_STATION # default settings
|
||||
|
||||
@ -2349,11 +2347,7 @@ def journal_entry( # noqa: C901, CCR001
|
||||
this.body_id = state['BodyID']
|
||||
this.body_type = state['BodyType']
|
||||
this.coordinates = state['StarPos']
|
||||
this.system_address = state['SystemAddress']
|
||||
this.system_name = state['SystemName']
|
||||
this.station_name = state['StationName']
|
||||
this.station_type = state['StationType']
|
||||
this.station_marketid = state['MarketID']
|
||||
this_format_common(this, state)
|
||||
|
||||
if event_name == 'docked':
|
||||
# Trigger a send/retry of pending EDDN messages
|
||||
|
@ -18,6 +18,7 @@ referenced in this file (or only in any other core plugin), and if so...
|
||||
`build.py` TO ENSURE THE FILES ARE ACTUALLY PRESENT
|
||||
IN AN END-USER INSTALLATION ON WINDOWS.
|
||||
"""
|
||||
# pylint: disable=import-error
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
@ -40,6 +41,9 @@ from edmc_data import DEBUG_WEBSERVER_HOST, DEBUG_WEBSERVER_PORT
|
||||
from EDMCLogging import get_main_logger
|
||||
from ttkHyperlinkLabel import HyperlinkLabel
|
||||
from l10n import translations as tr
|
||||
from plugins.common_coreutils import (api_keys_label_common, PADX, PADY, BUTTONX, SEPY, BOXY, STATION_UNDOCKED,
|
||||
show_pwd_var_common, station_link_common, this_format_common,
|
||||
cmdr_data_initial_common)
|
||||
|
||||
|
||||
# TODO:
|
||||
@ -118,9 +122,7 @@ class This:
|
||||
|
||||
|
||||
this = This()
|
||||
show_password_var = tk.BooleanVar()
|
||||
|
||||
STATION_UNDOCKED: str = '×' # "Station" name to display when not docked = U+00D7
|
||||
__cleanup = str.maketrans({' ': None, '\n': None})
|
||||
IMG_KNOWN_B64 = """
|
||||
R0lGODlhEAAQAMIEAFWjVVWkVWS/ZGfFZ////////////////yH5BAEKAAQALAAAAAAQABAAAAMvSLrc/lAFIUIkYOgNXt5g14Dk0AQlaC1CuglM6w7wgs7r
|
||||
@ -269,14 +271,6 @@ def plugin_stop() -> None:
|
||||
logger.debug('Done.')
|
||||
|
||||
|
||||
def toggle_password_visibility():
|
||||
"""Toggle if the API Key is visible or not."""
|
||||
if show_password_var.get():
|
||||
this.apikey.config(show="") # type: ignore
|
||||
else:
|
||||
this.apikey.config(show="*") # type: ignore
|
||||
|
||||
|
||||
def plugin_prefs(parent: ttk.Notebook, cmdr: str | None, is_beta: bool) -> nb.Frame:
|
||||
"""
|
||||
Plugin preferences setup hook.
|
||||
@ -289,12 +283,6 @@ def plugin_prefs(parent: ttk.Notebook, cmdr: str | None, is_beta: bool) -> nb.Fr
|
||||
:param is_beta: Whether game beta was detected.
|
||||
:return: An instance of `myNotebook.Frame`.
|
||||
"""
|
||||
PADX = 10 # noqa: N806
|
||||
BUTTONX = 12 # noqa: N806
|
||||
PADY = 1 # noqa: N806
|
||||
BOXY = 2 # noqa: N806
|
||||
SEPY = 10 # noqa: N806
|
||||
|
||||
frame = nb.Frame(parent)
|
||||
frame.columnconfigure(1, weight=1)
|
||||
|
||||
@ -349,23 +337,10 @@ def plugin_prefs(parent: ttk.Notebook, cmdr: str | None, is_beta: bool) -> nb.Fr
|
||||
|
||||
cur_row += 1
|
||||
# LANG: EDSM API key label
|
||||
this.apikey_label = nb.Label(frame, text=tr.tl('API Key'))
|
||||
this.apikey_label.grid(row=cur_row, padx=PADX, pady=PADY, sticky=tk.W)
|
||||
this.apikey = nb.EntryMenu(frame, show="*", width=50)
|
||||
this.apikey.grid(row=cur_row, column=1, padx=PADX, pady=BOXY, sticky=tk.EW)
|
||||
api_keys_label_common(this, cur_row, frame)
|
||||
cur_row += 1
|
||||
|
||||
prefs_cmdr_changed(cmdr, is_beta)
|
||||
|
||||
show_password_var.set(False) # Password is initially masked
|
||||
|
||||
show_password_checkbox = nb.Checkbutton(
|
||||
frame,
|
||||
text=tr.tl('Show API Key'), # LANG: Text EDSM Show API Key
|
||||
variable=show_password_var,
|
||||
command=toggle_password_visibility
|
||||
)
|
||||
show_password_checkbox.grid(row=cur_row, columnspan=2, padx=BUTTONX, pady=PADY, sticky=tk.W)
|
||||
show_pwd_var_common(frame, cur_row, this)
|
||||
|
||||
return frame
|
||||
|
||||
@ -544,11 +519,7 @@ def journal_entry( # noqa: C901, CCR001
|
||||
|
||||
this.game_version = state['GameVersion']
|
||||
this.game_build = state['GameBuild']
|
||||
this.system_address = state['SystemAddress']
|
||||
this.system_name = state['SystemName']
|
||||
this.system_population = state['SystemPopulation']
|
||||
this.station_name = state['StationName']
|
||||
this.station_marketid = state['MarketID']
|
||||
this_format_common(this, state)
|
||||
|
||||
entry = new_entry
|
||||
|
||||
@ -658,7 +629,7 @@ Queueing: {entry!r}'''
|
||||
|
||||
|
||||
# Update system data
|
||||
def cmdr_data(data: CAPIData, is_beta: bool) -> str | None: # noqa: CCR001
|
||||
def cmdr_data(data: CAPIData, is_beta: bool) -> str | None:
|
||||
"""
|
||||
Process new CAPI data.
|
||||
|
||||
@ -668,14 +639,7 @@ def cmdr_data(data: CAPIData, is_beta: bool) -> str | None: # noqa: CCR001
|
||||
"""
|
||||
system = data['lastSystem']['name']
|
||||
|
||||
# Always store initially, even if we're not the *current* system provider.
|
||||
if not this.station_marketid and data['commander']['docked']:
|
||||
this.station_marketid = data['lastStarport']['id']
|
||||
# Only trust CAPI if these aren't yet set
|
||||
if not this.system_name:
|
||||
this.system_name = data['lastSystem']['name']
|
||||
if not this.station_name and data['commander']['docked']:
|
||||
this.station_name = data['lastStarport']['name']
|
||||
cmdr_data_initial_common(this, data)
|
||||
|
||||
# TODO: Fire off the EDSM API call to trigger the callback for the icons
|
||||
|
||||
@ -687,13 +651,7 @@ def cmdr_data(data: CAPIData, is_beta: bool) -> str | None: # noqa: CCR001
|
||||
this.system_link.update_idletasks()
|
||||
if config.get_str('station_provider') == 'EDSM':
|
||||
if this.station_link:
|
||||
if data['commander']['docked'] or this.on_foot and this.station_name:
|
||||
this.station_link['text'] = this.station_name
|
||||
elif data['lastStarport']['name'] and data['lastStarport']['name'] != "":
|
||||
this.station_link['text'] = STATION_UNDOCKED
|
||||
else:
|
||||
this.station_link['text'] = ''
|
||||
|
||||
station_link_common(data, this)
|
||||
# Do *NOT* set 'url' here, as it's set to a function that will call
|
||||
# through correctly. We don't want a static string.
|
||||
this.station_link.update_idletasks()
|
||||
|
@ -20,11 +20,8 @@ referenced in this file (or only in any other core plugin), and if so...
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import gzip
|
||||
import io
|
||||
import json
|
||||
from typing import Any, Mapping
|
||||
from plugins.common_coreutils import shipyard_url_common # pylint: disable=E0401
|
||||
|
||||
|
||||
def plugin_start3(plugin_dir: str) -> str:
|
||||
@ -46,17 +43,7 @@ def shipyard_url(loadout: Mapping[str, Any], is_beta: bool) -> bool | str:
|
||||
:param is_beta: Whether the game is in beta.
|
||||
:return: The constructed URL for the ship loadout.
|
||||
"""
|
||||
# Convert loadout to JSON and gzip compress it
|
||||
string = json.dumps(loadout, ensure_ascii=False, sort_keys=True, separators=(',', ':')).encode('utf-8')
|
||||
if not string:
|
||||
return False
|
||||
|
||||
out = io.BytesIO()
|
||||
with gzip.GzipFile(fileobj=out, mode='w') as f:
|
||||
f.write(string)
|
||||
|
||||
encoded_data = shipyard_url_common(loadout)
|
||||
# Construct the URL using the appropriate base URL based on is_beta
|
||||
base_url = 'https://edsy.org/beta/#/I=' if is_beta else 'https://edsy.org/#/I='
|
||||
encoded_data = base64.urlsafe_b64encode(out.getvalue()).decode().replace('=', '%3D')
|
||||
|
||||
return base_url + encoded_data
|
||||
return base_url + encoded_data if encoded_data else False
|
||||
|
@ -18,6 +18,7 @@ referenced in this file (or only in any other core plugin), and if so...
|
||||
`build.py` TO ENSURE THE FILES ARE ACTUALLY PRESENT
|
||||
IN AN END-USER INSTALLATION ON WINDOWS.
|
||||
"""
|
||||
# pylint: disable=import-error
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
@ -43,6 +44,8 @@ from EDMCLogging import get_main_logger
|
||||
from monitor import monitor
|
||||
from ttkHyperlinkLabel import HyperlinkLabel
|
||||
from l10n import translations as tr
|
||||
from plugins.common_coreutils import (api_keys_label_common, PADX, PADY, BUTTONX, SEPY, station_name_setter_common,
|
||||
show_pwd_var_common, station_link_common, this_format_common)
|
||||
|
||||
logger = get_main_logger()
|
||||
|
||||
@ -115,7 +118,7 @@ class This:
|
||||
self.system_address: str | None = None # type: ignore
|
||||
self.system_population: int | None = None
|
||||
self.station_link: tk.Widget = None # type: ignore
|
||||
self.station = None
|
||||
self.station_name = None
|
||||
self.station_marketid = None
|
||||
|
||||
# Prefs UI
|
||||
@ -144,7 +147,6 @@ class This:
|
||||
|
||||
|
||||
this = This()
|
||||
show_password_var = tk.BooleanVar()
|
||||
|
||||
# last time we updated, if unset in config this is 0, which means an instant update
|
||||
LAST_UPDATE_CONF_KEY = 'inara_last_update'
|
||||
@ -187,9 +189,9 @@ def station_url(system_name: str, station_name: str) -> str:
|
||||
if system_name and station_name:
|
||||
return requests.utils.requote_uri(f'https://inara.cz/galaxy-station/?search={system_name}%20[{station_name}]')
|
||||
|
||||
if this.system_name and this.station:
|
||||
if this.system_name and this.station_name:
|
||||
return requests.utils.requote_uri(
|
||||
f'https://inara.cz/galaxy-station/?search={this.system_name}%20[{this.station}]')
|
||||
f'https://inara.cz/galaxy-station/?search={this.system_name}%20[{this.station_name}]')
|
||||
|
||||
if system_name:
|
||||
return system_url(system_name)
|
||||
@ -233,21 +235,8 @@ def plugin_stop() -> None:
|
||||
logger.debug('Done.')
|
||||
|
||||
|
||||
def toggle_password_visibility():
|
||||
"""Toggle if the API Key is visible or not."""
|
||||
if show_password_var.get():
|
||||
this.apikey.config(show="")
|
||||
else:
|
||||
this.apikey.config(show="*")
|
||||
|
||||
|
||||
def plugin_prefs(parent: ttk.Notebook, cmdr: str, is_beta: bool) -> nb.Frame:
|
||||
"""Plugin Preferences UI hook."""
|
||||
PADX = 10 # noqa: N806
|
||||
BUTTONX = 12 # noqa: N806 # indent Checkbuttons and Radiobuttons
|
||||
PADY = 1 # noqa: N806 # close spacing
|
||||
BOXY = 2 # noqa: N806 # box spacing
|
||||
SEPY = 10 # noqa: N806 # seperator line spacing
|
||||
cur_row = 0
|
||||
|
||||
frame = nb.Frame(parent)
|
||||
@ -287,22 +276,10 @@ def plugin_prefs(parent: ttk.Notebook, cmdr: str, is_beta: bool) -> nb.Frame:
|
||||
cur_row += 1
|
||||
|
||||
# LANG: Inara API key label
|
||||
this.apikey_label = nb.Label(frame, text=tr.tl('API Key')) # Inara setting
|
||||
this.apikey_label.grid(row=cur_row, padx=PADX, pady=PADY, sticky=tk.W)
|
||||
this.apikey = nb.EntryMenu(frame, show="*", width=50)
|
||||
this.apikey.grid(row=cur_row, column=1, padx=PADX, pady=BOXY, sticky=tk.EW)
|
||||
api_keys_label_common(this, cur_row, frame)
|
||||
cur_row += 1
|
||||
|
||||
prefs_cmdr_changed(cmdr, is_beta)
|
||||
|
||||
show_password_var.set(False) # Password is initially masked
|
||||
show_password_checkbox = nb.Checkbutton(
|
||||
frame,
|
||||
text=tr.tl('Show API Key'), # LANG: Text Inara Show API key
|
||||
variable=show_password_var,
|
||||
command=toggle_password_visibility,
|
||||
)
|
||||
show_password_checkbox.grid(row=cur_row, columnspan=2, padx=BUTTONX, pady=PADY, sticky=tk.W)
|
||||
show_pwd_var_common(frame, cur_row, this)
|
||||
|
||||
return frame
|
||||
|
||||
@ -411,15 +388,11 @@ def journal_entry( # noqa: C901, CCR001
|
||||
# But then we update all the tracking copies before any other checks,
|
||||
# because they're relevant for URL providing even if *sending* isn't
|
||||
# appropriate.
|
||||
this.on_foot = state['OnFoot']
|
||||
event_name: str = entry['event']
|
||||
this.cmdr = cmdr
|
||||
this.FID = state['FID']
|
||||
this.multicrew = bool(state['Role'])
|
||||
this.system_name = state['SystemName']
|
||||
this.system_address = state['SystemAddress']
|
||||
this.station = state['StationName']
|
||||
this.station_marketid = state['MarketID']
|
||||
this_format_common(this, state)
|
||||
|
||||
if not monitor.is_live_galaxy():
|
||||
# Since Update 14 on 2022-11-29 Inara only accepts Live data.
|
||||
@ -613,7 +586,7 @@ def journal_entry( # noqa: C901, CCR001
|
||||
|
||||
elif event_name == 'Undocked':
|
||||
this.undocked = True
|
||||
this.station = None
|
||||
this.station_name = None
|
||||
|
||||
elif event_name == 'SupercruiseEntry':
|
||||
this.undocked = False
|
||||
@ -1368,14 +1341,7 @@ def journal_entry( # noqa: C901, CCR001
|
||||
this.system_link.update_idletasks()
|
||||
|
||||
if config.get_str('station_provider') == 'Inara':
|
||||
to_set: str = cast(str, this.station)
|
||||
if not to_set:
|
||||
if this.system_population is not None and this.system_population > 0:
|
||||
to_set = STATION_UNDOCKED
|
||||
else:
|
||||
to_set = ''
|
||||
|
||||
this.station_link['text'] = to_set
|
||||
station_name_setter_common(this)
|
||||
# Do *NOT* set 'url' here, as it's set to a function that will call
|
||||
# through correctly. We don't want a static string.
|
||||
this.station_link.update_idletasks()
|
||||
@ -1383,7 +1349,7 @@ def journal_entry( # noqa: C901, CCR001
|
||||
return '' # No error
|
||||
|
||||
|
||||
def cmdr_data(data: CAPIData, is_beta): # noqa: CCR001, reanalyze me later
|
||||
def cmdr_data(data: CAPIData, is_beta):
|
||||
"""CAPI event hook."""
|
||||
this.cmdr = data['commander']['name']
|
||||
|
||||
@ -1394,8 +1360,8 @@ def cmdr_data(data: CAPIData, is_beta): # noqa: CCR001, reanalyze me later
|
||||
# Only trust CAPI if these aren't yet set
|
||||
this.system_name = this.system_name if this.system_name else data['lastSystem']['name']
|
||||
|
||||
if not this.station and data['commander']['docked']:
|
||||
this.station = data['lastStarport']['name']
|
||||
if not this.station_name and data['commander']['docked']:
|
||||
this.station_name = data['lastStarport']['name']
|
||||
|
||||
# Override standard URL functions
|
||||
if config.get_str('system_provider') == 'Inara':
|
||||
@ -1405,14 +1371,7 @@ def cmdr_data(data: CAPIData, is_beta): # noqa: CCR001, reanalyze me later
|
||||
this.system_link.update_idletasks()
|
||||
|
||||
if config.get_str('station_provider') == 'Inara':
|
||||
if data['commander']['docked'] or this.on_foot and this.station:
|
||||
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'] = ''
|
||||
station_link_common(data, this)
|
||||
|
||||
# Do *NOT* set 'url' here, as it's set to a function that will call
|
||||
# through correctly. We don't want a static string.
|
||||
|
@ -18,14 +18,17 @@ referenced in this file (or only in any other core plugin), and if so...
|
||||
`build.py` TO ENSURE THE FILES ARE ACTUALLY PRESENT
|
||||
IN AN END-USER INSTALLATION ON WINDOWS.
|
||||
"""
|
||||
# pylint: disable=import-error
|
||||
from __future__ import annotations
|
||||
|
||||
import tkinter as tk
|
||||
from typing import Any, cast
|
||||
from typing import Any
|
||||
import requests
|
||||
from companion import CAPIData
|
||||
from config import appname, config
|
||||
from EDMCLogging import get_main_logger
|
||||
from plugins.common_coreutils import (station_link_common, this_format_common,
|
||||
cmdr_data_initial_common, station_name_setter_common)
|
||||
|
||||
logger = get_main_logger()
|
||||
|
||||
@ -91,12 +94,7 @@ def journal_entry(
|
||||
:param state: `monitor.state`
|
||||
:return: None if no error, else an error string.
|
||||
"""
|
||||
this.on_foot = state['OnFoot']
|
||||
this.system_address = state['SystemAddress']
|
||||
this.system_name = state['SystemName']
|
||||
this.system_population = state['SystemPopulation']
|
||||
this.station_name = state['StationName']
|
||||
this.station_marketid = state['MarketID']
|
||||
this_format_common(this, state)
|
||||
|
||||
# Only actually change URLs if we are current provider.
|
||||
if config.get_str('system_provider') == 'spansh':
|
||||
@ -106,14 +104,7 @@ def journal_entry(
|
||||
this.system_link.update_idletasks()
|
||||
|
||||
if config.get_str('station_provider') == 'spansh':
|
||||
to_set: str = cast(str, this.station_name)
|
||||
if not to_set:
|
||||
if this.system_population is not None and this.system_population > 0:
|
||||
to_set = STATION_UNDOCKED
|
||||
else:
|
||||
to_set = ''
|
||||
|
||||
this.station_link['text'] = to_set
|
||||
station_name_setter_common(this)
|
||||
# Do *NOT* set 'url' here, as it's set to a function that will call
|
||||
# through correctly. We don't want a static string.
|
||||
this.station_link.update_idletasks()
|
||||
@ -129,15 +120,7 @@ def cmdr_data(data: CAPIData, is_beta: bool) -> str | None:
|
||||
:param is_beta: Whether game beta was detected.
|
||||
:return: Optional error string.
|
||||
"""
|
||||
# Always store initially, even if we're not the *current* system provider.
|
||||
if not this.station_marketid and data['commander']['docked']:
|
||||
this.station_marketid = data['lastStarport']['id']
|
||||
|
||||
# Only trust CAPI if these aren't yet set
|
||||
if not this.system_name:
|
||||
this.system_name = data['lastSystem']['name']
|
||||
if not this.station_name and data['commander']['docked']:
|
||||
this.station_name = data['lastStarport']['name']
|
||||
cmdr_data_initial_common(this, data)
|
||||
|
||||
# Override standard URL functions
|
||||
if config.get_str('system_provider') == 'spansh':
|
||||
@ -146,12 +129,7 @@ def cmdr_data(data: CAPIData, is_beta: bool) -> str | None:
|
||||
# through correctly. We don't want a static string.
|
||||
this.system_link.update_idletasks()
|
||||
if config.get_str('station_provider') == 'spansh':
|
||||
if data['commander']['docked'] or this.on_foot and this.station_name:
|
||||
this.station_link['text'] = this.station_name
|
||||
elif data['lastStarport']['name'] and data['lastStarport']['name'] != "":
|
||||
this.station_link['text'] = STATION_UNDOCKED
|
||||
else:
|
||||
this.station_link['text'] = ''
|
||||
station_link_common(data, this)
|
||||
# Do *NOT* set 'url' here, as it's set to a function that will call
|
||||
# through correctly. We don't want a static string.
|
||||
this.station_link.update_idletasks()
|
||||
|
Loading…
x
Reference in New Issue
Block a user