Skip to content

Commit

Permalink
Merge branch 'develop' into enhancement/1805/additional-prototyping
Browse files Browse the repository at this point in the history
  • Loading branch information
Rixxan authored Jul 22, 2024
2 parents c0deeeb + 2adb440 commit b74524a
Show file tree
Hide file tree
Showing 30 changed files with 583 additions and 248 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ build
dist.win32/
dist.*

# Ignore generated ChangeLog.html file
# Ignore generated ChangeLog files
ChangeLog.html
/scripts/script_output

# Ignore files
dump
Expand Down
12 changes: 12 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ This is the master changelog for Elite Dangerous Market Connector. Entries are
in the source (not distributed with the Windows installer) for the
currently used version.
---
Release 5.11.2
===

This release fixes a bug where minimizing to the system tray could cause the program to not un-minimize.

**Changes and Enhancements**
* Updated Translations
* Added a developer utility to help speed up changelog development

**Bug Fixes**
* Fixed a bug where minimizing to the system tray could cause the program to not un-minimize.

Release 5.11.1
===

Expand Down
11 changes: 7 additions & 4 deletions EDMC.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import os
import queue
import sys
from pathlib import Path
from time import sleep, time
from typing import TYPE_CHECKING, Any

Expand Down Expand Up @@ -212,22 +213,24 @@ def main(): # noqa: C901, CCR001
# system, chances are its the current locale, and not utf-8. Otherwise if it was copied, its probably
# utf8. Either way, try the system FIRST because reading something like cp1251 in UTF-8 results in garbage
# but the reverse results in an exception.
json_file = os.path.abspath(args.j)
json_file = Path(args.j).resolve()
try:
with open(json_file) as file_handle:
data = json.load(file_handle)
except UnicodeDecodeError:
with open(json_file, encoding='utf-8') as file_handle:
data = json.load(file_handle)
config.set('querytime', int(os.path.getmtime(args.j)))
file_path = Path(args.j)
modification_time = file_path.stat().st_mtime
config.set('querytime', int(modification_time))

else:
# Get state from latest Journal file
logger.debug('Getting state from latest journal file')
try:
monitor.currentdir = config.get_str('journaldir', default=config.default_journal_dir)
monitor.currentdir = Path(config.get_str('journaldir', default=config.default_journal_dir))
if not monitor.currentdir:
monitor.currentdir = config.default_journal_dir
monitor.currentdir = config.default_journal_dir_path

logger.debug(f'logdir = "{monitor.currentdir}"')
logfile = monitor.journal_newest_filename(monitor.currentdir)
Expand Down
21 changes: 9 additions & 12 deletions EDMCLogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
To utilise logging in a 'found' (third-party) plugin, include this:
import os
from pathlib import Path
import logging
plugin_name = os.path.basename(os.path.dirname(__file__))
# Retrieve the name of the plugin folder
plugin_name = Path(__file__).resolve().parent.name
# Set up logger with hierarchical name including appname and plugin_name
# plugin_name here *must* be the name of the folder the plugin resides in
# See, plug.py:load_plugins()
logger = logging.getLogger(f'{appname}.{plugin_name}')
"""
from __future__ import annotations
Expand All @@ -41,7 +42,6 @@
import logging.handlers
import os
import pathlib
import tempfile
import warnings
from contextlib import suppress
from fnmatch import fnmatch
Expand All @@ -51,9 +51,7 @@
from time import gmtime
from traceback import print_exc
from typing import TYPE_CHECKING, cast

import config as config_mod
from config import appcmdname, appname, config
from config import appcmdname, appname, config, trace_on

# TODO: Tests:
#
Expand Down Expand Up @@ -104,7 +102,7 @@


def _trace_if(self: logging.Logger, condition: str, message: str, *args, **kwargs) -> None:
if any(fnmatch(condition, p) for p in config_mod.trace_on):
if any(fnmatch(condition, p) for p in trace_on):
self._log(logging.TRACE, message, args, **kwargs) # type: ignore # we added it
return

Expand Down Expand Up @@ -184,8 +182,7 @@ def __init__(self, logger_name: str, loglevel: int | str = _default_loglevel):
# We want the files in %TEMP%\{appname}\ as {logger_name}-debug.log and
# rotated versions.
# This is {logger_name} so that EDMC.py logs to a different file.
logfile_rotating = pathlib.Path(tempfile.gettempdir())
logfile_rotating /= f'{appname}'
logfile_rotating = pathlib.Path(config.app_dir_path / 'logs')
logfile_rotating.mkdir(exist_ok=True)
logfile_rotating /= f'{logger_name}-debug.log'

Expand Down Expand Up @@ -489,8 +486,8 @@ def munge_module_name(cls, frame_info: inspect.Traceback, module_name: str) -> s
:return: The munged module_name.
"""
file_name = pathlib.Path(frame_info.filename).expanduser()
plugin_dir = pathlib.Path(config.plugin_dir_path).expanduser()
internal_plugin_dir = pathlib.Path(config.internal_plugin_dir_path).expanduser()
plugin_dir = config.plugin_dir_path.expanduser()
internal_plugin_dir = config.internal_plugin_dir_path.expanduser()
# Find the first parent called 'plugins'
plugin_top = file_name
while plugin_top and plugin_top.name != '':
Expand Down
17 changes: 9 additions & 8 deletions EDMCSystemProfiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
import webbrowser
import platform
import sys
from os import chdir, environ, path
from os import chdir, environ
import pathlib
import logging
from journal_lock import JournalLock

if getattr(sys, "frozen", False):
# Under py2exe sys.path[0] is the executable name
if sys.platform == "win32":
chdir(path.dirname(sys.path[0]))
chdir(pathlib.Path(sys.path[0]).parent)
# Allow executable to be invoked from any cwd
environ["TCL_LIBRARY"] = path.join(path.dirname(sys.path[0]), "lib", "tcl")
environ["TK_LIBRARY"] = path.join(path.dirname(sys.path[0]), "lib", "tk")
environ['TCL_LIBRARY'] = str(pathlib.Path(sys.path[0]).parent / 'lib' / 'tcl')
environ['TK_LIBRARY'] = str(pathlib.Path(sys.path[0]).parent / 'lib' / 'tk')

else:
# We still want to *try* to have CWD be where the main script is, even if
Expand All @@ -44,11 +44,12 @@ def get_sys_report(config: config.AbstractConfig) -> str:
plt = platform.uname()
locale.setlocale(locale.LC_ALL, "")
lcl = locale.getlocale()
monitor.currentdir = config.get_str(
monitor.currentdir = pathlib.Path(config.get_str(
"journaldir", default=config.default_journal_dir
)
)
if not monitor.currentdir:
monitor.currentdir = config.default_journal_dir
monitor.currentdir = config.default_journal_dir_path
try:
logfile = monitor.journal_newest_filename(monitor.currentdir)
if logfile is None:
Expand Down Expand Up @@ -115,12 +116,12 @@ def main() -> None:
root.withdraw() # Hide the window initially to calculate the dimensions
try:
icon_image = tk.PhotoImage(
file=path.join(cur_config.respath_path, "io.edcd.EDMarketConnector.png")
file=cur_config.respath_path / "io.edcd.EDMarketConnector.png"
)

root.iconphoto(True, icon_image)
except tk.TclError:
root.iconbitmap(path.join(cur_config.respath_path, "EDMarketConnector.ico"))
root.iconbitmap(cur_config.respath_path / "EDMarketConnector.ico")

sys_report = get_sys_report(cur_config)

Expand Down
45 changes: 30 additions & 15 deletions EDMarketConnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
import sys
import threading
import webbrowser
import tempfile
from os import chdir, environ, path
from os import chdir, environ
from time import localtime, strftime, time
from typing import TYPE_CHECKING, Any, Literal
from constants import applongname, appname, protocolhandler_redirect
Expand All @@ -32,26 +31,29 @@
if getattr(sys, 'frozen', False):
# Under py2exe sys.path[0] is the executable name
if sys.platform == 'win32':
chdir(path.dirname(sys.path[0]))
os.chdir(pathlib.Path(sys.path[0]).parent)
# Allow executable to be invoked from any cwd
environ['TCL_LIBRARY'] = path.join(path.dirname(sys.path[0]), 'lib', 'tcl')
environ['TK_LIBRARY'] = path.join(path.dirname(sys.path[0]), 'lib', 'tk')
environ['TCL_LIBRARY'] = str(pathlib.Path(sys.path[0]).parent / 'lib' / 'tcl')
environ['TK_LIBRARY'] = str(pathlib.Path(sys.path[0]).parent / 'lib' / 'tk')

else:
# We still want to *try* to have CWD be where the main script is, even if
# not frozen.
chdir(pathlib.Path(__file__).parent)


# config will now cause an appname logger to be set up, so we need the
# console redirect before this
if __name__ == '__main__':
# Keep this as the very first code run to be as sure as possible of no
# output until after this redirect is done, if needed.
if getattr(sys, 'frozen', False):
from config import config
# By default py2exe tries to write log to dirname(sys.executable) which fails when installed
# unbuffered not allowed for text in python3, so use `1 for line buffering
log_file_path = path.join(tempfile.gettempdir(), f'{appname}.log')
log_file_path = pathlib.Path(config.app_dir_path / 'logs')
log_file_path.mkdir(exist_ok=True)
log_file_path /= f'{appname}.log'

sys.stdout = sys.stderr = open(log_file_path, mode='wt', buffering=1) # Do NOT use WITH here.
# TODO: Test: Make *sure* this redirect is working, else py2exe is going to cause an exit popup

Expand Down Expand Up @@ -439,7 +441,7 @@ def __init__(self, master: tk.Tk): # noqa: C901, CCR001 # TODO - can possibly f
if sys.platform == 'win32':
from simplesystray import SysTrayIcon

def open_window(systray: 'SysTrayIcon') -> None:
def open_window(systray: 'SysTrayIcon', *args) -> None:
self.w.deiconify()

menu_options = (("Open", None, open_window),)
Expand All @@ -453,8 +455,8 @@ def open_window(systray: 'SysTrayIcon') -> None:
self.w.wm_iconbitmap(default='EDMarketConnector.ico')

else:
self.w.tk.call('wm', 'iconphoto', self.w, '-default',
tk.PhotoImage(file=path.join(config.respath_path, 'io.edcd.EDMarketConnector.png')))
image_path = config.respath_path / 'io.edcd.EDMarketConnector.png'
self.w.tk.call('wm', 'iconphoto', self.w, '-default', image=tk.PhotoImage(file=image_path))

# TODO: Export to files and merge from them in future ?
self.theme_icon = tk.PhotoImage(
Expand Down Expand Up @@ -604,7 +606,7 @@ def open_window(systray: 'SysTrayIcon') -> None:
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))
logfile_loc = pathlib.Path(tempfile.gettempdir()) / appname
logfile_loc = pathlib.Path(config.app_dir_path / 'logs')
self.help_menu.add_command(command=lambda: prefs.open_folder(logfile_loc)) # Open Log Folder
self.help_menu.add_command(command=lambda: prefs.help_open_system_profiler(self)) # Open Log Folde

