mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-04 01:21:03 +03:00
Merge pull request #1791 from EDCD/enhancement/ui/name-widgets
UI: Properly name main widgets & put each plugin in its own Frame
This commit is contained in:
commit
7b8130ba35
@ -523,20 +523,21 @@ class AppWindow(object):
|
|||||||
frame.grid(sticky=tk.NSEW)
|
frame.grid(sticky=tk.NSEW)
|
||||||
frame.columnconfigure(1, weight=1)
|
frame.columnconfigure(1, weight=1)
|
||||||
|
|
||||||
self.cmdr_label = tk.Label(frame)
|
self.cmdr_label = tk.Label(frame, name='cmdr_label')
|
||||||
self.cmdr = tk.Label(frame, compound=tk.RIGHT, anchor=tk.W, name='cmdr')
|
self.cmdr = tk.Label(frame, compound=tk.RIGHT, anchor=tk.W, name='cmdr')
|
||||||
self.ship_label = tk.Label(frame)
|
self.ship_label = tk.Label(frame, name='ship_label')
|
||||||
self.ship = HyperlinkLabel(frame, compound=tk.RIGHT, url=self.shipyard_url, name='ship')
|
self.ship = HyperlinkLabel(frame, compound=tk.RIGHT, url=self.shipyard_url, name='ship')
|
||||||
self.suit_label = tk.Label(frame)
|
self.suit_label = tk.Label(frame, name='suit_label')
|
||||||
self.suit = tk.Label(frame, compound=tk.RIGHT, anchor=tk.W, name='suit')
|
self.suit = tk.Label(frame, compound=tk.RIGHT, anchor=tk.W, name='suit')
|
||||||
self.system_label = tk.Label(frame)
|
self.system_label = tk.Label(frame, name='system_label')
|
||||||
self.system = HyperlinkLabel(frame, compound=tk.RIGHT, url=self.system_url, popup_copy=True, name='system')
|
self.system = HyperlinkLabel(frame, compound=tk.RIGHT, url=self.system_url, popup_copy=True, name='system')
|
||||||
self.station_label = tk.Label(frame)
|
self.station_label = tk.Label(frame, name='station_label')
|
||||||
self.station = HyperlinkLabel(frame, compound=tk.RIGHT, url=self.station_url, name='station')
|
self.station = HyperlinkLabel(frame, compound=tk.RIGHT, url=self.station_url, name='station')
|
||||||
# system and station text is set/updated by the 'provider' plugins
|
# system and station text is set/updated by the 'provider' plugins
|
||||||
# eddb, edsm and inara. Look for:
|
# eddb, edsm and inara. Look for:
|
||||||
#
|
#
|
||||||
# parent.children['system'] / parent.children['station']
|
# parent.nametowidget(f".{appname.lower()}.system")
|
||||||
|
# parent.nametowidget(f".{appname.lower()}.station")
|
||||||
|
|
||||||
ui_row = 1
|
ui_row = 1
|
||||||
|
|
||||||
@ -560,10 +561,26 @@ class AppWindow(object):
|
|||||||
self.station.grid(row=ui_row, column=1, sticky=tk.EW)
|
self.station.grid(row=ui_row, column=1, sticky=tk.EW)
|
||||||
ui_row += 1
|
ui_row += 1
|
||||||
|
|
||||||
|
plugin_no = 0
|
||||||
for plugin in plug.PLUGINS:
|
for plugin in plug.PLUGINS:
|
||||||
appitem = plugin.get_app(frame)
|
# Per plugin separator
|
||||||
|
plugin_sep = tk.Frame(
|
||||||
|
frame, highlightthickness=1, name=f"plugin_hr_{plugin_no + 1}"
|
||||||
|
)
|
||||||
|
# Per plugin frame, for it to use as its parent for own widgets
|
||||||
|
plugin_frame = tk.Frame(
|
||||||
|
frame,
|
||||||
|
name=f"plugin_{plugin_no + 1}"
|
||||||
|
)
|
||||||
|
appitem = plugin.get_app(plugin_frame)
|
||||||
if appitem:
|
if appitem:
|
||||||
tk.Frame(frame, highlightthickness=1).grid(columnspan=2, sticky=tk.EW) # separator
|
plugin_no += 1
|
||||||
|
plugin_sep.grid(columnspan=2, sticky=tk.EW)
|
||||||
|
ui_row = frame.grid_size()[1]
|
||||||
|
plugin_frame.grid(
|
||||||
|
row=ui_row, columnspan=2, sticky=tk.NSEW
|
||||||
|
)
|
||||||
|
plugin_frame.columnconfigure(1, weight=1)
|
||||||
if isinstance(appitem, tuple) and len(appitem) == 2:
|
if isinstance(appitem, tuple) and len(appitem) == 2:
|
||||||
ui_row = frame.grid_size()[1]
|
ui_row = frame.grid_size()[1]
|
||||||
appitem[0].grid(row=ui_row, column=0, sticky=tk.W)
|
appitem[0].grid(row=ui_row, column=0, sticky=tk.W)
|
||||||
@ -572,9 +589,26 @@ class AppWindow(object):
|
|||||||
else:
|
else:
|
||||||
appitem.grid(columnspan=2, sticky=tk.EW)
|
appitem.grid(columnspan=2, sticky=tk.EW)
|
||||||
|
|
||||||
|
else:
|
||||||
|
# This plugin didn't provide any UI, so drop the frames
|
||||||
|
plugin_frame.destroy()
|
||||||
|
plugin_sep.destroy()
|
||||||
|
|
||||||
# LANG: Update button in main window
|
# LANG: Update button in main window
|
||||||
self.button = ttk.Button(frame, text=_('Update'), width=28, default=tk.ACTIVE, state=tk.DISABLED)
|
self.button = ttk.Button(
|
||||||
self.theme_button = tk.Label(frame, width=32 if sys.platform == 'darwin' else 28, state=tk.DISABLED)
|
frame,
|
||||||
|
name='update_button',
|
||||||
|
text=_('Update'),
|
||||||
|
width=28,
|
||||||
|
default=tk.ACTIVE,
|
||||||
|
state=tk.DISABLED
|
||||||
|
)
|
||||||
|
self.theme_button = tk.Label(
|
||||||
|
frame,
|
||||||
|
name='themed_update_button',
|
||||||
|
width=32 if sys.platform == 'darwin' else 28,
|
||||||
|
state=tk.DISABLED
|
||||||
|
)
|
||||||
|
|
||||||
ui_row = frame.grid_size()[1]
|
ui_row = frame.grid_size()[1]
|
||||||
self.button.grid(row=ui_row, columnspan=2, sticky=tk.NSEW)
|
self.button.grid(row=ui_row, columnspan=2, sticky=tk.NSEW)
|
||||||
@ -685,11 +719,15 @@ class AppWindow(object):
|
|||||||
theme.register(self.help_menu)
|
theme.register(self.help_menu)
|
||||||
|
|
||||||
# Alternate title bar and menu for dark theme
|
# Alternate title bar and menu for dark theme
|
||||||
self.theme_menubar = tk.Frame(frame)
|
self.theme_menubar = tk.Frame(frame, name="alternate_menubar")
|
||||||
self.theme_menubar.columnconfigure(2, weight=1)
|
self.theme_menubar.columnconfigure(2, weight=1)
|
||||||
theme_titlebar = tk.Label(self.theme_menubar, text=applongname,
|
theme_titlebar = tk.Label(
|
||||||
image=self.theme_icon, cursor='fleur',
|
self.theme_menubar,
|
||||||
anchor=tk.W, compound=tk.LEFT)
|
name="alternate_titlebar",
|
||||||
|
text=applongname,
|
||||||
|
image=self.theme_icon, cursor='fleur',
|
||||||
|
anchor=tk.W, compound=tk.LEFT
|
||||||
|
)
|
||||||
theme_titlebar.grid(columnspan=3, padx=2, sticky=tk.NSEW)
|
theme_titlebar.grid(columnspan=3, padx=2, sticky=tk.NSEW)
|
||||||
self.drag_offset: Tuple[Optional[int], Optional[int]] = (None, None)
|
self.drag_offset: Tuple[Optional[int], Optional[int]] = (None, None)
|
||||||
theme_titlebar.bind('<Button-1>', self.drag_start)
|
theme_titlebar.bind('<Button-1>', self.drag_start)
|
||||||
@ -722,7 +760,7 @@ class AppWindow(object):
|
|||||||
tk.Frame(self.theme_menubar, highlightthickness=1).grid(columnspan=5, padx=self.PADX, sticky=tk.EW)
|
tk.Frame(self.theme_menubar, highlightthickness=1).grid(columnspan=5, padx=self.PADX, sticky=tk.EW)
|
||||||
theme.register(self.theme_minimize) # images aren't automatically registered
|
theme.register(self.theme_minimize) # images aren't automatically registered
|
||||||
theme.register(self.theme_close)
|
theme.register(self.theme_close)
|
||||||
self.blank_menubar = tk.Frame(frame)
|
self.blank_menubar = tk.Frame(frame, name="blank_menubar")
|
||||||
tk.Label(self.blank_menubar).grid()
|
tk.Label(self.blank_menubar).grid()
|
||||||
tk.Label(self.blank_menubar).grid()
|
tk.Label(self.blank_menubar).grid()
|
||||||
tk.Frame(self.blank_menubar, height=2).grid()
|
tk.Frame(self.blank_menubar, height=2).grid()
|
||||||
|
@ -1138,7 +1138,7 @@ _ = functools.partial(l10n.Translations.translate, context=__file__)
|
|||||||
Wrap each string that needs translating with the `_()` function, e.g.:
|
Wrap each string that needs translating with the `_()` function, e.g.:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
status["text"] = _('Happy!') # Main window status
|
somewidget["text"] = _("Happy!")
|
||||||
```
|
```
|
||||||
|
|
||||||
If you display localized strings in EDMarketConnector's main window you should
|
If you display localized strings in EDMarketConnector's main window you should
|
||||||
|
@ -50,7 +50,7 @@ import EDMCLogging
|
|||||||
import killswitch
|
import killswitch
|
||||||
import plug
|
import plug
|
||||||
from companion import CAPIData
|
from companion import CAPIData
|
||||||
from config import config
|
from config import appname, config
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from tkinter import Tk
|
from tkinter import Tk
|
||||||
@ -131,12 +131,14 @@ def plugin_app(parent: 'Tk'):
|
|||||||
:param parent: The tk parent to place our widgets into.
|
:param parent: The tk parent to place our widgets into.
|
||||||
:return: See PLUGINS.md#display
|
: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 = None
|
||||||
this.system_address = None
|
this.system_address = None
|
||||||
this.station = None
|
this.station = None
|
||||||
this.station_marketid = None # Frontier MarketID
|
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
|
this.station_link['popup_copy'] = lambda x: x != this.STATION_UNDOCKED
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ import killswitch
|
|||||||
import myNotebook as nb # noqa: N813
|
import myNotebook as nb # noqa: N813
|
||||||
import plug
|
import plug
|
||||||
from companion import CAPIData, category_map
|
from companion import CAPIData, category_map
|
||||||
from config import applongname, appversion_nobuild, config, debug_senders, user_agent
|
from config import applongname, appname, appversion_nobuild, config, debug_senders, user_agent
|
||||||
from EDMCLogging import get_main_logger
|
from EDMCLogging import get_main_logger
|
||||||
from monitor import monitor
|
from monitor import monitor
|
||||||
from myNotebook import Frame
|
from myNotebook import Frame
|
||||||
@ -382,7 +382,7 @@ class EDDNSender:
|
|||||||
logger.info(text)
|
logger.info(text)
|
||||||
return
|
return
|
||||||
|
|
||||||
self.eddn.parent.children['status']['text'] = text
|
self.eddn.parent.nametowidget(f".{appname.lower()}.status")['text'] = text
|
||||||
|
|
||||||
def send_message(self, msg: str) -> bool:
|
def send_message(self, msg: str) -> bool:
|
||||||
"""
|
"""
|
||||||
@ -2501,7 +2501,7 @@ def cmdr_data(data: CAPIData, is_beta: bool) -> Optional[str]: # noqa: CCR001
|
|||||||
this.commodities = this.outfitting = this.shipyard = None
|
this.commodities = this.outfitting = this.shipyard = None
|
||||||
this.marketId = data['lastStarport']['id']
|
this.marketId = data['lastStarport']['id']
|
||||||
|
|
||||||
status = this.parent.children['status']
|
status = this.parent.nametowidget(f".{appname.lower()}.status")
|
||||||
old_status = status['text']
|
old_status = status['text']
|
||||||
if not old_status:
|
if not old_status:
|
||||||
status['text'] = _('Sending data to EDDN...') # LANG: Status text shown while attempting to send data
|
status['text'] = _('Sending data to EDDN...') # LANG: Status text shown while attempting to send data
|
||||||
|
@ -49,7 +49,7 @@ import myNotebook
|
|||||||
import myNotebook as nb # noqa: N813
|
import myNotebook as nb # noqa: N813
|
||||||
import plug
|
import plug
|
||||||
from companion import CAPIData
|
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 edmc_data import DEBUG_WEBSERVER_HOST, DEBUG_WEBSERVER_PORT
|
||||||
from EDMCLogging import get_main_logger
|
from EDMCLogging import get_main_logger
|
||||||
from ttkHyperlinkLabel import HyperlinkLabel
|
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.
|
:param parent: The tk parent to place our widgets into.
|
||||||
:return: See PLUGINS.md#display
|
: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.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:
|
def plugin_stop() -> None:
|
||||||
@ -622,7 +628,6 @@ entry: {entry!r}'''
|
|||||||
):
|
):
|
||||||
# LANG: The Inara API only accepts Live galaxy data, not Legacy galaxy data
|
# LANG: The Inara API only accepts Live galaxy data, not Legacy galaxy data
|
||||||
logger.info("EDSM only accepts Live galaxy data")
|
logger.info("EDSM only accepts Live galaxy data")
|
||||||
# this.parent.children['status']['text'] =
|
|
||||||
this.legacy_galaxy_last_notified = datetime.now(timezone.utc)
|
this.legacy_galaxy_last_notified = datetime.now(timezone.utc)
|
||||||
return _("EDSM only accepts Live galaxy data")
|
return _("EDSM only accepts Live galaxy data")
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ import myNotebook as nb # noqa: N813
|
|||||||
import plug
|
import plug
|
||||||
import timeout_session
|
import timeout_session
|
||||||
from companion import CAPIData
|
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 EDMCLogging import get_main_logger
|
||||||
from monitor import monitor
|
from monitor import monitor
|
||||||
from ttkHyperlinkLabel import HyperlinkLabel
|
from ttkHyperlinkLabel import HyperlinkLabel
|
||||||
@ -218,8 +218,10 @@ def plugin_start3(plugin_dir: str) -> str:
|
|||||||
def plugin_app(parent: tk.Tk) -> None:
|
def plugin_app(parent: tk.Tk) -> None:
|
||||||
"""Plugin UI setup Hook."""
|
"""Plugin UI setup Hook."""
|
||||||
this.parent = parent
|
this.parent = parent
|
||||||
this.system_link = parent.children['system'] # system label in main window
|
# system label in main window
|
||||||
this.station_link = parent.children['station'] # station 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('<<InaraLocation>>', update_location)
|
||||||
this.system_link.bind_all('<<InaraShip>>', update_ship)
|
this.system_link.bind_all('<<InaraShip>>', update_ship)
|
||||||
|
|
||||||
@ -380,7 +382,6 @@ def journal_entry( # noqa: C901, CCR001
|
|||||||
):
|
):
|
||||||
# LANG: The Inara API only accepts Live galaxy data, not Legacy galaxy data
|
# LANG: The Inara API only accepts Live galaxy data, not Legacy galaxy data
|
||||||
logger.info(_("Inara only accepts Live galaxy data"))
|
logger.info(_("Inara only accepts Live galaxy data"))
|
||||||
# this.parent.children['status']['text'] =
|
|
||||||
this.legacy_galaxy_last_notified = datetime.now(timezone.utc)
|
this.legacy_galaxy_last_notified = datetime.now(timezone.utc)
|
||||||
return _("Inara only accepts Live galaxy data")
|
return _("Inara only accepts Live galaxy data")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user