Python gi.repository.Gtk.ListStore() Examples

The following are 30 code examples of gi.repository.Gtk.ListStore(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module gi.repository.Gtk , or try the search function .
Example #1
Source File: tag_completion.py    From gtg with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, tree):
        """ Initialize entry completion

        Create a list store which is connected to a LibLarch and
        kept updated. """
        super().__init__()

        self.tags = Gtk.ListStore(str)

        tree = tree.get_basetree()
        tree.add_filter(FILTER_NAME, tag_filter, {'flat': True})
        tag_tree = tree.get_viewtree('tag_completion', False)
        tag_tree.register_cllbck('node-added-inview', self._on_tag_added)
        tag_tree.register_cllbck('node-deleted-inview', self._on_tag_deleted)
        tag_tree.apply_filter(FILTER_NAME)

        self.set_model(self.tags)
        self.set_text_column(0)
        self.set_match_func(tag_match, 0)
        self.set_inline_completion(True)
        self.set_inline_selection(True)
        self.set_popup_single_match(False) 
Example #2
Source File: gui_utilities.py    From king-phisher with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def gtk_list_store_search(list_store, value, column=0):
	"""
	Search a :py:class:`Gtk.ListStore` for a value and return a
	:py:class:`Gtk.TreeIter` to the first match.

	:param list_store: The list store to search.
	:type list_store: :py:class:`Gtk.ListStore`
	:param value: The value to search for.
	:param int column: The column in the row to check.
	:return: The row on which the value was found.
	:rtype: :py:class:`Gtk.TreeIter`
	"""
	for row in list_store:
		if row[column] == value:
			return row.iter
	return None 
Example #3
Source File: actionbar.py    From Audio-Cutter with GNU General Public License v3.0 6 votes vote down vote up
def _setup_widgets(self):
        """Create/Setup the main widgets of the ActionBar."""
        # Save Button
        self._save_btn.set_label(_("Save"))
        self._save_btn.connect("clicked", self._on_save)
        self._save_btn.get_style_context().add_class("suggested-action")
        self._save_btn.set_sensitive(False)
        self.pack_end(self._save_btn)
        # Output format Combo box
        model = Gtk.ListStore(str, str)
        for mimetype, desc in AUDIO_MIMES.items():
            model.append([desc, mimetype])
        renderer_text = Gtk.CellRendererText()
        self._output_format.pack_start(renderer_text, True)
        self._output_format.add_attribute(renderer_text, "text", 0)
        self._output_format.set_active(0)
        self._output_format.set_model(model)
        self._output_format.set_sensitive(False)
        self.pack_end(self._output_format) 
Example #4
Source File: gui_utilities.py    From king-phisher with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def glib_idle_add_store_extend(store, things, clear=False, wait=False):
	"""
	Extend a GTK store object (either :py:class:`Gtk.ListStore` or
	:py:class:`Gtk.TreeStore`) object using :py:func:`GLib.idle_add`. This
	function is suitable for use in non-main GUI threads for synchronizing data.

	:param store: The GTK storage object to add *things* to.
	:type store: :py:class:`Gtk.ListStore`, :py:class:`Gtk.TreeStore`
	:param tuple things: The array of things to add to *store*.
	:param bool clear: Whether or not to clear the storage object before adding *things* to it.
	:param bool wait: Whether or not to wait for the operation to complete before returning.
	:return: Regardless of the *wait* parameter, ``None`` is returned.
	:rtype: None
	"""
	if not isinstance(store, Gtk.ListStore):
		raise TypeError('store must be a Gtk.ListStore instance')
	idle_add = glib_idle_add_wait if wait else glib_idle_add_once
	idle_add(_store_extend, store, things, clear) 
