<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>The Macaque - Latest Comments</title><link xmlns="http://www.w3.org/2005/Atom" rel="http://api.friendfeed.com/2008/03#sup" href="http://disqus.com/sup/all.sup#forumcomments-b0f0644c" type="application/json"/><link>http://themacaque.disqus.com/</link><description></description><atom:link href="http://themacaque.disqus.com/comments.rss" rel="self"></atom:link><language>en</language><lastBuildDate>Tue, 09 Apr 2013 01:37:03 -0000</lastBuildDate><item><title>Re: JQuery accordion with check box.</title><link>http://www.themacaque.com/?p=1037#comment-857114253</link><description>&lt;p&gt;:| doesn't seem to work for me... :( checkbox doesn't click but accordion is functional&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Lisa</dc:creator><pubDate>Tue, 09 Apr 2013 01:37:03 -0000</pubDate></item><item><title>Re: Event handlers in Python</title><link>http://www.themacaque.com/?p=110#comment-846045445</link><description>&lt;p&gt;For the benefit of the previous commenter. If you change requireSurname in line 3 of the code to requiredSurname, then it works. Mis-typing is the most common cause of errors where a variable has not been defined, in my limited experience.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Ward</dc:creator><pubDate>Fri, 29 Mar 2013 07:00:46 -0000</pubDate></item><item><title>Re: Event handlers in Python</title><link>http://www.themacaque.com/?p=110#comment-775989859</link><description>&lt;p&gt;Traceback (most recent call last):&lt;br&gt;  File "&amp;lt;pyshell#24&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;br&gt;    person = Person("Davide", "D'Arenzo")&lt;br&gt;  File "&amp;lt;pyshell#20&amp;gt;", line 5, in __init__&lt;br&gt;    self.surname = requiredSurname&lt;br&gt;NameError: global name 'requiredSurname' is not defined&lt;/p&gt;

&lt;p&gt;-_-&amp;lt;/pyshell#20&amp;gt;&amp;lt;/module&amp;gt;&amp;lt;/pyshell#24&amp;gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Guest</dc:creator><pubDate>Wed, 23 Jan 2013 16:30:09 -0000</pubDate></item><item><title>Re: JQuery accordion with check box.</title><link>http://www.themacaque.com/?p=1037#comment-770296207</link><description>&lt;p&gt;Awesome! I was about to give up until I found your post.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Oscar</dc:creator><pubDate>Wed, 16 Jan 2013 14:46:43 -0000</pubDate></item><item><title>Re: JQuery accordion with check box.</title><link>http://www.themacaque.com/?p=1037#comment-753461067</link><description>&lt;p&gt;Thanks, this is the exact snippet of code I was looking for.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">prpetten</dc:creator><pubDate>Mon, 05 Nov 2012 22:19:25 -0000</pubDate></item><item><title>Re: twisted.web.client.getPage with Base Auth Proxy Support</title><link>http://www.themacaque.com/?p=999#comment-753461057</link><description>&lt;p&gt;Hello,&lt;/p&gt;

&lt;p&gt;Can you please post the code so that I can take a look. The fact that the host is the proxy is correct because the Get has to go through the proxy and will later be fetch from the real host or maybe from the cache (if for example you are using a cache proxy).&lt;/p&gt;

&lt;p&gt;The request is initially send without auth because that is the way it should be sent until the proxy returns a PROXY_AUTH_ERROR when we will then use the correct auth creds.&lt;/p&gt;

&lt;p&gt;Again, please post the code here and I'll take a closer look.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">mandel</dc:creator><pubDate>Wed, 10 Oct 2012 15:54:20 -0000</pubDate></item><item><title>Re: twisted.web.client.getPage with Base Auth Proxy Support</title><link>http://www.themacaque.com/?p=999#comment-753461053</link><description>&lt;p&gt;Hi,&lt;br&gt; first thank you for sharing. I tried this code but it does not work.&lt;br&gt;It produces a bad request because the resulting request puts in the host filed the hostname of the proxy, and I receive a bad request from the server.&lt;br&gt;I am trying to get:&lt;br&gt;&lt;a href="http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8" rel="nofollow"&gt;http://devimages.apple.com/iph...&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and the generated request is:&lt;/p&gt;

