mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-15 00:30:33 +03:00
[1173] Right-Click Provider Options
This commit is contained in:
parent
4a1a107e03
commit
c8f2b6018c
@ -515,13 +515,13 @@ class AppWindow:
|
|||||||
self.cmdr_label = tk.Label(frame, name='cmdr_label')
|
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, name='ship_label')
|
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', popup_copy=True)
|
||||||
self.suit_label = tk.Label(frame, name='suit_label')
|
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, name='system_label')
|
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, name='station_label')
|
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', popup_copy=True)
|
||||||
# system and station text is set/updated by the 'provider' plugins
|
# system and station text is set/updated by the 'provider' plugins
|
||||||
# edsm and inara. Look for:
|
# edsm and inara. Look for:
|
||||||
#
|
#
|
||||||
@ -1627,7 +1627,7 @@ class AppWindow:
|
|||||||
hotkeymgr.play_bad()
|
hotkeymgr.play_bad()
|
||||||
|
|
||||||
def shipyard_url(self, shipname: str) -> str | None:
|
def shipyard_url(self, shipname: str) -> str | None:
|
||||||
"""Despatch a ship URL to the configured handler."""
|
"""Dispatch a ship URL to the configured handler."""
|
||||||
if not (loadout := monitor.ship()):
|
if not (loadout := monitor.ship()):
|
||||||
logger.warning('No ship loadout, aborting.')
|
logger.warning('No ship loadout, aborting.')
|
||||||
return ''
|
return ''
|
||||||
@ -1654,13 +1654,13 @@ class AppWindow:
|
|||||||
return f'file://localhost/{file_name}'
|
return f'file://localhost/{file_name}'
|
||||||
|
|
||||||
def system_url(self, system: str) -> str | None:
|
def system_url(self, system: str) -> str | None:
|
||||||
"""Despatch a system URL to the configured handler."""
|
"""Dispatch a system URL to the configured handler."""
|
||||||
return plug.invoke(
|
return plug.invoke(
|
||||||
config.get_str('system_provider', default='EDSM'), 'EDSM', 'system_url', monitor.state['SystemName']
|
config.get_str('system_provider', default='EDSM'), 'EDSM', 'system_url', monitor.state['SystemName']
|
||||||
)
|
)
|
||||||
|
|
||||||
def station_url(self, station: str) -> str | None:
|
def station_url(self, station: str) -> str | None:
|
||||||
"""Despatch a station URL to the configured handler."""
|
"""Dispatch a station URL to the configured handler."""
|
||||||
return plug.invoke(
|
return plug.invoke(
|
||||||
config.get_str('station_provider', default='EDSM'), 'EDSM', 'station_url',
|
config.get_str('station_provider', default='EDSM'), 'EDSM', 'station_url',
|
||||||
monitor.state['SystemName'], monitor.state['StationName']
|
monitor.state['SystemName'], monitor.state['StationName']
|
||||||
|
@ -782,3 +782,6 @@
|
|||||||
|
|
||||||
/* myNotebook.py: Can't Paste Images or Files in Text; */
|
/* myNotebook.py: Can't Paste Images or Files in Text; */
|
||||||
"Cannot paste non-text content." = "Cannot paste non-text content.";
|
"Cannot paste non-text content." = "Cannot paste non-text content.";
|
||||||
|
|
||||||
|
/* ttkHyperlinkLabel.py: Open Element In Selected Provider; */
|
||||||
|
"Open in {URL}" = "Open in {URL}";
|
@ -19,14 +19,17 @@ In addition to standard ttk.Label arguments, takes the following arguments:
|
|||||||
May be imported by plugins
|
May be imported by plugins
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
from functools import partial
|
||||||
import sys
|
import sys
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
import webbrowser
|
import webbrowser
|
||||||
from tkinter import font as tk_font
|
from tkinter import font as tk_font
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
import plug
|
||||||
|
from config import config, logger
|
||||||
from l10n import translations as tr
|
from l10n import translations as tr
|
||||||
|
from monitor import monitor
|
||||||
|
|
||||||
|
|
||||||
class HyperlinkLabel(tk.Label or ttk.Label): # type: ignore
|
class HyperlinkLabel(tk.Label or ttk.Label): # type: ignore
|
||||||
@ -64,6 +67,57 @@ class HyperlinkLabel(tk.Label or ttk.Label): # type: ignore
|
|||||||
text=kw.get('text'),
|
text=kw.get('text'),
|
||||||
font=kw.get('font', ttk.Style().lookup('TLabel', 'font')))
|
font=kw.get('font', ttk.Style().lookup('TLabel', 'font')))
|
||||||
|
|
||||||
|
# Add Menu Options
|
||||||
|
self.plug_options = kw.pop('plug_options', None)
|
||||||
|
self.name = kw.get('name', None)
|
||||||
|
if self.name == 'ship' and not bool(config.get_int("use_alt_shipyard_open")):
|
||||||
|
self.menu.add_separator()
|
||||||
|
for url in plug.provides('shipyard_url'):
|
||||||
|
self.menu.add_command(
|
||||||
|
label=tr.tl("Open in {URL}").format(URL=url), # LANG: Open Element In Selected Provider
|
||||||
|
command=partial(self.open_shipyard, url)
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.name == 'station':
|
||||||
|
self.menu.add_separator()
|
||||||
|
for url in plug.provides('station_url'):
|
||||||
|
self.menu.add_command(
|
||||||
|
label=tr.tl("Open in {URL}").format(URL=url), # LANG: Open Element In Selected Provider
|
||||||
|
command=partial(self.open_station, url)
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.name == 'system':
|
||||||
|
self.menu.add_separator()
|
||||||
|
for url in plug.provides('system_url'):
|
||||||
|
self.menu.add_command(
|
||||||
|
label=tr.tl("Open in {URL}").format(URL=url), # LANG: Open Element In Selected Provider
|
||||||
|
command=partial(self.open_system, url)
|
||||||
|
)
|
||||||
|
|
||||||
|
def open_shipyard(self, url: str):
|
||||||
|
"""Open the Current Ship Loadout in the Selected Provider."""
|
||||||
|
if loadout := monitor.ship():
|
||||||
|
opener = plug.invoke(url, 'EDSY', 'shipyard_url', loadout, monitor.is_beta)
|
||||||
|
if opener:
|
||||||
|
return webbrowser.open(opener)
|
||||||
|
logger.warning('No ship loadout, aborting.')
|
||||||
|
return ''
|
||||||
|
|
||||||
|
def open_system(self, url: str):
|
||||||
|
"""Open the Current System in the Selected Provider."""
|
||||||
|
opener = plug.invoke(url, 'EDSM', 'system_url', monitor.state['SystemName'])
|
||||||
|
if opener:
|
||||||
|
return webbrowser.open(opener)
|
||||||
|
|
||||||
|
def open_station(self, url: str):
|
||||||
|
"""Open the Current Station in the Selected Provider."""
|
||||||
|
opener = plug.invoke(
|
||||||
|
url, 'EDSM', 'station_url',
|
||||||
|
monitor.state['SystemName'], monitor.state['StationName']
|
||||||
|
)
|
||||||
|
if opener:
|
||||||
|
return webbrowser.open(opener)
|
||||||
|
|
||||||
def configure( # noqa: CCR001
|
def configure( # noqa: CCR001
|
||||||
self, cnf: dict[str, Any] | None = None, **kw: Any
|
self, cnf: dict[str, Any] | None = None, **kw: Any
|
||||||
) -> dict[str, tuple[str, str, str, Any, Any]] | None:
|
) -> dict[str, tuple[str, str, str, Any, Any]] | None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user