Skip to content

Commit c80f17d

Browse files
committed
Changed settings handling
1 parent 87389d8 commit c80f17d

6 files changed

Lines changed: 104 additions & 110 deletions

File tree

src/gui/config_dialog.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def __init__( # noqa: PLR0913
7373
"""Initialize the dialog with window selection and settings callbacks."""
7474
super().__init__(parent)
7575
self.hide()
76+
self.app_settings = parent.settings
7677
self.err_msg = QMessageBox(self)
7778
self.lower_switch = None
7879
self.upper_switch = None
@@ -429,7 +430,7 @@ def update_layout_frame(self) -> None:
429430

430431
self.layout_preview = ScreenLayoutWidget(
431432
self, self.screen_width, self.screen_height_org,
432-
windows, self.assets_dir, window_details=True,
433+
windows, self.assets_dir, self.app_settings,
433434
)
434435
self.layout_container_layout.addWidget(self.layout_preview)
435436

src/gui/layout_preview.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
if TYPE_CHECKING:
1717
from pathlib import Path
1818

19+
from uwp_config import ApplicationSettings
20+
1921
logger = logging.getLogger(__name__)
2022

2123

@@ -28,7 +30,7 @@ def __init__(self, # noqa: PLR0913
2830
screen_height: int,
2931
windows: list[WindowInfo],
3032
assets_dir: Path,
31-
window_details: int = 1,
33+
app_settings: ApplicationSettings,
3234
) -> None:
3335
"""Set up base variables."""
3436
super().__init__(parent)
@@ -38,12 +40,13 @@ def __init__(self, # noqa: PLR0913
3840
self.active_labels = None
3941
self.parent = parent
4042
self.colors = self.parent.colors
41-
self.use_images = self.parent.use_images
4243
self.assets_dir = assets_dir
4344

4445
self.windows = windows
4546

46-
self.window_details = window_details
47+
self.window_details = app_settings.details
48+
self.use_images = app_settings.use_images
49+
4750
self.screen_width = screen_width
4851
self.screen_height = screen_height
4952

src/gui/pyside_gui_manager.py

Lines changed: 42 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ def __init__(
9393
self.applied_config = None
9494
self.applied_config_name = None
9595

96-
self.compact_mode = None
9796
self.style_dark = True
9897

9998
self.timer = None
@@ -106,16 +105,10 @@ def __init__(
106105

107106
self._init_managers()
108107

109-
(self.compact_mode,
110-
self.use_images,
111-
self.snap,
112-
self.details,
113-
self.hotkey,
114-
self.layouts,
115-
self.overrides,
116-
self.ignored_windows) = self.cfg_man.load_settings()
108+
self.settings = self.cfg_man.load_settings()
117109

118-
self.win_man.ignored_windows = self.ignored_windows
110+
low_ignore_list = [item.lower() for item in self.settings.ignored_windows]
111+
self.win_man.ignored_windows = low_ignore_list
119112

120113
self._init_screen()
121114
self._init_ui_containers()
@@ -125,7 +118,7 @@ def __init__(
125118
self.reapply_timer()
126119
self.managed_widget.installEventFilter(self)
127120

128-
global_hotkeys.register_hotkey(self.hotkey, self.toggle_always_on_top, None)
121+
global_hotkeys.register_hotkey(self.settings.hotkey, self.toggle_always_on_top, None)
129122
global_hotkeys.start_checking_hotkeys()
130123

131124
# Set window title with version
@@ -180,9 +173,9 @@ def _apply_snap_selection(self) -> None:
180173
"""Set initial snap radio button based on snap value."""
181174
snap_left = 1
182175
snap_right = 2
183-
if self.snap == snap_left:
176+
if self.settings.snap == snap_left:
184177
self.left_radio.setChecked(True)
185-
elif self.snap == snap_right:
178+
elif self.settings.snap == snap_right:
186179
self.right_radio.setChecked(True)
187180
else:
188181
self.center_radio.setChecked(True)
@@ -202,7 +195,7 @@ def eventFilter(self, source: QObject, event: QWheelEvent) -> bool: # noqa: N80
202195
def get_geometry_and_minsize(self) -> tuple[int, int, int, int]:
203196
"""Get the sizes needed to set geometry and minsize."""
204197
compact_height_factor = 1
205-
if self.compact_mode:
198+
if self.settings.compact:
206199
width = UIConstants.COMPACT_WIDTH
207200
height = UIConstants.COMPACT_HEIGHT
208201
min_width = UIConstants.COMPACT_WIDTH
@@ -224,15 +217,15 @@ def toggle_elements(self, *, compact: bool, min_width: int) -> None:
224217
self.edit_config_button,
225218
self.image_folder_button,
226219
self.screenshot_button,
227-
self.details_switch,
220+
self.settings.details_switch,
228221
self.toggle_images_switch,
229222
self.aot_label,
230223
self.spacer_1,
231224
self.spacer_2,
232225
self.left_radio,
233226
self.center_radio,
234227
self.right_radio,
235-
self.snap_label,
228+
self.settings.snap_label,
236229
]
237230

238231
resized_buttons = [
@@ -321,7 +314,7 @@ def _build_combo_row(self, min_width: int) -> None:
321314
combo_layout = QHBoxLayout()
322315
combo_layout.setContentsMargins(10, 0, 10, 0)
323316
combo_layout.setSpacing(0)
324-
width = min_width - 20 if self.compact_mode else min_width / 2
317+
width = min_width - 20 if self.settings.compact else min_width / 2
325318

326319
self.combo_box = QComboBox(self)
327320
self.combo_box.setFixedWidth(width)
@@ -343,7 +336,7 @@ def _build_combo_row(self, min_width: int) -> None:
343336
def _build_managed_area(self) -> None:
344337
"""Create managed windows area with label and text edit."""
345338
self.managed_widget = QWidget(self)
346-
self.managed_widget.setVisible(self.compact_mode)
339+
self.managed_widget.setVisible(self.settings.compact)
347340

348341
mf_layout = QVBoxLayout(self.managed_widget)
349342
mf_layout.setContentsMargins(10, 0, 10, 0)
@@ -369,7 +362,7 @@ def _build_layout_preview(self) -> None:
369362
self.res_y,
370363
windows=[],
371364
assets_dir=self.assets_dir,
372-
window_details=self.details,
365+
app_settings=self.settings,
373366
)
374367
lc_layout.addWidget(self.layout_frame, 1)
375368
self.main_layout.addLayout(lc_layout, 1)
@@ -452,9 +445,9 @@ def _build_buttons_area(self) -> None:
452445
self.reapply_pause_label.setContentsMargins(10, 0, 10, 0)
453446
aot_bottom.addWidget(self.reapply_pause_label, alignment=Qt.AlignmentFlag.AlignLeft)
454447

455-
self.snap_label = QLabel("Application open position:", self)
456-
self.snap_label.setContentsMargins(10, 0, 50, 0)
457-
aot_bottom.addWidget(self.snap_label, alignment=Qt.AlignmentFlag.AlignRight)
448+
self.settings.snap_label = QLabel("Application open position:", self)
449+
self.settings.snap_label.setContentsMargins(10, 0, 50, 0)
450+
aot_bottom.addWidget(self.settings.snap_label, alignment=Qt.AlignmentFlag.AlignRight)
458451

459452
self.main_layout.addLayout(aot_bottom)
460453

@@ -479,14 +472,14 @@ def _build_images_and_snap_row(self) -> None:
479472
img_l.setSpacing(20)
480473

481474
self.auto_apply_switch = QCheckBox("Auto re-apply", self)
482-
self.details_switch = QCheckBox("Show window details", self)
475+
self.settings.details_switch = QCheckBox("Show window details", self)
483476
self.toggle_images_switch = QCheckBox("Images", self)
484477

485-
self.details_switch.setChecked(self.details)
486-
self.toggle_images_switch.setChecked(self.use_images)
478+
self.settings.details_switch.setChecked(self.settings.details)
479+
self.toggle_images_switch.setChecked(self.settings.use_images)
487480

488481
img_l.addWidget(self.auto_apply_switch)
489-
img_l.addWidget(self.details_switch)
482+
img_l.addWidget(self.settings.details_switch)
490483
img_l.addWidget(self.toggle_images_switch)
491484
img_l.addStretch() # push snap group right
492485

@@ -501,10 +494,10 @@ def _build_images_and_snap_row(self) -> None:
501494
for radio in [self.left_radio, self.center_radio, self.right_radio]:
502495
radio.setFixedWidth(radio_width)
503496

504-
self.snap_group = QButtonGroup(self)
505-
self.snap_group.addButton(self.left_radio, 1)
506-
self.snap_group.addButton(self.center_radio, 0)
507-
self.snap_group.addButton(self.right_radio, 2)
497+
self.settings.snap_group = QButtonGroup(self)
498+
self.settings.snap_group.addButton(self.left_radio, 1)
499+
self.settings.snap_group.addButton(self.center_radio, 0)
500+
self.settings.snap_group.addButton(self.right_radio, 2)
508501

509502
for radio in [self.left_radio, self.center_radio, self.right_radio]:
510503
snap_l.addWidget(radio)
@@ -532,19 +525,19 @@ def _connect_callbacks(self) -> None:
532525

533526
# Switches
534527
self.auto_apply_switch.stateChanged.connect(self._on_reapply_toggle)
535-
self.details_switch.stateChanged.connect(self._on_details_toggle)
528+
self.settings.details_switch.stateChanged.connect(self._on_details_toggle)
536529
self.toggle_images_switch.stateChanged.connect(self._on_images_toggle)
537530

538531
self.filter_switch.stateChanged.connect(self.update_config_list)
539532
self.theme_switch.stateChanged.connect(self._on_theme_toggle)
540533

541534
# Radio buttons
542-
self.snap_group.buttonToggled.connect(self._on_snap_toggle)
535+
self.settings.snap_group.buttonToggled.connect(self._on_snap_toggle)
543536

544537
# ------------- Theme & toggles -------------
545538

546539
def _apply_theme(self) -> None:
547-
font_size = text_small.pointSize() if self.compact_mode else text_normal.pointSize()
540+
font_size = text_small.pointSize() if self.settings.compact else text_normal.pointSize()
548541
self.setStyleSheet(f"""
549542
QWidget {{
550543
background: {self.colors.BACKGROUND};
@@ -679,16 +672,7 @@ def invert_colors(self) -> None:
679672

680673
def _save_settings(self) -> None:
681674
"""Save GUI settings."""
682-
self.cfg_man.save_settings(
683-
compact_mode=self.compact_mode,
684-
use_images=self.use_images,
685-
snap=self.snap,
686-
details=self.details,
687-
hotkey=self.hotkey,
688-
layouts=self.layouts,
689-
overrides=self.overrides,
690-
ignored_windows=self.ignored_windows,
691-
)
675+
self.cfg_man.save_settings(self.settings)
692676

693677
def reapply_timer(self) -> None:
694678
"""Timer for auto reapply."""
@@ -939,20 +923,20 @@ def open_image_folder(self) -> None:
939923
def toggle_compact(self, startup: int = 0) -> None:
940924
"""Toggle between compact and full mode."""
941925
if not startup:
942-
self.compact_mode = not self.compact_mode
926+
self.settings.compact = not self.settings.compact
943927
self._save_settings()
944928

945-
if self.compact_mode:
929+
if self.settings.compact:
946930
self.toggle_compact_button.setText("Full mode")
947931
self.aot_button.setText("AOT")
948932
self.detect_config_button.setText("Detect")
949933
else:
950934
self.toggle_compact_button.setText("Compact mode")
951-
self.aot_button.setText(f"Toggle AOT ({self.hotkey})")
935+
self.aot_button.setText(f"Toggle AOT ({self.settings.hotkey})")
952936
self.detect_config_button.setText("Detect config")
953937

954938
width, height, min_width, min_height = self.get_geometry_and_minsize()
955-
self.toggle_elements(compact=self.compact_mode, min_width=min_width)
939+
self.toggle_elements(compact=self.settings.compact, min_width=min_width)
956940
self.setMinimumSize(min_width, min_height)
957941
self._position_app_window()
958942
self.on_config_select()
@@ -963,11 +947,11 @@ def _position_app_window(self) -> None:
963947
width, height, _, _ = self.get_geometry_and_minsize()
964948
snap_left = 1
965949
snap_right = 2
966-
if self.snap == 0:
950+
if self.settings.snap == 0:
967951
pos_x = (self.res_x // 2) - (width // 2)
968-
elif self.snap == snap_left:
952+
elif self.settings.snap == snap_left:
969953
pos_x = 0
970-
elif self.snap == snap_right:
954+
elif self.settings.snap == snap_right:
971955
pos_x = self.res_x - width
972956
else:
973957
pos_x = 100
@@ -1009,28 +993,28 @@ def _on_reapply_toggle(self) -> None:
1009993
self.reapply = self.auto_apply_switch.isChecked()
1010994

1011995
def _on_details_toggle(self) -> None:
1012-
self.details = self.details_switch.isChecked()
996+
self.settings.details = self.settings.details_switch.isChecked()
1013997
self._save_settings()
1014998
if self.layout_frame:
1015-
self.layout_frame.window_details = self.details
999+
self.layout_frame.window_details = self.settings.details
10161000
self.layout_frame.update()
10171001

10181002
def _on_images_toggle(self) -> None:
1019-
self.use_images = self.toggle_images_switch.isChecked()
1003+
self.settings.use_images = self.toggle_images_switch.isChecked()
10201004
self._save_settings()
10211005
if self.layout_frame:
1022-
self.layout_frame.use_images = self.use_images
1006+
self.layout_frame.use_images = self.settings.use_images
10231007
self.layout_frame.update()
10241008

10251009
# Radio button actions
10261010

10271011
def _on_snap_toggle(self, button: QRadioButton) -> None:
10281012
if button == self.left_radio:
1029-
self.snap = 1
1013+
self.settings.snap = 1
10301014
elif button == self.center_radio:
1031-
self.snap = 0
1015+
self.settings.snap = 0
10321016
elif button == self.right_radio:
1033-
self.snap = 2
1017+
self.settings.snap = 2
10341018

10351019
self._position_app_window()
10361020
self._save_settings()
@@ -1053,7 +1037,7 @@ def on_config_select(self) -> None:
10531037
self.config = None
10541038
missing = []
10551039

1056-
if not self.compact_mode:
1040+
if not self.settings.compact:
10571041
self.update_window_layout(self.config, missing)
10581042
else:
10591043
self.update_managed_windows_list(self.config, missing)

0 commit comments

Comments
 (0)