From 33b79d6935816002dcea4c60227cfe79b4620c85 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Sun, 28 Aug 2022 14:31:55 +0200 Subject: [PATCH] prepare to add command line options --- krowlog.py | 38 ++++++++++++++++++++------------------ src/install.py | 12 ++++++++++-- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/krowlog.py b/krowlog.py index 339bc84..aea26b1 100644 --- a/krowlog.py +++ b/krowlog.py @@ -18,6 +18,11 @@ logging.basicConfig(level=logging.INFO) log = logging.getLogger("main") +def register_signal_handler(): + signal.signal(signal.SIGINT, stop_signal) + signal.signal(signal.SIGTERM, stop_signal) + + def stop_signal(signum, _stackframe): """ Handle terminate signal """ try: @@ -29,21 +34,7 @@ def stop_signal(signum, _stackframe): sys.exit(0) -if __name__ == "__main__": - app = QApplication(sys.argv) - app.setWindowIcon(Icon(constants.krow_icon)) # works only for Linux - - # make icon appear in Windows - # see https://stackoverflow.com/questions/1551605/how-to-set-applications-taskbar-icon-in-windows-7/1552105#1552105 - if sys.platform == 'win32' or sys.platform == 'cygwin': - myappid = 'krowlog' # arbitrary string - import ctypes - - ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid) - - # install stuff, e.g. a desktop file - install.install() - +def apply_time_workaround(): # workaround to make signals work in QT apps. # They do not work out of the box, because the main thread # is running in C++ code once app.exec() is executed @@ -53,7 +44,8 @@ if __name__ == "__main__": timer.timeout.connect(lambda: None) timer.start(100) - # init plugins + +def init_plugins(): PluginRegistry.load_plugin("KrowLogPlugin") PluginRegistry.load_plugin("OpenFilePlugin") PluginRegistry.load_plugin("LogFilePlugin") @@ -61,12 +53,22 @@ if __name__ == "__main__": PluginRegistry.load_plugin("TimeDiffPlugin") PluginRegistry.load_plugin("FilesBrowserPlugin") + +if __name__ == "__main__": + app = QApplication(sys.argv) + app.setWindowIcon(Icon(constants.krow_icon)) # works only for Linux (but only X11, not Wayland) + + # install stuff, e.g. a desktop file, set icon on Windows + install.install() + + apply_time_workaround() + + init_plugins() window = PluginRegistry.execute_single("create_main_window") window.show() PluginRegistry.execute("after_start") - signal.signal(signal.SIGINT, stop_signal) - signal.signal(signal.SIGTERM, stop_signal) + register_signal_handler() app.exec() diff --git a/src/install.py b/src/install.py index e788c56..5bae0d4 100644 --- a/src/install.py +++ b/src/install.py @@ -5,8 +5,7 @@ from pathlib import Path def install(): if sys.platform == 'win32' or sys.platform == 'cygwin': - # nothing to do - pass + _windows_set_icon() else: if _is_executable(): _linux_install_desktop_file() @@ -83,3 +82,12 @@ def _linux_install_icon_to_path(path: Path): """) path.write_text(svg, "utf8") pass + + +def _windows_set_icon(): + # make icon appear in Windows + # see https://stackoverflow.com/questions/1551605/how-to-set-applications-taskbar-icon-in-windows-7/1552105#1552105 + if sys.platform == 'win32' or sys.platform == 'cygwin': + myappid = 'krowlog' # arbitrary string + import ctypes + ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)