1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-13 07:47:14 +03:00

core plugins: Use nametowidget() to find system/station widgets

As we're experimenting with per-plugin frames up a level `parent.children`
would need to be `parent.parent.children`, but this way it will Just Work
without knowledge of the hierarchy.
This commit is contained in:
Athanasius 2022-12-31 16:27:22 +00:00
parent ce1303e9e6
commit f2de70bad6
No known key found for this signature in database
GPG Key ID: 772697E181BB2767
3 changed files with 19 additions and 9 deletions

View File

@ -50,7 +50,7 @@ import EDMCLogging
import killswitch
import plug
from companion import CAPIData
from config import config
from config import appname, config
if TYPE_CHECKING:
from tkinter import Tk
@ -131,12 +131,14 @@ def plugin_app(parent: 'Tk'):
:param parent: The tk parent to place our widgets into.
:return: See PLUGINS.md#display
"""
this.system_link = parent.children['system'] # system label in main window
# system label in main window
this.system_link = parent.nametowidget(f".{appname.lower()}.system")
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
# station label in main window
this.station_link = parent.nametowidget(f".{appname.lower()}.station")
this.station_link['popup_copy'] = lambda x: x != this.STATION_UNDOCKED

View File

@ -49,7 +49,7 @@ import myNotebook
import myNotebook as nb # noqa: N813
import plug
from companion import CAPIData
from config import applongname, appversion, config, debug_senders, user_agent
from config import applongname, appname, appversion, config, debug_senders, user_agent
from edmc_data import DEBUG_WEBSERVER_HOST, DEBUG_WEBSERVER_PORT
from EDMCLogging import get_main_logger
from ttkHyperlinkLabel import HyperlinkLabel
@ -250,9 +250,15 @@ def plugin_app(parent: tk.Tk) -> None:
:param parent: The tk parent to place our widgets into.
:return: See PLUGINS.md#display
"""
this.system_link = parent.children['system'] # system label in main window
# system label in main window
this.system_link = parent.nametowidget(f".{appname.lower()}.system")
if this.system_link is None:
logger.error("Couldn't look up system widget!!!")
return
this.system_link.bind_all('<<EDSMStatus>>', update_status)
this.station_link = parent.children['station'] # station label in main window
# station label in main window
this.station_link = parent.nametowidget(f".{appname.lower()}.station")
def plugin_stop() -> None:

View File

@ -43,7 +43,7 @@ import myNotebook as nb # noqa: N813
import plug
import timeout_session
from companion import CAPIData
from config import applongname, appversion, config, debug_senders
from config import applongname, appname, appversion, config, debug_senders
from EDMCLogging import get_main_logger
from monitor import monitor
from ttkHyperlinkLabel import HyperlinkLabel
@ -218,8 +218,10 @@ def plugin_start3(plugin_dir: str) -> str:
def plugin_app(parent: tk.Tk) -> None:
"""Plugin UI setup Hook."""
this.parent = parent
this.system_link = parent.children['system'] # system label in main window
this.station_link = parent.children['station'] # station label in main window
# system label in main window
this.system_link = parent.nametowidget(f".{appname.lower()}.system")
# station label in main window
this.station_link = parent.nametowidget(f".{appname.lower()}.station")
this.system_link.bind_all('<<InaraLocation>>', update_location)
this.system_link.bind_all('<<InaraShip>>', update_ship)