Example #5
Source File: clone_page.py    From king-phisher with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __init__(self, *args, **kwargs):
		super(ClonePageDialog, self).__init__(*args, **kwargs)
		self.resources = Gtk.ListStore(*tuple(column.g_type for column in self.view_columns))
		treeview = self.gobjects['treeview_resources']
		treeview.set_model(self.resources)
		self.treeview_manager = managers.TreeViewManager(treeview)
		self.treeview_manager.set_column_titles(
			tuple(column.title for column in self.view_columns),
			renderers=tuple(column.cell_renderer() for column in self.view_columns)
		)
		self.popup_menu = self.treeview_manager.get_popup_menu()

		self.button_cancel = self.gobjects['button_cancel']
		self.entry_directory = self.gobjects['entry_clone_directory']
		# managed separately to be kept out of the config
		self.entry_target = self.gtk_builder_get('entry_target')
		self.label_status = self.gobjects['label_status']
		self.spinner_status = self.gobjects['spinner_status'] 
Example #6
Source File: io_data_port_list.py    From RAFCON with Eclipse Public License 1.0 6 votes vote down vote up
def _default_value_cell_data_func(self, tree_view_column, cell, model, iter, data=None):
        """Function set renderer properties for every single cell independently

        The function controls the editable and color scheme for every cell in the default value column according
        the use_runtime_value flag and whether the state is a library state.

        :param tree_view_column: the Gtk.TreeViewColumn to be rendered
        :param cell: the current CellRenderer
        :param model: the Gtk.ListStore or TreeStore that is the model for TreeView
        :param iter: an iterator over the rows of the TreeStore/Gtk.ListStore Model
        :param data: optional data to be passed: see http://dumbmatter.com/2012/02/some-notes-on-porting-from-pygtk-to-pygobject/
        """
        if isinstance(self.model.state, LibraryState):
            use_runtime_value = model.get_value(iter, self.USE_RUNTIME_VALUE_STORAGE_ID)
            if use_runtime_value:
                cell.set_property("editable", True)
                cell.set_property('text', model.get_value(iter, self.RUNTIME_VALUE_STORAGE_ID))
                cell.set_property('foreground', "white")
            else:
                cell.set_property("editable", False)
                cell.set_property('text', model.get_value(iter, self.DEFAULT_VALUE_STORAGE_ID))
                cell.set_property('foreground', "dark grey")

        return 
Example #7
Source File: gtk_ui.py    From oversteer with GNU General Public License v3.0 6 votes vote down vote up
def set_emulation_modes(self, modes, startup = False):
        if startup:
            if modes == None:
                self.emulation_mode_combobox.set_sensitive(False)
                return
            else:
                self.emulation_mode_combobox.set_sensitive(True)
        model = self.emulation_mode_combobox.get_model()
        if model == None:
            model = Gtk.ListStore(str, str)
        else:
            self.emulation_mode_combobox.set_model(None)
            model.clear()
        for key, values in enumerate(modes):
            model.append(values[:2])
            if values[2]:
                self.emulation_mode_combobox.set_active(key)
        self.emulation_mode_combobox.set_model(model) 
Example #8
Source File: preferences_window.py    From RAFCON with Eclipse Public License 1.0 6 votes vote down vote up
def __init__(self, core_config_model, view, gui_config_model):
        assert isinstance(view, PreferencesWindowView)
        assert isinstance(core_config_model, ConfigModel)
        assert isinstance(gui_config_model, ConfigModel)
        ExtendedController.__init__(self, core_config_model, view)
        self.core_config_model = core_config_model
        self.gui_config_model = gui_config_model
        self.observe_model(gui_config_model)

        # (config_key, config_value, text_visible, toggle_activatable, toggle_visible, text_editable, toggle_value)
        self.core_list_store = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING, bool, bool, bool, bool, bool)
        self.library_list_store = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING)
        self.gui_list_store = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING, bool, bool, bool, bool, bool)
        self.shortcut_list_store = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING)

        self._lib_counter = 0
        self._gui_checkbox = Gtk.CheckButton(label="GUI Config")
        self._core_checkbox = Gtk.CheckButton(label="Core Config")
        self._last_path = self.core_config_model.config.path 
