示例#1
0
    def _save_state(self):

        if self._plugin.initialized:
            self._plugin.config["common"]["label_options_pos"] = \
              list(self._wnd_label_options.get_position())

            self._plugin.config["common"]["label_options_size"] = \
              list(self._wnd_label_options.get_size())

            self._plugin.config["common"]["label_options_fullname"] = \
              self._tgb_fullname.get_active()

            expanded = []
            for exp in self._exp_group:
                if exp.get_expanded():
                    expanded.append(safe_get_name(exp))

            self._plugin.config["common"]["label_options_exp_state"] = expanded

            if self._vp_criteria_area.get_mapped():
                self._plugin.config["common"]["label_options_pane_pos"] = \
                  self._vp_criteria_area.get_allocation().height - \
                  self._vp_criteria_area.get_position()

            self._plugin.config.save()
示例#2
0
    def _revert_options_by_page(self, options_out, page):

        widgets = self._option_groups[page]

        for widget in widgets:
            prefix, sep, name = safe_get_name(widget).partition("_")
            if sep and name in self._label_defaults:
                options_out[name] = copy.deepcopy(self._label_defaults[name])
    def _set_widget_values(self, widgets, options_in):

        for widget in widgets:
            prefix, sep, name = safe_get_name(widget).partition("_")
            if sep and name in options_in:
                ops = OP_MAP.get(type(widget))
                if ops:
                    setter = getattr(widget, ops[SETTER])
                    setter(options_in[name])
    def _get_widget_values(self, widgets, options_out):

        for widget in widgets:
            prefix, sep, name = safe_get_name(widget).partition("_")
            if sep and name in options_out:
                ops = OP_MAP.get(type(widget))
                if ops:
                    getter = getattr(widget, ops[GETTER])
                    options_out[name] = getter()
示例#5
0
    def _get_path_type(self, widget):

        widget_name = safe_get_name(widget)
        path_type = widget_name[widget_name.index("_") +
                                1:widget_name.rindex("_")]

        if path_type in PATH_TYPES:
            return path_type

        return None
    def destroy(self):

        while self._widgets:
            widget = self._widgets.pop()
            name = self._attr_prefix + safe_get_name(widget)

            attr_widget = getattr(self, name, None)
            if attr_widget is widget:
                delattr(self, name)

        if self._root_widget:
            self._root_widget.destroy()
            self._root_widget = None

        self._model = None
    def _save_state(self):

        if self._plugin.initialized:
            expanded = []
            for exp in self._exp_group:
                if exp.get_expanded():
                    expanded.append(safe_get_name(exp))

            self._plugin.config["common"]["prefs_state"] = expanded

            if self._vp_criteria_area.get_mapped():
                self._plugin.config["common"]["prefs_pane_pos"] = \
                  self._vp_criteria_area.get_allocation().height - \
                  self._vp_criteria_area.get_position()

            self._plugin.config.save()
        def find_item(menu):

            for child in menu.get_children():
                name = safe_get_name(child)

                if id_ == name:
                    return child

                if id_.startswith(name + ":"):
                    submenu = child.get_submenu()
                    if submenu:
                        return find_item(submenu)
                    else:
                        return None

            return None
示例#9
0
    def _install_label_tree(self):

        self._filterview.sidebar.add_tab(self._tree, MODULE_NAME, DISPLAY_NAME)

        # Override style so expanders are indented
        name = safe_get_name(self._tree)
        #path = self._tree.get_path()

        #rc_string = """
        #    style '%s' { GtkTreeView::indent-expanders = 1 }
        #    widget '%s' style '%s'
        #""" % (name, path, name)

        #Gtk.rc_parse_string(rc_string)
        #Gtk.rc_reset_styles(self._tree.get_toplevel().get_settings())
        style_provider = Gtk.CssProvider()
        style_provider.load_from_data(b"""
        %s { -GtkTreeView-indent-expanders: true; }
    """ % name.encode('utf8'))
        self._tree.get_style_context().add_provider(
            style_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
    def _do_open_file_dialog(self, widget):
        def on_response(widget, response):

            if self.valid and response == Gtk.ResponseType.OK:
                txt_widget.set_text(widget.get_filename())

            widget.destroy()

        name = safe_get_name(widget)
        path_type = name[name.index("_") + 1:name.rindex("_")]
        txt_widget = self.__dict__["_txt_%s_path" % path_type]

        dialog = Gtk.FileChooserDialog(_(TITLE_SELECT_FOLDER),
                                       self._blk_preferences.get_toplevel(),
                                       Gtk.FileChooserAction.SELECT_FOLDER,
                                       (_("_Cancel"), Gtk.ResponseType.CANCEL,
                                        _("_OK"), Gtk.ResponseType.OK))

        if __debug__: RT.register(dialog, __name__)

        dialog.set_destroy_with_parent(True)

        path = txt_widget.get_text()
        if not os.path.exists(path):
            path = ""

        dialog.set_filename(path)

        response = dialog.run()
        on_response(dialog, response)

        widgets = labelplus.gtkui.common.gtklib.widget_get_descendents(
            dialog, (Gtk.ToggleButton, ), 1)
        if widgets:
            location_toggle = widgets[0]
            location_toggle.set_active(False)
    def __init__(self, filename, root, attr_prefix=""):

        self._model = None
        self._root_widget = None
        self._widgets = []

        self._attr_prefix = attr_prefix

        self._model = Gtk.Builder.new_from_file(filename)
        if __debug__: RT.register(self._model, __name__)

        self._root_widget = self._model.get_object(root)

        self._widgets = [
            w for w in self._model.get_objects()
            if isinstance(w, Gtk.Buildable)
        ]
        for widget in self._widgets:
            if __debug__: RT.register(widget, __name__)

            name = self._attr_prefix + safe_get_name(widget)

            if not hasattr(self, name):
                setattr(self, name, widget)
    def get_widgets(self, prefix=""):

        return [
            x for x in self._widgets if safe_get_name(x).startswith(prefix)
        ]