<?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>Just Another Physicist</title>
	<atom:link href="http://www.japh.de/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.japh.de/blog</link>
	<description></description>
	<lastBuildDate>Sun, 04 Jul 2010 22:48:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Python for Measurement and Data Acquisition</title>
		<link>http://www.japh.de/blog/python-for-measurement-and-data-acquisition/</link>
		<comments>http://www.japh.de/blog/python-for-measurement-and-data-acquisition/#comments</comments>
		<pubDate>Sun, 04 Jul 2010 10:42:00 +0000</pubDate>
		<dc:creator>Andreas</dc:creator>
				<category><![CDATA[Ohne Kategorie]]></category>
		<category><![CDATA[data acquisition]]></category>
		<category><![CDATA[experiment]]></category>
		<category><![CDATA[lab]]></category>
		<category><![CDATA[measurement]]></category>
		<category><![CDATA[physics]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.japh.de/blog/?p=600</guid>
		<description><![CDATA[I’m a PhD student in physics, working on experimental quantum computing with superconducting qubits. So as you might guess, data acquisition and analysis make up a big part of my daily work. To state an example, my current experiment requires me to control 15 different measurement devices such as microwave generators, voltage sources, arbitrary waveform [...]]]></description>
			<content:encoded><![CDATA[<p>I’m a PhD student in physics, working on experimental quantum computing with superconducting qubits. So as you might guess, data acquisition and analysis make up a big part of my daily work. To state an example, my current experiment requires me to control 15 different measurement devices such as microwave generators, voltage sources, arbitrary waveform generators, oscilloscopes, spectrum analyzers and fast data acquisition cards. All of this equipment needs to be properly interfaced and in order to perform an actual measurement it is necessary to perform many individual parameter changes and data transfer steps. Furthermore, huge amounts of numerical and binary data often need to be analyzed, aggregated and fed-back as parameters into the measurement system. In order to do all this, the software used in my group when I started my PhD was National Instrument’s “Labview”. Labview is an easy-to-use and quite powerful tool for building measurement and automation applications. In fact, when I first got in touch with it I was quite amazed of how easy it actually was to interface measurement devices and to build simple graphical user interfaces. Some of the features of Labview which I probably liked most were</p>
<ul>
<li>the ability to easily create rich user interfaces with diagrams, tables and data graphs.</li>
<li>the ease of use of the graphical programming interface, which provides many pre-build libraries and instrument drivers. </li>
<li>the very high execution speed of Labview scripts.</li>
</ul>
<p>However, as I started to build more complex experiments it became increasingly hard to come up with good solutions for interfacing them through Labview. For example, some limitations which quickly started to annoy me were</p>
<ul>
<li>the lack of a text-based programming language. Labview uses a graphical programming language called &quot;G&quot;, which makes it easy to “write” but hard to copy and read code. </li>
<li>the dataflow programming model of Labview, which makes it very hard to reuse individual parts of programs and to make use of object-oriented programming techniques.&#160; </li>
</ul>
<p>So after all, I wasn&#8217;t fully happy with using Labview for controlling my experiments since I felt that I would be somehow limited in the extension of my measurement system. Luckily, one day a post-doc working in our group told me that in his former lab a programming language called Python was used to control and interface most of their measurement equipment. Up to that day I only briefly heard of this language and I didn’t have the slightest experience with it. Nevertheless, I became very curious and I wanted to learn more about it. And as it turned out, I found Python to be a great tool for my work: It was flexible, easy to learn and it had many useful libraries that I could use for my data acquisition and processing needs. In fact, as of today Python seems to become more and more <em>the</em> standard scientific programming language, often replacing older and more inconvenient languages such as C/C++ and Fortran. So, being a physicist <em>and</em> a computer geek I was immediately convinced and started to use it on a daily basis. As of today, I have completely rewritten our whole measurement and data acquisition system in Python, with very satisfying results. Unfortunately, during this work I also learned that Python has some shortcomings of its own that can make it complicated to use it in a scientific environment. For me, some of the most troubling (but solvable) issues included</p>
<ul>
<li>the Global Interpreter Lock (GIL): The Python interpreter cannot simultaneously execute code in different threads. This makes it quite hard to make full use of a&#160; multi-processor architecture. </li>
<li>the fact that Python code runs relatively slow: Numerical operations and the manipulation of large amounts of data (e.g. binary strings, lists and numbers), which are very common tasks in a measurement environment, run much slower than e.g. in Labview or C/C++.</li>
<li>the lack of an easy-to-use (for a scientist, not for a programmer) toolkit for building graphical user interfaces: Although there are several very good toolkits available that make it relatively easy to build a graphical user interface with Python (e.g. PyQt or Tkinter), all of them require some considerable learning effort and a large amount of programming. </li>
</ul>
<p>Fortunately it turned out that all of these problems can be somehow fixed or circumvented. In the following blog posts I will describe in detail how I resolved these issues and what I think is a good way to build a measurement system with Python. </p>
<p>Please feel free to comment on this article and to share your thoughts and experiences concerning the use of Python in a scientific environment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japh.de/blog/python-for-measurement-and-data-acquisition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QTextEdit with line numbers</title>
		<link>http://www.japh.de/blog/qtextedit-with-line-numbers/</link>
		<comments>http://www.japh.de/blog/qtextedit-with-line-numbers/#comments</comments>
		<pubDate>Sat, 05 Jun 2010 17:36:25 +0000</pubDate>
		<dc:creator>Andreas</dc:creator>
				<category><![CDATA[Ohne Kategorie]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[PyQt]]></category>
		<category><![CDATA[QPlainTextEdit]]></category>
		<category><![CDATA[Qt]]></category>
		<category><![CDATA[QTextEdit]]></category>

		<guid isPermaLink="false">http://www.japh.de/blog/?p=586</guid>
		<description><![CDATA[The Qt QPlainTextEdit class provides a very nice plaintext editor that can be used e.g. for displaying and editing source code. One thing missing in the class though is the ability to display line numbers in the margin of the editor, which (in my opinion) is a very important feature of any code editor. Luckily, [...]]]></description>
			<content:encoded><![CDATA[<p>The Qt QPlainTextEdit class provides a very nice plaintext editor that can be used e.g. for displaying and editing source code. One thing missing in the class though is the ability to display line numbers in the margin of the editor, which (in my opinion) is a very important feature of any code editor. Luckily, after a bit of searching on the web I found this excellent <a href="http://john.nachtimwald.com/2009/08/15/qtextedit-with-line-numbers/" target="_blank">blog entry</a> which includes a code snippet that extends QTextEdit with the ability to display line numbers. For one of my recent projects I used and slightly modified this code, eliminating among other things the QFrame that was used there and using a QPlainTextEdit instead of a QTextEdit as base class of the editor, which makes the processing of the line numbers slightly faster. Here is my modified version of the code:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#Original code (MIT license): http://john.nachtimwald.com/2009/08/15/qtextedit-with-line-numbers/</span>
<span style="color: #ff7700;font-weight:bold;">from</span> PyQt4.<span style="color: black;">QtGui</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span> 
<span style="color: #ff7700;font-weight:bold;">from</span> PyQt4.<span style="color: black;">QtCore</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> LineTextWidget<span style="color: black;">&#40;</span>QPlainTextEdit<span style="color: black;">&#41;</span>:
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> append<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>,<span style="color: #dc143c;">string</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">appendPlainText</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">string</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">class</span> NumberBar<span style="color: black;">&#40;</span>QWidget<span style="color: black;">&#41;</span>: 
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, <span style="color: #66cc66;">*</span>args<span style="color: black;">&#41;</span>:
            QWidget.<span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, <span style="color: #66cc66;">*</span>args<span style="color: black;">&#41;</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">edit</span> = <span style="color: #008000;">None</span>
            <span style="color: #808080; font-style: italic;"># This is used to update the width of the control.</span>
            <span style="color: #808080; font-style: italic;"># It is the highest line that is currently visibile.</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">highest_line</span> = <span style="color: #ff4500;">0</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">def</span> setTextEdit<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, edit<span style="color: black;">&#41;</span>:
            <span style="color: #008000;">self</span>.<span style="color: black;">edit</span> = edit
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">def</span> update<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, <span style="color: #66cc66;">*</span>args<span style="color: black;">&#41;</span>:
            width = QFontMetrics<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">edit</span>.<span style="color: black;">document</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">defaultFont</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>.<span style="color: black;">width</span><span style="color: black;">&#40;</span><span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">highest_line</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> + <span style="color: #ff4500;">10</span>
            <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">self</span>.<span style="color: black;">width</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">!</span>= width:
                <span style="color: #008000;">self</span>.<span style="color: black;">setFixedWidth</span><span style="color: black;">&#40;</span>width<span style="color: black;">&#41;</span>
                <span style="color: #008000;">self</span>.<span style="color: black;">edit</span>.<span style="color: black;">setViewportMargins</span><span style="color: black;">&#40;</span>width,<span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
            QWidget.<span style="color: black;">update</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, <span style="color: #66cc66;">*</span>args<span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">def</span> paintEvent<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, event<span style="color: black;">&#41;</span>:
            contents_y = <span style="color: #ff4500;">0</span>
            page_bottom = <span style="color: #008000;">self</span>.<span style="color: black;">edit</span>.<span style="color: black;">viewport</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">height</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            font_metrics = QFontMetrics<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">edit</span>.<span style="color: black;">document</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">defaultFont</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
            current_block = <span style="color: #008000;">self</span>.<span style="color: black;">edit</span>.<span style="color: black;">document</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">findBlock</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">edit</span>.<span style="color: black;">textCursor</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">position</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
            painter = QPainter<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>
&nbsp;
            <span style="color: #808080; font-style: italic;"># Iterate over all text blocks in the document.</span>
            block = <span style="color: #008000;">self</span>.<span style="color: black;">edit</span>.<span style="color: black;">firstVisibleBlock</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            viewport_offset = <span style="color: #008000;">self</span>.<span style="color: black;">edit</span>.<span style="color: black;">contentOffset</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            line_count = block.<span style="color: black;">blockNumber</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            painter.<span style="color: black;">setFont</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">edit</span>.<span style="color: black;">document</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">defaultFont</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">while</span> block.<span style="color: black;">isValid</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
                line_count += <span style="color: #ff4500;">1</span>
&nbsp;
                <span style="color: #808080; font-style: italic;"># The top left position of the block in the document</span>
                position = <span style="color: #008000;">self</span>.<span style="color: black;">edit</span>.<span style="color: black;">blockBoundingGeometry</span><span style="color: black;">&#40;</span>block<span style="color: black;">&#41;</span>.<span style="color: black;">topLeft</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>+viewport_offset
                <span style="color: #808080; font-style: italic;"># Check if the position of the block is out side of the visible</span>
                <span style="color: #808080; font-style: italic;"># area.</span>
                <span style="color: #ff7700;font-weight:bold;">if</span> position.<span style="color: black;">y</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> page_bottom:
                    <span style="color: #ff7700;font-weight:bold;">break</span>
&nbsp;
                <span style="color: #808080; font-style: italic;"># We want the line number for the selected line to be bold.</span>
                bold = <span style="color: #008000;">False</span>
                <span style="color: #ff7700;font-weight:bold;">if</span> block == current_block:
                    bold = <span style="color: #008000;">True</span>
                    font = painter.<span style="color: black;">font</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                    font.<span style="color: black;">setBold</span><span style="color: black;">&#40;</span><span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
                    painter.<span style="color: black;">setFont</span><span style="color: black;">&#40;</span>font<span style="color: black;">&#41;</span>
&nbsp;
                <span style="color: #808080; font-style: italic;"># Draw the line number right justified at the y position of the</span>
                <span style="color: #808080; font-style: italic;"># line. 3 is a magic padding number. drawText(x, y, text).</span>
                painter.<span style="color: black;">drawText</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">width</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> - font_metrics.<span style="color: black;">width</span><span style="color: black;">&#40;</span><span style="color: #008000;">str</span><span style="color: black;">&#40;</span>line_count<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> - <span style="color: #ff4500;">3</span>, <span style="color: #008000;">round</span><span style="color: black;">&#40;</span>position.<span style="color: black;">y</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> + font_metrics.<span style="color: black;">ascent</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>+font_metrics.<span style="color: black;">descent</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>-<span style="color: #ff4500;">1</span>, <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>line_count<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
                <span style="color: #808080; font-style: italic;"># Remove the bold style if it was set previously.</span>
                <span style="color: #ff7700;font-weight:bold;">if</span> bold:
                    font = painter.<span style="color: black;">font</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                    font.<span style="color: black;">setBold</span><span style="color: black;">&#40;</span><span style="color: #008000;">False</span><span style="color: black;">&#41;</span>
                    painter.<span style="color: black;">setFont</span><span style="color: black;">&#40;</span>font<span style="color: black;">&#41;</span>
&nbsp;
                block = block.<span style="color: black;">next</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
            <span style="color: #008000;">self</span>.<span style="color: black;">highest_line</span> = line_count
            painter.<span style="color: black;">end</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
            QWidget.<span style="color: black;">paintEvent</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, event<span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, <span style="color: #66cc66;">*</span>args<span style="color: black;">&#41;</span>:
        QPlainTextEdit.<span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, <span style="color: #66cc66;">*</span>args<span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #008000;">self</span>.<span style="color: black;">number_bar</span> = <span style="color: #008000;">self</span>.<span style="color: black;">NumberBar</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">number_bar</span>.<span style="color: black;">setTextEdit</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #008000;">self</span>.<span style="color: black;">viewport</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">installEventFilter</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> resizeEvent<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>,e<span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">number_bar</span>.<span style="color: black;">setFixedHeight</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">height</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        QPlainTextEdit.<span style="color: black;">resizeEvent</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>,e<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> setDefaultFont<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>,font<span style="color: black;">&#41;</span>:
      <span style="color: #008000;">self</span>.<span style="color: black;">document</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">setDefaultFont</span><span style="color: black;">&#40;</span>font<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> eventFilter<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, <span style="color: #008000;">object</span>, event<span style="color: black;">&#41;</span>:
        <span style="color: #808080; font-style: italic;"># Update the line numbers for all events on the text edit and the viewport.</span>
        <span style="color: #808080; font-style: italic;"># This is easier than connecting all necessary singals.</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">object</span> <span style="color: #ff7700;font-weight:bold;">is</span> <span style="color: #008000;">self</span>.<span style="color: black;">viewport</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
            <span style="color: #008000;">self</span>.<span style="color: black;">number_bar</span>.<span style="color: black;">update</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">False</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> QPlainTextEdit.<span style="color: black;">eventFilter</span><span style="color: black;">&#40;</span><span style="color: #008000;">object</span>, event<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#To test the class.</span>
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
  qApp = QApplication<span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#41;</span>
  qApp.<span style="color: black;">connect</span><span style="color: black;">&#40;</span>qApp, SIGNAL<span style="color: black;">&#40;</span><span style="color: #483d8b;">'lastWindowClosed()'</span><span style="color: black;">&#41;</span>, qApp,
                    SLOT<span style="color: black;">&#40;</span><span style="color: #483d8b;">'quit()'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
  MyWindow = QMainWindow<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
  MyEdit = LineTextWidget<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
  MyWindow.<span style="color: black;">setCentralWidget</span><span style="color: black;">&#40;</span>MyEdit<span style="color: black;">&#41;</span>
&nbsp;
  MyWindow.<span style="color: black;">show</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
  qApp.<span style="color: black;">exec_</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.japh.de/blog/qtextedit-with-line-numbers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A thread-safe observer pattern for Python and Qt</title>
		<link>http://www.japh.de/blog/a-thread-safe-observer-pattern-for-python-and-qt/</link>
		<comments>http://www.japh.de/blog/a-thread-safe-observer-pattern-for-python-and-qt/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 22:54:14 +0000</pubDate>
		<dc:creator>Andreas</dc:creator>
				<category><![CDATA[Ohne Kategorie]]></category>

		<guid isPermaLink="false">http://www.japh.de/blog/?p=575</guid>
		<description><![CDATA[Observer patterns are quite useful in many circumstances. As the name implies, such a pattern notifies an &#8220;observer&#8221; class about some change in another class, often called the &#8220;subject&#8221;. In Python it is very straightforward to implement such a pattern and the following code snippet -which I use quite often in my everyday programming- shows [...]]]></description>
			<content:encoded><![CDATA[<p>Observer patterns are quite useful in many circumstances. As the name implies, such a pattern notifies an &#8220;observer&#8221; class about some change in another class, often called the &#8220;subject&#8221;. In Python it is very straightforward to implement such a pattern and the following code snippet -which I use quite often in my everyday programming- shows a possible way to do it:</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;">weakref</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Subject:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>._observers = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">isNotifying</span> = <span style="color: #008000;">False</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> attach<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, observer<span style="color: black;">&#41;</span>:
        r = <span style="color: #dc143c;">weakref</span>.<span style="color: black;">ref</span><span style="color: black;">&#40;</span>observer<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> r <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">self</span>._observers:
            <span style="color: #008000;">self</span>._observers.<span style="color: black;">append</span><span style="color: black;">&#40;</span>r<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> setObservers<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>,observers<span style="color: black;">&#41;</span>:
      <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> observers == <span style="color: #008000;">None</span>:
        <span style="color: #008000;">self</span>._observers = observers
      <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #008000;">self</span>._observers = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> observers<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
      <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>._observers
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> detach<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, observer<span style="color: black;">&#41;</span>:
        r = <span style="color: #dc143c;">weakref</span>.<span style="color: black;">ref</span><span style="color: black;">&#40;</span>observer<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">try</span>:
            <span style="color: #ff7700;font-weight:bold;">if</span> DEBUG:
              <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Removing observer.&quot;</span>
            <span style="color: #008000;">self</span>._observers.<span style="color: black;">remove</span><span style="color: black;">&#40;</span>r<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">ValueError</span>:
            <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Could not remove observer %s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>r<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> notify<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>,<span style="color: #008000;">property</span> = <span style="color: #008000;">None</span>, value = <span style="color: #008000;">None</span>,modifier = <span style="color: #008000;">None</span><span style="color: black;">&#41;</span>:
      <span style="color: #ff7700;font-weight:bold;">try</span>:
        <span style="color: #808080; font-style: italic;">#This is to avoid infinite notification loop, e.g. when the notified class calls a function of the subject that triggers another notify and so on...</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">self</span>.<span style="color: black;">isNotifying</span>:
          <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;WARNING: notify was called recursively, aborting.&quot;</span>
          <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">False</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">isNotifying</span> = <span style="color: #008000;">True</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> observer <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">self</span>._observers:
            <span style="color: #ff7700;font-weight:bold;">if</span> observer<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> == <span style="color: #008000;">None</span>:
              <span style="color: #008000;">self</span>._observers.<span style="color: black;">remove</span><span style="color: black;">&#40;</span>observer<span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">elif</span> modifier <span style="color: #66cc66;">!</span>= observer<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
              observer<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">updated</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>,<span style="color: #008000;">property</span>,value<span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">isNotifying</span> = <span style="color: #008000;">False</span>
      <span style="color: #ff7700;font-weight:bold;">except</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;An error occured when notifying my observers...&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #dc143c;">sys</span>.<span style="color: black;">exc_info</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">ifNotifying</span> = <span style="color: #008000;">False</span>
        <span style="color: #ff7700;font-weight:bold;">raise</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#The corresponding observer class. It makes sure that the observing class has an &quot;updated&quot; function.</span>
<span style="color: #ff7700;font-weight:bold;">class</span> Observer:
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">def</span> updated<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>,subject = <span style="color: #008000;">None</span>,<span style="color: #008000;">property</span> = <span style="color: #008000;">None</span>,value = <span style="color: #008000;">None</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">pass</span></pre></div></div>

<p>And here&#8217;s how to use it:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> MySubject<span style="color: black;">&#40;</span>Subject<span style="color: black;">&#41;</span>:
&nbsp;
   <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
      Subject.<span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>
&nbsp;
   <span style="color: #ff7700;font-weight:bold;">def</span> addNumbers<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>,a,b<span style="color: black;">&#41;</span>:
      <span style="color: #808080; font-style: italic;">#Do something....</span>
      c = a+b
      <span style="color: #008000;">self</span>.<span style="color: black;">notify</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;addNumbersResult&quot;</span>,c<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> MyObserver<span style="color: black;">&#40;</span>Observer<span style="color: black;">&#41;</span>:
&nbsp;
<span style="color: #808080; font-style: italic;">#...</span>
&nbsp;
   <span style="color: #ff7700;font-weight:bold;">def</span> updated<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>,subject = <span style="color: #008000;">None</span>,<span style="color: #008000;">property</span> = <span style="color: #008000;">None</span>,value = <span style="color: #008000;">None</span><span style="color: black;">&#41;</span>:
      <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">property</span> == <span style="color: #483d8b;">&quot;addNumbersResult&quot;</span>:
         <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Addition complete. Result: %g&quot;</span> <span style="color: #66cc66;">%</span> value
&nbsp;
observer = MyObserver<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
subject = MySubject<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
subject.<span style="color: black;">attach</span><span style="color: black;">&#40;</span>observer<span style="color: black;">&#41;</span>
subject.<span style="color: black;">addNumbers</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span></pre></div></div>

<p>This will print &#8216;Addition complete: 3&#8242;.</p>
<p>Several things in the code above are worth noting:</p>
<ul>
<li>First, the Subject class stores only a weak reference to the observer. If we would use a normal reference instead, an observer would not be deleted (and thus garbage-collected) without explicitly detaching it from the subject, which in general is not what we want.</li>
<li>The &#8220;notify&#8221;  function contains a safeguard that makes sure that it never gets called recursively. This helps to avoid infinite loops which one can produce rather easily by e.g. having an observer which always triggers another &#8220;notify&#8221; event while being notified itself. This behaviour might not always be exactly what you want, so feel free to remove this feature if you don&#8217;t need it.</li>
</ul>
<p>This simple pattern is both versatile and very easy to use. Nevertheless, it can be dangerous to use it in a GUI application, especially when  multi-threading is involved. This is because most GUI toolkits -such as for example Qt- do not allow you to call any GUI-relevant function from a thread other than the main (GUI-) thread. Ignoring this restriction can yield a lot of unpleasant surprises and will often break your program. Suppose for example that you have a &#8220;Subject&#8221; class running in a worker thread and that this class notifies some GUI component. Now, if you would call any GUI-related function during the notification process (which gets executed in the worker thread) you will most likely produce some very unpredictable and unpleasant behaviour.</p>
<p>This problem can be circumvented if we introduce an observer class that does not process the &#8220;notify&#8221; directly upon reception but rather queues it and processes it later from the main (GUI-) thread. The following Python class does exactly this by using a timer function and an event queue. It is designed for use with Qt but can be easily generalized to work with other GUI toolkits as well.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#This is an observer class which is especially tailored to Qt widgets. Instead of processing &quot;updated&quot; calls directly,</span>
<span style="color: #808080; font-style: italic;">#this class queues them and periodically calls a function from the main thread that processes the events.</span>
<span style="color: #ff7700;font-weight:bold;">class</span> ObserverWidget<span style="color: black;">&#40;</span>Observer<span style="color: black;">&#41;</span>:
&nbsp;
  <span style="color: #808080; font-style: italic;">#This function gets called from the notifying (possibly non-GUI) thread.</span>
  <span style="color: #808080; font-style: italic;">#It is NOT safe to call GUI-related functions from this function.</span>
  <span style="color: #ff7700;font-weight:bold;">def</span> updatedThread<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>,subject = <span style="color: #008000;">None</span>,<span style="color: #008000;">property</span> = <span style="color: #008000;">None</span>,value = <span style="color: #008000;">None</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">pass</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">#This function gets called from the main (GUI) thread.</span>
  <span style="color: #808080; font-style: italic;">#It is safe to call GUI-related functions from this function.</span>
  <span style="color: #ff7700;font-weight:bold;">def</span> updatedGui<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>,subject = <span style="color: #008000;">None</span>,<span style="color: #008000;">property</span> = <span style="color: #008000;">None</span>,value = <span style="color: #008000;">None</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">pass</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">#We intercept the &quot;update&quot; call from the subject and queue it.</span>
  <span style="color: #ff7700;font-weight:bold;">def</span> updated<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>,subject = <span style="color: #008000;">None</span>,<span style="color: #008000;">property</span> = <span style="color: #008000;">None</span>,value = <span style="color: #008000;">None</span><span style="color: black;">&#41;</span>:
    <span style="color: #008000;">self</span>.<span style="color: black;">updatedThread</span><span style="color: black;">&#40;</span>subject,<span style="color: #008000;">property</span>,value<span style="color: black;">&#41;</span>
    <span style="color: #008000;">self</span>.<span style="color: black;">updateQueue</span>.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>subject,<span style="color: #008000;">property</span>,value<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">#This function periodically processes the update queue.</span>
  <span style="color: #ff7700;font-weight:bold;">def</span> processUpdateQueue<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">updateQueue</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span>:
      event = <span style="color: #008000;">self</span>.<span style="color: black;">updateQueue</span>.<span style="color: black;">pop</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
      <span style="color: #008000;">self</span>.<span style="color: black;">updatedGui</span><span style="color: black;">&#40;</span><span style="color: #66cc66;">*</span>event<span style="color: black;">&#41;</span> 
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">def</span> clearUpdateQueue<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
    <span style="color: #008000;">self</span>.<span style="color: black;">updateQueue</span> = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>,parent = <span style="color: #008000;">None</span><span style="color: black;">&#41;</span>:
    <span style="color: #008000;">self</span>.<span style="color: black;">updateQueue</span> =  <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
    <span style="color: #008000;">self</span>.<span style="color: black;">updateQueueTimer</span> = QTimer<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #008000;">self</span>.<span style="color: black;">updateQueueTimer</span>.<span style="color: black;">setInterval</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">100</span><span style="color: black;">&#41;</span>
    <span style="color: #008000;">self</span>.<span style="color: black;">connect</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">updateQueueTimer</span>,SIGNAL<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;timeout()&quot;</span><span style="color: black;">&#41;</span>,<span style="color: #008000;">self</span>.<span style="color: black;">processUpdateQueue</span><span style="color: black;">&#41;</span>
    <span style="color: #008000;">self</span>.<span style="color: black;">updateQueueTimer</span>.<span style="color: black;">start</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>To use this pattern you just inherit from &#8220;ObserverWidget&#8221; and use the functions &#8220;updatedThread&#8221; (for everything that can be done in the &#8220;Subject&#8221; thread) and &#8220;updatedGui&#8221; (for everything that should be done in the main thread) instead of &#8220;updated&#8221; to process your event notifications. If you use this class, please make sure that the class which you derive from it also derives from QWidget (or a child class of it) and that you call the constructor of this GUI class  BEFORE calling the constructor of the ObserverWidget.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japh.de/blog/a-thread-safe-observer-pattern-for-python-and-qt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python: Reloading a class definition at runtime</title>
		<link>http://www.japh.de/blog/python-reloading-a-class-definition-at-runtime/</link>
		<comments>http://www.japh.de/blog/python-reloading-a-class-definition-at-runtime/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 13:25:56 +0000</pubDate>
		<dc:creator>Andreas</dc:creator>
				<category><![CDATA[Ohne Kategorie]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[Design patterns]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[reloadable]]></category>

		<guid isPermaLink="false">http://www.japh.de/blog/python-a-reloadable-class-pattern/</guid>
		<description><![CDATA[Python comes with a very useful function called &#8220;reload&#8221;, which allows to dynamically reload the code of a given module at runtime. This technique is quite useful if one wants for example to reload some part of a larger application without having to close and restart the whole system.
Personally, I often use &#8220;reload&#8221; to dynamically [...]]]></description>
			<content:encoded><![CDATA[<p style="TEXT-ALIGN: justify">Python comes with a very useful function called &#8220;reload&#8221;, which allows to dynamically reload the code of a given module at runtime. This technique is quite useful if one wants for example to reload some part of a larger application without having to close and restart the whole system.</p>
<p style="TEXT-ALIGN: justify">Personally, I often use &#8220;reload&#8221; to dynamically update classes when doing rapid prototyping. By this technique I can for example reload a single widget of a GUI without having to restart the whole program, saving me tons of precious development time.</p>
<p style="TEXT-ALIGN: justify">To provide the &#8220;reload&#8221; functionality in an object-oriented fashion, I just wrote a small class called &#8220;Reloadable&#8221;. This class provides a function &#8220;reloadClass&#8221; that takes care of the whole reload process: First, it calls &#8220;reload&#8221; for the module that defined the original class (the name of which is stored in the variable &#8220;self.__module__&#8221;), fetches a reference to the reloaded class type (by using the class name given in &#8220;self.__class__.__name__&#8221;) and replaces the &#8220;self.__class__&#8221; variable by this new type. After this, the class instance will have all its functions and variables replaced by their reloaded version but will nevertheless keep all instance variables that were already defined. Finally, &#8220;reloadClass&#8221; calls the function &#8220;onReload&#8221;, which can be redefined in a subclass to implement some specific reloading tasks. Easy, isn&#8217;t it? Please also note that all other instances belonging to the reloaded class will stay unaffected by this operations.</p>
<p>Here is the code snippet that defines &#8220;Reloadable&#8221;:</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;">sys</span>
<span style="color: #ff7700;font-weight:bold;">class</span> Reloadable<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
&nbsp;
  <span style="color: #808080; font-style: italic;">#Reload the module that defines the class and replace the &quot;__class__&quot; variable with a new instance of the class.</span>
  <span style="color: #ff7700;font-weight:bold;">def</span> reloadClass<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
    newModule = <span style="color: #008000;">reload</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">modules</span><span style="color: black;">&#91;</span><span style="color: #008000;">self</span>.__module__<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
    <span style="color: #008000;">self</span>.__class__ = <span style="color: #008000;">eval</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;newModule.%s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: #008000;">self</span>.__class__.__name__<span style="color: black;">&#41;</span>
    <span style="color: #008000;">self</span>.<span style="color: black;">onReload</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">#Re-implement this function in the derived class to perform specific tasks after the reload (e.g. call &quot;__init__&quot;)</span>
  <span style="color: #ff7700;font-weight:bold;">def</span> onReload<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">pass</span></pre></div></div>

<p>There is also a nice code snippet on <a href="http://code.activestate.com/recipes/160164-automatically-upgrade-class-instances-on-reload/">code.activestate.com</a> that will automatically reload all instances of a class when the corresponding module is reloaded.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japh.de/blog/python-reloading-a-class-definition-at-runtime/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Presentation: Python for Scientists</title>
		<link>http://www.japh.de/blog/presentation-python-for-scientists/</link>
		<comments>http://www.japh.de/blog/presentation-python-for-scientists/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 20:15:45 +0000</pubDate>
		<dc:creator>Andreas</dc:creator>
				<category><![CDATA[Ohne Kategorie]]></category>

		<guid isPermaLink="false">http://www.japh.de/blog/?p=550</guid>
		<description><![CDATA[This is a presentation I gave at our weekly group seminar. It discusses the use of the programming language Python in a scientific environment, putting emphasis on data acquisition, processing and presentation. Enjoy!
Python for Scientists
View more presentations from japh44.

]]></description>
			<content:encoded><![CDATA[<p>This is a presentation I gave at our weekly group seminar. It discusses the use of the programming language Python in a scientific environment, putting emphasis on data acquisition, processing and presentation. Enjoy!</p>
<div id="__ss_3376657" style="width: 425px;"><strong style="display:block;margin:12px 0 4px"><a title="Python for Scientists" href="http://www.slideshare.net/japh44/python-for-scientists">Python for Scientists</a></strong><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="564" height="490" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=pythonpresentationnew-100309100416-phpapp02&amp;stripped_title=python-for-scientists" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="564" height="490" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=pythonpresentationnew-100309100416-phpapp02&amp;stripped_title=python-for-scientists" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div style="padding: 5px 0pt 12px; text-align: center;">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/japh44">japh44</a>.</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.japh.de/blog/presentation-python-for-scientists/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Science 2.0</title>
		<link>http://www.japh.de/blog/science-2-0/</link>
		<comments>http://www.japh.de/blog/science-2-0/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 12:42:18 +0000</pubDate>
		<dc:creator>Andreas</dc:creator>
				<category><![CDATA[Science]]></category>

		<guid isPermaLink="false">http://www.japh.de/blog/science-2-0-smart-tools-for-scientists/</guid>
		<description><![CDATA[


Online Scientific Collaboration: Beyond the tip of the Iceberg


Scientific research is becoming more and more dependent on the use of information technology in order to acquire, process and share research data. The amount of data that is generated within this process increases with an exponential rate, making it very hard and sometimes impossible to manage [...]]]></description>
			<content:encoded><![CDATA[<div>
<dl id="attachment_539" class="alignleft" style="width: 206px;">
<dt><a href="http://en.wiktionary.org/wiki/tip_of_the_iceberg"><img title="The tip of the Iceberg" src="http://www.japh.de/blog/upload/iceberg1.jpg" alt="The tip of the Iceberg" width="196" height="285" /></a></dt>
<dd>Online Scientific Collaboration: Beyond the tip of the Iceberg</dd>
</dl>
</div>
<p>Scientific research is becoming more and more dependent on the use of information technology in order to acquire, process and share research data. The amount of data that is generated within this process increases with an exponential rate, making it very hard and sometimes impossible to manage or even analyze all of it. Therefore, scientists have to rely on a broad range of software tools that help them to be more productive.</p>
<p>Me, being a scientist myself and trying to cut my way through the daily data jungle, I use this blog as a discussion board for some useful tools, techniques and technologies that I use in my everyday work. I will focus mainly on online collaboration tools since I think they are still not as much accepted and used as they should be, but I will also discuss some other techniques that can be used directly in the lab with no social skills whatsoever required <img src='http://www.japh.de/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I will only discuss tools which I use and like myself in order to give you some real first-hand experience . To begin with, here are some topics that I&#8217;m currently interested in and that I will probably discuss in the upcoming posts:</p>
<ul>
<li>To serve and protect: Software Configuration Management tools (especially Subversion) for Scientists.</li>
<li>Controlling everything: Embeddable scripting languages (especially Lua) for simulation, configuration and automation.</li>
<li>Snake charmer: Using Python for your everyday scientific needs: Plotting, calculation, measurement, data analysis, &#8230;</li>
<li>Social online tools for scientists: How to use Slideshare, Mendeley&amp; Co to promote your work and to spread your knowledge.</li>
<li>Knowledge base: Using Wikis and blogs for your research.</li>
</ul>
<p>I aim at writing one extensive article each week.  Happy reading!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japh.de/blog/science-2-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
