<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Martin Plicka</title>
    <description>The latest articles on DEV Community by Martin Plicka (@martinplicka).</description>
    <link>https://dev.to/martinplicka</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F6041%2FhHfsnGxB.jpg</url>
      <title>DEV Community: Martin Plicka</title>
      <link>https://dev.to/martinplicka</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/martinplicka"/>
    <language>en</language>
    <item>
      <title>Compiling UI and resource files with PyQt</title>
      <dc:creator>Martin Plicka</dc:creator>
      <pubDate>Thu, 01 Jun 2017 13:31:23 +0000</pubDate>
      <link>https://dev.to/martinplicka/compiling-ui-and-resource-files-with-pyqt</link>
      <guid>https://dev.to/martinplicka/compiling-ui-and-resource-files-with-pyqt</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This article was originally published years ago at &lt;a href="https://mplicka.cz/en/blog/compiling-ui-and-resource-files-with-pyqt"&gt;https://mplicka.cz/en/blog/compiling-ui-and-resource-files-with-pyqt&lt;/a&gt; and it's about Qt4/PyQt4. Since it still has some hits coming from Google search, some people may find it useful.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;PyQt is a python binding for popular Qt library (which became LGPLed for non-commercial purposes recently). If you use Qt Designer, you have to compile XML description of UI or Qt resource files to Python code to use them in your application.&lt;/p&gt;

&lt;p&gt;In C++, you can easily use &lt;code&gt;qmake&lt;/code&gt; tool or Automake for creating suitable Makefile. For Python, there is no Makefile needed since Python compiles modules as they are loaded into VM. With PyQt, you can use &lt;code&gt;uic&lt;/code&gt; module for compiling ui files or loading them as a Python class.&lt;/p&gt;

&lt;p&gt;Alternatively, you can use &lt;code&gt;pyuic4&lt;/code&gt; and &lt;code&gt;pyrcc4&lt;/code&gt; command line tools in the similar way as appropriate Qt tools (&lt;code&gt;uic&lt;/code&gt;, &lt;code&gt;rcc&lt;/code&gt;). I'm using this way to produce Python code. Both tools have similar usage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#compile ui file from Qt Designer&lt;/span&gt;
pyuic4 ui_file.ui &lt;span class="nt"&gt;-o&lt;/span&gt; compiled_ui_file.py
&lt;span class="c"&gt;#compile resource file (icons, etc..)&lt;/span&gt;
pyrcc4 resource_file.qrc &lt;span class="nt"&gt;-o&lt;/span&gt; compiled_resource_file.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Formerly, I had one shell script to compile all my resource files in project at once (because I was too lazy). This solution has two main disadvantages. At first, compilation of all resources takes more time than compiling of modified files only. This varies with amount of resource files your project has. The second one is more annoying to me. Since I also track compiled versions of UI and resource files (for no particular reason yet) with Mercurial, it always creates new changeset because ''pyuic4'' tool adds information about compile time to Python code comments. So I refreshed my Makefile knowledge (and also used some old code snippets) and created following Makefile for compiling UI and resource files separately.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight make"&gt;&lt;code&gt;&lt;span class="c"&gt;###### EDIT ##################### 
#Directory with ui and resource files
&lt;/span&gt;&lt;span class="nv"&gt;RESOURCE_DIR&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; src/resources

&lt;span class="c"&gt;#Directory for compiled resources
&lt;/span&gt;&lt;span class="nv"&gt;COMPILED_DIR&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; src/ui

&lt;span class="c"&gt;#UI files to compile
&lt;/span&gt;&lt;span class="nv"&gt;UI_FILES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; confirm.ui main.ui repair.ui settings.ui statistics.ui
&lt;span class="c"&gt;#Qt resource files to compile
&lt;/span&gt;&lt;span class="nv"&gt;RESOURCES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; images.qrc 

&lt;span class="c"&gt;#pyuic4 and pyrcc4 binaries
&lt;/span&gt;&lt;span class="nv"&gt;PYUIC&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; pyuic4.bat
&lt;span class="nv"&gt;PYRCC&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; pyrcc4

