From 9fb8a45ef71e968a375322566f7dac3213bb3317 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Sun, 31 Oct 2021 18:05:10 +0100 Subject: [PATCH] save highlighters remove user config (not needed) --- bigtext.py | 2 +- colorbutton.py | 1 - highlighting.py | 30 +++++++++++++++--------------- settings.py | 15 +-------------- settingsstore.py | 15 +-------------- 5 files changed, 18 insertions(+), 45 deletions(-) diff --git a/bigtext.py b/bigtext.py index 6f916ed..abb45e8 100644 --- a/bigtext.py +++ b/bigtext.py @@ -37,7 +37,7 @@ class FileObserver(FileSystemEventHandler): def on_modified(self, event): # slow down the updates. This is needed, because the file is modified # constantly, which would lead to constant re-rendering, which would - # block the UI thread an make the UI unresponsive. + # block the UI thread and make the UI unresponsive. # Note: we don't miss events, because they are queued and de-duplicated time.sleep(0.5) self.big_text.update() diff --git a/colorbutton.py b/colorbutton.py index c4a4f9e..4d00321 100644 --- a/colorbutton.py +++ b/colorbutton.py @@ -79,7 +79,6 @@ class ColorButton(QWidget): def _color_selected(self, index: int): self.color = self.color_drop_down.currentData() - print(self.color) def set_color(self, color: str): self.color = color diff --git a/highlighting.py b/highlighting.py index 2e2e9f3..06d90e8 100644 --- a/highlighting.py +++ b/highlighting.py @@ -15,19 +15,19 @@ class Highlighting: @staticmethod def read_config(settings: Settings) -> [HighlightRegex]: result = [] - config = settings.config + session = settings.session - for section in config.sections(): + for section in session.sections(): if not section.startswith("highlighting."): continue - query = config.get(section, "query", fallback="") + query = session.get(section, "query", fallback="") if len(query) == 0: continue - ignore_case = config.getboolean(section, "ignore-case", fallback=True) - is_regex = config.getboolean(section, "is-regex", fallback=False) - line_background_color = config.get(section, "line.background.color", fallback="None") - hit_background_color = config.get(section, "hit.background.color", fallback="None") + ignore_case = session.getboolean(section, "ignore-case", fallback=True) + is_regex = session.getboolean(section, "is-regex", fallback=False) + line_background_color = session.get(section, "line.background.color", fallback="None") + hit_background_color = session.get(section, "hit.background.color", fallback="None") try: highlight = HighlightRegex( @@ -52,16 +52,16 @@ class Highlighting: highlighter: HighlightRegex = highlighter section = "highlighting.%d" % section_counter section_counter = section_counter + 1 - settings.config.add_section(section) - settings.config.set(section, "query", highlighter.query) - settings.config.set(section, "ignore-case", str(highlighter.ignore_case)) - settings.config.set(section, "is-regex", str(highlighter.is_regex)) - settings.config.set(section, "line.background.color", highlighter.line_background_color) - settings.config.set(section, "hit.background.color", highlighter.hit_background_color) + settings.session.add_section(section) + settings.session.set(section, "query", highlighter.query) + settings.session.set(section, "ignore-case", str(highlighter.ignore_case)) + settings.session.set(section, "is-regex", str(highlighter.is_regex)) + settings.session.set(section, "line.background.color", highlighter.line_background_color) + settings.session.set(section, "hit.background.color", highlighter.hit_background_color) @staticmethod def remove_highlighting_sections(settings: Settings): - for section in settings.config.sections(): + for section in settings.session.sections(): if not section.startswith("highlighting."): continue - settings.config.remove_section(section) + settings.session.remove_section(section) diff --git a/settings.py b/settings.py index c31292e..bae5dbc 100644 --- a/settings.py +++ b/settings.py @@ -3,22 +3,9 @@ from configparser import ConfigParser class Settings(): - def __init__(self, config: ConfigParser, session: ConfigParser): - self.config = config + def __init__(self, session: ConfigParser): self.session = session - def set_config(self, section: str, option: str, value: str): - return self.config.set(section, option, value) - - def get_config(self, section: str, option: str): - return self.config.get(section, option) - - def getint_config(self, section: str, option: str): - return self.config.getint(section, option) - - def getboolean_config(self, section: str, option: str): - return self.config.getboolean(section, option) - def set_session(self, section: str, option: str, value: str): return self.session.set(section, option, value) diff --git a/settingsstore.py b/settingsstore.py index 2c7835d..76fce57 100644 --- a/settingsstore.py +++ b/settingsstore.py @@ -12,10 +12,6 @@ class SettingsStore(): def __init__(self): pass - @staticmethod - def _config_file() -> str: - return join(Path.home(), ".ravenlog", "settings.ini") - @staticmethod def _session_file() -> str: if sys.platform == 'win32' or sys.platform == 'cygwin': @@ -25,17 +21,8 @@ class SettingsStore(): @staticmethod def load() -> Settings: - - config = SettingsStore._load_config() session = SettingsStore._load_session() - return Settings(config, session) - - @staticmethod - def _load_config() -> ConfigParser: - config_file = SettingsStore._config_file() - config = ConfigParser() - config.read(config_file) - return config + return Settings(session) @staticmethod def _load_session() -> ConfigParser: