75 lines
2.0 KiB
Python
75 lines
2.0 KiB
Python
import logging
|
|
import signal
|
|
from PySide6 import QtCore
|
|
from PySide6.QtWidgets import QApplication
|
|
from PySide6.QtCore import QTimer
|
|
import sys
|
|
import constants
|
|
from src import install
|
|
from src.pluginregistry import PluginRegistry
|
|
import gettext
|
|
from src.ui.icon import Icon
|
|
|
|
__version__ = '0.2.0'
|
|
|
|
gettext.install('krowlog', 'locale')
|
|
|
|
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:
|
|
log.info("Terminate signal received. %s", signum)
|
|
QtCore.QCoreApplication.quit()
|
|
except Exception:
|
|
log.exception("Exception occurred while terminating")
|
|
sys.exit(1)
|
|
sys.exit(0)
|
|
|
|
|
|
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
|
|
# Forcing an empty lambda to be executed periodically gives
|
|
# control back to python and allows python to react to signals
|
|
timer = QTimer()
|
|
timer.timeout.connect(lambda: None)
|
|
timer.start(100)
|
|
|
|
|
|
def init_plugins():
|
|
PluginRegistry.load_plugin("KrowLogPlugin")
|
|
PluginRegistry.load_plugin("OpenFilePlugin")
|
|
PluginRegistry.load_plugin("LogFilePlugin")
|
|
PluginRegistry.load_plugin("NotesPlugin")
|
|
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")
|
|
|
|
register_signal_handler()
|
|
|
|
app.exec()
|