save highlighters
remove user config (not needed)
This commit is contained in:
@@ -37,7 +37,7 @@ class FileObserver(FileSystemEventHandler):
|
|||||||
def on_modified(self, event):
|
def on_modified(self, event):
|
||||||
# slow down the updates. This is needed, because the file is modified
|
# slow down the updates. This is needed, because the file is modified
|
||||||
# constantly, which would lead to constant re-rendering, which would
|
# 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
|
# Note: we don't miss events, because they are queued and de-duplicated
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
self.big_text.update()
|
self.big_text.update()
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ class ColorButton(QWidget):
|
|||||||
|
|
||||||
def _color_selected(self, index: int):
|
def _color_selected(self, index: int):
|
||||||
self.color = self.color_drop_down.currentData()
|
self.color = self.color_drop_down.currentData()
|
||||||
print(self.color)
|
|
||||||
|
|
||||||
def set_color(self, color: str):
|
def set_color(self, color: str):
|
||||||
self.color = color
|
self.color = color
|
||||||
|
|||||||
@@ -15,19 +15,19 @@ class Highlighting:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def read_config(settings: Settings) -> [HighlightRegex]:
|
def read_config(settings: Settings) -> [HighlightRegex]:
|
||||||
result = []
|
result = []
|
||||||
config = settings.config
|
session = settings.session
|
||||||
|
|
||||||
for section in config.sections():
|
for section in session.sections():
|
||||||
if not section.startswith("highlighting."):
|
if not section.startswith("highlighting."):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
query = config.get(section, "query", fallback="")
|
query = session.get(section, "query", fallback="")
|
||||||
if len(query) == 0:
|
if len(query) == 0:
|
||||||
continue
|
continue
|
||||||
ignore_case = config.getboolean(section, "ignore-case", fallback=True)
|
ignore_case = session.getboolean(section, "ignore-case", fallback=True)
|
||||||
is_regex = config.getboolean(section, "is-regex", fallback=False)
|
is_regex = session.getboolean(section, "is-regex", fallback=False)
|
||||||
line_background_color = config.get(section, "line.background.color", fallback="None")
|
line_background_color = session.get(section, "line.background.color", fallback="None")
|
||||||
hit_background_color = config.get(section, "hit.background.color", fallback="None")
|
hit_background_color = session.get(section, "hit.background.color", fallback="None")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
highlight = HighlightRegex(
|
highlight = HighlightRegex(
|
||||||
@@ -52,16 +52,16 @@ class Highlighting:
|
|||||||
highlighter: HighlightRegex = highlighter
|
highlighter: HighlightRegex = highlighter
|
||||||
section = "highlighting.%d" % section_counter
|
section = "highlighting.%d" % section_counter
|
||||||
section_counter = section_counter + 1
|
section_counter = section_counter + 1
|
||||||
settings.config.add_section(section)
|
settings.session.add_section(section)
|
||||||
settings.config.set(section, "query", highlighter.query)
|
settings.session.set(section, "query", highlighter.query)
|
||||||
settings.config.set(section, "ignore-case", str(highlighter.ignore_case))
|
settings.session.set(section, "ignore-case", str(highlighter.ignore_case))
|
||||||
settings.config.set(section, "is-regex", str(highlighter.is_regex))
|
settings.session.set(section, "is-regex", str(highlighter.is_regex))
|
||||||
settings.config.set(section, "line.background.color", highlighter.line_background_color)
|
settings.session.set(section, "line.background.color", highlighter.line_background_color)
|
||||||
settings.config.set(section, "hit.background.color", highlighter.hit_background_color)
|
settings.session.set(section, "hit.background.color", highlighter.hit_background_color)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def remove_highlighting_sections(settings: Settings):
|
def remove_highlighting_sections(settings: Settings):
|
||||||
for section in settings.config.sections():
|
for section in settings.session.sections():
|
||||||
if not section.startswith("highlighting."):
|
if not section.startswith("highlighting."):
|
||||||
continue
|
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():
|
class Settings():
|
||||||
|
|
||||||
def __init__(self, config: ConfigParser, session: ConfigParser):
|
def __init__(self, session: ConfigParser):
|
||||||
self.config = config
|
|
||||||
self.session = session
|
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):
|
def set_session(self, section: str, option: str, value: str):
|
||||||
return self.session.set(section, option, value)
|
return self.session.set(section, option, value)
|
||||||
|
|
||||||
|
|||||||
@@ -12,10 +12,6 @@ class SettingsStore():
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _config_file() -> str:
|
|
||||||
return join(Path.home(), ".ravenlog", "settings.ini")
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _session_file() -> str:
|
def _session_file() -> str:
|
||||||
if sys.platform == 'win32' or sys.platform == 'cygwin':
|
if sys.platform == 'win32' or sys.platform == 'cygwin':
|
||||||
@@ -25,17 +21,8 @@ class SettingsStore():
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def load() -> Settings:
|
def load() -> Settings:
|
||||||
|
|
||||||
config = SettingsStore._load_config()
|
|
||||||
session = SettingsStore._load_session()
|
session = SettingsStore._load_session()
|
||||||
return Settings(config, session)
|
return Settings(session)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _load_config() -> ConfigParser:
|
|
||||||
config_file = SettingsStore._config_file()
|
|
||||||
config = ConfigParser()
|
|
||||||
config.read(config_file)
|
|
||||||
return config
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _load_session() -> ConfigParser:
|
def _load_session() -> ConfigParser:
|
||||||
|
|||||||
Reference in New Issue
Block a user