store font size in settings file
This commit is contained in:
10
bigtext.py
10
bigtext.py
@@ -20,6 +20,7 @@ from line import Line
|
|||||||
from logFileModel import LogFileModel
|
from logFileModel import LogFileModel
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from ravenui import RavenUI
|
||||||
from settings import Settings
|
from settings import Settings
|
||||||
from watchdog.observers import Observer
|
from watchdog.observers import Observer
|
||||||
from watchdog.events import FileSystemEventHandler
|
from watchdog.events import FileSystemEventHandler
|
||||||
@@ -136,7 +137,11 @@ class InnerBigText(QWidget):
|
|||||||
def wheelEvent(self, event: QWheelEvent):
|
def wheelEvent(self, event: QWheelEvent):
|
||||||
direction = 1 if event.angleDelta().y() < 0 else -1
|
direction = 1 if event.angleDelta().y() < 0 else -1
|
||||||
if event.modifiers() == Qt.KeyboardModifier.ControlModifier:
|
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()
|
self.update()
|
||||||
else:
|
else:
|
||||||
# print("wheel event fired :) %s" % (direction))
|
# print("wheel event fired :) %s" % (direction))
|
||||||
@@ -229,7 +234,8 @@ class InnerBigText(QWidget):
|
|||||||
def paintEvent(self, event: QPaintEvent) -> None:
|
def paintEvent(self, event: QPaintEvent) -> None:
|
||||||
# print("paintEvent")
|
# print("paintEvent")
|
||||||
painter = QPainter(self)
|
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))
|
painter.setPen(QColor(0, 0, 0))
|
||||||
self.update_font_metrics(painter)
|
self.update_font_metrics(painter)
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from PyQt6.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLineEdit, QCheck
|
|||||||
|
|
||||||
from bigtext import BigText
|
from bigtext import BigText
|
||||||
from logFileModel import LogFileModel
|
from logFileModel import LogFileModel
|
||||||
|
from ravenui import RavenUI
|
||||||
|
|
||||||
|
|
||||||
class FilterTask(QRunnable):
|
class FilterTask(QRunnable):
|
||||||
@@ -123,7 +124,7 @@ class FilterWidget(QWidget):
|
|||||||
self.filter_model.truncate()
|
self.filter_model.truncate()
|
||||||
self.source_model.set_query_highlight()
|
self.source_model.set_query_highlight()
|
||||||
self.filter_model.set_query_highlight()
|
self.filter_model.set_query_highlight()
|
||||||
self.source_model.settings.callback_update_ui()
|
RavenUI.update_ui()
|
||||||
|
|
||||||
def filter_changed(self):
|
def filter_changed(self):
|
||||||
query = self.query_field.text()
|
query = self.query_field.text()
|
||||||
|
|||||||
25
main.py
25
main.py
@@ -1,20 +1,16 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
import re
|
|
||||||
import signal
|
import signal
|
||||||
import time
|
|
||||||
|
|
||||||
from PyQt6 import QtCore
|
from PyQt6 import QtCore
|
||||||
from PyQt6.lupdate import lupdate
|
|
||||||
from PyQt6.QtWidgets import *
|
from PyQt6.QtWidgets import *
|
||||||
from PyQt6.QtCore import *
|
from PyQt6.QtCore import *
|
||||||
from PyQt6.QtGui import *
|
from PyQt6.QtGui import *
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from aboutdialog import AboutDialog
|
from aboutdialog import AboutDialog
|
||||||
from bigtext import BigText
|
from ravenui import RavenUI
|
||||||
from logFileModel import LogFileModel
|
|
||||||
from settings import Settings
|
from settings import Settings
|
||||||
|
from settingsstore import SettingsStore
|
||||||
from tabs import Tabs
|
from tabs import Tabs
|
||||||
|
|
||||||
MAX_LINE_LENGTH = 4096
|
MAX_LINE_LENGTH = 4096
|
||||||
@@ -22,24 +18,25 @@ MAX_LINE_LENGTH = 4096
|
|||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
log = logging.getLogger("main")
|
log = logging.getLogger("main")
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(QMainWindow):
|
class MainWindow(QMainWindow):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(MainWindow, self).__init__(*args, **kwargs)
|
super(MainWindow, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
self.settings = Settings(lambda : self.update())
|
self.settings = SettingsStore.load()
|
||||||
self.setWindowTitle(self.tr("RavenLog"))
|
self.setWindowTitle(self.tr("RavenLog"))
|
||||||
self.setGeometry(0, 0, 640, 480)
|
self.setGeometry(0, 0, 640, 480)
|
||||||
self.setDockNestingEnabled(True)
|
self.setDockNestingEnabled(True)
|
||||||
|
|
||||||
self.tabs = Tabs(self.settings)
|
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/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("/home/andi/ws/ravenlog/example.log")
|
||||||
|
self.tabs.create_tab("/var/log/syslog")
|
||||||
|
|
||||||
self.setCentralWidget(self.tabs)
|
self.setCentralWidget(self.tabs)
|
||||||
#self.main_tool_bar = self.create_main_tool_bar()
|
# self.main_tool_bar = self.create_main_tool_bar()
|
||||||
#self.addToolBar(self.main_tool_bar)
|
# self.addToolBar(self.main_tool_bar)
|
||||||
self.setStatusBar(QStatusBar(self))
|
self.setStatusBar(QStatusBar(self))
|
||||||
self.setMenuBar(self.create_menu_bar())
|
self.setMenuBar(self.create_menu_bar())
|
||||||
|
|
||||||
@@ -96,6 +93,7 @@ class MainWindow(QMainWindow):
|
|||||||
def destruct(self):
|
def destruct(self):
|
||||||
self.tabs.destruct()
|
self.tabs.destruct()
|
||||||
self.close()
|
self.close()
|
||||||
|
SettingsStore.save(self.settings)
|
||||||
|
|
||||||
|
|
||||||
def stop_signal(signum, _stackframe):
|
def stop_signal(signum, _stackframe):
|
||||||
@@ -113,8 +111,8 @@ if __name__ == "__main__":
|
|||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
app.setWindowIcon(QIcon("icon6.png"))
|
app.setWindowIcon(QIcon("icon6.png"))
|
||||||
|
|
||||||
#translator = QTranslator()
|
# translator = QTranslator()
|
||||||
#if translator.load(QLocale("de"), "messages_de.ts"):
|
# if translator.load(QLocale("de"), "messages_de.ts"):
|
||||||
# app.installTranslator(translator)
|
# app.installTranslator(translator)
|
||||||
|
|
||||||
# workaround to make signals work in QT apps.
|
# workaround to make signals work in QT apps.
|
||||||
@@ -128,6 +126,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
window = MainWindow()
|
window = MainWindow()
|
||||||
window.show()
|
window.show()
|
||||||
|
RavenUI.window = window
|
||||||
|
|
||||||
signal.signal(signal.SIGINT, stop_signal)
|
signal.signal(signal.SIGINT, stop_signal)
|
||||||
signal.signal(signal.SIGTERM, stop_signal)
|
signal.signal(signal.SIGTERM, stop_signal)
|
||||||
|
|||||||
7
ravenui.py
Normal file
7
ravenui.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
class RavenUI():
|
||||||
|
# no type hint because of circular dependencies
|
||||||
|
window = None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def update_ui():
|
||||||
|
RavenUI.window.update()
|
||||||
42
settings.py
42
settings.py
@@ -1,29 +1,43 @@
|
|||||||
|
from configparser import ConfigParser
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
from PyQt6.QtGui import QFont
|
from PyQt6.QtGui import QFont
|
||||||
|
|
||||||
|
from ravenui import RavenUI
|
||||||
|
|
||||||
|
|
||||||
class Settings():
|
class Settings():
|
||||||
|
|
||||||
def __init__(self, callback_update_ui: Callable[[], None]):
|
def __init__(self, config: ConfigParser):
|
||||||
self.callback_update_ui = callback_update_ui
|
self.config = config
|
||||||
self.font_size(12)
|
|
||||||
|
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
|
@staticmethod
|
||||||
def max_line_length():
|
def max_line_length():
|
||||||
return 4096
|
return 4096
|
||||||
|
|
||||||
def font(self) -> QFont:
|
# def font(self) -> QFont:
|
||||||
return self._font
|
# return self._font
|
||||||
|
|
||||||
def get_font_size(self) -> int:
|
# def get_font_size(self) -> int:
|
||||||
return self._font_size
|
# return self._font_size
|
||||||
|
|
||||||
def update_font_size(self, increment: int):
|
# def update_font_size(self, increment: int):
|
||||||
font_size = min(max(4, self._font_size + increment), 50)
|
# font_size = min(max(4, self._font_size + increment), 50)
|
||||||
self.font_size(font_size)
|
# self.font_size(font_size)
|
||||||
|
|
||||||
def font_size(self, font_size: int):
|
# def font_size(self, font_size: int):
|
||||||
self._font_size = font_size
|
# self._font_size = font_size
|
||||||
self._font = QFont("monospace", font_size)
|
# self._font = QFont("monospace", font_size)
|
||||||
self.callback_update_ui()
|
# #RavenUI.update_ui()
|
||||||
|
|||||||
36
settingsstore.py
Normal file
36
settingsstore.py
Normal file
@@ -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)
|
||||||
Reference in New Issue
Block a user