&lt;p&gt;GET /iphone/samples/bipbop/bipbopall.m3u8 HTTP/1.0&lt;br&gt;host: &lt;a href="http://myproxy.com" rel="nofollow"&gt;http://myproxy.com&lt;/a&gt;&lt;br&gt;connection: close&lt;br&gt;user-agent: Twisted PageGetter&lt;/p&gt;

&lt;p&gt;were &lt;a href="http://myproxy.com" rel="nofollow"&gt;http://myproxy.com&lt;/a&gt; is my proxy (without authentication). Moreover there is this connection:close which I do not understand.&lt;/p&gt;

&lt;p&gt;while the correct request would have been (if I do not use proxy)&lt;/p&gt;

&lt;p&gt;GET /iphone/samples/bipbop/bipbopall.m3u8 HTTP/1.0&lt;br&gt;Host: &lt;a href="http://devimages.apple.com" rel="nofollow"&gt;devimages.apple.com&lt;/a&gt;&lt;br&gt;User-Agent: Twisted PageGetter&lt;/p&gt;

&lt;p&gt;can you help me on that please? Thank you&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">claudio</dc:creator><pubDate>Thu, 04 Oct 2012 16:43:03 -0000</pubDate></item><item><title>Re: JQuery accordion with check box.</title><link>http://www.themacaque.com/?p=1037#comment-753461058</link><description>&lt;p&gt;Just wanted to thank you for this piece of information -- it would have taken me a while to figure this out otherwise!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">auser</dc:creator><pubDate>Thu, 05 Jul 2012 06:46:33 -0000</pubDate></item><item><title>Re: ReadDirectoryChangesW, if you want it asynch use the correct flag</title><link>http://www.themacaque.com/?p=1013#comment-753461028</link><description>&lt;p&gt;&lt;/p&gt;&lt;p&gt;That is a complicated question. Most of what I've learned has been out of the following urls:&lt;/p&gt;&lt;br&gt;&amp;lt;ul&amp;gt;&lt;br&gt;&amp;lt;li&amp;gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa365465(v=vs.85).aspx" rel="nofollow"&gt;MSDN Documentation&lt;/a&gt;&amp;lt;/li&amp;gt;&lt;br&gt;&amp;lt;li&amp;gt;Understanding ReadDirectoryChangesW: &lt;a href="http://qualapps.blogspot.com/2010/05/understanding-readdirectorychangesw.html" rel="nofollow"&gt;Part-1&lt;/a&gt; &lt;a href="http://qualapps.blogspot.com/2010/05/understanding-readdirectorychangesw_19.html" rel="nofollow"&gt;Part -2&lt;/a&gt;&amp;lt;/li&amp;gt;&lt;br&gt;&amp;lt;li&amp;gt;&lt;a href="http://pypi.python.org/pypi/watcher/" rel="nofollow"&gt;Python FileSystemWatcher implementation&lt;/a&gt;&amp;lt;/li&amp;gt;&lt;br&gt;&amp;lt;/ul&amp;gt;&lt;br&gt;&lt;p&gt;You can also look at the ubuntu one and bazaar projects which have code that shows the usage of the function in python.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">mandel</dc:creator><pubDate>Thu, 19 Jan 2012 09:58:32 -0000</pubDate></item><item><title>Re: ReadDirectoryChangesW, if you want it asynch use the correct flag</title><link>http://www.themacaque.com/?p=1013#comment-753461019</link><description>&lt;p&gt;Thanks a lot for looking into this issue. The flag solved it. Could you point me to where I could look stuff like this up? Cannot find anything helpful even now that I know how it should work.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tim-Erwin</dc:creator><pubDate>Thu, 19 Jan 2012 08:43:52 -0000</pubDate></item><item><title>Re: Bitten in the ass by ReadDirectoryChangesW and multithreading</title><link>http://www.themacaque.com/?p=859#comment-753460832</link><description>&lt;p&gt;&lt;/p&gt;&lt;p&gt;@Tim-Erwin I have written a blog post with a propoer response to you issues which you can find &lt;a href="http://www.themacaque.com/?p=1013" rel="nofollow"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;br&gt;&lt;p&gt;As you will read in the post the issue is not related to the ReadDirectoryChangesW call but with the CreateFile one.. yes, the windows API is THAT bad.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;I hope the code helps you and please let me know how it goes :)&lt;/p&gt;&lt;br&gt;&lt;p&gt;PS: You are not spamming the post at all, I love to have this kind of comments because they will help other programmers.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">mandel</dc:creator><pubDate>Tue, 17 Jan 2012 11:24:09 -0000</pubDate></item><item><title>Re: Bitten in the ass by ReadDirectoryChangesW and multithreading</title><link>http://www.themacaque.com/?p=859#comment-753460824</link><description>&lt;p&gt;Well, seems I got the idea right so far. What you wrote is exacly what I expected. Now the problem: The WaitForSingleObject() is not reached until a change is made in the watched folder. I pasted a simple demonstration here: &lt;a href="http://pastebin.com/iVf1eKWw" rel="nofollow"&gt;http://pastebin.com/iVf1eKWw&lt;/a&gt;&lt;br&gt;If you'd give me your email I could also send you the more complex version without spamming this page too much. Really appreciate your effort.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tim-Erwin</dc:creator><pubDate>Wed, 11 Jan 2012 20:43:23 -0000</pubDate></item><item><title>Re: Bitten in the ass by ReadDirectoryChangesW and multithreading</title><link>http://www.themacaque.com/?p=859#comment-753460819</link><description>&lt;p&gt;@Tim lets look at the issue step by step:&lt;br&gt;&amp;lt;ol&amp;gt;&lt;br&gt;&amp;lt;li&amp;gt;&lt;b&gt;Does the loop change anything here? &lt;/b&gt;&lt;/p&gt;&lt;p&gt;It make no difference besides the fact that you will only get those events that fill the Overlapped object and not more.&lt;/p&gt;&amp;lt;/li&amp;gt;&lt;br&gt;&amp;lt;li&amp;gt;&lt;b&gt;I expected the thread not to wait on ReadDirectoryChangesW() but on WaitForSingleObject(), however, I don’t get past the former until a change is made. Am I mistaken?&lt;/b&gt;&lt;p&gt;Your expectations are correct, and the code is indeed waiting in the WaitForSingleObject. take a close look at the code:&lt;/p&gt;&lt;br&gt;&lt;pre&gt; win32file.ReadDirectoryChangesW(dh,&lt;br&gt;     buf,&lt;br&gt;     False, #sub-tree&lt;br&gt;     flags,&lt;br&gt;     overlapped)&lt;br&gt; # Wait for our event, or for 5 seconds.&lt;br&gt; rc = win32event.WaitForSingleObject(overlapped.hEvent, 5000)&lt;br&gt;&lt;/pre&gt;&lt;br&gt;&lt;p&gt;The code will never go passs the call from WaitForSingleObject until the ReadDirectoryChangesW writes events in the overlapped object and signals that it finished using it. Once it does we will continue and will get the return code, in this case stored in rc.&lt;/p&gt;&lt;br&gt;&amp;lt;/li&amp;gt;&lt;br&gt;&amp;lt;li&amp;gt;&lt;b&gt; I already created an application using Threads (tried your proposal anyways); surely, the application itself is not hanging then, but each single thread is.&lt;/b&gt;&lt;p&gt;Yes, each of the threads will hang until either you get events, the timeout for waiting runs out or you send a _stop_waiting event. Where are you setting the _stop_waiting event?&lt;/p&gt;&amp;lt;/li&amp;gt;&lt;br&gt;&amp;lt;/ol&amp;gt;&lt;br&gt;&lt;p&gt;Is there anywhere where you store the code and I can take a look. It will be easier to help you if you show the entire code :) &lt;/p&gt;&lt;p&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">mandel</dc:creator><pubDate>Mon, 09 Jan 2012 11:34:07 -0000</pubDate></item><item><title>Re: Bitten in the ass by ReadDirectoryChangesW and multithreading</title><link>http://www.themacaque.com/?p=859#comment-753460814</link><description>&lt;p&gt;Thanks a lot for taking your time for me. I think we need to clarify a few things here:&lt;br&gt;* Does the loop change anything here? I'm asking because you're stressing it. I only omitted it to make things easier.&lt;br&gt;* I expected the thread not to wait on ReadDirectoryChangesW() but on WaitForSingleObject(), however, I don't get past the former until a change is made. Am I mistaken?&lt;br&gt;* I already created an application using Threads (tried your proposal anyways); surely, the application itself is not hanging then, but each single thread is. I thought I could wait for a change OR 5000 millis and then go on. Alternatively, I tried WaitForMultipleObjects((overlapped.hEvent, _stop_waiting), ...) but SetEvent(_stop_waiting) has no effect.&lt;/p&gt;

