<?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; pygtk</title>
	<atom:link href="http://www.le-web.org/tag/pygtk/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>
		<item>
		<title>PyGTK: How to display a systray icon from a cronjob</title>
		<link>http://www.le-web.org/2008/11/06/pygtk-how-to-display-a-systray-icon-from-a-cronjob/</link>
		<comments>http://www.le-web.org/2008/11/06/pygtk-how-to-display-a-systray-icon-from-a-cronjob/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 11:51:58 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Python/PyGTK]]></category>
		<category><![CDATA[Tips, Tricks & Scripts]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[pygtk]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[systray]]></category>

		<guid isPermaLink="false">http://www.le-web.org/?p=55</guid>
		<description><![CDATA[It is nice to give some user feedback when someting happen in a background application. For example when a cronjob is running it would be nice to show a systray icon.


When the cron-job runs the DISPLAY environment variable is not defined so your gtk application can&#8217;t access to xserver. So before importing pygtk you should [...]]]></description>
			<content:encoded><![CDATA[<p>It is nice to give some user feedback when someting happen in a background application. For example when a cronjob is running it would be nice to show a systray icon.<br />
<span id="more-55"></span><br />
<!--adsense--><br />
When the cron-job runs the DISPLAY environment variable is not defined so your gtk application can&#8217;t access to xserver. So before importing pygtk you should check if DISPLAY is defined. If not just define it to default value &#8220;:0.0&#8243;.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#if DISPLAY is not set, then set it to default ':0.0'</span>
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">getenv</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">'DISPLAY'</span>, <span style="color: #483d8b;">''</span> <span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span> == <span style="color: #ff4500;">0</span>:
	<span style="color: #dc143c;">os</span>.<span style="color: black;">putenv</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">'DISPLAY'</span>, <span style="color: #483d8b;">':0.0'</span> <span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> pygtk
pygtk.<span style="color: black;">require</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;2.0&quot;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>But what happens if your gtk application really can&#8217;t connect to the xserver (xserver is not runnig, you are not logged in &#8230;). In this case your application should not try to use xserver related functions. For example when I try to use gtk.StatusIcon the application ends with a segmentation fault.</p>
<p>To check if your application can access to xserver just get the default display. If it is None then you can&#8217;t access it.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">display = gtk.<span style="color: black;">gdk</span>.<span style="color: black;">display_get_default</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> display <span style="color: #ff7700;font-weight:bold;">is</span> <span style="color: #008000;">None</span>:
	...</pre></div></div>

<p><!--adsense--><br />
Now, putting all together I made this simple application: <a href="http://www.le-web.org/wp-content/uploads/2008/11/notify.py">notify.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;">11</span>/notify.<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/notify.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 />
Try it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">python notify.py</pre></div></div>

<p>Now to try it from cron, you can add it in you crontab to be called every 10 minutes (use full path to notify.py):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#40;</span> crontab -l; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;0 * * * * python /FULLPATH/notify.py&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> crontab -
<span style="color: #7a0874; font-weight: bold;">&#40;</span> crontab -l; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;10 * * * * python /FULLPATH/notify.py&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> crontab -
<span style="color: #7a0874; font-weight: bold;">&#40;</span> crontab -l; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;20 * * * * python /FULLPATH/notify.py&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> crontab -
<span style="color: #7a0874; font-weight: bold;">&#40;</span> crontab -l; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;30 * * * * python /FULLPATH/notify.py&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> crontab -
<span style="color: #7a0874; font-weight: bold;">&#40;</span> crontab -l; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;40 * * * * python /FULLPATH/notify.py&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> crontab -
<span style="color: #7a0874; font-weight: bold;">&#40;</span> crontab -l; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;50 * * * * python /FULLPATH/notify.py&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> crontab -</pre></div></div>

<p>Check your crontab:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">crontab <span style="color: #660033;">-l</span></pre></div></div>

<p>you should see the lines with &#8220;python /FULLPATH/notify.py&#8221;.</p>
<p>To remove it from your crontab just call:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">crontab <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> notify.py <span style="color: #000000; font-weight: bold;">|</span> crontab -</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.le-web.org/2008/11/06/pygtk-how-to-display-a-systray-icon-from-a-cronjob/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PyGTK: Allow only one instance of your application (2)</title>
		<link>http://www.le-web.org/2008/11/04/pygtk-allow-only-one-instance-of-your-application-2/</link>
		<comments>http://www.le-web.org/2008/11/04/pygtk-allow-only-one-instance-of-your-application-2/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 11:05:30 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Python/PyGTK]]></category>
		<category><![CDATA[Tips, Tricks & Scripts]]></category>
		<category><![CDATA[pygtk]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.le-web.org/?p=54</guid>
		<description><![CDATA[In the post &#8220;PyGTK: Allow only one instance of your application&#8221; I presented a method to raise a PyGTK application&#8217;s window, but the solution was not perfect.


To raise the application&#8217;s window (from the application it self), I used the code:

self.window.present_with_time&#40; int&#40;time.time&#40;&#41;&#41; &#41;
self.window.present&#40;&#41;


 gtk.Window.present_with_time(): works all the time but it does not activate the window
gtk.Window.present: it [...]]]></description>
			<content:encoded><![CDATA[<p>In the post <a title="Python: Allow only one instance of your application" href="http://www.le-web.org/2008/11/03/pygtk-allow-only-one-instance-of-your-application">&#8220;PyGTK: Allow only one instance of your application&#8221;</a> I presented a method to raise a PyGTK application&#8217;s window, but the solution was not perfect.<br />
<span id="more-54"></span><br />
<!--adsense--><br />
To raise the application&#8217;s window (from the application it self), I used the code:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #008000;">self</span>.<span style="color: black;">window</span>.<span style="color: black;">present_with_time</span><span style="color: black;">&#40;</span> <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>
<span style="color: #008000;">self</span>.<span style="color: black;">window</span>.<span style="color: black;">present</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<ul>
<li> gtk.Window.present_with_time(): works all the time but it does not activate the window</li>
<li>gtk.Window.present: it does not works all the time (ex: it does not works if the application shows a modal dialog on the main window), but when it does it activate the window too</li>
</ul>
<p>Using this method,  in the worst case the window is raised but is not activate.<br />
<!--adsense--><br />
But this method was not good enough for me. I wanted a method that works all the time: raise the window and activate/focut it.<br />
So this is the new solution:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #008000;">self</span>.<span style="color: black;">window</span>.<span style="color: black;">present_with_time</span><span style="color: black;">&#40;</span> <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>
<span style="color: #008000;">self</span>.<span style="color: black;">window</span>.<span style="color: black;">window</span>.<span style="color: black;">focus</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<ul>
<li> gtk.Window.present_with_time(): raise the window</li>
<li>self.window.window.focus(): focus the window</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.le-web.org/2008/11/04/pygtk-allow-only-one-instance-of-your-application-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PyGTK: Allow only one instance of your application</title>
		<link>http://www.le-web.org/2008/11/03/pygtk-allow-only-one-instance-of-your-application/</link>
		<comments>http://www.le-web.org/2008/11/03/pygtk-allow-only-one-instance-of-your-application/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 13:37:41 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Python/PyGTK]]></category>
		<category><![CDATA[Tips, Tricks & Scripts]]></category>
		<category><![CDATA[pygtk]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.le-web.org/?p=51</guid>
		<description><![CDATA[In the post &#8220;Python: Allow only one instance of your application&#8221; I presented a method that works great for non GUI applications. It work&#8217;s fine for GUI applications too but if the application is already running the second instance will just quit. What if the application instance&#8217;s window is hidden by other window ?


In this [...]]]></description>
			<content:encoded><![CDATA[<p>In the post <a title="Python: Allow only one instance of your application" href="http://www.le-web.org/2008/10/30/python-allow-only-one-instance-of-your-application">&#8220;Python: Allow only one instance of your application&#8221;</a> I presented a method that works great for non GUI applications. It work&#8217;s fine for GUI applications too but if the application is already running the second instance will just quit. What if the application instance&#8217;s window is hidden by other window ?<br />
<span id="more-51"></span><br />
<!--adsense--><br />
In this case the best behavior is: if the GUI application is already running, the second application raise it and then quit. This provides a better user experience.</p>
<p>I read about gtk.gdk.Window.raise_() method. I don&#8217;t know why but it&#8217;s working (at least in my case) !!! The application&#8217;s window remains behind other windows.</p>
<p>The only working functions that I found, was:</p>
<ul>
<li> gtk.Window.present_with_time(): works all the time but it does not activate the window</li>
<li>gtk.Window.present: it does not works all the time (ex: it does not works if the application shows a modal dialog on the main window), but when it does it activate the window too</li>
</ul>
<p>The best way is to call them both. In the worst case the window is raised but is not activate.</p>
<p>The problem with this functions is that it must be called in the application instance, because I didn&#8217;t find a way to create a gtk.Window for an external xid (only gtk.gdk.Window). So when the second application starts it must inform the &#8220;only&#8221; application instance to raise it&#8217;s window.</p>
<p>There are different methods to comunicate between applications and I will not discuss them here. A simple and &#8220;lazy&#8221; solution is to create a file. The application instance will check from time to time if the file exists. If the file exists raise it&#8217;s window. We can can write some information in this file so that the application instance can use it.<br />
<!--adsense--><br />
This is my &#8220;Hello World !&#8221; application instance: <a href="http://www.le-web.org/wp-content/uploads/2008/11/gtkapplicationinstance.py">gtkapplicationinstance.py</a>. This application checks every second if it needs to raise itself.</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>/gtkapplicationinstance.<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/gtkapplicationinstance.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>

]]></content:encoded>
			<wfw:commentRss>http://www.le-web.org/2008/11/03/pygtk-allow-only-one-instance-of-your-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

