Skip to content

Commit e76f200

Browse files
committed
Hides disabled items and remembers the last window size used.
1 parent 31b8cef commit e76f200

2 files changed

Lines changed: 63 additions & 15 deletions

File tree

usr/share/biglinux/biglinux-settings/base_page.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def __init__(self, main_window, **kwargs):
3232
# Dictionaries to map UI widgets to their corresponding shell scripts
3333
self.switch_scripts = {}
3434
self.status_indicators = {}
35-
self._search_mode = False
3635

3736
def create_scrolled_content(self):
3837
"""Cria a estrutura básica de scroll e box vertical."""
@@ -49,10 +48,8 @@ def create_scrolled_content(self):
4948
return self.content_box
5049

5150
def set_search_mode(self, enabled):
52-
"""Adjust margins for search mode (compact) or normal mode."""
53-
if not hasattr(self, "content_box"):
54-
return
55-
self._search_mode = enabled
51+
"""Placeholder method for search mode compatibility."""
52+
pass
5653

5754
def on_reload_clicked(self, widget):
5855
"""Callback for the reload button. Triggers a full UI state sync."""
@@ -228,17 +225,18 @@ def sync_all_switches(self):
228225
switch.handler_block_by_func(self.on_switch_changed)
229226

230227
if status == "true_disabled":
231-
# State: Enabled but cannot be changed.
232-
row.set_sensitive(False)
233-
row.set_tooltip_text(message)
234-
switch.set_active(True)
228+
# State: Enabled but cannot be changed - hide it from interface.
229+
row.set_visible(False)
230+
row._hidden_no_support = True
235231
elif status is None:
236-
row.set_sensitive(False)
237-
row.set_tooltip_text(message)
232+
# Feature not supported - hide it from interface.
238233
row.set_visible(False)
234+
row._hidden_no_support = True
239235
else:
240236
row.set_sensitive(True)
237+
row.set_visible(True)
241238
row.set_tooltip_text(None)
239+
row._hidden_no_support = False
242240
switch.handler_block_by_func(self.on_switch_changed)
243241
switch.set_active(status)
244242
switch.handler_unblock_by_func(self.on_switch_changed)
@@ -261,12 +259,14 @@ def sync_all_switches(self):
261259
indicator.remove_css_class("status-unavailable")
262260

263261
if status is None:
264-
row.set_sensitive(False)
265-
row.set_tooltip_text(message)
266-
indicator.add_css_class("status-unavailable")
262+
# Feature not supported - hide it from interface.
263+
row.set_visible(False)
264+
row._hidden_no_support = True
267265
else:
268266
row.set_sensitive(True)
267+
row.set_visible(True)
269268
row.set_tooltip_text(None)
269+
row._hidden_no_support = False
270270
if status:
271271
indicator.add_css_class("status-on")
272272
else:
@@ -333,6 +333,11 @@ def get_matching_rows(self, search_text):
333333
row = listbox.get_first_child()
334334
while row:
335335
if isinstance(row, (Adw.PreferencesRow, Gtk.ListBoxRow)):
336+
# Skip rows hidden due to lack of support
337+
if getattr(row, "_hidden_no_support", False):
338+
row = row.get_next_sibling()
339+
continue
340+
336341
text = self._get_row_text(row).lower()
337342
if search_text in text:
338343
matching.append((row, child))
@@ -369,6 +374,11 @@ def _filter_group(self, group, search_text, hide_group_headers=False):
369374
row = listbox.get_first_child()
370375
while row:
371376
if isinstance(row, (Adw.PreferencesRow, Gtk.ListBoxRow)):
377+
# Skip rows hidden due to lack of support
378+
if getattr(row, "_hidden_no_support", False):
379+
row = row.get_next_sibling()
380+
continue
381+
372382
if not search_text:
373383
row.set_visible(True)
374384
visible_count += 1

usr/share/biglinux/biglinux-settings/main.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
gi.require_version("Adw", "1")
66
gi.require_version("Gdk", "4.0")
77
import gettext
8+
import json
89
import locale
910
import os
1011

@@ -22,6 +23,8 @@
2223

2324
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
2425
ICONS_DIR = os.path.join(BASE_DIR, "icons")
26+
CONFIG_DIR = os.path.expanduser("~/.config/biglinux-settings")
27+
CONFIG_FILE = os.path.join(CONFIG_DIR, "config.json")
2528

2629
locale.setlocale(locale.LC_ALL, "")
2730
locale.bindtextdomain(DOMAIN, LOCALE_DIR)
@@ -47,7 +50,12 @@ class BiglinuxSettingsWindow(Adw.ApplicationWindow):
4750
def __init__(self, **kwargs):
4851
super().__init__(**kwargs)
4952
self.set_title(_("BigLinux Settings"))
50-
self.set_default_size(1000, 700)
53+
54+
# Load saved window size or use defaults
55+
saved_size = self._load_window_config()
56+
width = saved_size.get("width", 1000)
57+
height = saved_size.get("height", 700)
58+
self.set_default_size(width, height)
5159

5260
icon_theme = Gtk.IconTheme.get_for_display(Gdk.Display.get_default())
5361
icon_theme.add_search_path(ICONS_DIR)
@@ -59,6 +67,36 @@ def __init__(self, **kwargs):
5967
self.load_css()
6068
self.setup_ui()
6169

70+
# Connect close signal to save window size
71+
self.connect("close-request", self._on_close_request)
72+
73+
def _load_window_config(self):
74+
"""Load window configuration from JSON file."""
75+
if os.path.exists(CONFIG_FILE):
76+
try:
77+
with open(CONFIG_FILE, encoding="utf-8") as f:
78+
return json.load(f)
79+
except (json.JSONDecodeError, OSError) as e:
80+
print(f"Error loading window config: {e}")
81+
return {}
82+
83+
def _save_window_config(self):
84+
"""Save window configuration to JSON file."""
85+
try:
86+
os.makedirs(CONFIG_DIR, exist_ok=True)
87+
width = self.get_width()
88+
height = self.get_height()
89+
config = {"width": width, "height": height}
90+
with open(CONFIG_FILE, "w", encoding="utf-8") as f:
91+
json.dump(config, f, indent=2)
92+
except OSError as e:
93+
print(f"Error saving window config: {e}")
94+
95+
def _on_close_request(self, window):
96+
"""Handle window close request - save configuration."""
97+
self._save_window_config()
98+
return False # Allow window to close
99+
62100
def load_css(self):
63101
self.css_provider = Gtk.CssProvider()
64102
css_path = os.path.join(BASE_DIR, "styles.css")

0 commit comments

Comments
 (0)