PyGTK: Copy a file to clipboard (paste it in Nautilus)
PyGTK provide clipboard functionality for standard targets: text, file(s) and image. Nautilus if does not use the standard URI target for copy/cat/paste file because this target does not provide the desired action (copy or cut).
For copy/cat/paste Nautilus use a special clipboard target named “x-special/gnome-copied-files”. The content of this target is a text with items separated by new line character (“\n”). The first line is the action (“copy” or “cut”) and then one URI per line.
To copy the file /path/abc.txt the target “x-special/gnome-copied-files” contains the text:
copy file:///path/abc.txt
The class “gtk.Clipboard” has the method
def set_with_data(targets, get_func, clear_func, user_data)
to set the content of the clipboard to any targets and to provide functions for clipboard requests (get/clean).
Using this method I write a simple code to handle copy path to clipboard (gnomeclipboardtools.py):
<br /> <b>Warning</b>: include(/home2/macadanc/public_html/le-web.org/wp-content/uploads/2008/12/gnomeclipboardtools.py) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in <b>/home2/macadanc/public_html/le-web.org/wp-content/plugins/include-it/plugin.php</b> on line <b>86</b><br /> <br /> <b>Warning</b>: include() [<a href='function.include'>function.include</a>]: Failed opening '/home2/macadanc/public_html/le-web.org/wp-content/uploads/2008/12/gnomeclipboardtools.py' for inclusion (include_path='.:/usr/share/pear') in <b>/home2/macadanc/public_html/le-web.org/wp-content/plugins/include-it/plugin.php</b> on line <b>86</b><br />
Using it is very simple:
import gnomeclipboardtools gnomeclipboardtools.clipboard_copy_path( '/path/abc.txt' )

October 20th, 2009 at 13:51
not working on ubuntu jaunty: in the nautilus status bar i get “no file in the clipboard” or similar…