Skip to content

Commit 8174c79

Browse files
committed
Optimizing interface responsiveness
1 parent a58c1b3 commit 8174c79

11 files changed

Lines changed: 92 additions & 76 deletions

src/configuration/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Config(BaseModel):
99
"""
1010
The Config class represents a configuration object for application.
1111
12-
It defines the structure of the configuration, including rule application interval, logging settings, and rules.
12+
It defines the structure of the configuration, including rule application interval, and rules.
1313
"""
1414

1515
version: Optional[int] = Field(default=None)

src/configuration/migration/all_migration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
from configuration.migration.base import BaseMigration
44
from configuration.migration.m0_rules_to_split_rules_config import MigrationRules2SplitRulesConfig
55
from configuration.migration.m1_new_fields_in_rule import NewFieldsInRule
6-
from configuration.migration.m2_remove_high_io_priority import RemoveHighIoPriority
6+
from configuration.migration.m2_remove_high_io_priority_and_logging import RemoveHighIoPriorityAndLogging
77
from constants.log import LOG
88
from service.config_service import ConfigService
99
from util.messages import show_error
1010

1111
MIGRATIONS: list[type[BaseMigration]] = [
1212
MigrationRules2SplitRulesConfig,
1313
NewFieldsInRule,
14-
RemoveHighIoPriority
14+
RemoveHighIoPriorityAndLogging
1515
]
1616
"""
1717
List of migration classes to be executed in order.

src/configuration/migration/base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from abc import ABC, abstractmethod
22

3+
from pydantic.config import JsonDict
4+
35

46
class BaseMigration(ABC):
57
@staticmethod
68
@abstractmethod
7-
def should_migrate(config: dict) -> bool:
9+
def should_migrate(config: JsonDict) -> bool:
810
"""
911
Checks if migration is necessary.
1012
@@ -15,7 +17,7 @@ def should_migrate(config: dict) -> bool:
1517

