<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>le-Web.org &#187; gnome</title>
	<atom:link href="http://www.le-web.org/tag/gnome/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.le-web.org</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 04 Dec 2008 10:21:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PyGTK: Copy a file to clipboard (paste it in Nautilus)</title>
		<link>http://www.le-web.org/2008/12/04/pygtk-copy-a-file-to-clipboard-paste-it-in-nautilus/</link>
		<comments>http://www.le-web.org/2008/12/04/pygtk-copy-a-file-to-clipboard-paste-it-in-nautilus/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 10:21:13 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Python/PyGTK]]></category>
		<category><![CDATA[Tips, Tricks & Scripts]]></category>
		<category><![CDATA[clipboard]]></category>
		<category><![CDATA[gnome]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[nautilus]]></category>
		<category><![CDATA[pygtk]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.le-web.org/?p=74</guid>
		<description><![CDATA[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 &#8220;x-special/gnome-copied-files&#8221;. The content of this target is a text with items separated [...]]]></description>
			<content:encoded><![CDATA[<p>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).<br />
<span id="more-74"></span><br />
<!--adsense--><br />
For copy/cat/paste Nautilus use a special clipboard target named &#8220;x-special/gnome-copied-files&#8221;. The content of this target is a text with items separated by new line character (&#8220;\n&#8221;). The first line is the action (&#8220;copy&#8221; or &#8220;cut&#8221;) and then one URI per line.</p>
<p>To copy the file /path/abc.txt the target &#8220;x-special/gnome-copied-files&#8221; contains the text:</p>
<pre>copy
file:///path/abc.txt</pre>
<p>The class &#8220;gtk.Clipboard&#8221; has the method</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> set_with_data<span style="color: black;">&#40;</span>targets, get_func, clear_func, user_data<span style="color: black;">&#41;</span></pre></div></div>

<p>to set the content of the clipboard to any targets and to provide functions for clipboard requests (get/clean).<br />
<!--adsense--><br />
Using this method I write a simple code to handle copy path to clipboard (<a href="http://www.le-web.org/wp-content/uploads/2008/12/gnomeclipboardtools.py">gnomeclipboardtools.py</a>):</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>br /<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>b<span style="color: #66cc66;">&gt;</span>Warning<span style="color: #66cc66;">&lt;</span>/b<span style="color: #66cc66;">&gt;</span>:  include<span style="color: black;">&#40;</span>/home2/macadanc/public_html/le-web.<span style="color: black;">org</span>/wp-content/uploads/<span style="color: #ff4500;">2008</span>/<span style="color: #ff4500;">12</span>/gnomeclipboardtools.<span style="color: black;">py</span><span style="color: black;">&#41;</span> <span style="color: black;">&#91;</span><span style="color: #66cc66;">&lt;</span>a href=<span style="color: #483d8b;">'function.include'</span><span style="color: #66cc66;">&gt;</span>function.<span style="color: black;">include</span><span style="color: #66cc66;">&lt;</span>/a<span style="color: #66cc66;">&gt;</span><span style="color: black;">&#93;</span>: failed to <span style="color: #008000;">open</span> stream: No such <span style="color: #008000;">file</span> <span style="color: #ff7700;font-weight:bold;">or</span> directory <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #66cc66;">&lt;</span>b<span style="color: #66cc66;">&gt;</span>/home2/macadanc/public_html/le-web.<span style="color: black;">org</span>/wp-content/plugins/include-it/plugin.<span style="color: black;">php</span><span style="color: #66cc66;">&lt;</span>/b<span style="color: #66cc66;">&gt;</span> on line <span style="color: #66cc66;">&lt;</span>b<span style="color: #66cc66;">&gt;</span><span style="color: #ff4500;">86</span><span style="color: #66cc66;">&lt;</span>/b<span style="color: #66cc66;">&gt;&lt;</span>br /<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>br /<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>b<span style="color: #66cc66;">&gt;</span>Warning<span style="color: #66cc66;">&lt;</span>/b<span style="color: #66cc66;">&gt;</span>:  include<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: black;">&#91;</span><span style="color: #66cc66;">&lt;</span>a href=<span style="color: #483d8b;">'function.include'</span><span style="color: #66cc66;">&gt;</span>function.<span style="color: black;">include</span><span style="color: #66cc66;">&lt;</span>/a<span style="color: #66cc66;">&gt;</span><span style="color: black;">&#93;</span>: Failed opening <span style="color: #483d8b;">'/home2/macadanc/public_html/le-web.org/wp-content/uploads/2008/12/gnomeclipboardtools.py'</span> <span style="color: #ff7700;font-weight:bold;">for</span> inclusion <span style="color: black;">&#40;</span>include_path=<span style="color: #483d8b;">'.:/usr/share/pear'</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #66cc66;">&lt;</span>b<span style="color: #66cc66;">&gt;</span>/home2/macadanc/public_html/le-web.<span style="color: black;">org</span>/wp-content/plugins/include-it/plugin.<span style="color: black;">php</span><span style="color: #66cc66;">&lt;</span>/b<span style="color: #66cc66;">&gt;</span> on line <span style="color: #66cc66;">&lt;</span>b<span style="color: #66cc66;">&gt;</span><span style="color: #ff4500;">86</span><span style="color: #66cc66;">&lt;</span>/b<span style="color: #66cc66;">&gt;&lt;</span>br /<span style="color: #66cc66;">&gt;</span></pre></div></div>

<p>Using it is very simple:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> gnomeclipboardtools
gnomeclipboardtools.<span style="color: black;">clipboard_copy_path</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">'/path/abc.txt'</span> <span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.le-web.org/2008/12/04/pygtk-copy-a-file-to-clipboard-paste-it-in-nautilus/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PyGTK: Get GNOME icon associated with a file</title>
		<link>http://www.le-web.org/2008/11/18/pygtk-get-gnome-icon-associated-with-a-file/</link>
		<comments>http://www.le-web.org/2008/11/18/pygtk-get-gnome-icon-associated-with-a-file/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 15:16:55 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Python/PyGTK]]></category>
		<category><![CDATA[Tips, Tricks & Scripts]]></category>
		<category><![CDATA[gnome]]></category>
		<category><![CDATA[icon]]></category>
		<category><![CDATA[mime]]></category>
		<category><![CDATA[pygtk]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.le-web.org/?p=64</guid>
		<description><![CDATA[If in your application you need to display a list of files/folders it would be nice to display icons near filenames.


Icons are associated with files using mime types. For a file you need to get it&#8217;s mime and the get the icon associated with this mime.
The module gnomevfs provides almost all you need:

def gnomevfs.get_mime_type(uri)

Returns a [...]]]></description>
			<content:encoded><![CDATA[<p>If in your application you need to display a list of files/folders it would be nice to display icons near filenames.<br />
<span id="more-64"></span><br />
<!--adsense--><br />
Icons are associated with files using <a href="http://en.wikipedia.org/wiki/MIME">mime types</a>. For a file you need to get it&#8217;s mime and the get the icon associated with this mime.<br />
The module gnomevfs provides almost all you need:</p>
<ul>
<li>def gnomevfs.get_mime_type(uri)</li>
</ul>
<p style="padding-left: 60px;">Returns a string containing the mime type (ex: for the file &#8220;file.tar.gz&#8221; the mime is &#8220;application/x-compressed-tar&#8221;).</p>
<ul>
<li>def gnomevfs.mime_get_icon(mime_type)</li>
</ul>
<p style="padding-left: 60px;">Returns a string with an icon name.</p>
<p>I said almost because gnomevfs.mime_get_icon always returns None (at least in my version).</p>
<p>Since the gnomevfs.get_mime_type works fine I decide to write a little class to associate the mime with the icons.</p>
<p>Gnome use icon names like &#8220;gnome-mime-&lt;mime&gt;&#8221;. Ex: for the mime &#8220;application/x-compressed-tar&#8221; the gnome icon name is &#8220;gnome-mime-application-x-compressed-tar&#8221;.</p>
<p>My class try to associate the mime with an icon, by searching for icons with the name:</p>
<ul>
<li>&#8220;gnome-mime-&lt;mime&gt;&#8221;</li>
<li>if the path is a directory it will try the icon name &#8220;folder&#8221; and if &#8220;folder&#8221; don&#8217;t exists just returns gtk.STOCK_DIRECTORY</li>
<li>&#8220;mime-&lt;mime&gt;&#8221;</li>
<li>returns gtk.STOCK_FILE</li>
</ul>
<p>In order to optimize mime to icon association the class use a cache.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>br /<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>b<span style="color: #66cc66;">&gt;</span>Warning<span style="color: #66cc66;">&lt;</span>/b<span style="color: #66cc66;">&gt;</span>:  include<span style="color: black;">&#40;</span>/home2/macadanc/public_html/le-web.<span style="color: black;">org</span>/wp-content/uploads/<span style="color: #ff4500;">2008</span>/<span style="color: #ff4500;">11</span>/gnomefileicons.<span style="color: black;">py</span><span style="color: black;">&#41;</span> <span style="color: black;">&#91;</span><span style="color: #66cc66;">&lt;</span>a href=<span style="color: #483d8b;">'function.include'</span><span style="color: #66cc66;">&gt;</span>function.<span style="color: black;">include</span><span style="color: #66cc66;">&lt;</span>/a<span style="color: #66cc66;">&gt;</span><span style="color: black;">&#93;</span>: failed to <span style="color: #008000;">open</span> stream: No such <span style="color: #008000;">file</span> <span style="color: #ff7700;font-weight:bold;">or</span> directory <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #66cc66;">&lt;</span>b<span style="color: #66cc66;">&gt;</span>/home2/macadanc/public_html/le-web.<span style="color: black;">org</span>/wp-content/plugins/include-it/plugin.<span style="color: black;">php</span><span style="color: #66cc66;">&lt;</span>/b<span style="color: #66cc66;">&gt;</span> on line <span style="color: #66cc66;">&lt;</span>b<span style="color: #66cc66;">&gt;</span><span style="color: #ff4500;">86</span><span style="color: #66cc66;">&lt;</span>/b<span style="color: #66cc66;">&gt;&lt;</span>br /<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>br /<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>b<span style="color: #66cc66;">&gt;</span>Warning<span style="color: #66cc66;">&lt;</span>/b<span style="color: #66cc66;">&gt;</span>:  include<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: black;">&#91;</span><span style="color: #66cc66;">&lt;</span>a href=<span style="color: #483d8b;">'function.include'</span><span style="color: #66cc66;">&gt;</span>function.<span style="color: black;">include</span><span style="color: #66cc66;">&lt;</span>/a<span style="color: #66cc66;">&gt;</span><span style="color: black;">&#93;</span>: Failed opening <span style="color: #483d8b;">'/home2/macadanc/public_html/le-web.org/wp-content/uploads/2008/11/gnomefileicons.py'</span> <span style="color: #ff7700;font-weight:bold;">for</span> inclusion <span style="color: black;">&#40;</span>include_path=<span style="color: #483d8b;">'.:/usr/share/pear'</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #66cc66;">&lt;</span>b<span style="color: #66cc66;">&gt;</span>/home2/macadanc/public_html/le-web.<span style="color: black;">org</span>/wp-content/plugins/include-it/plugin.<span style="color: black;">php</span><span style="color: #66cc66;">&lt;</span>/b<span style="color: #66cc66;">&gt;</span> on line <span style="color: #66cc66;">&lt;</span>b<span style="color: #66cc66;">&gt;</span><span style="color: #ff4500;">86</span><span style="color: #66cc66;">&lt;</span>/b<span style="color: #66cc66;">&gt;&lt;</span>br /<span style="color: #66cc66;">&gt;</span></pre></div></div>

<p><!--adsense--><br />
Using it is very simple:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> gnomefileicons
&nbsp;
fileicons = gnomefileicons.<span style="color: black;">GnomeFileIcons</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> fileicons.<span style="color: black;">getIcon</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'/path/file.tar.gz'</span><span style="color: black;">&#41;</span></pre></div></div>

</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.le-web.org/2008/11/18/pygtk-get-gnome-icon-associated-with-a-file/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

