使用 python 在 nautilus 扩展中使用 gtk
以下代码
import gtk
import nautilus
import os
def alert(message):
"""A function to debug"""
dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE, message)
dialog.run()
dialog.destroy()
class TestExtension(nautilus.MenuProvider):
def __init__(self):
pass
def get_file_items(self, window, files):
items = []
"""Called when the user selects a file in Nautilus."""
item = nautilus.MenuItem("NautilusPython::test_item", "Test", "Test")
item.connect("activate", self.menu_activate_cb, files)
items.append(item)
return items
def menu_activate_cb(self, menu, files):
"""Called when the user selects the menu."""
for name in files:
alert(name)
不会产生任何消息。
但是
import easygui
import nautilus
import os
def alert(message):
"""A function to debug"""
easygui.msgbox(message)
class TestExtension(nautilus.MenuProvider):
def __init__(self):
pass
def get_file_items(self, window, files):
items = []
"""Called when the user selects a file in Nautilus."""
item = nautilus.MenuItem("NautilusPython::test_item", "Test", "Test")
item.connect("activate", self.menu_activate_cb, files)
items.append(item)
return items
def menu_activate_cb(self, menu, files):
"""Called when the user selects the menu."""
for name in files:
alert(name)
效果很好并生成所请求的消息。
有人可以解释这一点 - 或者更好 - 提供解决方法吗?
(更好的是,当将alert()调用移动到get_file_items()时,消息会正确显示)
The following code
import gtk
import nautilus
import os
def alert(message):
"""A function to debug"""
dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE, message)
dialog.run()
dialog.destroy()
class TestExtension(nautilus.MenuProvider):
def __init__(self):
pass
def get_file_items(self, window, files):
items = []
"""Called when the user selects a file in Nautilus."""
item = nautilus.MenuItem("NautilusPython::test_item", "Test", "Test")
item.connect("activate", self.menu_activate_cb, files)
items.append(item)
return items
def menu_activate_cb(self, menu, files):
"""Called when the user selects the menu."""
for name in files:
alert(name)
does not produce any Messages.
However
import easygui
import nautilus
import os
def alert(message):
"""A function to debug"""
easygui.msgbox(message)
class TestExtension(nautilus.MenuProvider):
def __init__(self):
pass
def get_file_items(self, window, files):
items = []
"""Called when the user selects a file in Nautilus."""
item = nautilus.MenuItem("NautilusPython::test_item", "Test", "Test")
item.connect("activate", self.menu_activate_cb, files)
items.append(item)
return items
def menu_activate_cb(self, menu, files):
"""Called when the user selects the menu."""
for name in files:
alert(name)
works nicely and produces the requested Messages.
Can someone explain this - or better - provide a workaround?
(Even better is that when moving the alert()-call into get_file_items()
the message appears correctly)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 nautilus 邮件列表上,Ahmad Sherif 发现了我的错误:
感谢艾哈迈德指出了这一点。
在第二篇文章中,Ahmad 解释了如何更好地调试:
应用艾哈迈德解释的步骤,我能够看到错误代码生成的错误消息。
On the nautilus mailing list Ahmad Sherif found my error:
Thanks to Ahmad for pointing this out.
In a second posting Ahmad explained how to debug better:
Applying the steps Ahmad explained I was able to see the error-message my faulty code generated.