我们从Python开源项目中,提取了以下15个代码示例,用于说明如何使用gi.repository.Gtk.TreePath()。
def change_active(self, widget, path): selected_path = Gtk.TreePath(path) for row in self: if row.path == selected_path: row[3] = not row[3] num = row[0] if row[3]: if num in self.boot_inactive: self.boot_inactive.remove(num) else: self.boot_active.append(num) else: if num in self.boot_active: self.boot_active.remove(num) else: self.boot_inactive.append(num)
def check_button_sensitive(self): """Check the up, down and remove buttons and disable or enable them. Depending on the selected item. :return: """ if self.selection is None: return model, tree_iter = self.selection.get_selected() self.button_edit.set_sensitive(True) self.button_up.set_sensitive(True) self.button_down.set_sensitive(True) self.button_remove.set_sensitive(True) if model.get_path(tree_iter) == gtk.TreePath("0"): self.button_up.set_sensitive(False) if model.get_path(tree_iter) == gtk.TreePath(str(len(model) - 1)): self.button_down.set_sensitive(False) if len(model) == 1: self.button_remove.set_sensitive(False)
def _install_from_list_view(self, pkgname): from softwarecenter.ui.gtk3.panes.availablepane import AvailablePane available_pane.notebook.set_current_page(AvailablePane.Pages.LIST) self._p() available_pane.on_search_terms_changed(None, "ark,artha,software-center") self._p() # select the first item in the list available_pane.app_view.tree_view.set_cursor(Gtk.TreePath(0), None, False) # ok to just use the test app here app = Application("", pkgname) self._p() # pretend we started an install available_pane.backend.emit("transaction-started", app.pkgname, app.appname, "testid101", TransactionTypes.INSTALL) # wait a wee bit self._zzz()
def change_boot_next(self, widget, path): selected_path = Gtk.TreePath(path) for row in self: if row.path == selected_path: row[4] = not row[4] self.boot_next = row[0] if row[4] else None else: row[4] = False
def on_button_up_clicked(self, _): """Called on up button clicked. Move the selected item one position up. :param _: :return: """ model, tree_iter = self.selection.get_selected() tree_iter_2 = model.get_iter( gtk.TreePath(str(int(model.get_path(tree_iter).to_string()) - 1))) model.swap(tree_iter, tree_iter_2) self.check_button_sensitive()
def on_button_down_clicked(self, _): """Called on down button clicked. Move the selected item on position down. :param _: :return: """ model, tree_iter = self.selection.get_selected() tree_iter_2 = model.get_iter( gtk.TreePath(str(int(model.get_path(tree_iter).to_string()) + 1))) model.swap(tree_iter, tree_iter_2) self.check_button_sensitive()
def on_row_activated( # pylint: disable=no-self-use self, treeview, treepath, column): '''Signal handler for activating a row in the browsing treeview :param treeview: The browsing treeview :type treeview: Gtk.TreeView object :param treepath: The path of the activated row in the browsing treeview :type treepath: Gtk.TreePath object :param column: The column of the activated row in the browsing treeview :type column: Gtk.TreeViewColumn object ''' if _ARGS.debug: sys.stdout.write( 'on_row_activated() %s %s %s\n' %(repr(treeview), repr(treepath), repr(column)))
def _treepath_sort_to_model(self, sort_treepath): if isinstance(sort_treepath, str): sort_treepath = Gtk.TreePath(sort_treepath) filter_treepath = self._tv_model_sort.convert_path_to_child_path(sort_treepath) return self._tv_model_filter.convert_path_to_child_path(filter_treepath)
def __row_activated(self, target: Gtk.TreeView, path: Gtk.TreePath, column: Gtk.TreeViewColumn): i = path.get_indices()[0] connection = self._manager.get_connection(i) self.__command_ssh.run(connection, connection.args)
def expand_path(self, path): if path is not None and not isinstance(path, Gtk.TreePath): raise TypeError("Expects Gtk.TreePath or None, got %s" % type(path)) model = self.get_model() old = self.expanded_path self.expanded_path = path if old is not None: start, end = self.get_visible_range() or (None, None) if ((start and start.compare(old) != -1) or (end and end.compare(old) != 1)): self._needs_collapse.append(old) else: try: # try... a lazy solution to Bug #846204 model.row_changed(old, model.get_iter(old)) except: LOG.exception( "apptreeview.expand_path: Supplied 'old' " "path is an invalid tree path: '%s'" % old) if path == None: return model.row_changed(path, model.get_iter(path))
def _restore_treeview_state(self, state): expanded_rows, vadj = state for ind in expanded_rows: path = Gtk.TreePath.new_from_string(ind) self.app_view.tree_view.expand_row(path, False) va = self.app_view.tree_view_scroll.get_vadjustment() if va: va.set_lower(vadj) va.set_value(vadj) #~ @interrupt_build_and_wait
def on_search_entry_key_press_event(self, event): """callback when a key is pressed in the search entry widget""" if not self.is_applist_view_showing(): return if ((event.keyval == Gdk.keyval_from_name("Down") or event.keyval == Gdk.keyval_from_name("KP_Down")) and self.is_applist_view_showing() and len(self.app_view.tree_view.get_model()) > 0): # select the first item in the applist search result self.app_view.tree_view.grab_focus() self.app_view.tree_view.set_cursor(Gtk.TreePath(), None, False)
def press(self, widget, event): """press Called when the user presses a mouse button. Left click: Paint the currently active foreground color. Right Click: Remove the pixel under the mouse. Middle Click: Fill with the active foreground color. """ if self.image is None: return None main_window = self.get_toplevel() var_name = main_window.var_list.active image_width = len(self.image[0]) image_height = len(self.image) x = math.floor((event.x)/self.scale) y = math.floor((event.y)/self.scale) if x+1 > image_width or y+1 > image_height or x < 0 or y < 0: return None if event.button == 2: r, g, b, a = main_window.paint_color.get_rgba() color = [Gdk.RGBA(r, g, b), var_name] original = self.image[y][x] for yi, y in enumerate(self.image): for xi, x in enumerate(y): if str(self.image[yi][xi]) != str(original): continue self.image[yi][xi] = color self.view.queue_draw() return None elif event.button == 1 and self.get_color: color = self.image[y][x] main_window.var_list.active = None main_window.paint_color.set_rgba(color[0]) for index, item in enumerate(main_window.var_list.list): path = Gtk.TreePath().new_from_string(str(index)) if item[0] == color[1]: item[1] = True main_window.var_list.active = item[0] else: item[1] = False return None if event.button == 1: color = main_window.paint_color.get_rgba() elif event.button == 3: color = None if self.last is not None and self.square: lx, ly = self.last for xi in range(image_width): for yi in range(image_height): if ((x > lx and lx <= xi <= x or x < lx and lx >= xi >= x) and (y > ly and ly <= yi <= y or y < ly and ly >= yi >= y)): self.image[yi][xi] = [color, var_name] else: self.image[y][x] = [color, var_name] self.last = [x, y] self.view.queue_draw() return None