Expand Down Expand Up @@ -831,9 +833,20 @@ def postprefs(self, dologin: bool = True, **postargs):
)
update_msg = update_msg.replace('\\n', '\n')
update_msg = update_msg.replace('\\r', '\r')
stable_popup = tk.messagebox.askyesno(title=title, message=update_msg, parent=postargs.get('Parent'))
stable_popup = tk.messagebox.askyesno(title=title, message=update_msg)
if stable_popup:
webbrowser.open("https://github.com/edCD/eDMarketConnector/releases/latest")
webbrowser.open("https://github.com/EDCD/eDMarketConnector/releases/latest")
if postargs.get('Restart_Req'):
# LANG: Text of Notification Popup for EDMC Restart
restart_msg = tr.tl('A restart of EDMC is required. EDMC will now restart.')
restart_box = tk.messagebox.Message(
title=tr.tl('Restart Required'), # LANG: Title of Notification Popup for EDMC Restart
message=restart_msg,
type=tk.messagebox.OK
)
restart_box.show()
if restart_box:
app.onexit(restart=True)

def set_labels(self):
"""Set main window labels, e.g. after language change."""
Expand Down Expand Up @@ -1625,7 +1638,7 @@ def shipyard_url(self, shipname: str) -> str | None:
# Avoid file length limits if possible
provider = config.get_str('shipyard_provider', default='EDSY')
target = plug.invoke(provider, 'EDSY', 'shipyard_url', loadout, monitor.is_beta)
file_name = path.join(config.app_dir_path, "last_shipyard.html")
file_name = config.app_dir_path / "last_shipyard.html"

with open(file_name, 'w') as f:
f.write(SHIPYARD_HTML_TEMPLATE.format(
Expand Down Expand Up @@ -1837,7 +1850,7 @@ def exit_tray(self, systray: 'SysTrayIcon') -> None:
)
exit_thread.start()

def onexit(self, event=None) -> None:
def onexit(self, event=None, restart: bool = False) -> None:
"""Application shutdown procedure."""
if sys.platform == 'win32':
shutdown_thread = threading.Thread(
Expand Down Expand Up @@ -1900,6 +1913,8 @@ def onexit(self, event=None) -> None:
self.w.destroy()

logger.info('Done.')
if restart:
os.execv(sys.executable, ['python'] + sys.argv)

def drag_start(self, event) -> None:
"""Initiate dragging the window."""
Expand Down
17 changes: 14 additions & 3 deletions L10n/en.template
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,11 @@
/* prefs.py: Label for location of third-party plugins folder; In files: prefs.py:908; */
"Plugins folder" = "Plugins folder";

/* prefs.py: Label on button used to open a filesystem folder; In files: prefs.py:915; */
"Open" = "Open";
/* prefs.py: Label on button used to open the Plugin Folder; */
"Open Plugins Folder" = "Open Plugins Folder";

/* prefs.py: Selecting the Location of the Plugin Directory on the Filesystem; */
"Plugin Directory Location" = "Plugin Directory Location";

/* prefs.py: Tip/label about how to disable plugins; In files: prefs.py:923; */
"Tip: You can disable a plugin by{CR}adding '{EXT}' to its folder name" = "Tip: You can disable a plugin by{CR}adding '{EXT}' to its folder name";
Expand Down Expand Up @@ -804,12 +807,20 @@
/* EDMarketConnector.py: Inform the user the Update Track has changed; */
"Update Track Changed to {TRACK}" = "Update Track Changed to {TRACK}";


/* EDMarketConnector.py: Inform User of Beta -> Stable Transition Risks; */
"Update track changed to Stable from Beta. You will no longer receive Beta updates. You will stay on your current Beta version until the next Stable release.\r\n\r\nYou can manually revert to the latest Stable version. To do so, you must download and install the latest Stable version manually. Note that this may introduce bugs or break completely if downgrading between major versions with significant changes.\r\n\r\nDo you want to open GitHub to download the latest release?" = "Update track changed to Stable from Beta. You will no longer receive Beta updates. You will stay on your current Beta version until the next Stable release.\r\n\r\nYou can manually revert to the latest Stable version. To do so, you must download and install the latest Stable version manually. Note that this may introduce bugs or break completely if downgrading between major versions with significant changes.\r\n\r\nDo you want to open GitHub to download the latest release?";

/* EDMarketConnector.py: Title of Notification Popup for EDMC Restart; */
"Restart Required" = "Restart Required";

/* EDMarketConnector.py: Text of Notification Popup for EDMC Restart; */
"A restart of EDMC is required. EDMC will now restart." = "A restart of EDMC is required. EDMC will now restart.";

/* myNotebook.py: Can't Paste Images or Files in Text; */
"Cannot paste non-text content." = "Cannot paste non-text content.";

/* ttkHyperlinkLabel.py: Open Element In Selected Provider; */
"Open in {URL}" = "Open in {URL}";

/* ttkHyperlinkLabel.py: Copy the Inara SLEF Format of the active ship to the clipboard; */
"Copy Inara SLEF" = "Copy Inara SLEF";
Loading

0 comments on commit b74524a

Please sign in to comment.