mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-13 15:57:14 +03:00
Merge branch 'develop' into enhancement/2203/add-global-exception-handling
This commit is contained in:
commit
44f809f9c5
@ -20,6 +20,7 @@ import subprocess
|
||||
import sys
|
||||
import threading
|
||||
import webbrowser
|
||||
import tempfile
|
||||
from os import chdir, environ, path
|
||||
from time import localtime, strftime, time
|
||||
from typing import TYPE_CHECKING, Any, Literal
|
||||
@ -49,8 +50,6 @@ if __name__ == '__main__':
|
||||
# output until after this redirect is done, if needed.
|
||||
if getattr(sys, 'frozen', False):
|
||||
# By default py2exe tries to write log to dirname(sys.executable) which fails when installed
|
||||
import tempfile
|
||||
|
||||
# unbuffered not allowed for text in python3, so use `1 for line buffering
|
||||
log_file_path = path.join(tempfile.gettempdir(), f'{appname}.log')
|
||||
sys.stdout = sys.stderr = open(log_file_path, mode='wt', buffering=1) # Do NOT use WITH here.
|
||||
@ -634,7 +633,8 @@ class AppWindow:
|
||||
self.help_menu.add_command(command=lambda: self.updater.check_for_updates()) # Check for Updates...
|
||||
# About E:D Market Connector
|
||||
self.help_menu.add_command(command=lambda: not self.HelpAbout.showing and self.HelpAbout(self.w))
|
||||
self.help_menu.add_command(command=prefs.help_open_log_folder) # Open Log Folder
|
||||
logfile_loc = pathlib.Path(tempfile.gettempdir()) / appname
|
||||
self.help_menu.add_command(command=lambda: prefs.open_folder(logfile_loc)) # Open Log Folder
|
||||
|
||||
self.menubar.add_cascade(menu=self.help_menu)
|
||||
if sys.platform == 'win32':
|
||||
|
@ -38,7 +38,7 @@ if sys.platform == 'win32':
|
||||
import ctypes
|
||||
from ctypes.wintypes import BOOL, HWND, LPARAM, LPWSTR
|
||||
|
||||
from watchdog.events import FileCreatedEvent, FileSystemEventHandler
|
||||
from watchdog.events import FileSystemEventHandler, FileSystemEvent
|
||||
from watchdog.observers import Observer
|
||||
from watchdog.observers.api import BaseObserver
|
||||
|
||||
@ -60,7 +60,7 @@ else:
|
||||
FileSystemEventHandler = object # dummy
|
||||
if TYPE_CHECKING:
|
||||
# this isn't ever used, but this will make type checking happy
|
||||
from watchdog.events import FileCreatedEvent
|
||||
from watchdog.events import FileSystemEvent
|
||||
from watchdog.observers import Observer
|
||||
from watchdog.observers.api import BaseObserver
|
||||
|
||||
@ -346,7 +346,7 @@ class EDLogs(FileSystemEventHandler):
|
||||
"""
|
||||
return bool(self.thread and self.thread.is_alive())
|
||||
|
||||
def on_created(self, event: 'FileCreatedEvent') -> None:
|
||||
def on_created(self, event: 'FileSystemEvent') -> None:
|
||||
"""Watchdog callback when, e.g. client (re)started."""
|
||||
if not event.is_directory and self._RE_LOGFILE.search(basename(event.src_path)):
|
||||
|
||||
|
@ -550,23 +550,6 @@ def journal_entry( # noqa: C901, CCR001
|
||||
|
||||
# Ship change
|
||||
if event_name == 'Loadout' and this.shipswap:
|
||||
cur_ship = {
|
||||
'shipType': state['ShipType'],
|
||||
'shipGameID': state['ShipID'],
|
||||
'shipName': state['ShipName'], # Can be None
|
||||
'shipIdent': state['ShipIdent'], # Can be None
|
||||
'isCurrentShip': True,
|
||||
}
|
||||
|
||||
if state['HullValue']:
|
||||
cur_ship['shipHullValue'] = state['HullValue']
|
||||
|
||||
if state['ModulesValue']:
|
||||
cur_ship['shipModulesValue'] = state['ModulesValue']
|
||||
|
||||
cur_ship['shipRebuyCost'] = state['Rebuy']
|
||||
new_add_event('setCommanderShip', entry['timestamp'], cur_ship)
|
||||
|
||||
this.loadout = make_loadout(state)
|
||||
new_add_event('setCommanderShipLoadout', entry['timestamp'], this.loadout)
|
||||
this.shipswap = False
|
||||
@ -854,7 +837,7 @@ def journal_entry( # noqa: C901, CCR001
|
||||
for ship in this.fleet:
|
||||
new_add_event('setCommanderShip', entry['timestamp'], ship)
|
||||
# Loadout
|
||||
if event_name == 'Loadout' and not this.newsession:
|
||||
if event_name == 'Loadout':
|
||||
loadout = make_loadout(state)
|
||||
if this.loadout != loadout:
|
||||
this.loadout = loadout
|
||||
@ -868,6 +851,26 @@ def journal_entry( # noqa: C901, CCR001
|
||||
|
||||
new_add_event('setCommanderShipLoadout', entry['timestamp'], this.loadout)
|
||||
|
||||
cur_ship = {
|
||||
'shipType': state['ShipType'],
|
||||
'shipGameID': state['ShipID'],
|
||||
'shipName': state['ShipName'], # Can be None
|
||||
'shipIdent': state['ShipIdent'], # Can be None
|
||||
'isCurrentShip': True,
|
||||
'shipMaxJumpRange': entry['MaxJumpRange'],
|
||||
'shipCargoCapacity': entry['CargoCapacity']
|
||||
}
|
||||
if state['HullValue']:
|
||||
cur_ship['shipHullValue'] = state['HullValue']
|
||||
|
||||
if state['ModulesValue']:
|
||||
cur_ship['shipModulesValue'] = state['ModulesValue']
|
||||
|
||||
if state['Rebuy']:
|
||||
cur_ship['shipRebuyCost'] = state['Rebuy']
|
||||
|
||||
new_add_event('setCommanderShip', entry['timestamp'], cur_ship)
|
||||
|
||||
# Stored modules
|
||||
if event_name == 'StoredModules':
|
||||
items = {mod['StorageSlot']: mod for mod in entry['Items']} # Impose an order
|
||||
|
23
prefs.py
23
prefs.py
@ -8,7 +8,6 @@ import pathlib
|
||||
import sys
|
||||
import tempfile
|
||||
import tkinter as tk
|
||||
import webbrowser
|
||||
from os import system
|
||||
from os.path import expanduser, expandvars, join, normpath
|
||||
from tkinter import colorchooser as tkColorChooser # type: ignore # noqa: N812
|
||||
@ -40,14 +39,21 @@ logger = get_main_logger()
|
||||
|
||||
def help_open_log_folder() -> None:
|
||||
"""Open the folder logs are stored in."""
|
||||
logfile_loc = pathlib.Path(tempfile.gettempdir())
|
||||
logfile_loc /= f'{appname}'
|
||||
logger.warning(
|
||||
DeprecationWarning("This function is deprecated, use open_log_folder instead. "
|
||||
"This function will be removed in 6.0 or later")
|
||||
)
|
||||
open_folder(pathlib.Path(tempfile.gettempdir()) / appname)
|
||||
|
||||
|
||||
def open_folder(file: pathlib.Path) -> None:
|
||||
"""Open the given file in the OS file explorer."""
|
||||
if sys.platform.startswith('win'):
|
||||
# On Windows, use the "start" command to open the folder
|
||||
system(f'start "" "{logfile_loc}"')
|
||||
system(f'start "" "{file}"')
|
||||
elif sys.platform.startswith('linux'):
|
||||
# On Linux, use the "xdg-open" command to open the folder
|
||||
system(f'xdg-open "{logfile_loc}"')
|
||||
system(f'xdg-open "{file}"')
|
||||
|
||||
|
||||
class PrefsVersion:
|
||||
@ -296,6 +302,9 @@ class PreferencesDialog(tk.Toplevel):
|
||||
):
|
||||
self.geometry(f"+{position.left}+{position.top}")
|
||||
|
||||
# Set Log Directory
|
||||
self.logfile_loc = pathlib.Path(tempfile.gettempdir()) / appname
|
||||
|
||||
def __setup_output_tab(self, root_notebook: ttk.Notebook) -> None:
|
||||
output_frame = nb.Frame(root_notebook)
|
||||
output_frame.columnconfigure(0, weight=1)
|
||||
@ -623,7 +632,7 @@ class PreferencesDialog(tk.Toplevel):
|
||||
config_frame,
|
||||
# LANG: Label on button used to open a filesystem folder
|
||||
text=tr.tl('Open Log Folder'), # Button that opens a folder in Explorer/Finder
|
||||
command=lambda: help_open_log_folder()
|
||||
command=lambda: open_folder(self.logfile_loc)
|
||||
).grid(column=2, padx=self.PADX, pady=0, sticky=tk.NSEW, row=cur_row)
|
||||
|
||||
# Big spacer
|
||||
@ -884,7 +893,7 @@ class PreferencesDialog(tk.Toplevel):
|
||||
plugins_frame,
|
||||
# LANG: Label on button used to open a filesystem folder
|
||||
text=tr.tl('Open'), # Button that opens a folder in Explorer/Finder
|
||||
command=lambda: webbrowser.open(f'file:///{config.plugin_dir_path}')
|
||||
command=lambda: open_folder(config.plugin_dir_path)
|
||||
).grid(column=1, padx=self.PADX, pady=self.PADY, sticky=tk.N, row=cur_row)
|
||||
|
||||
enabled_plugins = list(filter(lambda x: x.folder and x.module, plug.PLUGINS))
|
||||
|
@ -1,5 +1,5 @@
|
||||
requests==2.31.0
|
||||
pillow==10.3.0
|
||||
watchdog==3.0.0
|
||||
watchdog==4.0.0
|
||||
infi.systray==0.1.12; sys_platform == 'win32'
|
||||
semantic-version==2.10.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user