2016-10-09 5 views
0

アクションを使用してツリービューウィジェットに右クリックしてコンテキストメニューを追加したいと思います。 Iはhttp://python-gtk-3-tutorial.readthedocs.io/en/latest/application.html#actionshttps://developer.gnome.org/gnome-devel-demos/stable/gmenu.py.htmlからミキシング情報により、このコードを試みたが、働いていない。PyGtk3アクションでツリービューの右クリックメニュー

action = Gio.SimpleAction.new("test", None) 
action.connect('activate', self.my_func) 
self.add_action(action) 

self.tree_view.connect("button-press-event", self.on_click) 

def on_click(self, widget, event): 
     if event.button == 3: 
      path, _, _, _ = widget.get_path_at_pos(int(event.x), int(event.y)) 
      treeiter = self.model.get_iter(path) 
      action_group = Gio.ActionGroup() 
      action_group.action_added("app.test") 
      treeiter.insert_action_group(action_group) 
      menu = Gtk.Menu() 
      menu.attach_to_widget(treeiter) 
      menu.popup() 

答えて

1

Gio.ActionGroupは抽象インタフェースで直接構築することができない(NotImplementedErrorをActionGroupを構築することができません)。その代わりに、action_addedの代わりにGio.SimpleActionGroupとそのinsert()メソッドが必要です。

+0

これは置き換えられた 'Gtk.ActionGroup'ではなく' Gio.ActionGroup'です。 – ptomato

関連する問題