本文整理汇总了Python中gi.repository.Gtk.TreePath方法的典型用法代码示例。如果您正苦于以下问题:Python Gtk.TreePath方法的具体用法?Python Gtk.TreePath怎么用?Python Gtk.TreePath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi.repository.Gtk
的用法示例。
在下文中一共展示了Gtk.TreePath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cell_edited_callback
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TreePath [as 别名]
def cell_edited_callback(self, text_cell, path, new_text):
"""If a backend name is changed, it saves the changes in the Backend
@param text_cell: not used. The Gtk.CellRendererText that emitted the
signal. Only here because it's passed by the signal
@param path: the Gtk.TreePath of the edited cell
@param new_text: the new name of the backend
"""
# we strip everything not permitted in backend names
new_text = ''.join(c for c in new_text if (c.isalnum() or
c in [" ", "-", "_"]))
selected_iter = self.liststore.get_iter(path)
# update the backend name
backend_id = self.liststore.get_value(selected_iter,
self.COLUMN_BACKEND_ID)
backend = self.dialog.get_requester().get_backend(backend_id)
if backend:
backend.set_human_name(new_text)
# update the text in the liststore
self.liststore.set(selected_iter, self.COLUMN_TEXT, new_text)
示例2: _activate
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TreePath [as 别名]
def _activate(self, treeview, path, column):
"""Enter the completion text of the treeview into the commandline.
Args:
treeview: TreeView that was activated.
path: Activated TreePath.
column: Activated TreeViewColumn.
"""
if treeview:
count = path.get_indices()[0]
self._app["commandline"].grab_focus()
else:
count = self._tab_position
comp_type = self._get_comp_type()
row = self._liststores[comp_type][1][count]
self._app["commandline"].set_text(":" + self._prefixed_digits + row[0])
self._app["commandline"].set_position(-1)
示例3: file_select
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TreePath [as 别名]
def file_select(self, treeview, path, column, close):
"""Show image or open directory for activated file in library.
Args:
treeview: The Gtk.TreeView which emitted the signal.
path: Gtk.TreePath that was activated.
column: Column that was activated.
close: If True close the library when finished.
"""
# Empty directory
if not path:
self._app["statusbar"].message("No file to select", "error")
return
count = path.get_indices()[0]
fil = self.files[count]
self[os.getcwd()] = fil
if os.getcwd() == self._app["tags"].directory:
self._tag_select(fil, close)
elif os.path.isdir(fil): # Open directory
self.move_up(fil)
else:
self._image_select(fil, close)
示例4: test_file_select
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TreePath [as 别名]
def test_file_select(self):
"""Select file in library."""
# Directory by position
path = Gtk.TreePath([self.lib.files.index("directory")])
self.lib.file_select(None, path, None, False)
self.assertEqual(self.lib.files, ["symlink with spaces .jpg"])
self.lib.move_up()
# Library still focused
self.assertTrue(self.lib.is_focus())
# Image by position closing library
path = Gtk.TreePath([self.lib.files.index("arch_001.jpg")])
self.lib.file_select(None, path, None, True)
expected_images = ["arch-logo.png", "arch_001.jpg", "symlink_to_image",
"vimiv.bmp", "vimiv.svg", "vimiv.tiff"]
expected_images = [os.path.abspath(image) for image in expected_images]
self.assertEqual(self.vimiv.get_paths(), expected_images)
open_image = self.vimiv.get_path()
expected_image = os.path.abspath("arch_001.jpg")
self.assertEqual(expected_image, open_image)
# Library closed, image has focus
self.assertFalse(self.lib.is_focus())
self.assertFalse(self.lib.grid.is_focus())
self.assertTrue(self.vimiv["main_window"].is_focus())
示例5: test_button_click
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TreePath [as 别名]
def test_button_click(self):
"""Click mouse button."""
self.vimiv["library"].file_select(None, Gtk.TreePath(1), None, True)
image_before = self.vimiv.get_path()
event = Gdk.Event().new(Gdk.EventType.BUTTON_PRESS)
event.button = 1
self.vimiv["window"].emit("button_press_event", event)
image_after = self.vimiv.get_path()
self.assertNotEqual(image_before, image_after)
# Double click should not work
event = Gdk.Event().new(Gdk.EventType.DOUBLE_BUTTON_PRESS)
event.button = 1
self.vimiv["window"].emit("button_press_event", event)
self.assertEqual(image_after, self.vimiv.get_path())
# Focus library via mouse click
event = Gdk.Event().new(Gdk.EventType.BUTTON_PRESS)
event.button = 2
self.vimiv["window"].emit("button_press_event", event)
self.assertTrue(self.vimiv["library"].is_focus())
示例6: row_activated
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TreePath [as 别名]
def row_activated(self, iter, model):
if not self.active:
return
if self.mode == HINT and self.store.get_path(iter) != Gtk.TreePath(self.path):
moves = self.store[iter][0][2]
if moves is not None:
# score = self.store[iter][1][0]
model.add_variation(self.engine.board, moves)
if self.mode == SPY and self.store.get_path(iter) != Gtk.TreePath(self.path):
moves = self.store[iter][0][2]
if moves is not None:
# score = self.store[iter][1][0]
board = self.engine.board.board
# SPY analyzer has inverted color boards
# we need to chage it to get the board in gamemodel variations board list later
board.setColor(1 - board.color)
king = board.kings[board.color]
null_move = Move(newMove(king, king))
model.add_variation(self.engine.board, [null_move] + moves)
示例7: add_move
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TreePath [as 别名]
def add_move(self, gamemodel, ply):
if ply == gamemodel.lowply:
self.store.append(["%4s." % gamemodel.lowply, "1234567", "1234567", 0, self.get_background_rgba(), self.get_background_rgba()])
return
if self.figuresInNotation:
notat = toFAN(gamemodel.getBoardAtPly(ply - 1), gamemodel.getMoveAtPly(ply - 1))
else:
notat = toSAN(gamemodel.getBoardAtPly(ply - 1), gamemodel.getMoveAtPly(ply - 1), localRepr=True)
row, column = self.ply_to_row_col(ply)
if len(self.store) - 1 < row:
mvcount = "%s." % ((ply + 1) // 2)
if column == self.white_column:
self.store.append([mvcount, notat, "", row, self.get_background_rgba(), self.get_background_rgba()])
else:
self.store.append([mvcount, "", notat, row, self.get_background_rgba(), self.get_background_rgba()])
else:
treeiter = self.store.get_iter(Gtk.TreePath(row))
col = 1 if column == self.white_column else 2
self.store.set_value(treeiter, col, notat)
示例8: change_active
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TreePath [as 别名]
def change_active(self, widget, path):
selected_path = Gtk.TreePath(path)
for row in self:
if row.path == selected_path:
row[EFIStore.ROW_ACTIVE] = not row[EFIStore.ROW_ACTIVE]
num = row[EFIStore.ROW_NUM]
if row[EFIStore.ROW_ACTIVE]:
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)
示例9: _find_tag
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TreePath [as 别名]
def _find_tag(self, tag):
if isinstance(tag, int):
row = self.db.execute(
'SELECT * FROM tags WHERE id = ?', (tag,)
).fetchone()
else:
row = self.db.execute(
'SELECT * FROM tags WHERE name = ?', (tag,)
).fetchone()
if row is None:
raise IndexNotFoundError
try:
offset, n_children = self._get_offset_n_children(row)
except ValueError:
return
mytreepath = (offset,)
if mytreepath not in self.cache:
myiter = MyTreeIter(Gtk.TreePath(mytreepath), row, n_children, IS_TAG)
self.cache[mytreepath] = myiter
return Gtk.TreePath(mytreepath)
示例10: row_deleted
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TreePath [as 别名]
def row_deleted(self, path, node=None):
"""Notify the model a row has been deleted.
Use the node parameter to ensure the user_data reference associated
with the path is properly freed by this model.
:Parameters:
path : Gtk.TreePath
Path to the row that has been deleted.
node : object
Python object used as the node returned from "on_get_iter". This is
optional but ensures the model will not leak references to this object.
"""
super(GenericTreeModel, self).row_deleted(path)
node_id = id(node)
if node_id in self._held_refs:
del self._held_refs[node_id]
#
# GtkTreeModel Interface Implementation
#
示例11: testTreePathMethods
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TreePath [as 别名]
def testTreePathMethods(self):
db = new_test_database()
mockindex = tests.MockObject()
mockindex._db = db
mockindex.update_iter = tests.MockObject()
mockindex.update_iter.pages = tests.MockObject()
model = PagesTreeModelMixin(mockindex)
# Test all pages
for name, treepath in TREEPATHS:
myiter = model.get_mytreeiter(treepath)
self.assertEqual(myiter.row['name'], name)
self.assertEqual(myiter.treepath, Gtk.TreePath(treepath))
my_treepath = model.find(Path(name))
self.assertEqual(my_treepath, Gtk.TreePath(treepath))
# Test non-existing
p = model.get_mytreeiter((1, 2, 3, 4, 5))
self.assertIsNone(p)
self.assertRaises(IndexNotFoundError, model.find, Path('non-existing-page'))
示例12: _get_selected_path
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TreePath [as 别名]
def _get_selected_path(self):
"""
Helper function to get the selected path
@return Gtk.TreePath : returns exactly one path for the selected object
or None
"""
selection = self.get_selection()
if selection:
model, selected_paths = self.get_selection().get_selected_rows()
if selected_paths:
return selected_paths[0]
return None
示例13: load
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TreePath [as 别名]
def load(self, tagname):
"""Load all images in a tag as current filelist.
Args:
tagname: Name of tag to operate on.
"""
os.chdir(self.directory)
# Read file and get all tagged images as list
tagged_images = self._read(tagname)
# Populate filelist
self._app.populate(tagged_images, expand_single=False)
if self._app.get_paths():
self._app["main_window"].show()
self._app["library"].set_hexpand(False)
self._app["image"].load()
# Focus in library if it is open
if self._app["library"].grid.is_visible():
self._app["library"].reload(self.directory)
tag_pos = self._app["library"].files.index(tagname)
self._app["library"].set_cursor(Gtk.TreePath(tag_pos),
None, False)
# Remember last tag selected
self.last = tagname
else:
message = "Tagfile '%s' has no valid images" % (tagname)
self._app["statusbar"].message(message, "error")
self.last = ""
示例14: move_pos
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TreePath [as 别名]
def move_pos(self, forward=True, defined_pos=None):
"""Move to a specific position in the library.
Defaults to moving to the last file. Can be used for the first file or
any defined position.
Args:
forward: If True move forwards.
defined_pos: If not empty defines the position to move to.
"""
if not self.files:
self._app["statusbar"].message("No position to go to", "error")
return
max_pos = len(self.files)
# Direct call from scroll
if isinstance(defined_pos, int):
new_pos = defined_pos
elif forward:
new_pos = self._app["eventhandler"].num_receive(max_pos) - 1
else:
new_pos = self._app["eventhandler"].num_receive() - 1
if new_pos < 0 or new_pos > max_pos:
self._app["statusbar"].message("Unsupported index", "warning")
return
self.set_cursor(Gtk.TreePath(new_pos), None, False)
self.scroll_to_cell(Gtk.TreePath(new_pos), None, True, 0.5, 0)
# Clear the prefix
self._app["eventhandler"].num_clear()
示例15: _on_activated
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TreePath [as 别名]
def _on_activated(self, iconview, path):
"""Select and show image when thumbnail was activated.
Args:
iconview: Gtk.IconView that emitted the signal.
path: Gtk.TreePath of the activated thumbnail.
"""
self.toggle(True)
count = path.get_indices()[0] + 1
self._app["eventhandler"].num_clear()
self._app["eventhandler"].set_num_str(count)
self._app["image"].move_pos()