Package list lightdm-gtk-greeter-settings / d67e5ec
"theme-name"/"icon-theme-name": updated Andrew P. 7 years ago
2 changed file(s) with 37 addition(s) and 31 deletion(s). Raw diff Collapse all Expand all
2121 import shlex
2222 import sys
2323 from glob import iglob
24 from functools import partialmethod
2425 from itertools import chain
2526 from locale import gettext as _
2627
8182
8283 def init_window(self):
8384 self._widgets = self.Widgets(builder=self.builder)
84
8585 self._multihead_dialog = None
8686 self._entry_menu = None
8787 self._initial_values = {}
234234 if not self._entry_menu:
235235 def new_item(activate=None):
236236 item = Gtk.MenuItem('')
237 item.get_child().props.use_markup = True
238 item.get_child().props.ellipsize = Pango.EllipsizeMode.END
239 item.get_child().props.max_width_chars = 90
237 label = item.get_child()
238 label.props.use_markup = True
239 label.props.ellipsize = Pango.EllipsizeMode.END
240 label.props.max_width_chars = 90
240241 if activate:
241242 item.connect('activate', activate)
242243 else:
345346 return ''
346347
347348 # [greeter] theme-name
348 def on_entry_setup_greeter_theme_name(self, entry):
349 GtkThemesPattern = (sys.prefix, 'share', 'themes', '*', 'gtk-3.0', 'gtk.css')
350
351 def on_entry_setup_greeter_theme_name(self, entry, pattern=GtkThemesPattern):
349352 values = entry.widgets['values']
350 for theme in sorted(iglob(os.path.join(sys.prefix, 'share', 'themes', '*', 'gtk-3.0'))):
351 values.append_text(theme.split(os.path.sep)[-2])
352
353 def on_entry_changed_greeter_theme_name(self, entry):
354 if not entry.value or \
355 entry.value in (row[0] for row in entry.widgets['values'].props.model):
353 idx = pattern.index('*') - len(pattern)
354 for path in sorted(iglob(os.path.join(*pattern))):
355 values.append_text(path.split(os.path.sep)[idx])
356
357 def on_entry_changed_greeter_theme_name(self, entry, pattern=GtkThemesPattern):
358 value = entry.value
359 if value:
360 path = (p if p != '*' else value.strip() for p in pattern)
361 entry.error = helpers.check_path_accessibility(os.path.join(*path))
362 else:
356363 entry.error = None
357 else:
358 entry.error = C_('option|greeter|theme-name', 'Selected theme is not available')
359364
360365 # [greeter] icon-theme-name
361 def on_entry_setup_greeter_icon_theme_name(self, entry):
362 values = entry.widgets['values']
363 for theme in sorted(iglob(os.path.join(sys.prefix, 'share', 'icons', '*', 'index.theme'))):
364 values.append_text(theme.split(os.path.sep)[-2])
365
366 def on_entry_changed_greeter_icon_theme_name(self, entry):
367 if not entry.value or \
368 entry.value in (row[0] for row in entry.widgets['values'].props.model):
369 entry.error = None
370 else:
371 entry.error = C_('option|greeter|icon-theme-name', 'Selected theme is not available')
366 IconThemesPattern = (sys.prefix, 'share', 'icons', '*', 'index.theme')
367 on_entry_setup_greeter_icon_theme_name = partialmethod(on_entry_setup_greeter_theme_name,
368 pattern=IconThemesPattern)
369
370 on_entry_changed_greeter_icon_theme_name = partialmethod(on_entry_changed_greeter_theme_name,
371 pattern=IconThemesPattern)
372372
373373 # [greeter] allow-debugging
374374 def on_entry_changed_greeter_allow_debugging(self, entry):
375 if (Gtk.MAJOR_VERSION, Gtk.MINOR_VERSION, Gtk.MICRO_VERSION) < (3, 14, 0) and \
376 string2bool(entry.value):
375 gtk_version = Gtk.MAJOR_VERSION, Gtk.MINOR_VERSION, Gtk.MICRO_VERSION
376 minimal_version = 3, 14, 0
377 if gtk_version < minimal_version and string2bool(entry.value):
377378 entry.error = C_('option|greeter|allow-debugging',
378 'GtkInspector is not available on your system')
379 'GtkInspector is not available on your system\n'
380 'Gtk version: {current} < {minimal}').format(
381 current=gtk_version, minimal=minimal_version)
379382 else:
380383 entry.error = None
381384
403406 if os.path.isabs(value):
404407 argv = shlex.split(value)
405408 error = helpers.check_path_accessibility(argv[0], executable=True)
406 elif not value:
407 error = _('Do not leave this field empty')
408409 entry.error = error
409410
410411 # [greeter] reader
120120 return 'true' if value else 'false'
121121
122122
123 def string2bool(value):
124 return value and value.lower() in ('true', 'yes', '1')
123 def string2bool(value, fallback=False):
124 if isinstance(value, str):
125 if value in ('true', 'yes', '1'):
126 return True
127 if value in ('false', 'no', '0'):
128 return False
129 return fallback
125130
126131
127132 def show_message(**kwargs):