&lt;span class="c"&gt;#################################
# DO NOT EDIT FOLLOWING
&lt;/span&gt;
&lt;span class="nv"&gt;COMPILED_UI&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;UI_FILES:%.ui&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(COMPILED_DIR)&lt;/span&gt;/ui_%.py&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;COMPILED_RESOURCES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;RESOURCES:%.qrc&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(COMPILED_DIR)&lt;/span&gt;/%_rc.py&lt;span class="o"&gt;)&lt;/span&gt;

&lt;span class="nl"&gt;all &lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;resources ui &lt;/span&gt;

&lt;span class="nl"&gt;resources &lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;$(COMPILED_RESOURCES) &lt;/span&gt;

&lt;span class="nl"&gt;ui &lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;$(COMPILED_UI)&lt;/span&gt;

&lt;span class="nl"&gt;$(COMPILED_DIR)/ui_%.py &lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;$(RESOURCE_DIR)/%.ui&lt;/span&gt;
    &lt;span class="nv"&gt;$(PYUIC)&lt;/span&gt; &lt;span class="nv"&gt;$&amp;lt;&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; &lt;span class="nv"&gt;$@&lt;/span&gt;

&lt;span class="nl"&gt;$(COMPILED_DIR)/%_rc.py &lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;$(RESOURCE_DIR)/%.qrc&lt;/span&gt;
    &lt;span class="nv"&gt;$(PYRCC)&lt;/span&gt; &lt;span class="nv"&gt;$&amp;lt;&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; &lt;span class="nv"&gt;$@&lt;/span&gt;

&lt;span class="nl"&gt;clean &lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; 
    &lt;span class="nv"&gt;$(RM)&lt;/span&gt; &lt;span class="nv"&gt;$(COMPILED_UI)&lt;/span&gt; &lt;span class="nv"&gt;$(COMPILED_RESOURCES)&lt;/span&gt; &lt;span class="nv"&gt;$(COMPILED_UI:.py=.pyc)&lt;/span&gt; &lt;span class="nv"&gt;$(COMPILED_RESOURCES:.py=.pyc)&lt;/span&gt;  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It works with GNU Make (from Cygwin or MigGW on Windows). It compiles files in following manner:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;window.ui --&amp;gt; ui_window.py (GUI definition)&lt;/li&gt;
&lt;li&gt;images.qrc --&amp;gt; images_rc.py (resources)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now you can easily compile only modified files by only typing &lt;code&gt;make&lt;/code&gt; in console. Make sure that your current working directory contains Makefile shown above.&lt;/p&gt;

</description>
      <category>python</category>
      <category>qt</category>
      <category>pyqt</category>
    </item>
    <item>
      <title>Hi, I'm Martin Plicka</title>
      <dc:creator>Martin Plicka</dc:creator>
      <pubDate>Mon, 24 Apr 2017 14:49:35 +0000</pubDate>
      <link>https://dev.to/martinplicka/hi-im-martin-plicka</link>
      <guid>https://dev.to/martinplicka/hi-im-martin-plicka</guid>
      <description>&lt;p&gt;I have been coding for some years.&lt;/p&gt;

&lt;p&gt;You can find me on Twitter as &lt;a href="https://twitter.com/MartinPlicka" rel="noopener noreferrer"&gt;@MartinPlicka&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I live in Prague. I work for e-FRACTAL LTD, bringing you &lt;a href="https://www.phonecopy.com/" rel="noopener noreferrer"&gt;PhoneCopy.com&lt;/a&gt; service.&lt;/p&gt;

&lt;p&gt;I mostly program in these languages: Python.&lt;/p&gt;

&lt;p&gt;Check &lt;a href="https://mplicka.cz/" rel="noopener noreferrer"&gt;my blog&lt;/a&gt; with occasional posts about technology (both in English and Czech), or music and other topics (in Czech)&lt;/p&gt;

</description>
      <category>introduction</category>
    </item>
  </channel>
</rss>