Example #9
Source File: outcomes.py    From RAFCON with Eclipse Public License 1.0 6 votes vote down vote up
def __init__(self, model, view):
        assert isinstance(model, AbstractStateModel)
        # initiate data base and tree
        # id, name, to-state, to-outcome, name-color, to-state-color, outcome, state, outcome_model
        list_store = Gtk.ListStore(int, GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT,
                                   GObject.TYPE_PYOBJECT)
        super(StateOutcomesListController, self).__init__(model, view, view['tree_view'], list_store, logger)

        self.to_state_combo_list = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING)
        self.to_outcome_combo_list = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING)
        # key-outcome_id -> label,  to_state_id,  transition_id
        self.dict_to_other_state = {}
        # key-outcome_id ->  label,  to_outcome_id,  transition_id
        self.dict_to_other_outcome = {}
        # not used at the moment key-outcome_id -> label,  from_state_id,  transition_id
        self.dict_from_other_state = {}  # if widget gets extended
        # TODO check why the can happen should not be handed always the LibraryStateModel
        if not (model.state.is_root_state or model.state.is_root_state_of_library):
            self.observe_model(model.parent)

        if self.model.get_state_machine_m() is not None:
            self.observe_model(self.model.get_state_machine_m())
        else:
            logger.warning("State model has no state machine model -> state model: {0}".format(self.model)) 
Example #10
Source File: file_parser.py    From innstereo with GNU General Public License v2.0 6 votes vote down vote up
def create_treeview(self):
        """
        Creates the viewport and adds it to the dialog window.

        The parsing dialog displays the parsing results in a TreeView.
        This requires setting up a TreeStore that has enough columns for a
        typical file to be imported. The TreeViewColumns are set up for text 
        and appended to the TreeView. The TreeView is then added to to
        the ScrolledWindow defined in Glade.
        """
        self.store = Gtk.ListStore(str, str, str, str, str, str, str, str)
        self.view = Gtk.TreeView(self.store)
        for x in range(8):
            renderer = Gtk.CellRendererText()
            column = Gtk.TreeViewColumn(str(x), renderer, text=x)
            column.set_alignment(0.5)
            column.set_expand(True)
            self.view.append_column(column)

        self.scr_win.add(self.view)
        self.dialog.show_all() 
Example #11
Source File: editform.py    From addons-source with GNU General Public License v2.0 6 votes vote down vote up
def build_interface(self):
        """
        Builds the interface.
        """
        self.model = Gtk.ListStore(str, str)
        self.view = Gtk.TreeView(model=self.model)
        self.selection = self.view.get_selection()

        renderer = Gtk.CellRendererText()
        column = Gtk.TreeViewColumn(_('Key'), renderer, text=0)
        self.view.append_column(column)

        renderer = Gtk.CellRendererText()
        renderer.set_property('editable', True)
        renderer.connect('edited', self.__cell_edited, (self.model, 1))
        column = Gtk.TreeViewColumn(_('Value'), renderer, text=1)
        self.view.append_column(column)

        scrollwin = Gtk.ScrolledWindow()
        scrollwin.add(self.view)
        scrollwin.set_policy(Gtk.PolicyType.AUTOMATIC,
                             Gtk.PolicyType.AUTOMATIC)

        self.pack_start(scrollwin, expand=True, fill=True, padding=0) 
Example #12
Source File: MediaVerify.py    From addons-source with GNU General Public License v2.0 6 votes vote down vote up
def create_tab(self, title):
        """
        Create a page in the notebook.
        """
        scrolled_window = Gtk.ScrolledWindow()
        scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC,
                                   Gtk.PolicyType.AUTOMATIC)
        view = Gtk.TreeView()
        column = Gtk.TreeViewColumn(_('Files'))
        view.append_column(column)
        cell = Gtk.CellRendererText()
        column.pack_start(cell, True)
        column.add_attribute(cell, 'text', 0)
        column.set_sort_column_id(0)
        column.set_sort_indicator(True)
        model = Gtk.ListStore(str, str)
        view.set_model(model)
        page = self.notebook.get_n_pages()
        view.connect('button-press-event', self.button_press, page)
        scrolled_window.add(view)
        self.models.append(model)
        self.views.append(view)
        label = Gtk.Label(title)
        self.notebook.append_page(scrolled_window, label) 
