We need config and session data. config is what the user changes. Only read by the app. session is what the app remembers. Read and written by the app.
135 lines
4.0 KiB
Python
135 lines
4.0 KiB
Python
import logging
|
|
import signal
|
|
|
|
from PyQt6 import QtCore
|
|
from PyQt6.QtWidgets import *
|
|
from PyQt6.QtCore import *
|
|
from PyQt6.QtGui import *
|
|
import sys
|
|
|
|
from aboutdialog import AboutDialog
|
|
from ravenui import RavenUI
|
|
from settings import Settings
|
|
from settingsstore import SettingsStore
|
|
from tabs import Tabs
|
|
|
|
MAX_LINE_LENGTH = 4096
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
log = logging.getLogger("main")
|
|
|
|
|
|
class MainWindow(QMainWindow):
|
|
def __init__(self, *args, **kwargs):
|
|
super(MainWindow, self).__init__(*args, **kwargs)
|
|
|
|
self.settings = SettingsStore.load()
|
|
self.setWindowTitle(self.tr("RavenLog"))
|
|
self.setGeometry(0, 0, 640, 480)
|
|
self.setDockNestingEnabled(True)
|
|
|
|
self.tabs = Tabs(self.settings)
|
|
self.tabs.create_tab("/home/andi/ws/performanceDb/data/production/logs_2018-09-06_2018-09-06.csv")
|
|
self.tabs.create_tab("/home/andi/ws/performanceDb/data/production/vapbdcom.csv")
|
|
self.tabs.create_tab("/home/andi/ws/ravenlog/example.log")
|
|
self.tabs.create_tab("/var/log/syslog")
|
|
|
|
self.setCentralWidget(self.tabs)
|
|
# self.main_tool_bar = self.create_main_tool_bar()
|
|
# self.addToolBar(self.main_tool_bar)
|
|
self.setStatusBar(QStatusBar(self))
|
|
self.setMenuBar(self.create_menu_bar())
|
|
|
|
def create_main_tool_bar(self):
|
|
result = QToolBar("main toolbar")
|
|
return result
|
|
|
|
def update_font_size(self, font_size):
|
|
self.settings.font_size(int(font_size))
|
|
self.tabs.update()
|
|
|
|
def create_menu_bar(self) -> QMenuBar:
|
|
menu_bar = QMenuBar()
|
|
|
|
menu_bar.addMenu(self.file_menu())
|
|
menu_bar.addMenu(self.help_menu())
|
|
|
|
return menu_bar
|
|
|
|
def file_menu(self) -> QMenu:
|
|
file_menu = QMenu(self.tr("File", "name of the file menu"), self)
|
|
|
|
open_file = QAction(self.tr("Open..."), self)
|
|
open_file.triggered.connect(self._open_file)
|
|
|
|
close_action = QAction(self.tr("Close", "menu item to close the application"), self)
|
|
close_action.triggered.connect(self.destruct)
|
|
|
|
file_menu.addAction(open_file)
|
|
file_menu.addAction(close_action)
|
|
return file_menu
|
|
|
|
def help_menu(self) -> QMenu:
|
|
help_menu = QMenu(self.tr("Help", "name of the help menu"), self)
|
|
|
|
about_action = QAction(self.tr("About"), self)
|
|
about_action.triggered.connect(self._open_about_dialog)
|
|
help_menu.addAction(about_action)
|
|
|
|
return help_menu
|
|
|
|
def _open_about_dialog(self):
|
|
dialog = AboutDialog()
|
|
dialog.exec()
|
|
|
|
def _open_file(self) -> None:
|
|
dialog = QFileDialog(self)
|
|
(selected_file, _filter) = dialog.getOpenFileName(caption=self.tr("Open File"))
|
|
self.tabs.create_tab(selected_file)
|
|
|
|
def closeEvent(self, event):
|
|
self.destruct()
|
|
|
|
def destruct(self):
|
|
self.tabs.destruct()
|
|
self.close()
|
|
SettingsStore.save(self.settings)
|
|
|
|
|
|
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)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app = QApplication(sys.argv)
|
|
app.setWindowIcon(QIcon("icon6.png"))
|
|
|
|
# translator = QTranslator()
|
|
# if translator.load(QLocale("de"), "messages_de.ts"):
|
|
# app.installTranslator(translator)
|
|
|
|
# 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)
|
|
|
|
window = MainWindow()
|
|
RavenUI.window = window
|
|
window.show()
|
|
|
|
signal.signal(signal.SIGINT, stop_signal)
|
|
signal.signal(signal.SIGTERM, stop_signal)
|
|
|
|
app.exec()
|