コード例 #1
0
 def format_value(value=None, enabled=True):
     if not enabled:
         return _('<i>disabled</i>')
     if value == '':
         return _('<i>empty string</i>')
     elif value is None:
         return _('<i>None</i>')
     else:
         return escape_markup(str(value))
コード例 #2
0
 def format_value(value=None, enabled=True):
     if not enabled:
         return _('<i>disabled</i>')
     if value == '':
         return _('<i>empty string</i>')
     elif value is None:
         return _('<i>None</i>')
     else:
         return escape_markup(str(value))
コード例 #3
0
    def _create_row_tuple(self, options):
        name = options[Option.Name]
        error = None

        text = options.get(Option.Text)
        if Option.Text in options:
            if text is not None:
                if Option.Markup in options:
                    error = get_markup_error(text)
                    if error:
                        text = '<i>{text}</i>'.format(text=escape_markup(text))
                else:
                    text = escape_markup(text)
                text = '"' + text + '"'
            elif name == Indicators.Host:
                text = escape_markup(platform.node())

        display_name = self.Names.get(name, name)
        if name == Indicators.External:
            if options.get(Option.Path):
                title = '{name} ({value})'.format(
                    name=escape_markup(display_name),
                    value=escape_markup(options[Option.Path]))
            else:
                title = escape_markup(display_name)
        else:
            title = escape_markup(display_name)

        if text:
            markup = '{name}: {text}'.format(name=title, text=text)
        else:
            markup = title

        if Option.Image in options or get_greeter_version() < 0x020100:
            icon = options.get(Option.Image)
            if icon and icon.startswith('#'):
                icon = icon[1:]
            elif icon:
                icon = 'image-x-generic'
            else:
                if name in self.Icons:
                    icon = self.Icons[name]
                elif name in BuiltInIndicators:
                    icon = 'applications-system'
                else:
                    icon = 'application-x-executable'
        else:
            icon = ''

        has_state = name in SingleIndicators

        return Row._make(Name=name,
                         Tooltip=self.Tooltips.get(name),
                         Icon=icon,
                         Markup=markup,
                         HasState=has_state,
                         State=has_state,
                         Options=TreeStoreDataWrapper(options))
コード例 #4
0
    def _create_row_tuple(self, options):
        name = options[Option.Name]
        error = None

        text = options.get(Option.Text)
        if Option.Text in options:
            if text is not None:
                if Option.Markup in options:
                    error = get_markup_error(text)
                    if error:
                        text = '<i>{text}</i>'.format(text=escape_markup(text))
                else:
                    text = escape_markup(text)
                text = '"' + text + '"'
            elif name == Indicators.Host:
                text = escape_markup(platform.node())

        display_name = self.Names.get(name, name)
        if name == Indicators.External:
            if options.get(Option.Path):
                title = '{name} ({value})'.format(name=escape_markup(display_name),
                                                  value=escape_markup(options[Option.Path]))
            else:
                title = escape_markup(display_name)
        else:
            title = escape_markup(display_name)

        if text:
            markup = '{name}: {text}'.format(name=title, text=text)
        else:
            markup = title

        if Option.Image in options or get_greeter_version() < 0x020100:
            icon = options.get(Option.Image)
            if icon and icon.startswith('#'):
                icon = icon[1:]
            elif icon:
                icon = 'image-x-generic'
            else:
                if name in self.Icons:
                    icon = self.Icons[name]
                elif name in BuiltInIndicators:
                    icon = 'applications-system'
                else:
                    icon = 'application-x-executable'
        else:
            icon = ''

        has_state = name in SingleIndicators

        return Row._make(Name=name,
                         Tooltip=self.Tooltips.get(name),
                         Icon=icon,
                         Markup=markup,
                         HasState=has_state, State=has_state,
                         Options=TreeStoreDataWrapper(options))
