mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-08 05:20:03 +03:00
[2186] Additional Files
This commit is contained in:
parent
27093d8862
commit
57cd75e75e
@ -218,10 +218,6 @@ class JournalLock:
|
||||
if sys.platform == 'win32':
|
||||
self.attributes('-toolwindow', tk.TRUE)
|
||||
|
||||
elif sys.platform == 'darwin':
|
||||
# http://wiki.tcl.tk/13428
|
||||
parent.call('tk::unsupported::MacWindowStyle', 'style', self, 'utility')
|
||||
|
||||
self.resizable(tk.FALSE, tk.FALSE)
|
||||
|
||||
frame = ttk.Frame(self)
|
||||
|
@ -282,7 +282,7 @@ class EDDNSender:
|
||||
msg['header'] = {
|
||||
# We have to lie and say it's *this* version, but denote that
|
||||
# it might not actually be this version.
|
||||
'softwareName': f'{applongname} [{system() if sys.platform != "darwin" else "Mac OS"}]'
|
||||
'softwareName': f'{applongname} [{system()}]'
|
||||
' (legacy replay)',
|
||||
'softwareVersion': str(appversion_nobuild()),
|
||||
'uploaderID': cmdr,
|
||||
@ -1074,7 +1074,7 @@ class EDDN:
|
||||
gb = this.game_build
|
||||
|
||||
return {
|
||||
'softwareName': f'{applongname} [{system() if sys.platform != "darwin" else "Mac OS"}]',
|
||||
'softwareName': f'{applongname} [{system()}]',
|
||||
'softwareVersion': str(appversion_nobuild()),
|
||||
'uploaderID': this.cmdr_name,
|
||||
'gameversion': gv,
|
||||
|
63
protocol.py
63
protocol.py
@ -58,66 +58,7 @@ class GenericProtocolHandler:
|
||||
self.master.event_generate('<<CompanionAuthEvent>>', when="tail")
|
||||
|
||||
|
||||
if sys.platform == 'darwin' and getattr(sys, 'frozen', False): # noqa: C901 # its guarding ALL macos stuff.
|
||||
import struct
|
||||
|
||||
import objc # type: ignore
|
||||
from AppKit import NSAppleEventManager, NSObject # type: ignore
|
||||
|
||||
kInternetEventClass = kAEGetURL = struct.unpack('>l', b'GURL')[0] # noqa: N816 # API names
|
||||
keyDirectObject = struct.unpack('>l', b'----')[0] # noqa: N816 # API names
|
||||
|
||||
class DarwinProtocolHandler(GenericProtocolHandler):
|
||||
"""
|
||||
MacOS protocol handler implementation.
|
||||
|
||||
Uses macOS event stuff.
|
||||
"""
|
||||
|
||||
POLL = 100 # ms
|
||||
|
||||
def start(self, master: 'tkinter.Tk') -> None:
|
||||
"""Start Protocol Handler."""
|
||||
GenericProtocolHandler.start(self, master)
|
||||
self.lasturl: str | None = None
|
||||
self.eventhandler = EventHandler.alloc().init()
|
||||
|
||||
def poll(self) -> None:
|
||||
"""Poll event until URL is updated."""
|
||||
# No way of signalling to Tkinter from within the callback handler block that doesn't cause Python to crash,
|
||||
# so poll. TODO: Resolved?
|
||||
if self.lasturl and self.lasturl.startswith(self.redirect):
|
||||
self.event(self.lasturl)
|
||||
self.lasturl = None
|
||||
|
||||
class EventHandler(NSObject):
|
||||
"""Handle NSAppleEventManager IPC stuff."""
|
||||
|
||||
def init(self) -> None:
|
||||
"""
|
||||
Init method for handler.
|
||||
|
||||
(I'd assume this is related to the subclassing of NSObject for why its not __init__)
|
||||
"""
|
||||
self = objc.super(EventHandler, self).init()
|
||||
NSAppleEventManager.sharedAppleEventManager().setEventHandler_andSelector_forEventClass_andEventID_(
|
||||
self,
|
||||
'handleEvent:withReplyEvent:',
|
||||
kInternetEventClass,
|
||||
kAEGetURL
|
||||
)
|
||||
return self
|
||||
|
||||
def handleEvent_withReplyEvent_(self, event, replyEvent) -> None: # noqa: N802 N803 # Required to override
|
||||
"""Actual event handling from NSAppleEventManager."""
|
||||
protocolhandler.lasturl = parse.unquote(
|
||||
event.paramDescriptorForKeyword_(keyDirectObject).stringValue()
|
||||
).strip()
|
||||
|
||||
protocolhandler.master.after(DarwinProtocolHandler.POLL, protocolhandler.poll)
|
||||
|
||||
|
||||
elif (config.auth_force_edmc_protocol
|
||||
if (config.auth_force_edmc_protocol
|
||||
or (
|
||||
sys.platform == 'win32'
|
||||
and getattr(sys, 'frozen', False)
|
||||
@ -480,8 +421,6 @@ def get_handler_impl() -> Type[GenericProtocolHandler]:
|
||||
|
||||
:return: An instantiatable GenericProtocolHandler
|
||||
"""
|
||||
if sys.platform == 'darwin' and getattr(sys, 'frozen', False):
|
||||
return DarwinProtocolHandler # pyright: reportUnboundVariable=false
|
||||
|
||||
if (
|
||||
(sys.platform == 'win32' and config.auth_force_edmc_protocol)
|
||||
|
13
stats.py
13
stats.py
@ -374,7 +374,7 @@ class StatsResults(tk.Toplevel):
|
||||
self.transient(parent)
|
||||
|
||||
# position over parent
|
||||
if sys.platform != 'darwin' or parent.winfo_rooty() > 0: # http://core.tcl.tk/tk/tktview/c84f660833546b1b84e7
|
||||
if parent.winfo_rooty() > 0: # http://core.tcl.tk/tk/tktview/c84f660833546b1b84e7
|
||||
self.geometry(f"+{parent.winfo_rootx()}+{parent.winfo_rooty()}")
|
||||
|
||||
# remove decoration
|
||||
@ -382,10 +382,6 @@ class StatsResults(tk.Toplevel):
|
||||
if sys.platform == 'win32':
|
||||
self.attributes('-toolwindow', tk.TRUE)
|
||||
|
||||
elif sys.platform == 'darwin':
|
||||
# http://wiki.tcl.tk/13428
|
||||
parent.call('tk::unsupported::MacWindowStyle', 'style', self, 'utility')
|
||||
|
||||
frame = ttk.Frame(self)
|
||||
frame.grid(sticky=tk.NSEW)
|
||||
|
||||
@ -423,13 +419,6 @@ class StatsResults(tk.Toplevel):
|
||||
ttk.Frame(page).grid(pady=5) # bottom spacer
|
||||
notebook.add(page, text=_('Ships')) # LANG: Status dialog title
|
||||
|
||||
if sys.platform != 'darwin':
|
||||
buttonframe = ttk.Frame(frame)
|
||||
buttonframe.grid(padx=10, pady=(0, 10), sticky=tk.NSEW) # type: ignore # the tuple is supported
|
||||
buttonframe.columnconfigure(0, weight=1)
|
||||
ttk.Label(buttonframe).grid(row=0, column=0) # spacer
|
||||
ttk.Button(buttonframe, text='OK', command=self.destroy).grid(row=0, column=1, sticky=tk.E)
|
||||
|
||||
# wait for window to appear on screen before calling grab_set
|
||||
self.wait_visibility()
|
||||
self.grab_set()
|
||||
|
2
td.py
2
td.py
@ -32,7 +32,7 @@ def export(data: CAPIData) -> None:
|
||||
with open(data_path / data_filename, 'wb') as h:
|
||||
# Format described here: https://github.com/eyeonus/Trade-Dangerous/wiki/Price-Data
|
||||
h.write('#! trade.py import -\n'.encode('utf-8'))
|
||||
this_platform = "Mac OS" if sys.platform == 'darwin' else system()
|
||||
this_platform = system()
|
||||
cmdr_name = data['commander']['name'].strip()
|
||||
h.write(
|
||||
f'# Created by {applongname} {appversion()} on {this_platform} for Cmdr {cmdr_name}.\n'.encode('utf-8')
|
||||
|
@ -13,13 +13,7 @@ from EDMCLogging import get_main_logger
|
||||
|
||||
logger = get_main_logger()
|
||||
|
||||
if sys.platform == 'darwin':
|
||||
from Foundation import ( # type: ignore
|
||||
NSApplicationSupportDirectory, NSBundle, NSDocumentDirectory, NSSearchPathForDirectoriesInDomains,
|
||||
NSUserDefaults, NSUserDomainMask
|
||||
)
|
||||
|
||||
elif sys.platform == 'win32':
|
||||
if sys.platform == 'win32':
|
||||
import ctypes
|
||||
import uuid
|
||||
from ctypes.wintypes import DWORD, HANDLE, HKEY, LONG, LPCVOID, LPCWSTR
|
||||
@ -115,91 +109,7 @@ class OldConfig:
|
||||
OUT_EDDN_DELAY = 4096
|
||||
OUT_STATION_ANY = OUT_EDDN_SEND_STATION_DATA | OUT_MKT_TD | OUT_MKT_CSV
|
||||
|
||||
if sys.platform == 'darwin': # noqa: C901 # It's gating *all* the functions
|
||||
|
||||
def __init__(self):
|
||||
self.app_dir = join(
|
||||
NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, True)[0], appname
|
||||
)
|
||||
if not isdir(self.app_dir):
|
||||
mkdir(self.app_dir)
|
||||
|
||||
self.plugin_dir = join(self.app_dir, 'plugins')
|
||||
if not isdir(self.plugin_dir):
|
||||
mkdir(self.plugin_dir)
|
||||
|
||||
if getattr(sys, 'frozen', False):
|
||||
self.internal_plugin_dir = normpath(join(dirname(sys.executable), pardir, 'Library', 'plugins'))
|
||||
self.respath = normpath(join(dirname(sys.executable), pardir, 'Resources'))
|
||||
self.identifier = NSBundle.mainBundle().bundleIdentifier()
|
||||
|
||||
else:
|
||||
self.internal_plugin_dir = join(dirname(__file__), 'plugins')
|
||||
self.respath = dirname(__file__)
|
||||
# Don't use Python's settings if interactive
|
||||
self.identifier = f'uk.org.marginal.{appname.lower()}'
|
||||
NSBundle.mainBundle().infoDictionary()['CFBundleIdentifier'] = self.identifier
|
||||
|
||||
self.default_journal_dir: str | None = join(
|
||||
NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, True)[0],
|
||||
'Frontier Developments',
|
||||
'Elite Dangerous'
|
||||
)
|
||||
self.home = expanduser('~')
|
||||
|
||||
self.defaults = NSUserDefaults.standardUserDefaults()
|
||||
self.settings = dict(self.defaults.persistentDomainForName_(self.identifier) or {}) # make writeable
|
||||
|
||||
# Check out_dir exists
|
||||
if not self.get('outdir') or not isdir(str(self.get('outdir'))):
|
||||
self.set('outdir', NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, True)[0])
|
||||
|
||||
def get(self, key: str, default: None | list | str = None) -> None | list | str:
|
||||
"""Look up a string configuration value."""
|
||||
val = self.settings.get(key)
|
||||
if val is None:
|
||||
return default
|
||||
|
||||
if isinstance(val, str):
|
||||
return str(val)
|
||||
|
||||
if isinstance(val, list):
|
||||
return list(val) # make writeable
|
||||
|
||||
return default
|
||||
|
||||
def getint(self, key: str, default: int = 0) -> int:
|
||||
"""Look up an integer configuration value."""
|
||||
try:
|
||||
return int(self.settings.get(key, default)) # should already be int, but check by casting
|
||||
|
||||
except ValueError as e:
|
||||
logger.error(f"Failed to int({key=})", exc_info=e)
|
||||
return default
|
||||
|
||||
except Exception as e:
|
||||
logger.debug('The exception type is ...', exc_info=e)
|
||||
return default
|
||||
|
||||
def set(self, key: str, val: int | str | list) -> None:
|
||||
"""Set value on the specified configuration key."""
|
||||
self.settings[key] = val
|
||||
|
||||
def delete(self, key: str) -> None:
|
||||
"""Delete the specified configuration key."""
|
||||
self.settings.pop(key, None)
|
||||
|
||||
def save(self) -> None:
|
||||
"""Save current configuration to disk."""
|
||||
self.defaults.setPersistentDomain_forName_(self.settings, self.identifier)
|
||||
self.defaults.synchronize()
|
||||
|
||||
def close(self) -> None:
|
||||
"""Close the configuration."""
|
||||
self.save()
|
||||
self.defaults = None
|
||||
|
||||
elif sys.platform == 'win32':
|
||||
if sys.platform == 'win32':
|
||||
|
||||
def __init__(self):
|
||||
self.app_dir = join(known_folder_path(FOLDERID_LocalAppData), appname) # type: ignore
|
||||
|
21
theme.py
21
theme.py
@ -268,8 +268,7 @@ class _Theme:
|
||||
# (Mostly) system colors
|
||||
style = ttk.Style()
|
||||
self.current = {
|
||||
'background': (sys.platform == 'darwin' and 'systemMovableModalBackground' or
|
||||
style.lookup('TLabel', 'background')),
|
||||
'background': (style.lookup('TLabel', 'background')),
|
||||
'foreground': style.lookup('TLabel', 'foreground'),
|
||||
'activebackground': (sys.platform == 'win32' and 'SystemHighlight' or
|
||||
style.lookup('TLabel', 'background', ['active'])),
|
||||
@ -366,8 +365,6 @@ class _Theme:
|
||||
if 'bg' not in attribs:
|
||||
widget['background'] = self.current['background']
|
||||
widget['activebackground'] = self.current['activebackground']
|
||||
if sys.platform == 'darwin' and isinstance(widget, tk.Button):
|
||||
widget['highlightbackground'] = self.current['background']
|
||||
|
||||
if 'font' not in attribs:
|
||||
widget['font'] = self.current['font']
|
||||
@ -426,21 +423,7 @@ class _Theme:
|
||||
return # Don't need to mess with the window manager
|
||||
self.active = theme
|
||||
|
||||
if sys.platform == 'darwin':
|
||||
from AppKit import NSAppearance, NSApplication, NSMiniaturizableWindowMask, NSResizableWindowMask
|
||||
root.update_idletasks() # need main window to be created
|
||||
if theme == self.THEME_DEFAULT:
|
||||
appearance = NSAppearance.appearanceNamed_('NSAppearanceNameAqua')
|
||||
|
||||
else: # Dark (Transparent only on win32)
|
||||
appearance = NSAppearance.appearanceNamed_('NSAppearanceNameDarkAqua')
|
||||
|
||||
for window in NSApplication.sharedApplication().windows():
|
||||
window.setStyleMask_(window.styleMask() & ~(
|
||||
NSMiniaturizableWindowMask | NSResizableWindowMask)) # disable zoom
|
||||
window.setAppearance_(appearance)
|
||||
|
||||
elif sys.platform == 'win32':
|
||||
if sys.platform == 'win32':
|
||||
GWL_STYLE = -16 # noqa: N806 # ctypes
|
||||
WS_MAXIMIZEBOX = 0x00010000 # noqa: N806 # ctypes
|
||||
# tk8.5.9/win/tkWinWm.c:342
|
||||
|
24
update.py
24
update.py
@ -115,21 +115,6 @@ class Updater:
|
||||
|
||||
return
|
||||
|
||||
if sys.platform == 'darwin':
|
||||
import objc
|
||||
|
||||
try:
|
||||
objc.loadBundle(
|
||||
'Sparkle', globals(), join(dirname(sys.executable), os.pardir, 'Frameworks', 'Sparkle.framework')
|
||||
)
|
||||
# loadBundle presumably supplies `SUUpdater`
|
||||
self.updater = SUUpdater.sharedUpdater() # noqa: F821
|
||||
|
||||
except Exception:
|
||||
# can't load framework - not frozen or not included in app bundle?
|
||||
print_exc()
|
||||
self.updater = None
|
||||
|
||||
def set_automatic_updates_check(self, onoroff: bool) -> None:
|
||||
"""
|
||||
Set (Win)Sparkle to perform automatic update checks, or not.
|
||||
@ -142,9 +127,6 @@ class Updater:
|
||||
if sys.platform == 'win32' and self.updater:
|
||||
self.updater.win_sparkle_set_automatic_check_for_updates(onoroff)
|
||||
|
||||
if sys.platform == 'darwin' and self.updater:
|
||||
self.updater.SUEnableAutomaticChecks(onoroff)
|
||||
|
||||
def check_for_updates(self) -> None:
|
||||
"""Trigger the requisite method to check for an update."""
|
||||
if self.use_internal():
|
||||
@ -155,9 +137,6 @@ class Updater:
|
||||
elif sys.platform == 'win32' and self.updater:
|
||||
self.updater.win_sparkle_check_update_with_ui()
|
||||
|
||||
elif sys.platform == 'darwin' and self.updater:
|
||||
self.updater.checkForUpdates_(None)
|
||||
|
||||
def check_appcast(self) -> EDMCVersion | None:
|
||||
"""
|
||||
Manually (no Sparkle or WinSparkle) check the update_feed appcast file.
|
||||
@ -184,9 +163,6 @@ class Updater:
|
||||
|
||||
return None
|
||||
|
||||
if sys.platform == 'darwin':
|
||||
sparkle_platform = 'macos'
|
||||
|
||||
else:
|
||||
# For *these* purposes anything else is the same as 'windows', as
|
||||
# non-win32 would be running from source.
|
||||
|
Loading…
x
Reference in New Issue
Block a user