Example #13
Source File: DescendantCount.py    From addons-source with GNU General Public License v2.0 6 votes vote down vote up
def build_gui(self):
        """
        Build the GUI interface.
        """
        tip = _("Click name to change active\n"
                "Double-click name to edit")
        self.set_tooltip(tip)
        top = Gtk.TreeView()
        top.connect('button-press-event', self._button_press)
        renderer = Gtk.CellRendererText()
        renderer.set_property('ellipsize', Pango.EllipsizeMode.END)
        column = Gtk.TreeViewColumn(_('Person'), renderer, text=0)
        column.set_expand(True)
        column.set_resizable(True)
        column.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
        column.set_sort_column_id(0)
        top.append_column(column)
        renderer = Gtk.CellRendererText()
        column = Gtk.TreeViewColumn(_('Descendants'), renderer, text=1)
        column.set_sort_column_id(1)
        top.append_column(column)
        self.model = Gtk.ListStore(str, int, str)
        top.set_model(self.model)
        return top 
Example #14
Source File: DenominoViso.py    From addons-source with GNU General Public License v2.0 6 votes vote down vote up
def create_lstore(self,list_of_lists):
        lstore_args = []
        for cell in list_of_lists[0]:
            if type(cell) == type("string"):
                lstore_args.append(GObject.TYPE_STRING)
            elif type(cell) == type(1):
                lstore_args.append(GObject.TYPE_UINT)
            elif type(cell) == type(False):
                lstore_args.append(GObject.TYPE_BOOLEAN)
            else:
                raise TypeError("%s" % type(cell))
        lstore = Gtk.ListStore(*lstore_args)
        for row in list_of_lists:
            iter = lstore.append()
            index_values = []
            for i,v in enumerate(row):
                index_values.append(i)
                index_values.append(v)
            lstore.set(iter,*index_values)
        return lstore 
Example #15
Source File: handler.py    From WattmanGTK with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, builder, GPUs):
        self.builder = builder
        self.GPUs = GPUs
        self.GPU = GPUs[0]
        self.init_state = {}
        self.set_maximum_values()
        self.set_initial_values()
        self.init_state = self.create_state_dict()
        self.update_gui()

        # initialise GPU selection combobox
        textrenderer = Gtk.CellRendererText()
        self.gpustore = Gtk.ListStore(str)
        for i, card in enumerate(GPUs):
            self.gpustore.append([f"{i+1}: {card.fancyname}"])
        combobox = self.builder.get_object("GPU Selection")
        combobox.set_model(self.gpustore)
        combobox.pack_start(textrenderer, True)
        combobox.add_attribute(textrenderer, "text", 0)
        combobox.set_entry_text_column(0)
        combobox.set_active(0)
        combobox.connect("changed", self.on_GPU_changed)

        # TODO implement POLKIT for writing as root, for now --> disable button
        self.builder.get_object("Lock").set_sensitive(False) 
Example #16
Source File: tag_editor.py    From gtg with GNU General Public License v3.0 6 votes vote down vote up
def __load_icon(self):
        """
        Loads emblem icons from the current icon theme

        Sometimes an icon can't be loaded because of a bug in system
        libraries, e.g. bug #1079587. Gracefuly degradate and skip
        the loading of a corrupted icon.
        """
        self.symbol_model = Gtk.ListStore(GdkPixbuf.Pixbuf, str)
        for icon in Gtk.IconTheme.get_default().list_icons(context="Emblems"):
            try:
                img = Gtk.IconTheme.get_default().load_icon(icon, 16, 0)
                self.symbol_model.append([img, icon])
            except GObject.GError:
                log.error(f"Failed to load icon '{icon}'")
        self.symbol_iv.set_model(self.symbol_model)
        self.loaded = True

    # PUBLIC IF ##### 
