prepare to add command line options
This commit is contained in:
38
krowlog.py
38
krowlog.py
@@ -18,6 +18,11 @@ logging.basicConfig(level=logging.INFO)
|
|||||||
log = logging.getLogger("main")
|
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):
|
def stop_signal(signum, _stackframe):
|
||||||
""" Handle terminate signal """
|
""" Handle terminate signal """
|
||||||
try:
|
try:
|
||||||
@@ -29,21 +34,7 @@ def stop_signal(signum, _stackframe):
|
|||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def apply_time_workaround():
|
||||||
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()
|
|
||||||
|
|
||||||
# workaround to make signals work in QT apps.
|
# workaround to make signals work in QT apps.
|
||||||
# They do not work out of the box, because the main thread
|
# They do not work out of the box, because the main thread
|
||||||
# is running in C++ code once app.exec() is executed
|
# is running in C++ code once app.exec() is executed
|
||||||
@@ -53,7 +44,8 @@ if __name__ == "__main__":
|
|||||||
timer.timeout.connect(lambda: None)
|
timer.timeout.connect(lambda: None)
|
||||||
timer.start(100)
|
timer.start(100)
|
||||||
|
|
||||||
# init plugins
|
|
||||||
|
def init_plugins():
|
||||||
PluginRegistry.load_plugin("KrowLogPlugin")
|
PluginRegistry.load_plugin("KrowLogPlugin")
|
||||||
PluginRegistry.load_plugin("OpenFilePlugin")
|
PluginRegistry.load_plugin("OpenFilePlugin")
|
||||||
PluginRegistry.load_plugin("LogFilePlugin")
|
PluginRegistry.load_plugin("LogFilePlugin")
|
||||||
@@ -61,12 +53,22 @@ if __name__ == "__main__":
|
|||||||
PluginRegistry.load_plugin("TimeDiffPlugin")
|
PluginRegistry.load_plugin("TimeDiffPlugin")
|
||||||
PluginRegistry.load_plugin("FilesBrowserPlugin")
|
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 = PluginRegistry.execute_single("create_main_window")
|
||||||
window.show()
|
window.show()
|
||||||
|
|
||||||
PluginRegistry.execute("after_start")
|
PluginRegistry.execute("after_start")
|
||||||
|
|
||||||
signal.signal(signal.SIGINT, stop_signal)
|
register_signal_handler()
|
||||||
signal.signal(signal.SIGTERM, stop_signal)
|
|
||||||
|
|
||||||
app.exec()
|
app.exec()
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
def install():
|
def install():
|
||||||
if sys.platform == 'win32' or sys.platform == 'cygwin':
|
if sys.platform == 'win32' or sys.platform == 'cygwin':
|
||||||
# nothing to do
|
_windows_set_icon()
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
if _is_executable():
|
if _is_executable():
|
||||||
_linux_install_desktop_file()
|
_linux_install_desktop_file()
|
||||||
@@ -83,3 +82,12 @@ def _linux_install_icon_to_path(path: Path):
|
|||||||
</svg>""")
|
</svg>""")
|
||||||
path.write_text(svg, "utf8")
|
path.write_text(svg, "utf8")
|
||||||
pass
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user