I’ve an application written using PyGTK (GTK+2). I’d like to integrate it with Nautilus via an extension (something I am trying to learn). My current desktop has GNOME3 and Nautilus 3, which is written in GTK+3 and the extensions for Nautilus uses PyGObject.
Can I integrate my application in GTK+2 with Nautilus 3? (without porting my application to GTK+3, yet). Any hint?
I’m planning to port my application to GTK+3 (PyGObject), but it’ll require more time than I have now.
Yes, it is possible. For instance, you can use Nautilus to call your program with the files or directories as arguments. The program you are calling can be written with any toolkit, or even be just a shell script.
A tiny example or an extension:
The extension is written using GObject Introspection (Nautilus 3), and it is generic: you can call any external program you want that accepts files as arguments. The key is
GObject.spawn_async().get_file_itemsis the method that Nautilus call when the user interacts with files. In that, you can bind a contextual menu (withNautilus.MenuItem()). Then, you connect that menu with the method that calls your program (call_my_program()).You can create other filters in the method
get_file_items. For instance, to show the contextual menu only if there are text plain files selected (usingfd.is_mime_type()). You can do whatever you have in mind. Beware of performing only non-blocking operations, otherwise you could block Nautilus.To test the extension, you can install it in
~/.local/share/nautilus-python/extensions.