diff --git a/bigtext.py b/bigtext.py index 72ce294..325d438 100644 --- a/bigtext.py +++ b/bigtext.py @@ -20,6 +20,7 @@ from line import Line from logFileModel import LogFileModel import re +from ravenui import RavenUI from settings import Settings from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler @@ -136,7 +137,11 @@ class InnerBigText(QWidget): def wheelEvent(self, event: QWheelEvent): direction = 1 if event.angleDelta().y() < 0 else -1 if event.modifiers() == Qt.KeyboardModifier.ControlModifier: - self.model.settings.update_font_size(-direction) + # self.model.settings.update_font_size(-direction) + old_font_size = self.model.settings.getint('general', 'font_size') + new_font_size = old_font_size - direction + self.model.settings.set('general', 'font_size', str(new_font_size)) + RavenUI.update_ui() self.update() else: # print("wheel event fired :) %s" % (direction)) @@ -229,7 +234,8 @@ class InnerBigText(QWidget): def paintEvent(self, event: QPaintEvent) -> None: # print("paintEvent") painter = QPainter(self) - painter.setFont(self.model.settings.font()) + # painter.setFont(self.model.settings.font()) + painter.setFont(QFont("monospace", self.model.settings.getint('general', "font_size"))) painter.setPen(QColor(0, 0, 0)) self.update_font_metrics(painter) diff --git a/filterwidget.py b/filterwidget.py index 94dd437..e3051fa 100644 --- a/filterwidget.py +++ b/filterwidget.py @@ -10,6 +10,7 @@ from PyQt6.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLineEdit, QCheck from bigtext import BigText from logFileModel import LogFileModel +from ravenui import RavenUI class FilterTask(QRunnable): @@ -123,7 +124,7 @@ class FilterWidget(QWidget): self.filter_model.truncate() self.source_model.set_query_highlight() self.filter_model.set_query_highlight() - self.source_model.settings.callback_update_ui() + RavenUI.update_ui() def filter_changed(self): query = self.query_field.text() diff --git a/main.py b/main.py index c03b78b..d59515a 100644 --- a/main.py +++ b/main.py @@ -1,20 +1,16 @@ import logging -import os -import re import signal -import time from PyQt6 import QtCore -from PyQt6.lupdate import lupdate from PyQt6.QtWidgets import * from PyQt6.QtCore import * from PyQt6.QtGui import * import sys from aboutdialog import AboutDialog -from bigtext import BigText -from logFileModel import LogFileModel +from ravenui import RavenUI from settings import Settings +from settingsstore import SettingsStore from tabs import Tabs MAX_LINE_LENGTH = 4096 @@ -22,24 +18,25 @@ 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 = Settings(lambda : self.update()) + 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/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.main_tool_bar = self.create_main_tool_bar() + # self.addToolBar(self.main_tool_bar) self.setStatusBar(QStatusBar(self)) self.setMenuBar(self.create_menu_bar()) @@ -96,6 +93,7 @@ class MainWindow(QMainWindow): def destruct(self): self.tabs.destruct() self.close() + SettingsStore.save(self.settings) def stop_signal(signum, _stackframe): @@ -113,8 +111,8 @@ if __name__ == "__main__": app = QApplication(sys.argv) app.setWindowIcon(QIcon("icon6.png")) - #translator = QTranslator() - #if translator.load(QLocale("de"), "messages_de.ts"): + # translator = QTranslator() + # if translator.load(QLocale("de"), "messages_de.ts"): # app.installTranslator(translator) # workaround to make signals work in QT apps. @@ -128,6 +126,7 @@ if __name__ == "__main__": window = MainWindow() window.show() + RavenUI.window = window signal.signal(signal.SIGINT, stop_signal) signal.signal(signal.SIGTERM, stop_signal) diff --git a/ravenui.py b/ravenui.py new file mode 100644 index 0000000..1a8b3d6 --- /dev/null +++ b/ravenui.py @@ -0,0 +1,7 @@ +class RavenUI(): + # no type hint because of circular dependencies + window = None + + @staticmethod + def update_ui(): + RavenUI.window.update() diff --git a/settings.py b/settings.py index af11bb4..95d1c7b 100644 --- a/settings.py +++ b/settings.py @@ -1,29 +1,43 @@ +from configparser import ConfigParser from typing import Callable from PyQt6.QtGui import QFont +from ravenui import RavenUI + class Settings(): - def __init__(self, callback_update_ui: Callable[[], None]): - self.callback_update_ui = callback_update_ui - self.font_size(12) + def __init__(self, config: ConfigParser): + self.config = config + + def set(self, section: str, option: str, value: str): + return self.config.set(section, option, value) + + def get(self, section: str, option: str): + return self.config.get(section, option) + + def getint(self, section: str, option: str): + return self.config.getint(section, option) + + def getboolean(self, section: str, option: str): + return self.config.getboolean(section, option) @staticmethod def max_line_length(): return 4096 - def font(self) -> QFont: - return self._font + # def font(self) -> QFont: + # return self._font - def get_font_size(self) -> int: - return self._font_size + # def get_font_size(self) -> int: + # return self._font_size - def update_font_size(self, increment: int): - font_size = min(max(4, self._font_size + increment), 50) - self.font_size(font_size) + # def update_font_size(self, increment: int): + # font_size = min(max(4, self._font_size + increment), 50) + # self.font_size(font_size) - def font_size(self, font_size: int): - self._font_size = font_size - self._font = QFont("monospace", font_size) - self.callback_update_ui() \ No newline at end of file + # def font_size(self, font_size: int): + # self._font_size = font_size + # self._font = QFont("monospace", font_size) + # #RavenUI.update_ui() diff --git a/settingsstore.py b/settingsstore.py new file mode 100644 index 0000000..ded1ed1 --- /dev/null +++ b/settingsstore.py @@ -0,0 +1,36 @@ +import os +from typing import Callable + +from settings import Settings +from pathlib import Path +from os.path import join, isfile +from configparser import ConfigParser + + +class SettingsStore(): + def __init__(self): + pass + + @staticmethod + def _config_file() -> str: + return join(Path.home(), ".ravenlog", "settings.ini") + + @staticmethod + def load() -> Settings: + config_file = SettingsStore._config_file() + config = ConfigParser() + + # apply default settings + config.add_section('general') + config.set('general', 'font_size', '12') + config.read(config_file) + + return Settings(config) + + @staticmethod + def save(settings: Settings): + config_file = SettingsStore._config_file() + dir = os.path.dirname(config_file) + os.makedirs(dir, exist_ok=True) + with open(config_file, 'w+') as fp: + settings.config.write(fp)