繁体   English   中英

GenericTreeModel与PyGObject Introspection Gtk + 3?

[英]GenericTreeModel with PyGObject Introspection Gtk+ 3?

我正在尝试在Python3中基于GenericTreeModel编写自己的Gtk + 3-TreeModel,但是这个错误:

AttributeError:'gi.repository.Gtk'对象没有属性'GenericTreeModel'

是否已重命名GenericTreeModel?

提前致谢。

PyGObject最近通过pygtkcompat获得了GenericTreeModel支持。

这是3.7.90中的新功能 ,修正了3.7.91

所以现在你应该能够使用兼容性模块迁移GenericTreeModels,至少作为一个开始。

所以我一直在处理这个问题。 这是我的结果:

  • 正如Havok已经说过的那样: GenericTreeModel不再存在,并且必须使用普通的gtk.TreeModel接口并覆盖适当的方法(命名为do_… ):

     class TreeModel(GObject.GObject, gtk.TreeModel): def do_get_iter(self, iter, path): … iter.user_data = whatever() return True 
  • 使用自定义iters等时,继承自ListStore或TreeStore不起作用。

  • 具有调用信息的存储库被破坏(请参阅launchpad:gtk3#1024492 ),以便在没有iter参数的情况下调用do_get_iter方法,因此您无法在其上设置自定义数据。 要修复它,将/usr/share/gir-1.0/Gtk-3.0.gir iter参数的方向从"out"更改为"in"并运行:

     g-ir-compiler --output=/usr/lib/girepository-1.0/Gtk-3.0.typelib /usr/share/gir-1.0/Gtk-3.0.gir 

我在PyGObject和Gtk中都找不到对GenericTreeModel的引用,但我认为你要找的只是TreeModel:

http://developer.gnome.org/gtk3/stable/GtkTreeModel.html

TreeModel是接口,由ListStore,TreeModelFilter,TreeModelSort和TreeStore实现。

>>> from gi.repository import Gtk
>>> dir(Gtk.TreeModel)
['__bool__', '__class__', '__delattr__', '__delitem__', '__dict__', '__doc__',
 '__format__', '__gdoc__', '__getattribute__', '__getitem__', '__gtype__', '__hash__', 
 '__info__', '__init__', '__iter__', '__len__', '__module__', '__new__', '__nonzero__',
 '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', 
 '__str__', '__subclasshook__', '__weakref__', '_convert_row', '_convert_value', 
 '_getiter', 'filter_new', 'foreach', 'get', 'get_column_type', 'get_flags', 'get_iter',
 'get_iter_first', 'get_iter_from_string', 'get_n_columns', 'get_path', 
 'get_string_from_iter', 'get_value', 'iter_children', 'iter_has_child', 
 'iter_n_children', 'iter_next', 'iter_nth_child', 'iter_parent', 'iter_previous', 
 'ref_node', 'row_changed', 'row_deleted', 'row_has_child_toggled', 'row_inserted', 
 'set_row', 'sort_new_with_model', 'unref_node']

编辑:

在旧的PyGtk API中找到了你想要的东西,遗憾的是,这是一个仅限PyGtk的创作。 有了内省的东西,你只能得到Gtk直接提供的东西,所以你必须直接处理TreeModel。

希望能帮助到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM