Use gtk in nautilus extension using python

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 create 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) 

It works beautifully and creates the requested messages.

Can someone explain this - or better - provide a workaround?

(Even better, when you move the alert (), a call to get_file_items() message appears correctly)

+4
source share
1 answer

Ahmad Sherif found my error on the nautilus mailing list :

gtk.MessageDialog does not work with your code because the fifth argument must be either a string or No, and the variable name is of type nautilus.FileInfo, which means that you need to call alert(name.get_name()) not just alert(name)
For more information on nautilus.FileInfo see docs .

Thanks to Ahmad for this.

In a second publication, Ahmad explained how best to debug:

I think you could get such debugging information if you started Nautilus from the terminal. [...]
You must first exit Nautilus ( nautilus -q ) and then run it ( nautilus --no-desktop ). If [nautilus] made [automatically] reappear [after exiting], you should edit /usr/share/applications/nautilus.desktop as follows (backup being a good idea):

  • Replace "X-GNOME-AutoRestart = true" with "X-GNOME-AutoRestart = false"
  • Comment on this line "X-GNOME-Autostart-Phase = Desktop" at "#" at the beginning of the line. Actually, I forgot why I did it, but this is how my configuration :).
  • Add this line "AutostartCondition = GNOME / apps / nautilus / preferences / show_desktop"
  • Finally, you must restart the session, and then try to log out and start again.

Loans go to wrc1944 [...] for a regenerative solution.

Applying the steps that Ahmad explained, I was able to see the error message in which the error code was generated.

+2
source

All Articles