Package list lightdm-gtk-greeter-settings / f53ba19
Display error text in entry-menu Andrew P. 7 years ago
1 changed file(s) with 68 addition(s) and 30 deletion(s). Raw diff Collapse all Expand all
290290 else:
291291 entry.enabled = enabled
292292
293 def on_entry_fix_clicked(self, item):
294 entry, action = item._fix_entry_data
295 action(entry)
296
293297 def on_entry_label_clicked(self, widget, event, entry, group, key):
294298 if event.button != 3:
295299 return
296300
297301 if not self._entry_menu:
298 def new_item(activate=None):
302 def new_item(activate=None, width=90):
299303 item = Gtk.MenuItem('')
300304 label = item.get_child()
301305 label.props.use_markup = True
302306 label.props.ellipsize = Pango.EllipsizeMode.END
303 label.props.max_width_chars = 90
307 label.props.max_width_chars = width
304308 if activate:
305309 item.connect('activate', activate)
306310 else:
307311 item.props.sensitive = False
308312 return item
309313
310 self._entry_menu = Gtk.Menu()
311 self._entry_menu_label_item = new_item()
312 self._entry_menu_separator_item = Gtk.SeparatorMenuItem()
313 self._entry_menu_initial_item = new_item(self.on_entry_reset_clicked)
314 self._entry_menu_default_item = new_item(self.on_entry_reset_clicked)
315
316 self._entry_menu.append(self._entry_menu_label_item)
317 self._entry_menu.append(self._entry_menu_separator_item)
318 self._entry_menu.append(self._entry_menu_initial_item)
319 self._entry_menu.append(self._entry_menu_default_item)
320 self._entry_menu.show_all()
314 class EntryMenu:
315 menu = Gtk.Menu()
316 value = new_item()
317 error_separator = Gtk.SeparatorMenuItem()
318 error = new_item()
319 error_action = new_item(self.on_entry_fix_clicked)
320 reset_separator = Gtk.SeparatorMenuItem()
321 initial = new_item(self.on_entry_reset_clicked)
322 default = new_item(self.on_entry_reset_clicked)
323
324 menu.append(value)
325 menu.append(error_separator)
326 menu.append(error)
327 menu.append(error_action)
328 menu.append(reset_separator)
329 menu.append(initial)
330 menu.append(default)
331 menu.show_all()
332
333 self._entry_menu = EntryMenu()
321334
322335 def format_value(value=None, enabled=True):
323336 if not enabled:
329342 else:
330343 return escape_markup(str(value))
331344
332 self._entry_menu_label_item.props.label = '{key} = {value}'.format(
345 menu = self._entry_menu
346
347 menu.value.props.label = '{key} = {value}'.format(
333348 group=group.name,
334349 key=key,
335350 value=format_value(value=entry.value, enabled=entry.enabled))
336351
352 error = entry.error
353 error_action = None
354 if error:
355 aname = ('get_entry_fix_%s_%s' % (group.name, key)).replace('-', '_')
356 get_fix = getattr(self, aname, None)
357 if get_fix:
358 label, error_action = get_fix(entry)
359 if label:
360 menu.error_action.props.label = label or ''
361 if error_action:
362 menu.error_action._fix_entry_data = entry, error_action
363 menu.error.set_label(error)
364
365 menu.error.props.visible = error is not None
366 menu.error_action.props.visible = error_action is not None
367 menu.error_separator.props.visible = error_action is not None
368
337369 if entry in self._changed_entries:
338370 initial = self._initial_values[entry]
339371
340372 if entry.enabled != initial.enabled and not initial.enabled:
341 self._entry_menu_initial_item._reset_entry_data = entry, None, initial.enabled
373 menu.initial._reset_entry_data = entry, None, initial.enabled
342374 else:
343 self._entry_menu_initial_item._reset_entry_data = entry, initial.value, None
375 menu.initial._reset_entry_data = entry, initial.value, None
344376
345377 value = format_value(value=initial.value, enabled=initial.enabled)
346 self._entry_menu_initial_item.set_tooltip_markup(value)
347 self._entry_menu_initial_item.props.visible = True
348 self._entry_menu_initial_item.props.label = \
378 menu.initial.set_tooltip_markup(value)
379 menu.initial.props.visible = True
380 menu.initial.props.label = \
349381 _('Reset to initial value: <b>{value}</b>').format(value=value)
350382 else:
351 self._entry_menu_initial_item.props.visible = False
383 menu.initial.props.visible = False
352384
353385 default = group.defaults[key]
354386 if default is not None and entry.value != default:
355387 value = format_value(value=default)
356 self._entry_menu_default_item._reset_entry_data = entry, default, None
357 self._entry_menu_default_item.set_tooltip_markup(value)
358 self._entry_menu_default_item.props.visible = True
359 self._entry_menu_default_item.props.label = \
388 menu.default._reset_entry_data = entry, default, None
389 menu.default.set_tooltip_markup(value)
390 menu.default.props.visible = True
391 menu.default.props.label = \
360392 _('Reset to default value: <b>{value}</b>').format(value=value)
361393 else:
362 self._entry_menu_default_item.props.visible = False
363
364 self._entry_menu_separator_item.props.visible = \
365 (self._entry_menu_initial_item.props.visible or
366 self._entry_menu_default_item.props.visible)
367 self._entry_menu.popup(None, None, None, None, 0, Gtk.get_current_event_time())
394 menu.default.props.visible = False
395
396 menu.reset_separator.props.visible = \
397 menu.initial.props.visible or menu.default.props.visible
398
399 self._entry_menu.menu.popup(None, None, None, None, 0, Gtk.get_current_event_time())
368400
369401 # [greeter] screensaver-timeout
370402 def on_entry_setup_greeter_screensaver_timeout(self, entry):
453485 else:
454486 entry.error = helpers.check_path_accessibility(value)
455487
488 def get_entry_fix_greeter_default_user_image(self, entry):
489 value = entry.value
490 if not entry.error or value.startswith('#'):
491 return None, None
492 return None, None
493
456494 # [greeter] background
457495 def on_entry_changed_greeter_background(self, entry):
458496 value = entry.value