def init_window(self, is_duplicate=None, get_defaults=None, get_name=str):
        self._widgets = self.Widgets(builder=self.builder)
        self._get_defaults = get_defaults
        self._add_indicator = None
        self._is_duplicate = is_duplicate
        self._get_name = get_name
        self._indicator_loaded = False
        self._name = None
        self._reversed = False

        self._name2page = {}
        for i in range(0, self._widgets.custom_options.get_n_pages()):
            page = self._widgets.custom_options.get_nth_page(i)
            name = Gtk.Buildable.get_name(page)
            self._name2page["~" + name.rsplit("_")[-1]] = i

        if get_greeter_version() < 0x020100:
            self._widgets.common_options.props.visible = False

            self._name2page = {
                Indicators.External: self._name2page[Indicators.External],
                Indicators.Text: self._name2page[Indicators.Text],
            }
            text_prefix = "option_text_fallback"
        else:
            self._name2page[Indicators.Text] = -1
            text_prefix = "option_text"

        self._option_type = IndicatorTypeEntry(WidgetsWrapper(self.builder, "option_type"))
        self._option_text = OptionEntry.StringEntry(WidgetsWrapper(self.builder, text_prefix))
        self._option_image = IndicatorIconEntry(WidgetsWrapper(self.builder, "option_image"))
        self._option_path = IndicatorPath(WidgetsWrapper(self.builder, "option_path"))
        self._option_hide_disabled = OptionEntry.BooleanEntry(WidgetsWrapper(self.builder, "option_hide_disabled"))

        for entry in (self._option_type, self._option_path):
            entry.changed.connect(self._on_option_changed)

        for name in Indicators:
            self._option_type.add_type(name, self._get_name(name))

        # Hiding first column created by Gtk.ComboBoxText
        self._widgets.path.get_cells()[0].props.visible = False

        for path in sorted(iglob(os.path.join(sys.prefix, "share", "unity", "indicators", "*"))):
            name = os.path.basename(path)
            parts = name.rsplit(".", maxsplit=1)
            if len(parts) == 2 and parts[0] == "com.canonical.indicator":
                name = parts[1]
            row = IndicatorPath.Row._make(
                Type=IndicatorPath.ItemType.Value, Title=name, Icon="application-x-executable"
            )
            self._widgets.path_model.append(row)

        for path in sorted(iglob(os.path.join(sys.prefix, "lib", "indicators3", "7", "*.so"))):
            row = IndicatorPath.Row._make(
                Type=IndicatorPath.ItemType.Value, Title=os.path.basename(path), Icon="application-x-executable"
            )
            self._widgets.path_model.append(row)
Exemplo n.º 2
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))
Exemplo n.º 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))
Exemplo n.º 4
0
    def __init__(self, widgets):
        super().__init__(widgets)

        if get_greeter_version() < 0x020100:
            self._get_value = self._get_value_19
            self._on_button_release = self._on_button_release_19

        for k, v in self.DefaultOptions.items():
            v[Option.Name] = k

        self._treeview = widgets['treeview']
        self._selection = widgets['selection']
        self._state_renderer = widgets['state_renderer']
        self._state_column = widgets['state_column']
        self._add = widgets['add']
        self._remove = widgets['remove']
        self._up = widgets['up']
        self._down = widgets['down']
        self._tools = widgets['tools']
        self._model = widgets['model']
        self._widgets_to_disable = [self._treeview, widgets['toolbar']]
        self._properties_dialog = None
        self._row_menu = None
        self._tools_menu = None
        self._show_unused = False

        self._treeview.connect('key-press-event', self._on_key_press)
        self._treeview.connect('row-activated', self._on_row_activated)
        self._treeview.connect('button-release-event', self._on_button_release)
        self._selection.connect('changed', self._on_selection_changed)
        self._state_renderer.connect('toggled', self._on_state_toggled)

        self._add.connect('clicked', self._on_add_clicked)
        self._remove.connect('clicked', self._on_remove_clicked)
        self._up.connect('clicked', self._on_up_clicked)
        self._down.connect('clicked', self._on_down_clicked)
        self._tools.connect('clicked', self._on_tools_clicked)

        self._on_row_changed_id = self._model.connect('row-changed',
                                                      self._on_model_changed)
        self._on_row_deleted_id = self._model.connect('row-deleted',
                                                      self._on_model_changed)
        self._on_row_inserted_id = self._model.connect(
            'row-inserted', self._on_model_row_inserted)
        self._on_rows_reordered_id = self._model.connect(
            'rows-reordered', self._on_model_changed)
