以下代码
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()
信息显示正确)