从pygtk中的button_press_event发送树视图信息
我正在编写一个使用树视图的 pygtk 应用程序,它与 button_press_event
有连接。我不知道如何将有关树视图的信息(特别是单击的行)传递给 gtk.Menu 或其他方法。如果我使用 row-activated
信号,它会传入行和列信息作为参数,但 button_press_event
不会发生这种情况。这是有问题的代码:
self.liststore = gtk.ListStore(str,int, int, int,str, 'gboolean')
self.treeview = gtk.TreeView(self.liststore)
self.treeview.connect("button_press_event",self.serverListEvent)
self.treeview.set_search_column(0)
self.draw_columns(self.treeview)
self.blackmenu = gtk.Menu()
self.bitem = gtk.MenuItem("Blacklist server")
self.blackmenu.append(self.bitem)
self.bitem.connect("activate",self.blacklistServer)
self.bitem.show()
def serverListEvent(self,treeview,event):
x = int(event.x)
y = int(event.y)
time = event.time
model = treeview.get_model()
pthinfo = treeview.get_path_at_pos(x, y)
if pthinfo is not None:
path, col, cellx, celly = pthinfo
# Error here for the model with the column
print 'url clicked '+model[col][0]
treeview.grab_focus()
treeview.set_cursor( path, col, 0)
# Popup blacklist menu on right click
if event.button == 3:
self.blackmenu.popup( None, None, None, event.button, time)
# Join game on double click
elif event.type == gtk.gdk._2BUTTON_PRESS:
self.joinGame(treeview,model[col][0])
return True
然后我需要将信息从单击的行传递到 self.joinGame 和 self.blacklistServer 方法,但不知道如何也可以这样做。
I am writing an pygtk app that uses a treeview, which has a connection to button_press_event
. What I can't figure out is how to pass the information about the treeview (specifically which row is clicked) to a gtk.Menu
or another method. If I used the row-activated
signal, it passes in the row and column information in as an argument, but this does not happen with button_press_event
. Here is the code in question:
self.liststore = gtk.ListStore(str,int, int, int,str, 'gboolean')
self.treeview = gtk.TreeView(self.liststore)
self.treeview.connect("button_press_event",self.serverListEvent)
self.treeview.set_search_column(0)
self.draw_columns(self.treeview)
self.blackmenu = gtk.Menu()
self.bitem = gtk.MenuItem("Blacklist server")
self.blackmenu.append(self.bitem)
self.bitem.connect("activate",self.blacklistServer)
self.bitem.show()
def serverListEvent(self,treeview,event):
x = int(event.x)
y = int(event.y)
time = event.time
model = treeview.get_model()
pthinfo = treeview.get_path_at_pos(x, y)
if pthinfo is not None:
path, col, cellx, celly = pthinfo
# Error here for the model with the column
print 'url clicked '+model[col][0]
treeview.grab_focus()
treeview.set_cursor( path, col, 0)
# Popup blacklist menu on right click
if event.button == 3:
self.blackmenu.popup( None, None, None, event.button, time)
# Join game on double click
elif event.type == gtk.gdk._2BUTTON_PRESS:
self.joinGame(treeview,model[col][0])
return True
I then need to pass the information from the clicked row to the self.joinGame
and self.blacklistServer
methods, but don't know how to do this either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我记得那个人有点棘手。我 设置我的树视图的 gtk.TreeSelection 到任何 选择模式首选。然后是这样的:
编辑:
我从未使用过 gtk.Menu 和 gtk.MenuItem,所以我不知道您已经将菜单连接到回调(blacklistServer)。这是未经测试的,但应该可以给你一个想法。
I remember that one being kindy tricky. I set up my treeview's gtk.TreeSelection to whatever mode of selection preferred. Then this:
Edit:
I never used gtk.Menu and gtk.MenuItem, so I didn't get that you already had your menu connected to a callback (blacklistServer). This is untested, but should give you an idea.