<?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>dennogumi.org &#187; programming</title>
	<atom:link href="http://www.dennogumi.org/tag/programming/feed" rel="self" type="application/rss+xml" />
	<link>http://www.dennogumi.org</link>
	<description>On the web since 1999</description>
	<lastBuildDate>Fri, 06 Jan 2012 14:56:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PyKDE4: new style signals and slots</title>
		<link>http://www.dennogumi.org/2010/03/pykde4-new-style-signals-and-slots</link>
		<comments>http://www.dennogumi.org/2010/03/pykde4-new-style-signals-and-slots#comments</comments>
		<pubDate>Sat, 06 Mar 2010 09:04:48 +0000</pubDate>
		<dc:creator>Einar</dc:creator>
				<category><![CDATA[KDE]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.dennogumi.org/?p=763</guid>
		<description><![CDATA[Those who use PyQt and PyKDE4 are certainly familiar with the syntax used to connect signals and slots: The main advantage of this syntax is that it&#8217;s very close to the C++ equivalent, and so you can translate easily from &#8230; <a href="http://www.dennogumi.org/2010/03/pykde4-new-style-signals-and-slots">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Those who use PyQt and PyKDE4 are certainly familiar with the syntax used to connect signals and slots:</p>
<pre class="brush: python; title: ; notranslate">
from PyQt4 import QtCore
from PyQt4 import QtGui
from PyKDE4 import kdeui

class MyGUI(QtGui.QWidget):

    def __init__(self, parent=None):
        super(MyGUI, self).__init__(parent)
        self.pushbutton = kdeui.KPushButton()
        self.pushbutton.setText(&quot;Push me!&quot;)

        QObject.connect(self.pushbutton, QtCore.SIGNAL(&quot;clicked()&quot;),
                               self.button_pushed)

    def button_pushed(self):
        print &quot;Button clicked&quot;
</pre>
<p>The main advantage of this syntax is that it&#8217;s very close to the C++ equivalent, and so you can translate easily from C++ to Python. Unfortunately the advantages of this syntax end here. The disadvantages, at least from a Python coding perspective, outweigh the advantages:</p>
<ul>
<li>It&#8217;s <em>extremely</em> error-prone: make a typo, and not only your signal won&#8217;t be connected, but you won&#8217;t even get a warning, your program will simply do nothing;</li>
<li>In case you have overloaded signals, you have to type the exact signature, going back to the first problem;</li>
<li>It&#8217;s not Pythonic at all.</li>
</ul>
<p>So, in recent PyQt versions (and thus also in PyKDE4) a <em>new style</em> approach was introduced (although the old style is always present should it be the need to). Using the new style, the signals become a property of the object that emits them. and then you use the connect function of that property. Here&#8217;s the example using the new style-signals:</p>
<pre class="brush: python; title: ; notranslate">
from PyQt4 import QtCore
from PyQt4 import QtGui
from PyKDE4 import kdeui

class MyGUI(QtGui.QWidget):

    def __init__(self, parent=None):
        super(MyGUI, self).__init__(parent)
        self.pushbutton = kdeui.KPushButton()
        self.pushbutton.setText(&quot;Push me!&quot;)
        # New style
        self.pushbutton.clicked.connect(self.button_pushed)

    def button_pushed(self):
        print &quot;Button clicked&quot;
</pre>
<p>As you can see it&#8217;s much clearer, and much more Pythonic. Also, typos  <strong>will</strong> trigger an AttributeError, which means you&#8217;ll be able to track where the problem is.  </p>
<p>What about overloaded signals? Normally the first defined is the default, but you can use a dictionary-like syntax to access other overloads (signal names are completely made up here):</p>
<pre class="brush: python; title: ; notranslate">
# One signal is without arguments, the other has a bool

# Signal without arguments
self.my_widget.connected.connect(self.handle_errors)
# Signal with a book
self.my_widget.connected[bool].connect(self.handle_errors)
</pre>
<p>Signals are emitted with the emit() function and disconnected with the disconnect() function:</p>
<pre class="brush: python; title: ; notranslate">
# Emit a signal
self.pushbutton.clicked.emit()
# Emit a signal with a value (an int)
self.my_widget.valueChanged.emit(int)
# Disconnect another
self.my_tabwidget.currentIndexChanged.disconnect()
</pre>
<p>To define new signals, you can use the <em>pyqtSignal</em> function, specifying which values will the signal take (if any): just define that as a class constant (like in the example) and then you can access them like the wrapped ones:</p>
<pre class="brush: python; title: ; notranslate">

class MyWidget(QWidget):

    # Signal with no arguments
    operationPerformed = QtCore.pyqtSignal()

    # Signal that takes arguments
    valueChanged = QtCore.pyqtSignal(int)
</pre>
<p>I merely scratched the surface with this. For more information, check out <a href="http://riverbankcomputing.co.uk/static/Docs/PyQt4/pyqt4ref.html" title="PyQt4 Reference Manual">PyQt&#8217;s reference manual</a>, which also covers other cases.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dennogumi.org/2010/03/pykde4-new-style-signals-and-slots/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>DataMatrix page up</title>
		<link>http://www.dennogumi.org/2008/10/datamatrix-page-up</link>
		<comments>http://www.dennogumi.org/2008/10/datamatrix-page-up#comments</comments>
		<pubDate>Sun, 12 Oct 2008 20:14:14 +0000</pubDate>
		<dc:creator>Einar</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[datamatrix]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.dennogumi.org/?p=466</guid>
		<description><![CDATA[Ok, ok&#8230; my definition of &#8220;tomorrow&#8221; is not like what most people use, apparently. Although I took quite a while, now there is a static page on DataMatrix. There you will find a summary of wht I wrote in my &#8230; <a href="http://www.dennogumi.org/2008/10/datamatrix-page-up">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Ok, ok&#8230; my definition of &#8220;tomorrow&#8221; is not like what most people use, apparently. Although I took quite a while, now <a href="http://www.dennogumi.org/projects-2/datamatrix">there is a static page on DataMatrix</a>. There you will find a summary of wht I wrote in my other blog posts regarding this module. Of course, it will be kept up-to-date should I release a new version.</p>
<p>Aside that, I put a contact form on this blog. It may be useful for reports that aren&#8217;t directly related to the posts.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dennogumi.org/2008/10/datamatrix-page-up/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DataMatrix 0.5</title>
		<link>http://www.dennogumi.org/2008/09/datamatrix-05</link>
		<comments>http://www.dennogumi.org/2008/09/datamatrix-05#comments</comments>
		<pubDate>Fri, 19 Sep 2008 19:54:58 +0000</pubDate>
		<dc:creator>Einar</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Science]]></category>
		<category><![CDATA[datamatrix]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.dennogumi.org/?p=451</guid>
		<description><![CDATA[At last, since it&#8217;s been like ages, I decided to put out a new version of DataMatrix. For those who haven&#8217;t seen my previous post, DataMatrix is a Pythonic implementation of R&#8217;s data.frame. It enables you to manipulate a text &#8230; <a href="http://www.dennogumi.org/2008/09/datamatrix-05">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>At last, since it&#8217;s been like ages, I decided to put out a new version of DataMatrix. For those who haven&#8217;t seen my previous post, DataMatrix is a Pythonic implementation of <a href="http://stat.ethz.ch/R-manual/R-patched/library/base/html/data.frame.html">R&#8217;s data.frame</a>. It enables you to manipulate a text file by columns or rows, to your liking, using a dictionary-like syntax. </p>
<p>In this new version there have been a few improvements and correction to a couple bugs (for example saveMatrix did not really save) and the start (only a stub at the moment) of an append function to add more columns (I&#8217;ll also think about a function to add rows).</p>
<p>DataMatrix is licensed under the GNU GPL, version 2 only. You can download <a href="http://www.dennogumi.org/files/datamatrix-0.5.win32.exe?cda6c1">the installer</a> (Windows) or <a href="http://www.dennogumi.org/files/datamatrix-0.5.tar.gz?cda6c1">the source distribution</a> (Linux and other *nixes). The only requirement is Python 2.5 or later installed on your system.</p>
<p> The README currently is a stub, but you can <a href="http://www.dennogumi.org/files/datamatrix.html">browse the pydoc generated documentation</a>, which details how to instantiate and use DataMatrix objects (or <a href="http://www.dennogumi.org/2008/06/dataframes-in-python-datamatrix">you can turn to my older post</a>). </p>
<p>Also, since git is the new &#8220;cool feature of the day&#8221;, DataMatrix is is hosted on github&#8217;s repository, and you can grab the source with </p>
<pre class="brush: cpp; title: ; notranslate">
git clone git://github.com/cswegger/datamatrix.git
</pre>
<p>Comments and suggestions are welcome. I&#8217;ll be putting a static page on DataMatrix tomorrow, if time permits.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dennogumi.org/2008/09/datamatrix-05/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>data.frames in Python &#8211; DataMatrix</title>
		<link>http://www.dennogumi.org/2008/06/dataframes-in-python-datamatrix</link>
		<comments>http://www.dennogumi.org/2008/06/dataframes-in-python-datamatrix#comments</comments>
		<pubDate>Sun, 29 Jun 2008 08:13:55 +0000</pubDate>
		<dc:creator>Einar</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Science]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.dennogumi.org/?p=405</guid>
		<description><![CDATA[For a long time I have tried to handle text files in Python in the same way that R&#8217;s data.frame does &#8211; that is, direct access to columns and rows of a loaded text file. As I don&#8217;t like R &#8230; <a href="http://www.dennogumi.org/2008/06/dataframes-in-python-datamatrix">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For a long time I have tried to handle text files in Python in the same way that R&#8217;s <a title="R Data Frames" href="http://pbil.univ-lyon1.fr/library/base/html/data.frame.html">data.frame</a> does &#8211; that is, direct access to columns and rows of a loaded text file. As I don&#8217;t like R at all, I struggled to find a Pythonic equivalent, and since I found none, I decided to eat my own food and write an implementation, which is what you&#8217;ll find below.</p>
<p><span id="more-405"></span></p>
<p>The idea is to store the values of the text file as a dictionary of columns which includes then a list of (row name, row value) tuples. Like this, you can access the columns by their name (I need to see if it&#8217;s workable to also use numbers), or you can view specific rows, including all or a subset of the columns. It&#8217;s decently faster and it allows for non-sequential access, which you can&#8217;t do when reading a file (or a file-like structure).</p>
<p><strong>Requirements</strong></p>
<p>I have tested this on Python 2.5.1. Older versions may or may not work. All modules called by this one should be shipped with Python itself.</p>
<p><strong>Download and installation<br />
</strong></p>
<p><a title="Download" href="http://www.dennogumi.org/files/datamatrix.py">Download the py file directly</a>. Currently there is no installation mechanism, so copy it wherever Python can find it.  There&#8217;s <a title="Documentation" href="http://www.dennogumi.org/files/datamatrix.html">some API documentation</a> generated with pydoc.</p>
<p>This module is licensed under the GNU General Public License, version 2.</p>
<p><strong>Usage</strong></p>
<p>First of all, import the module</p>
<pre class="brush: python; title: ; notranslate">

import datamatrix</pre>
<p>Then open a file and instantiate a DataMatrix object</p>
<pre class="brush: python; title: ; notranslate">

fh = open(&quot;somefile.txt&quot;)
data = datamatrix.DataMatrix(fh)</pre>
<p>By default no column with row names is specified, so if you have one, you have to specify it:</p>
<pre class="brush: python; title: ; notranslate">
data = datamatrix.DataMatrix(fh, row_names=1)
</pre>
<p>More options are in the documentation.</p>
<p>Once the DataMatrix is initialized, you can view how many columns are there and also view rows with the getRow method:</p>
<pre class="brush: python; title: ; notranslate">

&gt;&gt; data.columns
[&quot;GeneID&quot;,&quot;Great_Exp1&quot;,&quot;Great_Exp2&quot;]

&gt;&gt; data[&quot;Great_Exp1&quot;]
[(&quot;Gene1&quot;,56.34),
...
]

&gt;&gt; data.getRow(5)
[&quot;NOT_EXISTENT&quot;,&quot;56.545&quot;,&quot;4.56&quot;]
</pre>
<p>Sometimes you&#8217;d want to get only the column without the row identifier, and that&#8217;s where getColumn comes in:</p>
<pre class="brush: python; title: ; notranslate">

&gt;&gt; data.getColumn(&quot;Great_Exp1&quot;)
[56.34,2.55.....]
</pre>
<p>Should you want to save a DataMatrix instance, you can use the writeMatrix function:</p>
<pre class="brush: python; title: ; notranslate">

datamatrix.writeMatrix(data,fname=&quot;/path/to/somewhere/file.txt&quot;)
</pre>
<p>That&#8217;s all. Questions and suggestions, especially on coding and improvements, are very welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dennogumi.org/2008/06/dataframes-in-python-datamatrix/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>QSql vs DB-API?</title>
		<link>http://www.dennogumi.org/2007/12/qsql-vs-db-api</link>
		<comments>http://www.dennogumi.org/2007/12/qsql-vs-db-api#comments</comments>
		<pubDate>Fri, 28 Dec 2007 12:58:40 +0000</pubDate>
		<dc:creator>Einar</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.dennogumi.org/2007/12/28/qsql-vs-db-api</guid>
		<description><![CDATA[I&#8217;ve recently begun trying to create GUIs for my Python applications with PyQt, and I can say I&#8217;m absolutely loving the toolkit, relatively easy to use and featureful. As I&#8217;m trying to create a GUI for some module I wrote &#8230; <a href="http://www.dennogumi.org/2007/12/qsql-vs-db-api">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently begun trying to create GUIs for my Python applications with <a href="http://www.riverbankcomputing.co.uk/pyqt/index.php" title="PyQt at Riverbank Computing">PyQt</a>, and I can say I&#8217;m absolutely loving the toolkit, relatively easy to use and featureful. As I&#8217;m trying to create a GUI for some module I wrote that deals with databases (using MySQLdb), I also learnt that Qt has a series of classes for dealing with databases, mainly QSql.</p>
<p>My question, directed to whoever has experience with QSql and the Python DB-API, is: what are the advantages of one approach to the other? I&#8217;m leaning towards DB-API because like that I can create modules which work also in command line applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dennogumi.org/2007/12/qsql-vs-db-api/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using xcache (Feed is rejected)
Page Caching using xcache
Database Caching 1/27 queries in 0.028 seconds using xcache
Object Caching 497/559 objects using xcache

Served from: www.dennogumi.org @ 2012-02-07 16:00:03 -->
