save highlighters
remove user config (not needed)
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
15
settings.py
15
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)
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user