1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-13 07:47:14 +03:00

Added appearance config option and implementation for minimize to tray on close functionality

This commit is contained in:
Sayak Mukhopadhyay 2021-04-26 01:22:01 +05:30
parent e4e97f4642
commit df31aed6c5
4 changed files with 45 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import locale
import pathlib
import re
import sys
import threading
import webbrowser
from builtins import object, str
from os import chdir, environ
@ -16,6 +17,7 @@ from os.path import dirname, join
from sys import platform
from time import localtime, strftime, time
from typing import TYPE_CHECKING, Optional, Tuple
from infi.systray import SysTrayIcon
# Have this as early as possible for people running EDMarketConnector.exe
# from cmd.exe or a bat file or similar. Else they might not be in the correct
@ -330,6 +332,18 @@ class AppWindow(object):
self.prefsdialog = None
self.only_tray_close = 0
def open_window(systray):
self.only_tray_close = 2
shutdown_thread = threading.Thread(target=systray.shutdown)
shutdown_thread.setDaemon(True)
shutdown_thread.start()
self.w.deiconify()
menu_options = (("Open", None, open_window),)
self.systray = SysTrayIcon("EDMarketConnector.ico", applongname, menu_options, on_quit=self.exit_tray)
plug.load_plugins(master)
if platform != 'darwin':
@ -1373,6 +1387,23 @@ class AppWindow(object):
def onexit(self, event=None) -> None:
"""Application shutdown procedure."""
value = bool(config.get_int('close_system_tray'))
if value:
self.w.withdraw()
self.systray.start()
else:
self.exit()
def exit_tray(self, systray):
if self.only_tray_close > 0:
self.only_tray_close -= 1
else:
exit_thread = threading.Thread(target=self.exit)
exit_thread.setDaemon(True)
exit_thread.start()
def exit(self):
config.set_shutdown() # Signal we're in shutdown now.
# http://core.tcl.tk/tk/tktview/c84f660833546b1b84e7

View File

@ -19,6 +19,9 @@
/* Appearance setting. [EDMarketConnector.py] */
"Always on top" = "Always on top";
/* Appearance setting. [EDMarketConnector.py] */
"Close to system tray" = "Close to system tray";
/* CQC rank. [stats.py] */
"Amateur" = "Amateur";

View File

@ -636,6 +636,7 @@ class PreferencesDialog(tk.Toplevel):
# Appearance theme and language setting
self.lang = tk.StringVar(value=self.languages.get(config.get_str('language'), _('Default')))
self.always_ontop = tk.BooleanVar(value=bool(config.get_int('always_ontop')))
self.close_system_tray = tk.BooleanVar(value=bool(config.get_int('close_system_tray')))
self.theme = tk.IntVar(value=config.get_int('theme'))
self.theme_colors = [config.get_str('dark_text'), config.get_str('dark_highlight')]
self.theme_prompts = [
@ -791,6 +792,14 @@ class PreferencesDialog(tk.Toplevel):
)
self.ontop_button.grid(columnspan=3, padx=self.BUTTONX, sticky=tk.W, row=row.get()) # Appearance setting
self.system_tray_button = nb.Checkbutton(
appearance_frame,
text=_('Close to system tray'),
variable=self.close_system_tray,
command=self.themevarchanged
)
self.system_tray_button.grid(columnspan=3, padx=self.BUTTONX, sticky=tk.W, row=row.get()) # Appearance setting
nb.Label(appearance_frame).grid(sticky=tk.W) # big spacer
notebook.add(appearance_frame, text=_('Appearance')) # Tab heading in settings
@ -1163,6 +1172,7 @@ class PreferencesDialog(tk.Toplevel):
config.set('ui_scale', self.ui_scale.get())
config.set('ui_transparency', self.transparency.get())
config.set('always_ontop', self.always_ontop.get())
config.set('close_system_tray', self.close_system_tray.get())
config.set('theme', self.theme.get())
config.set('dark_text', self.theme_colors[0])
config.set('dark_highlight', self.theme_colors[1])

View File

@ -1,6 +1,7 @@
certifi==2020.12.5
requests==2.25.1
watchdog==2.0.3
infi.systray==0.1.12
# argh==0.26.2 watchdog dep
# pyyaml==5.3.1 watchdog dep
semantic-version==2.8.5