prepare to add command line options

This commit is contained in:
2022-08-28 14:31:55 +02:00
parent bfe8ae460e
commit 33b79d6935
2 changed files with 30 additions and 20 deletions

View File

@@ -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()

View File

@@ -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):
</svg>""")
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)