1618
@staticmethod
1719
@abstractmethod
18-
def migrate(config: dict) -> dict:
20+
def migrate(config: JsonDict) -> JsonDict:
1921
"""
2022
Performs the migration and returns the updated configuration.
2123

src/configuration/migration/m0_rules_to_split_rules_config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from typing import Optional
22

3+
from pydantic.config import JsonDict
4+
35
from configuration.migration.base import BaseMigration
46

57

@@ -9,11 +11,11 @@ def get_target_version() -> int:
911
return 1
1012

1113
@staticmethod
12-
def should_migrate(config: dict) -> bool:
14+
def should_migrate(config: JsonDict) -> bool:
1315
return 'version' not in config or config['version'] is None
1416

1517
@staticmethod
16-
def migrate(config: dict) -> Optional[dict]:
18+
def migrate(config: JsonDict) -> Optional[JsonDict]:
1719
if 'rules' not in config:
1820
return config
1921

src/configuration/migration/m1_new_fields_in_rule.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from typing import Optional
22

3+
from pydantic.config import JsonDict
4+
35
from configuration.migration.base import BaseMigration
46
from enums.bool import BoolStr
57
from enums.selector import SelectorType
@@ -11,11 +13,11 @@ def get_target_version() -> int:
1113
return 2
1214

1315
@staticmethod
14-
def should_migrate(config: dict) -> bool:
16+
def should_migrate(config: JsonDict) -> bool:
1517
return config['version'] == 1
1618

1719
@staticmethod
18-
def migrate(config: dict) -> Optional[dict]:
20+
def migrate(config: JsonDict) -> Optional[JsonDict]:
1921
for rule in config.get('processRules', []):
2022
rule['selectorBy'] = SelectorType.NAME.value
2123
rule['force'] = BoolStr.NO.value

src/configuration/migration/m2_remove_high_io_priority.py renamed to src/configuration/migration/m2_remove_high_io_priority_and_logging.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
import itertools
22
from typing import Optional
33

4+
from pydantic.config import JsonDict
5+
46
from configuration.migration.base import BaseMigration
57

68

7-
class RemoveHighIoPriority(BaseMigration):
9+
class RemoveHighIoPriorityAndLogging(BaseMigration):
810
@staticmethod
911
def get_target_version() -> int:
1012
return 3
1113

1214
@staticmethod
13-
def should_migrate(config: dict) -> bool:
15+
def should_migrate(config: JsonDict) -> bool:
1416
return config['version'] == 2
1517

1618
@staticmethod
17-
def migrate(config: dict) -> Optional[dict]:
19+
def migrate(config: JsonDict) -> Optional[JsonDict]:
1820
for rule in itertools.chain(config.get('processRules', []), config.get('serviceRules', [])):
1921
if rule.get('ioPriority') == 'High':
2022
del rule['ioPriority']
2123

24+
if 'logging' in config:
25+
del config['logging']
26+
2227
return config

src/ui/settings.py

Lines changed: 20 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import os
2-
from tkinter import messagebox, ttk, Tk, X, TOP, BOTH, NORMAL, DISABLED
2+
from tkinter import messagebox, ttk, Tk, X, TOP, BOTH, DISABLED, NORMAL
33
from typing import Optional
44

55
from configuration.migration.all_migration import run_all_migration
66
from constants.app_info import APP_NAME_WITH_VERSION, APP_NAME, TITLE_ERROR
77
from constants.files import LOG_FILE_NAME
88
from constants.log import LOG
9-
from constants.resources import APP_ICON, UI_SAVE, UI_LOG, UI_CONFIG
9+
from constants.resources import APP_ICON
1010
from constants.threads import THREAD_SETTINGS
1111
from constants.ui import UI_PADDING, RC_WIN_SIZE, ActionEvents, SETTINGS_TITLE, EditableTreeviewEvents, \
12-
RIGHT_PACK, LEFT_PACK, OPEN_CONFIG_LABEL, OPEN_LOG_LABEL, ExtendedTreeviewEvents
13-
from ui.widget.common.button import ExtendedButton
12+
ExtendedTreeviewEvents
13+
from ui.settings_actions import SettingsActions
1414
from ui.widget.common.entry import ExtendedEntry
1515
from ui.widget.settings.settings_tabs import SettingsTabs
1616
from ui.widget.settings.tabs.base_tab import BaseTab
@@ -22,7 +22,6 @@
2222
from util.history import HistoryManager
2323
from util.messages import yesno_error_box
2424
from util.scheduler import TaskScheduler
25-
from util.ui import load_img
2625

2726

2827
class Settings(Tk):
@@ -35,9 +34,15 @@ def __init__(self):
3534

3635
self._create_widgets()
3736
self._pack()
38-
self._setup_tooltips()
3937
self._setup_window()
4038

39+
self.after(1, self._after_init)
40+
41+
def _after_init(self):
42+
self._setup_tooltips()
43+
self._setup_binds()
44+
self._tabs.load_data()
45+
4146
def _setup_window(self):
4247
self._center_window()
4348

@@ -46,9 +51,15 @@ def _setup_window(self):
4651
self.title(APP_NAME_WITH_VERSION)
4752
self.minsize(*RC_WIN_SIZE)
4853

54+
def _setup_binds(self):
55+
self._tabs.bind(ExtendedTreeviewEvents.CHANGE, lambda _: self._update_actions_state(), "+")
56+
57+
self._actions.bind(ActionEvents.SAVE, lambda _: self._save(), "+")
58+
self._actions.bind(ActionEvents.CONFIG, lambda _: open_config_file(), "+")
59+
self._actions.bind(ActionEvents.LOG, lambda _: open_log_file(), "+")
60+
4961
self.bind("<Control-Tab>", lambda _: self._tabs.next_tab(), "+")
5062
self.bind("<Shift-Control-Tab>", lambda _: self._tabs.prev_tab(), "+")
51-
5263
self.bind("<Key>", self._fix_cyrillic_binds, "+")
5364
self.bind("<KeyPress>", self._global_actions, "+")
5465

@@ -118,26 +129,9 @@ def _center_window(self):
118129
self.geometry(f"{RC_WIN_SIZE[0]}x{RC_WIN_SIZE[1]}+{x}+{y}")
119130

120131
def _create_widgets(self):
121-
self._create_tabs()
122-
self._create_tooltips()
123-
self._create_actions()
124-
125-
def _create_tooltips(self):
132+
self._tabs = SettingsTabs(self)
126133
self._tooltip = Tooltip(self, text=self._tabs.get_default_tooltip())
127-
128-
def _create_tabs(self):
129-
self._tabs = tabs = SettingsTabs(self)
130-
tabs.load_data()
131-
tabs.bind(ExtendedTreeviewEvents.CHANGE, lambda _: self._update_actions_state(), "+")
132-
133-
def _create_actions(self):
134-
self._actions = actions = SettingsActions(self)
135-
136-
actions.bind(ActionEvents.SAVE, lambda _: self._save(), "+")
137-
actions.bind(ActionEvents.CONFIG, lambda _: open_config_file(), "+")
138-
actions.bind(ActionEvents.LOG, lambda _: open_log_file(), "+")
139-
140-
self._update_actions_state()
134+
self._actions = SettingsActions(self)
141135

142136
def _save(self):
143137
result = self._tabs.save_data()
@@ -345,41 +339,6 @@ def to_front(self):
345339
self.after_idle(self.attributes, '-topmost', False)
346340

347341

348-
class SettingsActions(ttk.Frame):
349-
def __init__(self, *args, **kwargs):
350-
super().__init__(*args, **kwargs)
351-
self._setup_btn()
352-
353-
def _setup_btn(self):
354-
self.open_config = open_config = ExtendedButton(
355-
self,
356-
text=f"{OPEN_CONFIG_LABEL}",
357-
event=ActionEvents.CONFIG,
358-
image=load_img(file=UI_CONFIG),
359-
description="**Opens** the __config file__."
360-
)
361-
362-
self.open_log = open_log = ExtendedButton(
363-
self,
364-
text=f"{OPEN_LOG_LABEL}",
365-
event=ActionEvents.LOG,
366-
image=load_img(file=UI_LOG),
367-
description="**Opens** the __log file__."
368-
)
369-
370-
self.save = save = ExtendedButton(
371-
self,
372-
text="Save",
373-
event=ActionEvents.SAVE,
374-
image=load_img(file=UI_SAVE),
375-
description="**Saves** the __settings__. \n**Hotkey:** __Ctrl+S__."
376-
)
377-
378-
open_config.pack(**LEFT_PACK)
379-
open_log.pack(**LEFT_PACK)
380-
save.pack(**RIGHT_PACK)
381-
382-
383342
__app: Optional[Settings] = None
384343

385344

src/ui/settings_actions.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from tkinter import ttk, DISABLED
2+
3+
from constants.resources import UI_CONFIG, UI_LOG, UI_SAVE
4+
from constants.ui import OPEN_CONFIG_LABEL, ActionEvents, OPEN_LOG_LABEL, LEFT_PACK, RIGHT_PACK
5+
from ui.widget.common.button import ExtendedButton
6+
from util.ui import load_img
7+
8+
9+
class SettingsActions(ttk.Frame):
10+
def __init__(self, *args, **kwargs):
11+
super().__init__(*args, **kwargs)
12+
self._setup_btn()
13+
14+
def _setup_btn(self):
15+
self.open_config = open_config = ExtendedButton(
16+
self,
17+
text=f"{OPEN_CONFIG_LABEL}",
18+
event=ActionEvents.CONFIG,
19+
image=load_img(file=UI_CONFIG),
20+
description="**Opens** the __config file__."
21+
)
22+
23+
self.open_log = open_log = ExtendedButton(
24+
self,
25+
text=f"{OPEN_LOG_LABEL}",
26+
event=ActionEvents.LOG,
27+
image=load_img(file=UI_LOG),
28+
description="**Opens** the __log file__."
29+
)
30+
31+
self.save = save = ExtendedButton(
32+
self,
33+
text="Save",
34+
state=DISABLED,
35+
event=ActionEvents.SAVE,
36+
image=load_img(file=UI_SAVE),
37+
description="**Saves** the __settings__. \n**Hotkey:** __Ctrl+S__."
38+
)
39+
40+
open_config.pack(**LEFT_PACK)
41+
open_log.pack(**LEFT_PACK)
42+
save.pack(**RIGHT_PACK)

src/ui/widget/settings/settings_tabs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def _create_tabs(self):
4040
process_rules_tab.place()
4141
service_rules_tab.place()
4242

43+
self._update_tabs_state()
44+
4345
def current_tab(self) -> BaseTab:
4446
current_index = self.index(self.select())
4547
tab_id = self.tabs()[current_index]
@@ -106,7 +108,7 @@ def _update_tabs_state(self):
106108
tabs = self.frames_by_tab()
107109

108110
for id, tab in tabs.items():
109-
star = "*" if tab.has_changes() or tab.has_error() else ""
111+
star = "*" if tab.has_changes() or tab.has_error() else " "
110112
self.tab(id, text=f" {tab.title()} {star}")
111113

112114
def next_tab(self):

src/ui/widget/settings/tabs/rules/base_rules_tab.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def __init__(self, master: Notebook, rule_type: RuleType):
2626
self.rules_list = self._create_rules_list()
2727
self.actions = self._create_actions()
2828

29-
self._update_actions_state()
3029
self._pack()
3130

3231
def _pack(self):

0 commit comments

Comments
 (0)