&lt;p&gt;Maybe I have not understood the idea here. Your Watch class from the Ubuntu One watcher, however, seems to do it exactly as I'm trying to - and I assume it works :)&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tim-Erwin</dc:creator><pubDate>Wed, 04 Jan 2012 09:52:31 -0000</pubDate></item><item><title>Re: Bitten in the ass by ReadDirectoryChangesW and multithreading</title><link>http://www.themacaque.com/?p=859#comment-753460812</link><description>&lt;p&gt;@Tim the problem you are having is the following:&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;&lt;p&gt;if you copy the code as it is (&lt;b&gt;without the loop&lt;/b&gt;) what is happening is that your main thread of the interpreter gets block because no changes where made, The way to do this is to call the method from a different thread.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;&lt;p&gt;For example, lets assume that copied the code in the example without the loop in a function called 'get_changes' the simplest way to execute the function in a diff thread is using the thrading module, for example:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;&lt;pre&gt;import threading&lt;p&gt;&lt;/p&gt;

&lt;p&gt;t = threading.Thread(target=get_changes, args=your_args_go_here)&lt;br&gt;t.start()&lt;br&gt;&lt;/p&gt;&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;&lt;p&gt;Here the target (which has to be a callable object) is the function that will be executed in a diff thread, and the args are the arguments to be passed to the callable object.&lt;/p&gt; &lt;p&gt;You can find more info on how to executed the function in a diff thread here: &lt;a href="http://docs.python.org/library/threading.html#threading.Thread" rel="nofollow"&gt;threading.Thread&lt;/a&gt;&lt;/p&gt;&lt;br&gt;&lt;p&gt;&lt;b&gt;Edit:&lt;/b&gt; Please let me know if this solves your question.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">mandel</dc:creator><pubDate>Tue, 03 Jan 2012 15:09:51 -0000</pubDate></item><item><title>Re: Bitten in the ass by ReadDirectoryChangesW and multithreading</title><link>http://www.themacaque.com/?p=859#comment-753460811</link><description>&lt;p&gt;Thanks for sharing this code (which can already be found elsewhere (e.g. &lt;a href="http://www.java2s.com/Open-Source/Python/Windows/pyExcelerator/pywin32-214/win32/test/test_win32file.py.htm)" rel="nofollow"&gt;http://www.java2s.com/Open-Sou...&lt;/a&gt;. However, here (Win 7) the ReadDirectoryChangesW() blocks although I provide an overlapped structure. I copy and paste your code (omitting the loop) line by line into the interpreter (python 2.7), and it hangs at ReadDirectoryChangesW() until I change something in the directory. I also tried closing the handle and waiting on muliple objects, setting one of them explicitely. Nothings seems to work. Any idea what I'm doing wrong?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tim-Erwin</dc:creator><pubDate>Tue, 03 Jan 2012 14:48:31 -0000</pubDate></item><item><title>Re: Listing all installed applications on Windows with python</title><link>http://www.themacaque.com/?p=932#comment-753460924</link><description>&lt;p&gt;For the title of the post :)&lt;br&gt;s/application/applications&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">shane</dc:creator><pubDate>Sun, 25 Sep 2011 10:49:45 -0000</pubDate></item><item><title>Re: Bitten in the ass by ReadDirectoryChangesW and multithreading</title><link>http://www.themacaque.com/?p=859#comment-753460807</link><description>&lt;p&gt;If you can use twisted the following is a better implementation: &lt;a href="http://www.themacaque.com/?p=900" rel="nofollow"&gt;http://www.themacaque.com/?p=9...&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">mandel</dc:creator><pubDate>Sat, 30 Jul 2011 14:50:17 -0000</pubDate></item><item><title>Re: Bitten in the ass by ReadDirectoryChangesW and multithreading</title><link>http://www.themacaque.com/?p=859#comment-753460804</link><description>&lt;p&gt;That is a known issue, the problem here is that you cannot delete the folder because the watcher contains a handle pointing to the directory which will stop a process from delete or renaming the directory.&lt;/p&gt;