Example #17
Source File: add.py    From Authenticator with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, **kwargs):
        Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
        GObject.GObject.__init__(self)

        self.is_edit = kwargs.get("edit", False)
        self._account = kwargs.get("account", None)

        self._providers_store = Gtk.ListStore(str, str)

        self.logo_img = Gtk.Image()
        self.username_entry = Gtk.Entry()
        self.provider_combo = Gtk.ComboBox.new_with_model_and_entry(
            self._providers_store)
        self.token_entry = Gtk.Entry()
        self._build_widgets()
        self._fill_data() 
Example #18
Source File: thumbnail.py    From vimiv with MIT License 5 votes vote down vote up
def __init__(self, app):
        """Create the necessary objects and settings.

        Args:
            app: The main application class to interact with.
        """
        super(Thumbnail, self).__init__()
        self._app = app

        # Settings
        self.toggled = False
        padding = settings["thumb_padding"].get_value()
        self._timer_id = GLib.Timeout
        self._markup = settings["markup"].get_value().replace("fore", "back")

        zoom_level = settings["default_thumbsize"].get_value()
        self._zoom_levels = [(64, 64), (128, 128), (256, 256), (512, 512)]
        self._zoom_level_index = self._zoom_levels.index(zoom_level)

        # Create the liststore and iconview
        self._liststore = Gtk.ListStore(GdkPixbuf.Pixbuf, str)
        self.connect("item-activated", self._on_activated)
        self.connect("key_press_event",
                     self._app["eventhandler"].on_key_press, "THUMBNAIL")
        self.connect("button_press_event",
                     self._app["eventhandler"].on_click, "THUMBNAIL")
        self.set_model(self._liststore)
        self.set_pixbuf_column(0)
        self.set_markup_column(1)

        self.set_item_width(0)
        self.set_item_padding(padding)
        self.last_focused = ""
        self._thumbnail_manager = ThumbnailManager()

        # Signals
        self._app["mark"].connect("marks-changed", self._on_marks_changed)
        self._app["transform"].connect("applied-to-file",
                                       self._on_transformations_applied_to_file)
        self._app["commandline"].search.connect("search-completed",
                                                self._on_search_completed) 
Example #19
Source File: LecturesPanel.py    From pychess with GNU General Public License v3.0 5 votes vote down vote up
def load(self, persp):
        self.persp = persp
        self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)

        self.tv = Gtk.TreeView()

        renderer = Gtk.CellRendererText()
        column = Gtk.TreeViewColumn(_("Title"), renderer, text=1)
        self.tv.append_column(column)

        renderer = Gtk.CellRendererText()
        column = Gtk.TreeViewColumn(_("Author"), renderer, text=2)
        self.tv.append_column(column)

        self.tv.connect("row-activated", self.row_activated)

        self.store = Gtk.ListStore(str, str, str)

        for file_name, title, author in LECTURES:
            self.store.append([file_name, title, author])

        self.tv.set_model(self.store)
        self.tv.get_selection().set_mode(Gtk.SelectionMode.BROWSE)
        self.tv.set_cursor(conf.get("learncombo%s" % LECTURE))

        scrollwin = Gtk.ScrolledWindow()
        scrollwin.add(self.tv)
        scrollwin.show_all()

        self.box.pack_start(scrollwin, True, True, 0)
        self.box.show_all()

        return self.box 
Example #20
Source File: completions.py    From vimiv with MIT License 5 votes vote down vote up
def show(self):
        """Show the completion information."""
        # Hacky way to not show the last selected item
        self.set_model(Gtk.ListStore(str, str))
        self._refilter(self._app["commandline"])
        self.info.show() 