Exemplo n.º 5
0
    def __init__(self, widgets):
        super().__init__(widgets)

        if get_greeter_version() < 0x020100:
            self._get_value = self._get_value_19
            self._on_button_release = self._on_button_release_19

        for k, v in self.DefaultOptions.items():
            v[Option.Name] = k

        self._treeview = widgets['treeview']
        self._selection = widgets['selection']
        self._state_renderer = widgets['state_renderer']
        self._state_column = widgets['state_column']
        self._add = widgets['add']
        self._remove = widgets['remove']
        self._up = widgets['up']
        self._down = widgets['down']
        self._tools = widgets['tools']
        self._model = widgets['model']
        self._widgets_to_disable = [self._treeview, widgets['toolbar']]
        self._properties_dialog = None
        self._row_menu = None
        self._tools_menu = None
        self._show_unused = False

        self._treeview.connect('key-press-event', self._on_key_press)
        self._treeview.connect('row-activated', self._on_row_activated)
        self._treeview.connect('button-release-event', self._on_button_release)
        self._selection.connect('changed', self._on_selection_changed)
        self._state_renderer.connect('toggled', self._on_state_toggled)

        self._add.connect('clicked', self._on_add_clicked)
        self._remove.connect('clicked', self._on_remove_clicked)
        self._up.connect('clicked', self._on_up_clicked)
        self._down.connect('clicked', self._on_down_clicked)
        self._tools.connect('clicked', self._on_tools_clicked)

        self._on_row_changed_id = self._model.connect('row-changed', self._on_model_changed)
        self._on_row_deleted_id = self._model.connect('row-deleted', self._on_model_changed)
        self._on_row_inserted_id = self._model.connect('row-inserted', self._on_model_row_inserted)
        self._on_rows_reordered_id = self._model.connect('rows-reordered', self._on_model_changed)
    def init_window(self, is_duplicate=None, get_defaults=None, get_name=str):
        self._widgets = self.Widgets(builder=self.builder)
        self._get_defaults = get_defaults
        self._add_indicator = None
        self._is_duplicate = is_duplicate
        self._get_name = get_name
        self._indicator_loaded = False
        self._name = None
        self._reversed = False

        self._name2page = {}
        for i in range(0, self._widgets.custom_options.get_n_pages()):
            page = self._widgets.custom_options.get_nth_page(i)
            name = Gtk.Buildable.get_name(page)
            self._name2page['~' + name.rsplit('_')[-1]] = i

        if get_greeter_version() < 0x020100:
            self._widgets.common_options.props.visible = False

            self._name2page = {
                Indicators.External: self._name2page[Indicators.External],
                Indicators.Text: self._name2page[Indicators.Text]
            }
            text_prefix = 'option_text_fallback'
        else:
            self._name2page[Indicators.Text] = -1
            text_prefix = 'option_text'

        self._option_type = IndicatorTypeEntry(
            WidgetsWrapper(self.builder, 'option_type'))
        self._option_text = OptionEntry.StringEntry(
            WidgetsWrapper(self.builder, text_prefix))
        self._option_image = IndicatorIconEntry(
            WidgetsWrapper(self.builder, 'option_image'))
        self._option_path = IndicatorPath(
            WidgetsWrapper(self.builder, 'option_path'))
        self._option_hide_disabled = \
            OptionEntry.BooleanEntry(WidgetsWrapper(self.builder, 'option_hide_disabled'))

        for entry in (self._option_type, self._option_path):
            entry.changed.connect(self._on_option_changed)

        for name in Indicators:
            self._option_type.add_type(name, self._get_name(name))

        # Hiding first column created by Gtk.ComboBoxText
        self._widgets.path.get_cells()[0].props.visible = False

        for path in sorted(
                iglob(
                    os.path.join(sys.prefix, 'share', 'unity', 'indicators',
                                 '*'))):
            name = os.path.basename(path)
            parts = name.rsplit('.', maxsplit=1)
            if len(parts) == 2 and parts[0] == 'com.canonical.indicator':
                name = parts[1]
            row = IndicatorPath.Row._make(Type=IndicatorPath.ItemType.Value,
                                          Title=name,
                                          Icon='application-x-executable')
            self._widgets.path_model.append(row)

        for path in sorted(
                iglob(
                    os.path.join(sys.prefix, 'lib', 'indicators3', '7',
                                 '*.so'))):
            row = IndicatorPath.Row._make(Type=IndicatorPath.ItemType.Value,
                                          Title=os.path.basename(path),
                                          Icon='application-x-executable')
            self._widgets.path_model.append(row)