&lt;p&gt;The simplest way to solve your problem is tho stop the watch and ensure that de CloseHandle method from COM is called. I'll be posting a new version on this code that uses twisted and that has a much cleaner approach.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">mandel</dc:creator><pubDate>Sat, 30 Jul 2011 14:02:07 -0000</pubDate></item><item><title>Re: Bitten in the ass by ReadDirectoryChangesW and multithreading</title><link>http://www.themacaque.com/?p=859#comment-753460795</link><description>&lt;p&gt;Thank you for this code! I tried you asynchronous method and it works, but I am having the following problem: When I try to delete the watched folder from python or from windows explorer, I get:&lt;/p&gt;

&lt;p&gt;WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'c:usersuserappdatalocaltempnew_dir'&lt;/p&gt;

&lt;p&gt;I believe this makes sense, but how should I solve this? Because my application should allow the user to remove a watched folder. Do you have any idea?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">simple_elegance</dc:creator><pubDate>Tue, 26 Jul 2011 10:34:33 -0000</pubDate></item><item><title>Re: Using gettext in compiled Qt ui files with PyQt</title><link>http://www.themacaque.com/?p=816#comment-753461045</link><description>&lt;p&gt;Thanks for explaining the general idea! The following code is a simple wrapper for pyuic4 that uses your technique.&lt;/p&gt;