Example #21
Source File: commentPanel.py    From pychess with GNU General Public License v3.0 5 votes vote down vote up
def load(self, gmwidg):

        self.gamemodel = gmwidg.board.view.model
        self.model_cids = [
            self.gamemodel.connect_after("game_changed", self.game_changed),
            self.gamemodel.connect_after("game_started", self.game_started),
            self.gamemodel.connect_after("moves_undone", self.moves_undone),
            self.gamemodel.connect_after("game_terminated", self.on_game_terminated),
        ]

        scrollwin = Gtk.ScrolledWindow()
        self.tv = Gtk.TreeView()
        self.tv.set_headers_visible(False)
        scrollwin.add(self.tv)
        scrollwin.show_all()

        self.store = Gtk.ListStore(str)
        self.tv.set_model(self.store)
        self.tv.get_selection().set_mode(Gtk.SelectionMode.BROWSE)
        uistuff.appendAutowrapColumn(self.tv, "Comment", text=0)
        self.tv_cid = self.tv.connect('cursor_changed', self.cursorChanged)

        self.boardview = gmwidg.board.view
        self.cid = self.boardview.connect("shownChanged", self.shownChanged)

        return scrollwin 
Example #22
Source File: template_grid.py    From wpgtk with GNU General Public License v2.0 5 votes vote down vote up
def on_add_clicked(self, widget):
        filechooser = Gtk.FileChooserDialog("Select an Image", self.parent,
                                            Gtk.FileChooserAction.OPEN,
                                            (Gtk.STOCK_CANCEL,
                                             Gtk.ResponseType.CANCEL,
                                             Gtk.STOCK_OPEN,
                                             Gtk.ResponseType.OK))
        filefilter = Gtk.FileFilter()
        filechooser.set_select_multiple(True)
        filefilter.set_name("Text")
        filefilter.add_mime_type("text/*")
        filechooser.add_filter(filefilter)
        response = filechooser.run()

        if response == Gtk.ResponseType.OK:
            for f in filechooser.get_filenames():
                files.add_template(f)
            self.item_names = [f for f in
                               files.get_file_list(OPT_DIR, False)
                               if '.base' in f]
            self.liststore = Gtk.ListStore(Pixbuf, str)
            for filen in self.item_names:
                pixbuf = Gtk.IconTheme.get_default().load_icon(icon, 64, 0)
                self.liststore.append([pixbuf, filen])
            self.file_view.set_model(self.liststore)
        filechooser.destroy()
        self.file_view.unselect_all() 
Example #23
Source File: theme_picker.py    From wpgtk with GNU General Public License v2.0 5 votes vote down vote up
def on_rm_clicked(self, widget):
        x = self.option_combo.get_active()
        current_walls = files.get_file_list()
        if current_walls:
            filename = current_walls[x]
            themer.delete_theme(filename)
            option_list = Gtk.ListStore(str)
            for elem in list(files.get_file_list()):
                option_list.append([elem])
            self.option_combo.set_model(option_list)
            self.option_combo.set_entry_text_column(0)
            self.colorscheme.set_model(option_list)
            self.colorscheme.set_entry_text_column(0)
            self.cpage.update_combo(option_list) 
