11import 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
33from typing import Optional
44
55from configuration .migration .all_migration import run_all_migration
66from constants .app_info import APP_NAME_WITH_VERSION , APP_NAME , TITLE_ERROR
77from constants .files import LOG_FILE_NAME
88from constants .log import LOG
9- from constants .resources import APP_ICON , UI_SAVE , UI_LOG , UI_CONFIG
9+ from constants .resources import APP_ICON
1010from constants .threads import THREAD_SETTINGS
1111from 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
1414from ui .widget .common .entry import ExtendedEntry
1515from ui .widget .settings .settings_tabs import SettingsTabs
1616from ui .widget .settings .tabs .base_tab import BaseTab
2222from util .history import HistoryManager
2323from util .messages import yesno_error_box
2424from util .scheduler import TaskScheduler
25- from util .ui import load_img
2625
2726
2827class 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
0 commit comments