&lt;p&gt;-------------------------------------------------------------------------------------------&lt;br&gt;### import and wrap compiler.UICompiler and&lt;br&gt;from PyQt4.uic.Compiler import compiler, qtproxies, indenter&lt;/p&gt;

&lt;p&gt;# pylint: disable=C0103&lt;br&gt;class _UICompiler(compiler.UICompiler):&lt;br&gt;        """Speciallized compiler for qt .ui files."""&lt;/p&gt;

&lt;p&gt;        def createToplevelWidget(self, classname, widgetname):&lt;br&gt;                o = indenter.getIndenter()&lt;br&gt;                o.level = 0&lt;br&gt;                o.write("import gettextn_ = gettext.translation('%s', fallback=True).ugettextn" % PO_FILE_NAME)&lt;br&gt;                return super(_UICompiler, self).createToplevelWidget(classname, widgetname)&lt;/p&gt;

&lt;p&gt;compiler.UICompiler = _UICompiler&lt;/p&gt;

&lt;p&gt;### wrap qtproxies.i18n_string&lt;br&gt;class _i18n_string(qtproxies.i18n_string):&lt;br&gt;        """Provide a translated text."""&lt;/p&gt;

&lt;p&gt;        def __str__(self):&lt;br&gt;                return "_('%s')" % self.string.encode('string-escape')&lt;/p&gt;

&lt;p&gt;qtproxies.i18n_string = _i18n_string&lt;br&gt; &lt;br&gt;### run /usr/bin/pyuic4&lt;br&gt;# there's no main function, so just import the module&lt;br&gt;import PyQt4.uic.pyuic&lt;/p&gt;

&lt;p&gt;-------------------------------------------------------------------------------------------&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">arequate</dc:creator><pubDate>Wed, 15 Jun 2011 14:30:38 -0000</pubDate></item><item><title>Re: Using gettext in compiled Qt ui files with PyQt</title><link>http://www.themacaque.com/?p=816#comment-753461044</link><description>&lt;p&gt;Recently I received an email asking me for a more detailed explanation of the post, what better to add it as a comment so that others can find it. From my email:&lt;/p&gt;

&lt;p&gt;The trick here is based on the fact that we are extending the uic compiler to modify the way it generates the python code. The idea is very simple. Lets imaging that you could tell the uic compiler to use gettext rather than the normal Qt translation methods.  That way instead of using the Qt method you would call those from gettext. Lets take a look at what I mean:&lt;/p&gt;

&lt;p&gt;Qt: tr('my translated string')&lt;br&gt;gettext: _('my translated string')&lt;/p&gt;

&lt;p&gt;As you can see the actual differences between the code are minimum, so this can clearly be done automatically. In PyQt4 and PySide (although I ahve not tested it) you can extend the python compiler class to modify its behaviour the way you want, and that is precisely what the blog pots talks about. Lets take a look step by step at this process:&lt;/p&gt;

&lt;p&gt;The first thing we would like to do is to create an extension of the compiler class, that we can do as follows:&lt;/p&gt;