Example #24
Source File: theme_picker.py    From wpgtk with GNU General Public License v2.0 5 votes vote down vote up
def on_add_clicked(self, widget):
        filechooser = Gtk.FileChooserDialog(
                      'Select an Image', self,
                      Gtk.FileChooserAction.OPEN,
                      (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                       Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

        filechooser.set_select_multiple(True)
        filefilter = Gtk.FileFilter()
        filefilter.set_name("Images")
        filefilter.add_mime_type("image/png")
        filefilter.add_mime_type("image/jpg")
        filefilter.add_mime_type("image/jpeg")
        filechooser.add_filter(filefilter)
        response = filechooser.run()

        if response == Gtk.ResponseType.OK:
            for f in filechooser.get_filenames():
                themer.create_theme(f)
            option_list = Gtk.ListStore(str)
            for elem in list(files.get_file_list()):
                option_list.append([elem])
            self.option_combo.set_model(option_list)
            self.option_combo.set_entry_text_column(0)
            self.colorscheme.set_model(option_list)
            self.colorscheme.set_entry_text_column(0)
            self.cpage.update_combo(option_list)
        filechooser.destroy() 
Example #25
Source File: combobox_enhanced.py    From gtg with GNU General Public License v3.0 5 votes vote down vote up
def listStoreFromList(list_obj):
    list_store = Gtk.ListStore(GObject.TYPE_STRING)
    for elem in list_obj:
        iter = list_store.append()
        list_store.set(iter, 0, elem)
    return list_store 
Example #26
Source File: ChannelsPanel.py    From pychess with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, icon):
        GObject.GObject.__init__(self)
        self.id2iter = {}

        pm = Gtk.ListStore(str, str, int, str)
        self.sort_model = Gtk.TreeModelSort(model=pm)
        self.set_model(self.sort_model)
        self.idSet = set()

        self.set_headers_visible(False)
        self.set_tooltip_column(3)
        self.set_search_column(1)
        self.sort_model.set_sort_column_id(1, Gtk.SortType.ASCENDING)
        self.sort_model.set_sort_func(1, self.compareFunction, 1)

        # First column
        crp = Gtk.CellRendererPixbuf()
        crp.props.pixbuf = icon
        self.rightcol = Gtk.TreeViewColumn("", crp)
        self.append_column(self.rightcol)

        # Second column
        crt = Gtk.CellRendererText()
        crt.props.ellipsize = Pango.EllipsizeMode.END
        self.leftcol = Gtk.TreeViewColumn("", crt, text=1)
        self.leftcol.set_expand(True)
        self.append_column(self.leftcol)

        # Mouse
        self.pressed = None
        self.stdcursor = Gdk.Cursor.new(Gdk.CursorType.LEFT_PTR)
        self.linkcursor = Gdk.Cursor.new(Gdk.CursorType.HAND2)
        self.connect("button_press_event", self.button_press)
        self.connect("button_release_event", self.button_release)
        self.connect("motion_notify_event", self.motion_notify)
        self.connect("leave_notify_event", self.leave_notify)

        # Selection
        self.get_selection().connect("changed", self.selection_changed) 
Example #27
Source File: backendscombo.py    From gtg with GNU General Public License v3.0 5 votes vote down vote up
def _liststore_init(self):
        """Setup the Gtk.ListStore"""
        self.liststore = Gtk.ListStore(str, str, GdkPixbuf.Pixbuf)
        self.set_model(self.liststore) 
Example #28
Source File: tag_completion.py    From gtg with GNU General Public License v3.0 5 votes vote down vote up
def _try_insert(self, name):
        """ Insert an item into ListStore if it is not already there.
        It keeps the list sorted. """
        position = 0
        for position, row in enumerate(self.tags, 1):
            if row[0] == name:
                # already there
                return
            elif row[0] > name:
                position -= 1
                break
        self.tags.insert(position, (name, )) 
Example #29
Source File: TaskerManager.py    From pychess with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):
        GObject.GObject.__init__(self)
        self.widgets = tasker_widgets
        tasker = self.widgets["internetGameTasker"]
        tasker.unparent()
        self.add(tasker)

        if ICLogon.dialog is None:
            ICLogon.dialog = ICLogon.ICLogon()

        liststore = Gtk.ListStore(str)
        liststore.append(["FICS"])
        liststore.append(["ICC"])
        self.ics_combo = self.widgets["ics_combo"]
        self.ics_combo.set_model(liststore)
        renderer_text = Gtk.CellRendererText()
        self.ics_combo.pack_start(renderer_text, True)
        self.ics_combo.add_attribute(renderer_text, "text", 0)
        self.ics_combo.connect("changed", ICLogon.dialog.on_ics_combo_changed)
        self.ics_combo.set_active(conf.get("ics_combo"))

        self.widgets["connectButton"].connect("clicked", self.connectClicked)
        self.widgets["opendialog2"].connect("clicked", self.openDialogClicked)

        big_start = get_pixbuf("glade/internet.png")
        self.widgets["startIcon"].set_from_pixbuf(big_start)

        uistuff.keep(self.widgets["ics_combo"], "ics_combo")
        uistuff.keep(self.widgets["autoLogin"], "autoLogin") 
Example #30
Source File: gtk_spreadsheet_sgskip.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def create_model(self):
        types = [float]*self.numCols
        store = Gtk.ListStore(*types)

        for row in self.data:
            store.append(tuple(row))
        return store