pygtk:如何从 popup_menu 切换 window_state
这是我的代码:
def configure_event(self, widget):
if self.is_hiding:
self.window.present()
else:
self.window.iconify()
def delete_event(self, widget, data=None):
gtk.main_quit()
return True
def popup_menu(self):
self.menu = gtk.Menu()
self.about = gtk.MenuItem("about")
if self.is_hiding:
self.expand = gtk.MenuItem("show")
else:
self.expand = gtk.MenuItem("hide")
self.quit = gtk.MenuItem("quit")
self.about.connect("activate", self.about_monitor)
self.expand.connect("activate", self.configure_event)
self.quit.connect("activate", self.delete_event)
self.menu.popup(None, None, gtk.status_icon_position_menu, event_button, event_time, self.tray_icon)
self.menu.append(self.about)
self.menu.append(self.expand)
self.menu.append(self.monitor)
self.menu.append(self.quit)
self.menu.show_all()
delete_event
有效,但 configure_event
无效。为什么?
This is my code:
def configure_event(self, widget):
if self.is_hiding:
self.window.present()
else:
self.window.iconify()
def delete_event(self, widget, data=None):
gtk.main_quit()
return True
def popup_menu(self):
self.menu = gtk.Menu()
self.about = gtk.MenuItem("about")
if self.is_hiding:
self.expand = gtk.MenuItem("show")
else:
self.expand = gtk.MenuItem("hide")
self.quit = gtk.MenuItem("quit")
self.about.connect("activate", self.about_monitor)
self.expand.connect("activate", self.configure_event)
self.quit.connect("activate", self.delete_event)
self.menu.popup(None, None, gtk.status_icon_position_menu, event_button, event_time, self.tray_icon)
self.menu.append(self.about)
self.menu.append(self.expand)
self.menu.append(self.monitor)
self.menu.append(self.quit)
self.menu.show_all()
delete_event
works, but configure_event
does not. Why?
查看它们两个的签名:
delete_event
有第三个参数data
(默认值为None
),但configure_event< /code> 只有两个。
虽然我不知道例外是什么,但我打赌例外是:
如果是这样,将
configure_event
的签名更改为:会修复它。请注意,我认为
None
的默认值是不必要的,因为 gtk 总是会传递一些东西。look at the signatures of both of them:
delete_event
has a third argumentdata
(that has a default ofNone
) butconfigure_event
only has two.although i don't know what the exception was i bet that the exception was:
if so changing
configure_event
's signature to:would fix it. note that i think the default value of
None
is unneeded as gtk will pass something in always.