&lt;p&gt;from PyQt4.uic.Compiler import compiler, qtproxies, indenter&lt;br&gt; &lt;br&gt;        # pylint: disable=C0103&lt;br&gt;        class _UICompiler(compiler.UICompiler):&lt;br&gt;            """Speciallized compiler for qt .ui files."""&lt;/p&gt;

&lt;p&gt;within this child class we are going to override the method that creates the top level widget, this allows us to add imports to the python code so that we can import the gettext method.&lt;/p&gt;

&lt;p&gt;def createToplevelWidget(self, classname, widgetname):&lt;br&gt;                o = indenter.getIndenter()&lt;br&gt;                o.level = 0&lt;br&gt;                o.write('from module.with.gettext.setup import _')&lt;br&gt;                return super(_UICompiler, self).createToplevelWidget(&lt;br&gt;                                   classname, widgetname)&lt;/p&gt;

&lt;p&gt;where 'from module.with.gettext.setup import _' represents the module in your python application in which you have done the setup of gettext. Of course you do not have to do that in a diff module, but I like to keep everything in the same place. This compiler class will already provide a compiled .uic code with the extra import, but ofcourse that is not everything. The next step is to tell the compiler to use gettext for the translations. To do that we extend a new class that is sued by the compiler class which is the &lt;/p&gt;

&lt;p&gt;qtproxies.i18n_string&lt;br&gt; &lt;br&gt;which as the name states takes care of the translations:&lt;/p&gt;

&lt;p&gt;class _i18n_string(qtproxies.i18n_string):&lt;br&gt;            """Provide a translated text."""&lt;br&gt; &lt;br&gt;            def __str__(self):&lt;br&gt;                return "_('%s')" % self.string.encode(&lt;br&gt;                                                'string-escape')&lt;/p&gt;

&lt;p&gt;There we are using '_' which is the name of the function used by gettext for translations, and what it does is to ensure that all translatable string in you app are translated in such a way.&lt;/p&gt;

&lt;p&gt;To ensure that the uic modules uses or extended classes we just have to import:&lt;/p&gt;

&lt;p&gt;from PyQt4.uic.Compiler import compiler, qtproxies, indenter&lt;/p&gt;

&lt;p&gt;And set the correct classes, one for the compiler:&lt;/p&gt;

&lt;p&gt;compiler.UICompiler = _UICompiler&lt;/p&gt;

&lt;p&gt;and for the translating class:&lt;/p&gt;

&lt;p&gt;qtproxies.i18n_string = _i18n_string&lt;/p&gt;

&lt;p&gt;All this in my example is done in a class method which extends all the required classes and sets them up. Once you have all this set you can call the uic compilation from your &lt;a href="http://setup.py" rel="nofollow"&gt;setup.py&lt;/a&gt;, for example:&lt;/p&gt;

&lt;p&gt;from PyQt4 import uic&lt;br&gt;            fp = open(py_file, 'w')&lt;br&gt;            uic.compileUi(ui_file, fp)&lt;br&gt;            fp.close()&lt;/p&gt;

&lt;p&gt;I hope the explanamtion makes more sense. I suppose that you are not the only one that have not understood the example fully so I'll put this answer in the post comments.&lt;/p&gt;

&lt;p&gt;I hope it helps and let me know if you need any other help.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">mandel</dc:creator><pubDate>Sun, 05 Jun 2011 10:06:30 -0000</pubDate></item><item><title>Re: WTF: Wintypes are present on *Nix</title><link>http://www.themacaque.com/?p=826#comment-753460991</link><description>&lt;p&gt;Good, thanks !&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Devil505</dc:creator><pubDate>Sat, 28 May 2011 05:45:13 -0000</pubDate></item><item><title>Re: WTF: Wintypes are present on *Nix</title><link>http://www.themacaque.com/?p=826#comment-753460985</link><description>&lt;p&gt;I sent the patch to the distutils-extra trunk and was accepted. If you get the newest version you should not have a problem with.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">mandel</dc:creator><pubDate>Fri, 27 May 2011 15:20:29 -0000</pubDate></item><item><title>Re: WTF: Wintypes are present on *Nix</title><link>http://www.themacaque.com/?p=826#comment-753460973</link><description>&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;I've also this error when In try to package ubuntu-sso-client for another linux distribution.&lt;/p&gt;

&lt;p&gt;Where could I find you patch, please ?&lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Devil505</dc:creator><pubDate>Fri, 27 May 2011 15:01:49 -0000</pubDate></item></channel></rss>