用 Python 编写的 Nautilus 扩展在调用 gtk.main() 时不会运行
我正在开发一个 nautilus 扩展,并且有以下代码:
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import urllib
import gtk
import pygtk
import nautilus
import gconf
import gtk.glade
class Slide (nautilus.MenuProvider):
f = None
def __init__(self):
self.client = gconf.client_get_default()
self.f = gtk.glade.XML( "papel.glade" )
self.window = self.f.get_widget("window1")
gtk.main()
def oi (self):
self.window.show()
def menu_activate_cb(self, menu, file):
self.oi()
def get_file_items(self, window, files):
if len(files) != 1:
return
item = nautilus.MenuItem('NautilusPython::slide_file_item', 'Slide', 'Slide')
item.connect('activate', self.menu_activate_cb, files[0])
return item,
def get_background_items(self, window, file):
item = nautilus.MenuItem('NautilusPython::slide_item', 'Slide', 'Slide')
item.connect('activate', self.menu_background_activate_cb, file)
return item,
def menu_background_activate_cb(self, menu, file):
self.oi()
该代码不起作用(幻灯片不会出现在上下文菜单中)。但如果我评论这些行:
self.f = gtk.glade.XML( "papel.glade" )
self.window = self.f.get_widget("window1")
gtk.main()
那么代码就会运行。我看不出这些线路有任何问题,有什么帮助吗?
I'm developing a nautilus extension and I have the following code:
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import urllib
import gtk
import pygtk
import nautilus
import gconf
import gtk.glade
class Slide (nautilus.MenuProvider):
f = None
def __init__(self):
self.client = gconf.client_get_default()
self.f = gtk.glade.XML( "papel.glade" )
self.window = self.f.get_widget("window1")
gtk.main()
def oi (self):
self.window.show()
def menu_activate_cb(self, menu, file):
self.oi()
def get_file_items(self, window, files):
if len(files) != 1:
return
item = nautilus.MenuItem('NautilusPython::slide_file_item', 'Slide', 'Slide')
item.connect('activate', self.menu_activate_cb, files[0])
return item,
def get_background_items(self, window, file):
item = nautilus.MenuItem('NautilusPython::slide_item', 'Slide', 'Slide')
item.connect('activate', self.menu_background_activate_cb, file)
return item,
def menu_background_activate_cb(self, menu, file):
self.oi()
The code does not work (Slide does not appear in the context menu). But if I comment the lines:
self.f = gtk.glade.XML( "papel.glade" )
self.window = self.f.get_widget("window1")
gtk.main()
then the code runs. I can't see any problem with those lines, any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试只注释 gtk.main()。如果之后它仍然运行,我猜测由于 nautilus 已经在运行,调用 gtk.main() 会启动一个新的 gtk 应用程序。与鹦鹉螺分开。您需要做的就是连接到 nautilus 并点击 window.show(),您可以在 oi 方法中执行此操作。
Try only commenting gtk.main(). If it still runs after that I'm guessing that since nautilus is already running, calling gtk.main() launches a new gtk application. separate from nautilus. All you need to do is connect to nautilus and hit window.show(), which you do in your oi method.