コード例 #5
0
    def on_show_menu(self, entry, group, key):
        def new_item(activate=None, width=90):
            item = Gtk.MenuItem('')
            label = item.get_child()
            label.props.use_markup = True
            label.props.ellipsize = Pango.EllipsizeMode.END
            label.props.max_width_chars = width
            if activate:
                item.connect('activate', activate)
            else:
                item.props.sensitive = False
            return item

        if not self._entry_menu:

            class EntryMenu:
                menu = Gtk.Menu()
                group = new_item()
                value = new_item()
                file = new_item()
                error_separator = Gtk.SeparatorMenuItem()
                error = new_item()
                error_action = new_item(self.on_entry_fix_clicked)
                reset_separator = Gtk.SeparatorMenuItem()
                initial = new_item(self.on_entry_reset_clicked)
                default = new_item(self.on_entry_reset_clicked)
                other = []

                menu.append(group)
                menu.append(value)
                menu.append(file)
                menu.append(error_separator)
                menu.append(error)
                menu.append(error_action)
                menu.append(reset_separator)
                menu.append(initial)
                menu.append(default)
                menu.show_all()

            self._entry_menu = EntryMenu()

        def format_value(value=None, enabled=True):
            if not enabled:
                return _('<i>disabled</i>')
            if value == '':
                return _('<i>empty string</i>')
            elif value is None:
                return _('<i>None</i>')
            else:
                return escape_markup(str(value))

        menu = self._entry_menu

        # [group]
        if group.name:
            menu.group.props.label = '[{group}]'.format(group=group.name)
            menu.group.show()
        else:
            menu.group.hide()

        # key = value
        if entry.enabled:
            menu.value.props.label = '{key} = {value}'.format(
                key=key,
                value=format_value(value=entry.value, enabled=entry.enabled))
        else:
            menu.value.props.label = '# {key} ='.format(key=key)

        # File with key definition
        config_values = self._config.key_values[group.name, key]
        if entry not in self._changed_entries and \
           config_values and config_values[-1][0] != helpers.get_config_path():
            menu.file.props.label = _('Value defined in file: {path}')\
                .format(path=escape_markup(config_values[-1][0]))
            menu.file.set_tooltip_text(config_values[-1][0])
            menu.file.show()
        else:
            menu.file.hide()

        # Error message
        error = entry.error
        error_action = None
        if error:
            aname = ('get_entry_fix_%s_%s' % (group.name, key)).replace(
                '-', '_')
            get_fix = getattr(self, aname, None)
            if get_fix:
                label, error_action = get_fix(entry)
                if label:
                    menu.error_action.props.label = label or ''
                if error_action:
                    menu.error_action._fix_entry_data = entry, error_action
            menu.error.set_label(escape_markup(error))

        menu.error.props.visible = error is not None
        menu.error_action.props.visible = error_action is not None
        menu.error_separator.props.visible = error_action is not None

        # Reset to initial value
        initial = self._initial_values[entry]
        if initial.enabled != entry.enabled or initial.value != entry.value:
            if entry.enabled != initial.enabled and not initial.enabled:
                menu.initial._reset_entry_data = entry, None, initial.enabled
            else:
                menu.initial._reset_entry_data = entry, initial.value, None

            value = format_value(value=initial.value, enabled=initial.enabled)
            menu.initial.set_tooltip_markup(value)
            menu.initial.props.visible = True
            menu.initial.props.label = \
                _('Reset to initial value: <b>{value}</b>').format(value=value)
        else:
            menu.initial.props.visible = False

        # Reset to default value
        default = group.defaults[key]
        if default is not None and entry.value != default:
            value = format_value(value=default)
            menu.default._reset_entry_data = entry, default, None
            menu.default.set_tooltip_markup(value)
            menu.default.props.visible = True
            menu.default.props.label = \
                _('Reset to default value: <b>{value}</b>').format(value=value)
        else:
            menu.default.props.visible = False

        # Reset to values from all other (.conf
        item_idx = 0
        if config_values and len(config_values) > 1:
            values = {
                None, default, self._initial_values[entry].value, entry.value
            }
            for __, value in config_values[:-1]:
                if value in values:
                    continue

                if len(menu.other) <= item_idx:
                    item = new_item(self.on_entry_reset_clicked)
                    menu.other.append(item)
                    menu.menu.append(item)
                else:
                    item = menu.other[item_idx]
                item._reset_entry_data = entry, value, None
                value = format_value(value=value)
                item.set_tooltip_markup(value)
                item.props.label = _('Reset to value: <b>{value}</b>').format(
                    value=value)
                item.show()
                item_idx += 1
        for item in menu.other[item_idx:]:
            item.hide()

        menu.reset_separator.props.visible = \
            menu.initial.props.visible or menu.default.props.visible or \
            any(item.props.visible for item in menu.other)

        self._entry_menu.menu.popup(None, None, None, None, 0,
                                    Gtk.get_current_event_time())
    def on_show_menu(self, entry, group, key):

        def new_item(activate=None, width=90):
            item = Gtk.MenuItem('')
            label = item.get_child()
            label.props.use_markup = True
            label.props.ellipsize = Pango.EllipsizeMode.END
            label.props.max_width_chars = width
            if activate:
                item.connect('activate', activate)
            else:
                item.props.sensitive = False
            return item

        if not self._entry_menu:
            class EntryMenu:
                menu = Gtk.Menu()
                group = new_item()
                value = new_item()
                file = new_item()
                error_separator = Gtk.SeparatorMenuItem()
                error = new_item()
                error_action = new_item(self.on_entry_fix_clicked)
                reset_separator = Gtk.SeparatorMenuItem()
                initial = new_item(self.on_entry_reset_clicked)
                default = new_item(self.on_entry_reset_clicked)
                other = []

                menu.append(group)
                menu.append(value)
                menu.append(file)
                menu.append(error_separator)
                menu.append(error)
                menu.append(error_action)
                menu.append(reset_separator)
                menu.append(initial)
                menu.append(default)
                menu.show_all()

            self._entry_menu = EntryMenu()

        def format_value(value=None, enabled=True):
            if not enabled:
                return _('<i>disabled</i>')
            if value == '':
                return _('<i>empty string</i>')
            elif value is None:
                return _('<i>None</i>')
            else:
                return escape_markup(str(value))

        menu = self._entry_menu

        # [group]
        if group.name:
            menu.group.props.label = '[{group}]'.format(group=group.name)
            menu.group.show()
        else:
            menu.group.hide()

        # key = value
        if entry.enabled:
            menu.value.props.label = '{key} = {value}'.format(
                key=key, value=format_value(value=entry.value, enabled=entry.enabled))
        else:
            menu.value.props.label = '# {key} ='.format(key=key)

        # File with key definition
        config_values = self._config.key_values[group.name, key]
        if entry not in self._changed_entries and \
           config_values and config_values[-1][0] != helpers.get_config_path():
            menu.file.props.label = _('Value defined in file: {path}')\
                .format(path=escape_markup(config_values[-1][0]))
            menu.file.set_tooltip_text(config_values[-1][0])
            menu.file.show()
        else:
            menu.file.hide()

        # Error message
        error = entry.error
        error_action = None
        if error:
            aname = ('get_entry_fix_%s_%s' % (group.name, key)).replace('-', '_')
            get_fix = getattr(self, aname, None)
            if get_fix:
                label, error_action = get_fix(entry)
                if label:
                    menu.error_action.props.label = label or ''
                if error_action:
                    menu.error_action._fix_entry_data = entry, error_action
            menu.error.set_label(escape_markup(error))

        menu.error.props.visible = error is not None
        menu.error_action.props.visible = error_action is not None
        menu.error_separator.props.visible = error_action is not None

        # Reset to initial value
        initial = self._initial_values[entry]
        if initial.enabled != entry.enabled or initial.value != entry.value:
            if entry.enabled != initial.enabled and not initial.enabled:
                menu.initial._reset_entry_data = entry, None, initial.enabled
            else:
                menu.initial._reset_entry_data = entry, initial.value, None

            value = format_value(value=initial.value, enabled=initial.enabled)
            menu.initial.set_tooltip_markup(value)
            menu.initial.props.visible = True
            menu.initial.props.label = \
                _('Reset to initial value: <b>{value}</b>').format(value=value)
        else:
            menu.initial.props.visible = False

        # Reset to default value
        default = group.defaults[key]
        if default is not None and entry.value != default:
            value = format_value(value=default)
            menu.default._reset_entry_data = entry, default, None
            menu.default.set_tooltip_markup(value)
            menu.default.props.visible = True
            menu.default.props.label = \
                _('Reset to default value: <b>{value}</b>').format(value=value)
        else:
            menu.default.props.visible = False

        # Reset to values from all other (.conf
        item_idx = 0
        if config_values and len(config_values) > 1:
            values = {None, default, self._initial_values[entry].value, entry.value}
            for __, value in config_values[:-1]:
                if value in values:
                    continue

                if len(menu.other) <= item_idx:
                    item = new_item(self.on_entry_reset_clicked)
                    menu.other.append(item)
                    menu.menu.append(item)
                else:
                    item = menu.other[item_idx]
                item._reset_entry_data = entry, value, None
                value = format_value(value=value)
                item.set_tooltip_markup(value)
                item.props.label = _('Reset to value: <b>{value}</b>').format(value=value)
                item.show()
                item_idx += 1
        for item in menu.other[item_idx:]:
            item.hide()

        menu.reset_separator.props.visible = \
            menu.initial.props.visible or menu.default.props.visible or \
            any(item.props.visible for item in menu.other)

        self._entry_menu.menu.popup(None, None, None, None, 0, Gtk.get_current_event_time())