<?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>Daten&#124;teiler &#187; Python</title>
	<atom:link href="http://www.datenteiler.de/kategorie/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.datenteiler.de</link>
	<description>Kopieren als Kulturtechnik</description>
	<lastBuildDate>Sat, 14 Jan 2012 14:39:01 +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>Windows-Programme mit Python steuern</title>
		<link>http://www.datenteiler.de/windows-programme-mit-python-steuern/</link>
		<comments>http://www.datenteiler.de/windows-programme-mit-python-steuern/#comments</comments>
		<pubDate>Sun, 04 Sep 2011 11:41:02 +0000</pubDate>
		<dc:creator>Christian Imhorst</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.datenteiler.de/?p=6287</guid>
		<description><![CDATA[Im Blog Der Bayer und der Würschtlmann bin ich auf den Beitrag Windows-(GUI-)Programme mit Python fernsteuern von Sebastian gestoßen. Für die Automatisierung der Windows-Programme benutzt er pywinauto, das einen sehr interessanten Eindruck macht, aber leider etwas durch die Abwesenheit von Dokumentation glänzt. Trotzdem soll man laut Sebastian schnell zu guten Ergebnissen kommen. Pywinauto ist sicherlich [...]]]></description>
			<content:encoded><![CDATA[<p>Im Blog <a href="http://dbudwm.wordpress.com">Der Bayer und der Würschtlmann</a> bin ich auf den Beitrag <a href="http://dbudwm.wordpress.com/2011/08/23/windows-gui-programme-mit-python-fernsteuern/">Windows-(GUI-)Programme mit Python fernsteuern</a> von Sebastian gestoßen. Für die Automatisierung der Windows-Programme benutzt er <a href="http://code.google.com/p/pywinauto/">pywinauto</a>, das einen sehr interessanten Eindruck macht, aber leider etwas durch die <a href="http://pywinauto.googlecode.com/hg/pywinauto/docs/index.html">Abwesenheit von Dokumentation</a> glänzt. Trotzdem soll man laut Sebastian schnell zu guten Ergebnissen kommen. Pywinauto ist sicherlich ein Vesuch wert, weil es objektorientierter und pythonmäßiger sein soll. Wenn man sich aber schon etwas mit dem Windows Script Host (WSH) oder dem Component Object Model (COM) auskennt, liegt einem Win32com vielleicht mehr.</p>
<p>Um überhaupt etwas mit Pywinauto oder Win32com zu machen, muss man <a href="http://docs.python.org/using/windows.html">Python unter Windows installiert</a> haben. Ich habe mich zum Beispiel für <a href="http://www.python.org/download/releases/">Python 3.2 entschieden</a>. Alternativ gibt es auch noch die <a href="http://www.heise.de/software/download/activepython_community_edition/37561">Communuty Edition von ActivePython</a>, das schon extra Module wie Win32com mitbringt. Beim original Python muss man auf jeden Fall noch die <a href="http://sourceforge.net/projects/pywin32/files/pywin32/ ">Erweiterung Pywin32</a> herunterladen, wenn man das Modul Win32com nutzen möchte. Allerdings kann es passieren, dass der erste Versuch, das Modul zu importieren, auf einen Fehler hinaus läuft:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">import</span> win32com.<span style="color: black;">client</span> 
Traceback <span style="color: black;">&#40;</span>most recent call last<span style="color: black;">&#41;</span>:
File <span style="color: #483d8b;">&quot;D:<span style="color: #000099; font-weight: bold;">\E</span>Q<span style="color: #000099; font-weight: bold;">\I</span>nventoryDumps<span style="color: #000099; font-weight: bold;">\t</span>estScript1.py&quot;</span>, line <span style="color: #ff4500;">1</span>, <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #66cc66;">&lt;</span>module<span style="color: #66cc66;">&gt;</span>
<span style="color: #ff7700;font-weight:bold;">import</span> win32com.<span style="color: black;">client</span> <span style="color: #ff7700;font-weight:bold;">as</span> win32
File <span style="color: #483d8b;">&quot;D:<span style="color: #000099; font-weight: bold;">\P</span>ython32<span style="color: #000099; font-weight: bold;">\l</span>ib<span style="color: #000099; font-weight: bold;">\s</span>ite-packages<span style="color: #000099; font-weight: bold;">\w</span>in32com<span style="color: #000099; font-weight: bold;">\_</span>_init__.py&quot;</span>, line <span style="color: #ff4500;">5</span>, <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #66cc66;">&lt;</span>module<span style="color: #66cc66;">&gt;</span>
<span style="color: #ff7700;font-weight:bold;">import</span> win32api, <span style="color: #dc143c;">sys</span>, <span style="color: #dc143c;">os</span>
<span style="color: #008000;">ImportError</span>: DLL load failed: The specified module could <span style="color: #ff7700;font-weight:bold;">not</span> be found.</pre></div></div>

<p>Ist das der Fall, kann man das Problem mit folgendem Befehl beheben:</p>

<div class="wp_syntax"><div class="code"><pre class="dos" style="font-family:monospace;">C:\Python32\Scripts\pywin32_postinstall.py</pre></div></div>

<p>Wenn die Installation erfolgreich ist, steht einem die Welt der Windows-Objekte wie COM oder WSH mehr oder weniger offen. So kann man mit COM Anwendungen aus dem Microsoft Office-Paket oder den Internet Explorer automatisieren. COM dient dabei zur Interprozesskommunikation und dynamische Objekterzeugung unter Windows. Bevor man die Funktionen von COM-Objekten nutzen kann, muss man sie instanzieren, wofür die COM-Komponenten Schnittstellen anbieten. Im folgenden Beispiel wird eine Instanz des Internet Explorers durch die Angabe seiner ProgID (&#8220;InternetExplorer.Application&#8221;) erzeugt:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> win32com.<span style="color: black;">client</span>
ie = win32com.<span style="color: black;">client</span>.<span style="color: black;">Dispatch</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;InternetExplorer.Application&quot;</span><span style="color: black;">&#41;</span>
ie.<span style="color: black;">Visible</span> = <span style="color: #ff4500;">1</span>
ie.<span style="color: black;">Navigate</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;http://www.datenteiler.de&quot;</span><span style="color: black;">&#41;</span>
ie.<span style="color: black;">GoHome</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
ie.<span style="color: black;">quit</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Nach der Instanzierung steht ein Internet Explorer bereit, der allerdings noch nicht zu sehen ist, außer als Prozess im Taskmanager oder mit dem Cmdlet <code>Get-Process</code> in der PowerShell. Der Prozess ist unabhängig vom Python-Interpreter. Wird die Konsole geschlossen, bleibt der Prozess erhalten und aktiv. Erst wenn man der Eigenschaft von <code>Visible</code> auf <em>wahr</em> setzt, wird diese Instanz des Internet Explorers sichtbar.<br />
Wenn man sich mit dem Einsatz von COM-Anwendungen in der PowerShell auskennt, kommt einem der Quelltext doch bekannt vor:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$ie</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> <span style="color: #008080; font-style: italic;">-ComObject</span> InternetExplorer.Application
<span style="color: #800080;">$ie</span>.Visible <span style="color: pink;">=</span> <span style="color: #800080;">$true</span>
<span style="color: #800080;">$ie</span>.Navigate<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;http://www.datenteiler.de&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$ie</span>.GoHome<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$ie</span>.Quit<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>Das folgende <a href="http://win32com.goermezer.de/content/view/136/254/">SendKey-Beispiel</a> mit dem WSH kann auch zu einem Déjà-vu führen, wenn man den Python-Quelltext mit dem VBScript-Code vergleicht. Erstmal das Beispiel um Tastendrücke zu simulieren in Python:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> win32api
<span style="color: #ff7700;font-weight:bold;">import</span> win32com.<span style="color: black;">client</span>
shell = win32com.<span style="color: black;">client</span>.<span style="color: black;">Dispatch</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;WScript.Shell&quot;</span><span style="color: black;">&#41;</span>
shell.<span style="color: black;">Run</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Notepad&quot;</span><span style="color: black;">&#41;</span> 
win32api.<span style="color: black;">Sleep</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1500</span><span style="color: black;">&#41;</span> 
shell.<span style="color: black;">AppActivate</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Notepad&quot;</span><span style="color: black;">&#41;</span> 
win32api.<span style="color: black;">Sleep</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1500</span><span style="color: black;">&#41;</span> 
shell.<span style="color: black;">SendKeys</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Hallo Welt!{ENTER}&quot;</span><span style="color: black;">&#41;</span> 
shell.<span style="color: black;">SendKeys</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;^s&quot;</span><span style="color: black;">&#41;</span>
shell.<span style="color: black;">SendKeys</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;{ENTER}&quot;</span><span style="color: black;">&#41;</span>
win32api.<span style="color: black;">Sleep</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1500</span><span style="color: black;">&#41;</span>
shell.<span style="color: black;">SendKeys</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Hallo.txt{ENTER}&quot;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Das Äquivalent in VBScript sieht dann so aus:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #008000;">' SendkeyBeispiel.vbs
</span><span style="color: #E56717; font-weight: bold;">Option</span> <span style="color: #E56717; font-weight: bold;">Explicit</span>
<span style="color: #151B8D; font-weight: bold;">Dim</span> objWScriptShell
<span style="color: #151B8D; font-weight: bold;">Set</span> objWScriptShell = <span style="color: #E56717; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;WScript.Shell&quot;</span>)
objWScriptShell.Run <span style="color: #800000;">&quot;notepad&quot;</span>
Wscript.Sleep 1500 <span style="color: #008000;">' Warte bis Notepad fertig ist
</span>objWScriptShell.SendKeys <span style="color: #800000;">&quot;Hallo Welt!{ENTER}&quot;</span>
objWScriptShell.SendKeys <span style="color: #800000;">&quot;^s&quot;</span>
objWScriptShell.SendKeys <span style="color: #800000;">&quot;{ENTER}&quot;</span>
Wscript.Sleep 1500
objWScriptShell.SendKeys <span style="color: #800000;">&quot;Hallo.txt{ENTER}&quot;</span>
WScript.Quit</pre></div></div>

<p>Man kann <a href="http://timgolden.me.uk/python/win32_how_do_i.html ">mit dem Win32Com-Modul in Python noch einiges mehr anfangen</a>, zum Beispiel die <a href="http://kvance.livejournal.com/985732.html ">Maus positionieren und Mausklicks senden</a>. Damit sind die Möglichkeiten von Python im Component Object Model oder des Windows Script Host bei weitem noch nicht ausgeschöpft. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.datenteiler.de/windows-programme-mit-python-steuern/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tanz den Bubblesort</title>
		<link>http://www.datenteiler.de/tanz-den-bubblesort/</link>
		<comments>http://www.datenteiler.de/tanz-den-bubblesort/#comments</comments>
		<pubDate>Mon, 29 Aug 2011 18:24:42 +0000</pubDate>
		<dc:creator>Christian Imhorst</dc:creator>
				<category><![CDATA[Programmieren]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.datenteiler.de/?p=6275</guid>
		<description><![CDATA[Endlich habe ich mal verstanden, wie der Bubblesort funktioniert! Nicht schlecht was die Jungs und Mädels dort Vortanzen. Hier zum Beispiel der Tanz in Python implementiert, allerdings nur mit dem unsortierten Anfang, dem sortierten Ende und ohne das Ganze im Mittelteil: # Bubblesort in Python &#160; def bubblesort&#40;a&#41;: for j in range&#40;len&#40;a&#41; - 1&#41;: for [...]]]></description>
			<content:encoded><![CDATA[<p>Endlich habe ich mal verstanden, wie der Bubblesort funktioniert! Nicht schlecht was die Jungs und Mädels dort Vortanzen. Hier zum Beispiel der Tanz in Python implementiert, allerdings nur mit dem unsortierten Anfang, dem sortierten Ende und ohne das Ganze im Mittelteil:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># Bubblesort in Python</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> bubblesort<span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">for</span> j <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span> - <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span> - j - <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
            <span style="color: #ff7700;font-weight:bold;">if</span> a<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> <span style="color: #66cc66;">&gt;</span> a<span style="color: black;">&#91;</span>i+<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>:
                tmp = a<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span>
                a<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> = a<span style="color: black;">&#91;</span>i+<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
                a<span style="color: black;">&#91;</span>i+<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> = tmp
    <span style="color: #ff7700;font-weight:bold;">return</span> a
&nbsp;
a = <span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span>, <span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">1</span>, <span style="color: #ff4500;">8</span>, <span style="color: #ff4500;">7</span>, <span style="color: #ff4500;">2</span>, <span style="color: #ff4500;">5</span>, <span style="color: #ff4500;">4</span>, <span style="color: #ff4500;">6</span>, <span style="color: #ff4500;">9</span><span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Unsortiert: &quot;</span>, a<span style="color: black;">&#41;</span>
&nbsp;
result = bubblesort<span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span>	
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Sortiert  : &quot;</span>, result<span style="color: black;">&#41;</span></pre></div></div>

<p>Ich hoffe nur, dass ich die Musik auch wieder aus meinem Kopf bekomme. ;-)</p>
<p><object style="height: 390px; width: 640px"><param name="movie" value="http://www.youtube.com/v/lyZQPjUT5B4?version=3"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="http://www.youtube.com/v/lyZQPjUT5B4?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="540" height="390"></object></p>
<p>[via <a href="http://www.zipfelmaus.com">zipfelmaus.com</a>]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.datenteiler.de/tanz-den-bubblesort/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Wissenswertes über Python: String-Formatierung</title>
		<link>http://www.datenteiler.de/wissenswertes-ueber-python-string-formatierung/</link>
		<comments>http://www.datenteiler.de/wissenswertes-ueber-python-string-formatierung/#comments</comments>
		<pubDate>Fri, 29 Apr 2011 15:40:07 +0000</pubDate>
		<dc:creator>Christian Imhorst</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.datenteiler.de/?p=5598</guid>
		<description><![CDATA[Bekannterweise sind Verkettungen von Strings in Python, mit dem Plus-Operator (+) sehr einfach zu machen. Man kann auch eine Zahl mit einem String verketten, wenn man die Zahl vorher explizit mit str() in einen String umwandelt: &#62;&#62;&#62; s = 'Ich bin ein String' &#62;&#62;&#62; i = 123 &#62;&#62;&#62; type&#40;s&#41; &#60;type 'str'&#62; &#62;&#62;&#62; type&#40;i&#41; &#60;type 'int'&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Bekannterweise sind Verkettungen von Strings in Python, mit dem Plus-Operator (<code>+</code>) sehr einfach zu machen. Man kann auch eine Zahl mit einem String verketten, wenn man die Zahl vorher explizit mit <code>str()</code> in einen String umwandelt:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> s = <span style="color: #483d8b;">'Ich bin ein String'</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> i = <span style="color: #ff4500;">123</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #008000;">type</span><span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&lt;</span>type <span style="color: #483d8b;">'str'</span><span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #008000;">type</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&lt;</span>type <span style="color: #483d8b;">'int'</span><span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">' '</span> + s + <span style="color: #483d8b;">'!'</span>
<span style="color: #483d8b;">'123 Ich bin ein String!'</span></pre></div></div>

<p>So praktisch sie auch sind, man sollte solche Verkettungen von Zeichenketten mit dem +-Operator vermeiden, da sie zu Lasten der Performance gehen. In Python sind Strings unveränderliche (immutable) Objekte, daher werden außer dem Ergebnis-String temporär weitere Strings angelegt, die hinterher von der Laufzeitumgebung wieder entsorgt werden müssen (<em>garbage collection</em>). In meinem Beispiel wird inklusive Ergebnis-String dreimal ein neuer String konstruiert und die beiden temporär erstellten Vorgänger werden wieder freigegeben. Dabei muss jedes Mal der Inhalt des alten Strings in den neuen kopiert werden, was alles zusammen Performance frisst.</p>
<p>Die Erzeugung des Ergebnis-Strings sollte man daher an einen <a href="http://docs.python.org/library/stdtypes.html#string-formatting">String-Formatierer</a> übergeben:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #483d8b;">'%d %s!'</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>i, s<span style="color: black;">&#41;</span>
<span style="color: #483d8b;">'123 Ich bin ein String!'</span></pre></div></div>

<p>Dabei sind <code>%d</code> und <code>%s</code> Platzhalter für den Inhalt der Variablen <code>i</code> und <code>s</code>. Die Platzhalter sind aber nicht frei wählbar, so steht <code>%d</code> für Dezimalzahlen, <code>%s</code> für Strings, <code>%x</code> für Hexadezimalzahlen, <code>%e</code>, <code>%f</code> und <code>%g</code> für Gleitkommazahlen. Bei der String-Formatierung entfällt nicht nur das Kopieren der String-Inhalte in neue Strings und das anschließende Aufräumen, sondern auch die explizite Typumwandlung der Ganzzahl in <code>i</code> in einen String mit <code>str()</code>, was einfach performanter ist.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.datenteiler.de/wissenswertes-ueber-python-string-formatierung/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Wie man in Python ein App für SHR schreibt</title>
		<link>http://www.datenteiler.de/wie-man-in-python-ein-app-fuer-shr-schreibt/</link>
		<comments>http://www.datenteiler.de/wie-man-in-python-ein-app-fuer-shr-schreibt/#comments</comments>
		<pubDate>Tue, 19 Apr 2011 19:05:56 +0000</pubDate>
		<dc:creator>Christian Imhorst</dc:creator>
				<category><![CDATA[Gnu/Linux]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[SHR]]></category>

		<guid isPermaLink="false">http://www.datenteiler.de/?p=5554</guid>
		<description><![CDATA[Für Python-Fans bieten die beiden Module Python-Elementary und Python-Evas eine schnelle und einfache Möglichkeit, grafische Oberflächen für den Enlightenment-Fenstermanager E17 und damit auch für das OpenMoko Betriebssystem SHR zu schreiben. Wer damit unter E17 experimentieren möchte, für den sind die beiden Module in Debian Sid (Unstable) bzw. in Experimental enthalten und unter Ubuntu ab 10.10 [...]]]></description>
			<content:encoded><![CDATA[<p>Für Python-Fans bieten die beiden Module Python-Elementary  und Python-Evas eine schnelle und einfache Möglichkeit, grafische Oberflächen für den Enlightenment-Fenstermanager E17 und damit auch für das OpenMoko Betriebssystem <a href="http://shr-project.org/trac">SHR</a> zu schreiben. Wer damit unter E17 experimentieren möchte, für den sind die beiden Module in Debian Sid (Unstable) bzw. in Experimental enthalten und unter Ubuntu ab 10.10 Maverick Meerkat, bzw. ab Linux Mint 10. In SHR sind sie schon dabei.</p>
<p>Für eine erste Hallo-Welt-Gui habe ich mich an das <a href="http://trac.enlightenment.org/e/wiki/Elementary">Elementary-Beispiel</a> im <a href="http://trac.enlightenment.org/e/wiki">Wiki von Enlightenment</a> gehalten, das in C geschrieben ist, bzw. an das Beispiel im <a href="http://shr-project.org/trac/wiki/Developing%20your%20own%20applications?version=94">Wiki von SHR</a>, das allerdings in VALA geschrieben wurde.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># Example for a GUI written with Python-Elementary.</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> elementary
<span style="color: #ff7700;font-weight:bold;">import</span> evas
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> HelloWorldGui<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">def</span> destroy<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, obj<span style="color: black;">&#41;</span>:
		<span style="color: #808080; font-style: italic;"># quit the window (mainloop)</span>
		elementary.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><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>:
		elementary.<span style="color: black;">init</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;"># new window - do the usual and give it a name, title and delete handler</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">win</span> = elementary.<span style="color: black;">Window</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;HelloWorld&quot;</span>, elementary.<span style="color: black;">ELM_WIN_BASIC</span><span style="color: black;">&#41;</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">win</span>.<span style="color: black;">title_set</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Hello&quot;</span><span style="color: black;">&#41;</span>
		<span style="color: #808080; font-style: italic;"># when the user clicks &quot;close&quot; on a window:</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">win</span>.<span style="color: black;">callback_destroy_add</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">destroy</span><span style="color: black;">&#41;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;"># add a standard background</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">bg</span> = elementary.<span style="color: black;">Background</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">win</span><span style="color: black;">&#41;</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">win</span>.<span style="color: black;">resize_object_add</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">bg</span><span style="color: black;">&#41;</span>
		<span style="color: #808080; font-style: italic;"># do not allow bg to expand</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">bg</span>.<span style="color: black;">size_hint_weight_set</span><span style="color: black;">&#40;</span>evas.<span style="color: black;">EVAS_HINT_EXPAND</span>, evas.<span style="color: black;">EVAS_HINT_EXPAND</span><span style="color: black;">&#41;</span>
		<span style="color: #808080; font-style: italic;"># add object as a resize object for the window</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">win</span>.<span style="color: black;">resize_object_add</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">bg</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">bg</span>.<span style="color: black;">show</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;"># add a box object - default is vertical. a box holds children </span>
		<span style="color: #808080; font-style: italic;"># in a row, either horizontally or vertically. nothing more.</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">mainBox</span> = elementary.<span style="color: black;">Box</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">win</span><span style="color: black;">&#41;</span>
		<span style="color: #808080; font-style: italic;"># do not allow box to expand</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">mainBox</span>.<span style="color: black;">size_hint_weight_set</span><span style="color: black;">&#40;</span>evas.<span style="color: black;">EVAS_HINT_EXPAND</span>, evas.<span style="color: black;">EVAS_HINT_EXPAND</span><span style="color: black;">&#41;</span>
		<span style="color: #808080; font-style: italic;"># add object as a resize object for the window</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">win</span>.<span style="color: black;">resize_object_add</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">mainBox</span><span style="color: black;">&#41;</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">mainBox</span>.<span style="color: black;">show</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;"># add a label widget </span>
		<span style="color: #008000;">self</span>.<span style="color: black;">lbl</span> = elementary.<span style="color: black;">Label</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">win</span><span style="color: black;">&#41;</span>
		<span style="color: #808080; font-style: italic;"># set text of the label</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">lbl</span>.<span style="color: black;">label_set</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Hello World!&quot;</span><span style="color: black;">&#41;</span>
		<span style="color: #808080; font-style: italic;"># do not allow label to expand </span>
		<span style="color: #008000;">self</span>.<span style="color: black;">lbl</span>.<span style="color: black;">size_hint_weight_set</span><span style="color: black;">&#40;</span>evas.<span style="color: black;">EVAS_HINT_EXPAND</span>, evas.<span style="color: black;">EVAS_HINT_EXPAND</span><span style="color: black;">&#41;</span>
		<span style="color: #808080; font-style: italic;"># pack the label at the end of the box </span>
		<span style="color: #008000;">self</span>.<span style="color: black;">mainBox</span>.<span style="color: black;">pack_end</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">lbl</span><span style="color: black;">&#41;</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">lbl</span>.<span style="color: black;">show</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;"># add a quit button</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">btnquit</span> = elementary.<span style="color: black;">Button</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">win</span><span style="color: black;">&#41;</span>
		<span style="color: #808080; font-style: italic;"># set label for button</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">btnquit</span>.<span style="color: black;">label_set</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Quit&quot;</span><span style="color: black;">&#41;</span>
		<span style="color: #808080; font-style: italic;"># do not allow button to expand </span>
		<span style="color: #008000;">self</span>.<span style="color: black;">btnquit</span>.<span style="color: black;">size_hint_align_set</span><span style="color: black;">&#40;</span>evas.<span style="color: black;">EVAS_HINT_EXPAND</span>, evas.<span style="color: black;">EVAS_HINT_EXPAND</span><span style="color: black;">&#41;</span>
		<span style="color: #808080; font-style: italic;"># pack the button at the end of the box</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">mainBox</span>.<span style="color: black;">pack_end</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">btnquit</span><span style="color: black;">&#41;</span>
		<span style="color: #808080; font-style: italic;"># when button is clicked</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">btnquit</span>.<span style="color: black;">callback_clicked_add</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">destroy</span><span style="color: black;">&#41;</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">btnquit</span>.<span style="color: black;">show</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;"># size of the window</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">win</span>.<span style="color: black;">resize</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">150</span>,<span style="color: #ff4500;">80</span><span style="color: black;">&#41;</span>
		<span style="color: #808080; font-style: italic;"># now we are done, show the window</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">win</span>.<span style="color: black;">show</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;"># run the mainloop</span>
		elementary.<span style="color: black;">run</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
		elementary.<span style="color: black;">shutdown</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>	
&nbsp;
<span style="color: #808080; font-style: italic;"># endof class HelloWorldGui</span>
&nbsp;
gui = HelloWorldGui<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Die Datei habe ich dann auf das OpenMoko <a href="http://www.datenteiler.de/freerunner-revolution/">kopiert</a> und dort im Terminal ausgeführt. Das Ergebnis sieht zwar nicht sehr schön aus, kann sich aber sehen lassen.</p>
<p><a href="http://www.datenteiler.de/wp-content/uploads/2011/04/Elementary.png"><img src="http://www.datenteiler.de/wp-content/uploads/2011/04/Elementary-230x300.png" alt="" title="Elementary" width="230" height="300" class="aligncenter size-medium wp-image-5569" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.datenteiler.de/wie-man-in-python-ein-app-fuer-shr-schreibt/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Pygame für Python 3 unter Ubuntu installieren</title>
		<link>http://www.datenteiler.de/pygame-fuer-python-3-unter-ubuntu-installieren/</link>
		<comments>http://www.datenteiler.de/pygame-fuer-python-3-unter-ubuntu-installieren/#comments</comments>
		<pubDate>Tue, 04 Jan 2011 19:06:49 +0000</pubDate>
		<dc:creator>Christian Imhorst</dc:creator>
				<category><![CDATA[Gnu/Linux]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.datenteiler.de/?p=5015</guid>
		<description><![CDATA[Da Pygame zwar für Python 2.6.5 aber nicht für Python 3 bei Ubuntu 10.04 Lucid oder 10.10 Maverick in den Paketquellen vorhanden ist, muss man Pygame für die aktuellste Python-Version selber installieren. Damit das funktioniert, benötigt man aber noch das ein oder andere Softwarepaket. sudo apt-get install python3-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev python-numpy subversion [...]]]></description>
			<content:encoded><![CDATA[<p>Da Pygame zwar für Python 2.6.5 aber nicht für Python 3 bei Ubuntu 10.04 Lucid oder 10.10 Maverick in den Paketquellen vorhanden ist, muss man Pygame für die aktuellste Python-Version selber installieren. Damit das funktioniert, benötigt man aber noch das ein oder andere Softwarepaket.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> python3-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev python-numpy subversion libportmidi-dev build-essential</pre></div></div>

<p>Sollte es bei der Installation Probleme geben, insbesondere bei <code>python3-dev</code>, fehlen vermutlich zwei Repositories in der Konfigurationsdatei <code>/etc/apt/sources.list</code>. Die kann man entweder mit dem Lieblingseditor für Lucid hinzufügen</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">deb http:<span style="color: #000000; font-weight: bold;">//</span>security.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu<span style="color: #000000; font-weight: bold;">/</span> lucid-security restricted main multiverse universe
deb http:<span style="color: #000000; font-weight: bold;">//</span>de.archive.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu<span style="color: #000000; font-weight: bold;">/</span> lucid-updates restricted main multiverse universe</pre></div></div>

<p>(falls man Maverick benutzt, muss man <em>lucid</em> halt durch <em>maverick</em> ersetzen), oder man setzt einfach zwei Haken in der Paketverwaltung <em>Synaptic</em> unter <strong>Einstellungen -> Paketquellen</strong> im Reiter <strong>Aktualisierungen</strong>:</p>
<p><a href="http://www.datenteiler.de/wp-content/uploads/2011/01/Paketquellen.png"><img src="http://www.datenteiler.de/wp-content/uploads/2011/01/Paketquellen-300x231.png" alt="" title="Paketquellen" width="300" height="231" class="aligncenter size-medium wp-image-5019" /></a></p>
<p>Danach muss man noch seine Paketquellen aktualisieren und eventuell updaten, was im Terminal so geht:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> update <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> dist-upgrade</pre></div></div>

<p>Jetzt sollte die Installation reibungslos funktionieren, und man kann mit Pygame für Python 3 weiter machen, indem man die aktuelle Version vom Server mit Hilfe von <em>Subversion</em> herunterlädt:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> <span style="color: #c20cb9; font-weight: bold;">svn</span>:<span style="color: #000000; font-weight: bold;">//</span>seul.org<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>pygame<span style="color: #000000; font-weight: bold;">/</span>trunk pygame</pre></div></div>

<p>Anschließend wechselt man ins neu erstellte Verzeichnis <code>pygame</code>, um zu kompilieren, und um die Installation zu starten:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> pygame
python3 setup.py build
<span style="color: #c20cb9; font-weight: bold;">sudo</span> python3 setup.py <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>Wenn man wissen will, ob alles geklappt hat, startet man Python 3 am besten im Terminal und importiert spaßeshalber einmal Pygame:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ python3
Python 3.1.2 <span style="color: #7a0874; font-weight: bold;">&#40;</span>r312:<span style="color: #000000;">79147</span>, Apr <span style="color: #000000;">15</span> <span style="color: #000000;">2010</span>, <span style="color: #000000;">12</span>:<span style="color: #000000;">35</span>:07<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
<span style="color: #7a0874; font-weight: bold;">&#91;</span>GCC 4.4.3<span style="color: #7a0874; font-weight: bold;">&#93;</span> on linux2
Type <span style="color: #ff0000;">&quot;help&quot;</span>, <span style="color: #ff0000;">&quot;copyright&quot;</span>, <span style="color: #ff0000;">&quot;credits&quot;</span> or <span style="color: #ff0000;">&quot;license&quot;</span> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">more</span> information.
<span style="color: #000000; font-weight: bold;">&gt;&gt;&gt;</span> import pygame
<span style="color: #000000; font-weight: bold;">&gt;&gt;&gt;</span> pygame.ver
<span style="color: #ff0000;">'1.9.2pre'</span></pre></div></div>

<p>Und schon ist man im Besitz der aktuellsten Pygame-Version für Python 3 unter Ubuntu.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.datenteiler.de/pygame-fuer-python-3-unter-ubuntu-installieren/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Symbian für Schlangenbeschwörer</title>
		<link>http://www.datenteiler.de/symbian-fuer-schlangenbeschwoerer/</link>
		<comments>http://www.datenteiler.de/symbian-fuer-schlangenbeschwoerer/#comments</comments>
		<pubDate>Sun, 05 Sep 2010 16:11:25 +0000</pubDate>
		<dc:creator>Christian Imhorst</dc:creator>
				<category><![CDATA[Gnu/Linux]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.datenteiler.de/?p=4685</guid>
		<description><![CDATA[Dieser Artikel erschien erstmals in freiesMagazin 09/10: Vergleicht man Symbian mit neueren Betriebssystemen für Smartphones, wirkt es doch recht altbacken. Böse Zungen behaupten sogar, dass es das Windows 98 der mobilen Betriebssysteme sei, weil die Oberfläche seit gefühlten 10 Jahren gleich aussieht. Die Unterstützung von Open-Source-Software ist bei Symbian allerdings vorbildlich modern. Zum einen ist [...]]]></description>
			<content:encoded><![CDATA[<p><b><em>Dieser Artikel erschien erstmals in <b><font color="#595959">freies</font></b><font color="#FF630A">Magazin</font> <a href="http://www.freiesmagazin.de/freiesMagazin-2010-09">09/10</a>:</em> Vergleicht man Symbian mit neueren Betriebssystemen für Smartphones, wirkt es doch recht altbacken. Böse Zungen behaupten sogar, dass es das Windows 98 der mobilen Betriebssysteme sei, weil die Oberfläche seit gefühlten 10 Jahren gleich aussieht. Die Unterstützung von Open-Source-Software ist bei Symbian allerdings vorbildlich modern. Zum einen ist das Betriebssystem selbst mittlerweile Open Source&nbsp;<a href="http://www.heise.de/newsticker/meldung/Symbian-wird-komplett-Open-Source-921815.html">[1]</a> und zum anderen werden etliche Werkzeuge an die Hand gegeben, um freie Software zu schreiben. Eines dieser Werkzeuge heißt Python, das Nokia 2005 auf die S60-Plattform portiert hat. Da die Einarbeitungszeit für Programmieranfänger kürzer ist als in C++, kann man schnell lauffähige Programme entwickeln, die durch Module flexibel erweiterbar sind. Es ist die perfekte Gelegenheit für Freunde von GNU/Linux, Solaris oder einem BSD-System, eigene Programme zu schreiben und ihr Handy für ein größeres Aufgabengebiet fit zu machen.</b></p>
<p><span id="more-4685"></span></p>
<h2>Installation</h2>
<p>Nachdem man überprüft hat, ob das eigene Handy zur S60-Reihe gehört&nbsp;<a href="http://de.wikipedia.org/wiki/S60">[2]</a>, benötigt man die die Datei <b><tt style="font-size: 1.3em;">PythonForS60_2.0.0.tar.gz</tt></b> von der Webseite garage.maemo.org&nbsp;<a href="https://garage.maemo.org/">[3]</a>. Von der Versionsnummer darf man sich nicht irritieren lassen; Python für S60 2.0 liegt Python 2.5.4 zugrunde. Nach dem Entpacken überträgt man die Dateien <b><tt style="font-size: 1.3em;">Python_2.0.0.sis</tt></b>, <b><tt style="font-size: 1.3em;">pips.sis</tt></b> und <b><tt style="font-size: 1.3em;">PythonScriptShell_2.0.0_3_0.sis</tt></b> aus dem Ordner <b><tt style="font-size: 1.3em;">PyS60Dependencies</tt></b> entweder per Bluetooth, USB-Kabel oder WLAN&nbsp;<a href="http://www.datenteiler.de/ein-kleiner-webserver-mit-python/">[4]</a> auf das Telefon. Anschließend installiert man sie in dieser Reihenfolge in den Telefonspeicher. Die Installation muss in den Telefonspeicher und darf nicht auf die Speicherkarte erfolgen, da Python-Programme ansonsten Probleme haben, den Python-Interpreter zu finden.</p>
<h2>Nach der Installation</h2>
<p>Jetzt gibt es verschiedene Möglichkeiten, Python-Programme auf dem Handy auszuführen. Die einfachste ist, das Programm gleich auf dem Telefon zu tippen. Dazu öffnet man die Python-Shell und wählt „Interactive console“. Je nach Tastatur kann das Tippen auf dem Handy sehr anstrengend sein; der schöne Nebeneffekt ist aber, dass man auch in der S-Bahn oder an der Supermarkt-Kasse mit einem Python-Editor wie Ped&nbsp;<a href="http://code.google.com/p/ped-s60/">[5]</a> programmieren kann. Die Menschen um einen herum denken dann, dass man sehr beliebt sein muss, weil man eine SMS nach der anderen schreibt, und man wird ausnahmsweise mal nicht für einen vereinsamten Ober-Geek gehalten.</p>
<h2>Eine Python-Shell fürs Handy</h2>
<p>Im Lieferumfang von Python für S60 gibt es zwar schon eine Bluetooth-Konsole&nbsp;<a href="http://www.datenteiler.de/mobiles-python-ii/">[6]</a>, die man auch sehr komfortabel mit den PUTools bedienen kann&nbsp;<a href="http://www.datenteiler.de/mit-gnulinux-fuer-pys60-entwickeln/">[7]</a>, aber was macht man, wenn kein Bluetooth, dafür aber WLAN vorhanden ist? Man richtet sich einfach eine Python-Shell übers WLAN ein. Die Verbindung zur WLAN-Shell steht auch schneller als die über Bluetooth, was ein entscheidender Vorteil ist, selbst wenn der Rechner über eine Bluetooth-Schnittstelle verfügt.</p>
<p>Damit die Python-Shell über WLAN funktioniert, benötigt man das Programm netcat, das im Normalfall unter GNU/Linux, Unix oder MacOS&nbsp;X schon installiert ist. Mit dem Befehl <b><tt style="font-size: 1.3em;">nc</tt></b> startet man das Kommando, um Daten mit TCP im Netzwerk zu übertragen:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">stty</span> raw <span style="color: #660033;">-echo</span> ; nc <span style="color: #660033;">-l</span> <span style="color: #000000;">1025</span> ; <span style="color: #c20cb9; font-weight: bold;">stty</span> sane</pre></div></div>

<p>Auf einigen GNU/Linux-Rechnern muss man noch den Schalter <b><tt style="font-size: 1.3em;">-p</tt></b> hinzufügen und <b><tt style="font-size: 1.3em;">nc -l -p 1025</tt></b> eingeben. Bevor man das Terminal via <b><tt style="font-size: 1.3em;">netcat</tt></b> in eine Python-Shell des Handys verwandeln kann, werden dessen Einstellungen mit dem Systembefehl <b><tt style="font-size: 1.3em;">stty</tt></b> neu gesetzt. Dabei schaltet die Option <b><tt style="font-size: 1.3em;">raw</tt></b> die Pufferung aus, damit eine Eingabe Zeichen für Zeichen an die Shell weitergereicht wird. Buchstaben werden dabei uninterpretiert weitergeleitet, was soviel heißt, dass es kein Newline-Zeichen oder ähnliches mehr gibt und <i>„Strg“</i>&nbsp;+&nbsp;<i>„D“</i> zum Beispiel keinen Datenstrom mehr beendet. Die Option <b><tt style="font-size: 1.3em;">echo</tt></b> verhindert, dass die eingegebene Taste nochmal im Terminal angezeigt wird. Anschließend startet <b><tt style="font-size: 1.3em;">netcat</tt></b>, um auf hereinkommende Verbindungsanfragen am Port 1025 zu lauschen. Im letzten Teil des Kommandos startet man noch einmal <b><tt style="font-size: 1.3em;">stty</tt></b>, diesmal aber mit der Option <b><tt style="font-size: 1.3em;">sane</tt></b>, um die Pufferung des Terminals wieder herzustellen. Damit kann man die Python-Shell erneut mit der Tastenkombination <i>„Strg“</i>&nbsp;+&nbsp;<i>„D“</i> beenden.</p>
<p>Das folgende Skript für Ubuntu 10.04 vereinfacht die Verbindungsanfrage:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;"># Script: wifishell.sh</span>
<span style="color: #666666; font-style: italic;"># Object: Starts TCP/IP Console for S60 mobiles afterwards</span>
<span style="color: #666666; font-style: italic;"># start wifishell.py on your S60</span>
&nbsp;
<span style="color: #007800;">IP</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ifconfig</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'inet '</span><span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">'127\.0\.0\.1'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> -d: <span style="color: #660033;">-f2</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $1}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">PORT</span>=<span style="color: #ff0000;">&quot;1025&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Your IP address is: <span style="color: #007800;">$IP</span> &quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Start now wifishell.py on your phone ...&quot;</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">stty</span> raw <span style="color: #660033;">-echo</span> ; nc <span style="color: #660033;">-l</span> <span style="color: #000000;">1025</span> ; <span style="color: #c20cb9; font-weight: bold;">stty</span> sane</pre></div></div>

<p>Im ersten Teil wird die IP-Adresse im eigenen Netzwerk ermittelt und in der Variable <b><tt style="font-size: 1.3em;">IP</tt></b> gespeichert, was aber nur für GNU/Linux-Rechner gilt. Verwendet man ein Betriebssystem wie MacOS&nbsp;X, Free-, Open- oder NetBSD, muss man stattdessen folgende Zeile in das Skript einfügen:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">IP</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ifconfig</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-E</span> <span style="color: #ff0000;">'inet.[0-9]'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">'127\.0\.0\.1'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $2}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Als Benutzer von OpenSolaris verwendet man folgende Zeile:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">IP</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ifconfig</span> <span style="color: #660033;">-a</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'inet '</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">'127\.0\.0\.1'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $2}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Wie bereits erwähnt, muss man bei manchen GNU/Linux-Betriebssystemen darauf achten, dass der Aufruf von <b><tt style="font-size: 1.3em;">netcat</tt></b> im zweiten Teil des Skripts mit den Schalter <b><tt style="font-size: 1.3em;">-p</tt></b> geschieht.</p>
<p>Das Gegenstück in Python, das Skript <b><tt style="font-size: 1.3em;">wifishell.py</tt></b>, muss auf das Handy kopiert werden. Wie alle anderen Python-Skripte auch, sollte es dort auf der Speicherkarte im Verzeichnis <b><tt style="font-size: 1.3em;">E:\Python\</tt></b> liegen. Sobald <b><tt style="font-size: 1.3em;">wifishell.sh</tt></b> auf dem GNU/Linux-Rechner oder der Unix-Maschine nach Anfragen auf dem Port 1025 lauscht, startet man über die Python-Shell auf dem Telefon das Skript <b><tt style="font-size: 1.3em;">wifishell.py</tt></b>, um eine Verbindung zum Terminal auf dem Computer herzustellen. Läuft alles glatt, verwandelt sich das Terminal in eine Python-Shell auf dem Handy.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># Script: wifishell.py</span>
<span style="color: #808080; font-style: italic;"># Object: Starts TCP/IP Console for S60 mobiles before start</span>
<span style="color: #808080; font-style: italic;"># wifishell.sh on your Unix box</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> btconsole, appuifw
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">try</span>: <span style="color: #808080; font-style: italic;"># next lines are important to select an access point</span>
    <span style="color: #dc143c;">sys</span>.<span style="color: black;">modules</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'socket'</span><span style="color: black;">&#93;</span> = <span style="color: #008000;">__import__</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'btsocket'</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">ImportError</span>:
    <span style="color: #ff7700;font-weight:bold;">pass</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">socket</span>
&nbsp;
ip = appuifw.<span style="color: black;">query</span><span style="color: black;">&#40;</span>u<span style="color: #483d8b;">&quot;IP address:&quot;</span>, <span style="color: #483d8b;">&quot;text&quot;</span><span style="color: black;">&#41;</span>
port = <span style="color: #ff4500;">1025</span>
&nbsp;
sock=<span style="color: #dc143c;">socket</span>.<span style="color: #dc143c;">socket</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">socket</span>.<span style="color: black;">AF_INET</span>, <span style="color: #dc143c;">socket</span>.<span style="color: black;">SOCK_STREAM</span><span style="color: black;">&#41;</span>
sock.<span style="color: black;">connect</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #008000;">str</span><span style="color: black;">&#40;</span>ip<span style="color: black;">&#41;</span>, port<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
btconsole.<span style="color: black;">run_with_redirected_io</span><span style="color: black;">&#40;</span>sock,btconsole.<span style="color: black;">interact</span>,<span style="color: #008000;">None</span>,<span style="color: #008000;">None</span>,<span style="color: #008000;">locals</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
sock.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Im Terminal sieht das dann so aus:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">stty</span> raw <span style="color: #660033;">-echo</span> ; nc <span style="color: #660033;">-l</span> <span style="color: #000000;">1025</span> ; <span style="color: #c20cb9; font-weight: bold;">stty</span> sane
Python 2.5.4 <span style="color: #7a0874; font-weight: bold;">&#40;</span>r254:<span style="color: #000000;">67916</span>, Nov  <span style="color: #000000;">6</span> <span style="color: #000000;">2009</span>, 04:<span style="color: #000000;">18</span>:<span style="color: #000000;">57</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>C<span style="color: #7a0874; font-weight: bold;">&#93;</span> on symbian_s60
<span style="color: #000000; font-weight: bold;">&gt;&gt;&gt;</span> import appuifw
<span style="color: #000000; font-weight: bold;">&gt;&gt;&gt;</span> appuifw.note<span style="color: #7a0874; font-weight: bold;">&#40;</span>u<span style="color: #ff0000;">'Hallo Welt!'</span>, <span style="color: #ff0000;">'info'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<h2>Hallo Welt!</h2>
<p>Als erstes Programm in Python für S60 schreibt man klassischerweise eines, das „Hallo Welt!“ auf dem Bildschirm ausgibt. Das wird in diesem Fall schon mit einer grafischen Oberfläche gemacht, was ganz leicht ist. Man lädt dazu einfach das Modul <b><tt style="font-size: 1.3em;">appuifw</tt></b>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;&gt;&gt;</span> import appuifw
<span style="color: #000000; font-weight: bold;">&gt;&gt;&gt;</span> appuifw.note<span style="color: #7a0874; font-weight: bold;">&#40;</span>u<span style="color: #ff0000;">'Hallo Welt!'</span>, <span style="color: #ff0000;">'info'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Im ersten Teil des Befehls erzeugt die Funktion <b><tt style="font-size: 1.3em;">note()</tt></b> des Moduls <b><tt style="font-size: 1.3em;">appuifw</tt></b> ein Hinweisfenster. Die  Zeichenkette in der Klammer muss Unicode sein, daher das vorangestellte „u“. Die zweite Zeichenkette gibt an, dass es sich beim Fenster nur um eine Information handelt. Eine Aktion des Benutzers ist nicht gefordert und das Fenster verschwindet nach einer Weile von allein.</p>
<div id="attachment_4713" class="wp-caption alignnone" style="width: 310px"><a href="http://www.datenteiler.de/wp-content/uploads/2010/09/symbian-hallo-welt.png"><img src="http://www.datenteiler.de/wp-content/uploads/2010/09/symbian-hallo-welt-300x231.png" alt="" title="symbian-hallo-welt" width="300" height="231" class="size-medium wp-image-4713" /></a><p class="wp-caption-text"><em>Der erste Programmierergebnis mit Python. </em></p></div>
<p>Neben <b><tt style="font-size: 1.3em;">appuifw</tt></b> für das Erstellen von Benutzeroberflächen können noch weitere spezielle Module für PyS60 in Programme importiert werden. Das sind <b><tt style="font-size: 1.3em;">e32</tt></b> als Schnittstelle zum Betriebssystem, <b><tt style="font-size: 1.3em;">sysinfo</tt></b> liest Geräteinformationen aus, <b><tt style="font-size: 1.3em;">audio</tt></b> zeichnet Klänge auf und spielt sie ab, <b><tt style="font-size: 1.3em;">e32calendar</tt></b> ermöglicht den Zugriff auf den Kalender, <b><tt style="font-size: 1.3em;">camera</tt></b> auf die Kamera, <b><tt style="font-size: 1.3em;">contacts</tt></b> auf Kontakte, <b><tt style="font-size: 1.3em;">e32dbm</tt></b> auf die Datenbank, <b><tt style="font-size: 1.3em;">location</tt></b> auf die Standortinformationen, <b><tt style="font-size: 1.3em;">messaging</tt></b> auf SMS-Funktionen, <b><tt style="font-size: 1.3em;">telephone</tt></b> auf die des Telefons und <b><tt style="font-size: 1.3em;">graphics</tt></b> zeichnet grafische Elemente&nbsp;<a href="http://pys60.garage.maemo.org/doc/s60/">[8]</a>.</p>
<p>Mit jedem einzelnen Modul kann man eine Menge Sachen anstellen, zum Beispiel das Handy etwas sagen zu lassen:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> audio
audio.<span style="color: black;">say</span><span style="color: black;">&#40;</span>u<span style="color: #483d8b;">&quot;Hello World!&quot;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Oder eine MP3-Datei abspielen:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> audio, e32
fn = u<span style="color: #483d8b;">&quot;e:<span style="color: #000099; font-weight: bold;">\\</span>Musik<span style="color: #000099; font-weight: bold;">\\</span>mymusic.mp3&quot;</span>
sound = audio.<span style="color: black;">Sound</span>.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span>fn<span style="color: black;">&#41;</span>
sound.<span style="color: black;">play</span><span style="color: black;">&#40;</span>times=<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
e32.<span style="color: black;">ao_sleep</span><span style="color: black;">&#40;</span>sound.<span style="color: black;">duration</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>/<span style="color: #ff4500;">1000000</span> + <span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span>
sound.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Oder ein kleines Skript schreiben, das per SMS um Hilfe ruft:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> messaging, appuifw
contact_number = <span style="color: #483d8b;">&quot;+49123456789&quot;</span>
contact_name = <span style="color: #483d8b;">&quot;Linus&quot;</span>
message = <span style="color: black;">&#40;</span>u<span style="color: #483d8b;">&quot;SOS, ruf mich an.&quot;</span><span style="color: black;">&#41;</span>
messaging.<span style="color: black;">sms_send</span><span style="color: black;">&#40;</span>contact_number, message, name=contact_name<span style="color: black;">&#41;</span>
appuifw.<span style="color: black;">note</span><span style="color: black;">&#40;</span>u<span style="color: #483d8b;">&quot;Die Nachricht wurde gesendet&quot;</span>, <span style="color: #483d8b;">&quot;info&quot;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Dieses Skript könnte man weiter ausbauen: Statt um Hilfe zu rufen, könnte es eine automatisierte Antwort auf bestimmte SMS geben, oder man erweitert die Hilfe-SMS um eine Standortbestimmung mit dem Modul <b><tt style="font-size: 1.3em;">positioning</tt></b>, wenn das Handy GPS unterstützt, um seinen Standort mitzusenden.</p>
<p>Die Akku-Ladung wird normalerweise mit Strichen oder Balken angezeigt. Wer es genau wissen will, schreibt einfach ein kleines Skript mit <b><tt style="font-size: 1.3em;">sysinfo</tt></b>:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> appuifw, sysinfo
battery = sysinfo.<span style="color: black;">battery</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
appuifw.<span style="color: black;">note</span><span style="color: black;">&#40;</span>u<span style="color: #483d8b;">'Battery: '</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>battery<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">' %'</span>, <span style="color: #483d8b;">'info'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Als Dateien speichert man die Skripte in das Verzeichnis <b><tt style="font-size: 1.3em;">E:\Python\</tt></b> auf dem Handy. Die Python-Shell schaut bevorzugt in diesem Ordner nach. Ausgeführt werden sie dann in der Python-Shell auf dem Handy, indem man „<em>Run script</em>“ und anschließend das Skript auswählt.</p>
<h2>SIS-Pakete selber bauen</h2>
<p>Nun kann es ganz schön lästig sein, immer diesen Weg einzuschlagen, wenn man mal kurz den Ladezustand überprüfen will. Einfacher ist es doch, gleich das Skript ohne Umweg über die Python-Shell zu starten. Dabei hilft das Programm <b><tt style="font-size: 1.3em;">ensymble</tt></b>&nbsp;<a href="http://code.google.com/p/ensymble/">[9]</a>. Bei vielen Distributionen ist es in den Paketquellen enthalten, da es aber „nur“ ein Python-Skript ist, kann man die Datei auch einfach von der Webseite herunterladen. Mit <b><tt style="font-size: 1.3em;">ensymble</tt></b> gibt es allerdings ein kleines Problem: Das Skript benötigt Python 2.5. Das wird besonders diejenigen nicht freuen, die Ubuntu 10.04 „Lucid Lynx“ benutzen, da dort die älteste Python-Version 2.6 ist. Wer kein Python 2.5 besitzt, sollte es kompilieren, und zwar mit Zlib-Unterstützung. Die freie Programmbibliothek zum Komprimieren und Dekomprimieren von Daten ist bei Python 2.5 standardmäßig deaktiviert, wird aber von <b><tt style="font-size: 1.3em;">ensymble</tt></b> benötigt&nbsp;<a href="http://www.datenteiler.de/wie-man-python-2-5-mit-zlib-kompiliert/">[10]</a>.</p>
<p>Ist <b><tt style="font-size: 1.3em;">ensymble</tt></b> heruntergeladen und steht Python 2.5 mit Zlib-Unterstützung bereit, müssen nur noch die Dateien <b><tt style="font-size: 1.3em;">ensymble.py</tt></b>, ein Skript (zum Beispiel das Skript für den Ladezustand des Akkus, das man <b><tt style="font-size: 1.3em;">batinfo.py</tt></b> nennen kann) und eine SVG-Datei als Icon im selben Ordner liegen. Für die SVG-Datei kann man sich für den Anfang gut bei den Icons des GNOME-Projekts unter <b><tt style="font-size: 1.3em;">/usr/share/icons/gnome/scalable</tt></b> bedienen, wenn man zu bequem ist, ein eigenes zu basteln. Dann kann die Verwandlung des Skripts in eine Installationsdatei für Symbian beginnen:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">python2.5 ensymble.py py2sis <span style="color: #660033;">--version</span>=1.0.0 <span style="color: #660033;">--icon</span>=battery-low.svg <span style="color: #660033;">--caption</span>=<span style="color: #ff0000;">&quot;Battery Info&quot;</span> <span style="color: #660033;">--vendor</span>=<span style="color: #ff0000;">&quot;Christian Imhorst&quot;</span> batinfo.py batinfo.sis</pre></div></div>

<p>Die Datei <b><tt style="font-size: 1.3em;">batinfo.sis</tt></b> lädt man anschließend auf das Handy und installiert es in den Telefonspeicher. Leider läuft das Programm nicht, wenn man es auf die Speicherkarte installiert, und es funktioniert natürlich nur auf Telefonen, auf denen auch Python für S60 bereits installiert ist. Nach der Installation findet man das Programm mit eigenem Icon im Installationsordner.</p>
<div id="attachment_4727" class="wp-caption alignnone" style="width: 310px"><a href="http://www.datenteiler.de/wp-content/uploads/2010/09/symbian-installationsordner.png"><img src="http://www.datenteiler.de/wp-content/uploads/2010/09/symbian-installationsordner-300x231.png" alt="" title="symbian-installationsordner" width="300" height="231" class="size-medium wp-image-4727" /></a><p class="wp-caption-text"><em>Das hochgeladene Skript findet man im Installationsordner wieder.</em></p></div>
<h2>Zum Schluss …</h2>
<p>… noch ein kleines Programm, um die Kalenderdatenbank des Telefons auszulesen und in einer Datei zu sichern. Die Termine kann man anschließend in den Kalender von Evolution oder Thunderbird importieren. Für solche kleinen Aufgaben ist Python für S60 einfach ideal:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># vcalendar export</span>
<span style="color: #ff7700;font-weight:bold;">import</span> e32calendar, appuifw
&nbsp;
cal = e32calendar.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>cal<span style="color: black;">&#41;</span> == <span style="color: #ff4500;">0</span>:
    appuifw.<span style="color: black;">note</span><span style="color: black;">&#40;</span> u<span style="color: #483d8b;">&quot;No calendar entries.&quot;</span>, <span style="color: #483d8b;">&quot;info&quot;</span> <span style="color: black;">&#41;</span>
id_list=<span style="color: #008000;">list</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: #008000;">id</span> <span style="color: #ff7700;font-weight:bold;">in</span> cal:
    id_list.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #008000;">id</span><span style="color: black;">&#41;</span>
&nbsp;
vCal = cal.<span style="color: black;">export_vcalendars</span><span style="color: black;">&#40;</span><span style="color: #008000;">tuple</span><span style="color: black;">&#40;</span>id_list<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># define the directory and file name</span>
vCalendar = u<span style="color: #483d8b;">&quot;e:<span style="color: #000099; font-weight: bold;">\\</span>vCal.vcf&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># create file</span>
<span style="color: #008000;">file</span> = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>vCalendar, <span style="color: #483d8b;">'w'</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># write vcal into file and close the file</span>
<span style="color: #008000;">file</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>vCal<span style="color: black;">&#41;</span>
<span style="color: #008000;">file</span>.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
appuifw.<span style="color: black;">note</span><span style="color: black;">&#40;</span> u<span style="color: #483d8b;">&quot;Success!&quot;</span>, <span style="color: #483d8b;">&quot;info&quot;</span> <span style="color: black;">&#41;</span></pre></div></div>

<p>Zu Beginn des Skripts werden die beiden Module <b><tt style="font-size: 1.3em;">e32calendar</tt></b> für den Zugriff auf den Kalender und <b><tt style="font-size: 1.3em;">appuifw</tt></b> für Benutzeroberflächen geladen. Einmal teilt ein Hinweisfenster im Skript mit, dass es keinen Kalendereintrag gefunden hat, und am Ende, dass es erfolgreich fertig geworden ist. Die Funktion <b><tt style="font-size: 1.3em;">open()</tt></b> aus dem Modul <b><tt style="font-size: 1.3em;">e32calendar</tt></b> öffnet den Kalender und übergibt ihn an <b><tt style="font-size: 1.3em;">cal</tt></b>. Die einzelnen Einträge werden nacheinander einer Liste übergeben, die dann komplett in die Datei <b><tt style="font-size: 1.3em;">vCal.vcf</tt></b> geschrieben wird.</p>
<h2>Literatur</h2>
<ul>
<li> Jürgen Scheible und Ville Tuulos, „<a href="http://www.amazon.de/gp/product/0470515058?ie=UTF8&#038;tag=imhorstnet-21&#038;linkCode=as2&#038;camp=1638&#038;creative=6742&#038;creativeASIN=0470515058">Mobile Python: Rapid prototyping of applications on the mobile platform (Symbian Press)</a><img src="http://www.assoc-amazon.de/e/ir?t=imhorstnet-21&#038;l=as2&#038;o=3&#038;a=0470515058" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />“, 2007
</li>
<li> Jürgen Scheible, „Python for S60 Tutorial“&nbsp;<a href="http://www.mobilenin.com/">[11]</a>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.datenteiler.de/symbian-fuer-schlangenbeschwoerer/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Wie man Python 2.5 mit Zlib kompiliert</title>
		<link>http://www.datenteiler.de/wie-man-python-2-5-mit-zlib-kompiliert/</link>
		<comments>http://www.datenteiler.de/wie-man-python-2-5-mit-zlib-kompiliert/#comments</comments>
		<pubDate>Sun, 04 Jul 2010 20:01:44 +0000</pubDate>
		<dc:creator>Christian Imhorst</dc:creator>
				<category><![CDATA[Gnu/Linux]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.datenteiler.de/?p=4673</guid>
		<description><![CDATA[Die freie Programmbibliothek zlib zum Komprimieren und Dekomprimieren von Daten mit dem Deflate-Algorithmus ist in Python 2.5 standardmäßig deaktiviert. Damit Python 2.5 Zlib wieder unterstützt, muss man vor dem Kompilieren configure mit der entsprechenden Flag ausführen. Dazu braucht es aber ein bisschen Vorarbeit: Das Paket zlib-dev muss installiert sein. Nur darin ist die Header-Datei des [...]]]></description>
			<content:encoded><![CDATA[<p>Die freie Programmbibliothek <a href="http://www.zlib.net/">zlib</a> zum Komprimieren und Dekomprimieren von Daten mit dem Deflate-Algorithmus ist in Python 2.5 standardmäßig deaktiviert. Damit Python 2.5 Zlib wieder unterstützt, muss man vor dem Kompilieren <em>configure</em> <a href="http://www.1stbyte.com/2005/06/26/configure-and-compile-python-with-zlib/">mit der entsprechenden Flag</a> ausführen. Dazu braucht es aber ein bisschen Vorarbeit:</p>
<p>Das Paket <em>zlib-dev</em> muss installiert sein. Nur darin ist die Header-Datei des Zlib-Projekts enthalten, die man dringend benötigt. Auch wenn Zlib selbst schon installiert ist, benötigt man die Projektdateien. Bei Debian-basierten Distributionen wie Ubuntu ist das Paket schnell installiert.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> zlib1g-dev</pre></div></div>

<p>Nach der Installation findet man die Header-Datei im Verzeichnis <code>/usr/include/zlib.h</code>. Jetzt wechselt man in das Verzeichnis mit den Quelldateien von Python 2.5 und führt <em>configure</em> mit der entsprechenden Flag aus:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--with-zlib</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>include</pre></div></div>

<p>Danach kompiliert man ganz normal mit <code>make &amp;&amp; sudo make install</code> weiter (oder, wer möchte, mit <code>checkinstall</code>).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.datenteiler.de/wie-man-python-2-5-mit-zlib-kompiliert/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>notify-osd: Nachrichten an den Desktop senden &#8212; mit Python</title>
		<link>http://www.datenteiler.de/notify-osd-nachrichten-an-den-desktop-senden-mit-python/</link>
		<comments>http://www.datenteiler.de/notify-osd-nachrichten-an-den-desktop-senden-mit-python/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 21:02:10 +0000</pubDate>
		<dc:creator>Christian Imhorst</dc:creator>
				<category><![CDATA[Gnu/Linux]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.datenteiler.de/?p=4442</guid>
		<description><![CDATA[Der Artikel notify-send: Nachrichten an den Desktop senden von linuxnetzer beschreibt, wie man mit dem Befehl notify-send über die Kommandozeile Nachrichten an den Gnome-Desktop versenden kann. Dazu muss man einfach das Paket libnotify-bin aus den Paketquellen installieren sudo apt-get install libnotify-bin und schon kann man mit folgendem Befehl eine Testnachricht an den Desktop senden: notify-send [...]]]></description>
			<content:encoded><![CDATA[<p>Der Artikel <a href="http://linuxnetz.wordpress.com/2010/04/21/notify-send/">notify-send: Nachrichten an den Desktop senden</a> von <a href="http://linuxnetz.wordpress.com/">linuxnetzer</a> beschreibt, wie man mit dem Befehl <code>notify-send</code> über die Kommandozeile Nachrichten an den Gnome-Desktop versenden kann. Dazu muss man einfach das Paket <code>libnotify-bin</code> aus den Paketquellen installieren</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libnotify-bin</pre></div></div>

<p>und schon kann man mit folgendem Befehl eine Testnachricht an den Desktop senden:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">notify-send <span style="color: #ff0000;">&quot;Testnachricht&quot;</span></pre></div></div>

<p>Etwas komplexer geht das Ganze auch mit Python, dafür muss man aber kein zusätzliches Software-Paket installieren. Auch wenn letzteres auf dem eigenen System nicht wirklich dramatisch ist, aber was macht man, wenn man zum Beispiel ein Backup-Skript anderen Benutzern zu Verfügung stellen will, das z.B. die Benachrichtigung &#8220;Backup beendet&#8221; am Desktop anzeigen soll, so wie im Beispiel von linuxnetzer? Man kann sie bitten, das Paket <code>libnotify-bin</code> zu installieren, oder man nutzt die Möglichkeit, sein eigenes Notify-Skript zu erstellen, das etwa folgendermaßen aussehen könnte:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> pynotify
&nbsp;
pynotify.<span style="color: black;">init</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Testnachricht&quot;</span><span style="color: black;">&#41;</span>
n = pynotify.<span style="color: black;">Notification</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Testnachricht&quot;</span>, <span style="color: #483d8b;">&quot;Dies ist ein Test.&quot;</span>, <span style="color: #483d8b;">&quot;icon&quot;</span><span style="color: black;">&#41;</span>
n.<span style="color: black;">show</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Selbstverständlich geht das auch als Einzeiler in der Shell, was allerdings doch recht lang ist:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">python <span style="color: #660033;">-c</span> <span style="color: #ff0000;">'import pynotify; pynotify.init(&quot;message&quot;); n = pynotify.Notification(&quot;Testnachricht&quot;, &quot;Dies ist ein Test.&quot;, &quot;icon&quot;); n.show()'</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.datenteiler.de/notify-osd-nachrichten-an-den-desktop-senden-mit-python/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Eine Python-Shell fürs Handy über WLAN</title>
		<link>http://www.datenteiler.de/eine-python-shell-fuers-handy-ueber-wlan/</link>
		<comments>http://www.datenteiler.de/eine-python-shell-fuers-handy-ueber-wlan/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 21:03:23 +0000</pubDate>
		<dc:creator>Christian Imhorst</dc:creator>
				<category><![CDATA[Gnu/Linux]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.datenteiler.de/?p=4221</guid>
		<description><![CDATA[Im Lieferumfang zu Python für S60-Handys von Nokia (PyS60) gibt es zwar schon eine Python-Shell fürs Handy über Bluetooth, aber was macht man, wenn kein Bluetooth, dafür aber WLAN vorhanden ist? Man richtet einfach eine Python-Shell über WLAN ein. Abgesehen davon steht die Shell über WLAN schneller, als man eine Bluetooth-Verbindung herstellen kann, weshalb sie [...]]]></description>
			<content:encoded><![CDATA[<p>Im Lieferumfang zu Python für S60-Handys von Nokia (PyS60) gibt es zwar schon eine <a href="http://www.datenteiler.de/mobiles-python-ii/">Python-Shell  fürs Handy über Bluetooth</a>, aber was macht man, wenn kein Bluetooth, dafür aber WLAN vorhanden ist? Man richtet einfach eine Python-Shell über WLAN ein.  Abgesehen davon steht die Shell über WLAN schneller, als man eine Bluetooth-Verbindung herstellen kann, weshalb sie sich auch eignet, selbst wenn Computer und Handy über Bluetooth-Schnittstellen verfügen.</p>
<p><span id="more-4221"></span></p>
<p>Damit die Python-Shell über WLAN funktioniert, benötigt man das Programm <code><a href="http://de.wikibooks.org/wiki/Linux-Kompendium:_netcat">netcat</a></code>, das im Normalfall unter Gnu/Linux, Unix oder MacOS X schon installiert ist. Mit dem Befehl <code>nc</code> startet man das Kommando, um Daten mit TCP im Netzwerk zu übertragen. Folgendes Kommando funktioniert so nur unter Gnu/Linux:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">stty</span> raw <span style="color: #660033;">-echo</span> ; nc <span style="color: #660033;">-l</span> <span style="color: #660033;">-p</span> <span style="color: #000000;">1025</span> ; <span style="color: #c20cb9; font-weight: bold;">stty</span> sane</pre></div></div>

<p>Auf anderen Unix-Maschinen muss man den Schalter <code>-p</code> weglassen und einfach nur <code>nc -l 1025</code> eingeben. Bevor man das Terminal via <code>netcat</code> in eine Python-Shell verwandeln kann, werden dessen Einstellungen mit dem Systembefehl <code>stty</code> neu gesetzt. Dabei schaltet die Option <code>raw</code> die Pufferung aus, damit eine Eingabe Zeichen für Zeichen an die Shell weitergereicht wird. Buchstaben werden dabei uninterpretiert weitergeleitet, was soviel heißt, dass es kein Newline-Zeichen oder ähnliches mehr gibt und Strg-D zum Beispiel keinen Datenstrom mehr beendet (<em>End of File</em>, EOF). Die Option <code>echo</code> verhindert, dass die eingegebene Taste nochmal im Terminal angezeigt wird. Anschließend startet <code>netcat</code>, um auf hereinkommende Verbindungsanfragen am Port <em>1025</em> zu lauschen. Im letzten Teil des Kommandos startet man wieder <code>stty</code>, diesmal aber mit der Option <code>sane</code>, um die Pufferung des Terminals wieder herzustellen, damit man die Python-Shell mit der Tastenkombination Strg-D (EOF) beenden kann.</p>
<p>Um <code>netcat</code> nicht vergeblich lauschen zu lassen, muss folgender Python-Code auf dem Telefon ausführt werden, damit die Verbindung hergestellt wird:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> btconsole
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #808080; font-style: italic;"># Try to import 'btsocket' as 'socket'</span>
<span style="color: #ff7700;font-weight:bold;">try</span>:
    <span style="color: #dc143c;">sys</span>.<span style="color: black;">modules</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'socket'</span><span style="color: black;">&#93;</span> = <span style="color: #008000;">__import__</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'btsocket'</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">ImportError</span>:
    <span style="color: #ff7700;font-weight:bold;">pass</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">socket</span>
&nbsp;
sock=<span style="color: #dc143c;">socket</span>.<span style="color: #dc143c;">socket</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">socket</span>.<span style="color: black;">AF_INET</span>, <span style="color: #dc143c;">socket</span>.<span style="color: black;">SOCK_STREAM</span><span style="color: black;">&#41;</span>
sock.<span style="color: black;">connect</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;192.168.0.10&quot;</span>,<span style="color: #ff4500;">1025</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
btconsole.<span style="color: black;">run_with_redirected_io</span><span style="color: black;">&#40;</span>sock,btconsole.<span style="color: black;">interact</span>,<span style="color: #008000;">None</span>,<span style="color: #008000;">None</span>,<span style="color: #008000;">locals</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
sock.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Wichtig ist dabei, dass man die IP-Adresse des lauschenden Rechners eingibt. In dem Beispiel ist das <em>192.168.0.10</em>, in der Realität wird es allerdings eine andere Adresse sein. Außerdem ist wichtig, dass ebenfalls Port <em>1025</em> benutzt wird. Man kann auch einen anderen Port wählen, den muss man dann nur auf beiden Seiten ändern. Wenn alles klappt, zeigt das Terminal eine Python-Shell auf dem Handy über WLAN:</p>
<p><a href="http://www.datenteiler.de/wp-content/uploads/2010/04/TCP-IP-Shell.jpeg"><img src="http://www.datenteiler.de/wp-content/uploads/2010/04/TCP-IP-Shell-300x212.jpg" alt="" title="TCP-IP-Shell" width="300" height="212" class="aligncenter size-medium wp-image-4275" /></a></p>
<p>Für die Vereinfachungen des Ganzen habe ich zwei Skripte geschrieben: Das erste Shell-Skript <a href='http://www.datenteiler.de/wp-content/uploads/2010/04/wifishell.sh.tar.gz'>wifishell.sh</a> wird auf dem Gnu/Linux-Rechner ausgeführt:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;"># Script:      wifishell.sh</span>
<span style="color: #666666; font-style: italic;"># Object:      Starts TCP/IP Console for S60 mobiles</span>
<span style="color: #666666; font-style: italic;">#              afterwards start console.py on your S60</span>
&nbsp;
<span style="color: #007800;">IP</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ifconfig</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'inet '</span><span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">'127.0.0.1'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> -d: <span style="color: #660033;">-f2</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $1}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">PORT</span>=<span style="color: #ff0000;">&quot;1025&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Your IP address is: <span style="color: #007800;">$IP</span> &quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Start now wifishell.py on your phone ...&quot;</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">stty</span> raw <span style="color: #660033;">-echo</span> ; nc <span style="color: #660033;">-l</span> <span style="color: #660033;">-p</span> <span style="color: #000000;">1025</span> ; <span style="color: #c20cb9; font-weight: bold;">stty</span> sane</pre></div></div>

<p>Im ersten Teil wird die IP-Adresse im eigenen Netzwerk ermittelt und in der Variable <em>IP</em> gespeichert. Dies gilt, wie gesagt, nur für Gnu/Linux-Rechner. Verwendet man ein Betriebssystem mit Free- oder OpenBSD, bzw. mit MacOS X, muss man stattdessen folgende Zeile in das Skript einfügen:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">IP</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ifconfig</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-E</span> <span style="color: #ff0000;">'inet.[0-9]'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">'127.0.0.1'</span> <span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $2}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Außerdem muss man darauf achten, dass der Aufruf von <code>netcat</code> im zweiten Teil des Skripts ohne den Schalter <code>-p</code> geschieht, wie das Beispiel auf einem Mac zeigt:</p>
<p><a href="http://www.datenteiler.de/wp-content/uploads/2010/04/TCP-IP-Shell-Mac.jpg"><img src="http://www.datenteiler.de/wp-content/uploads/2010/04/TCP-IP-Shell-Mac-300x218.jpg" alt="" title="TCP-IP-Shell-Mac" width="300" height="218" class="aligncenter size-medium wp-image-4288" /></a></p>
<p>Als Benutzer von OpenSolaris verwendet man übrigens  folgende Zeile im Skript:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">IP</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ifconfig</span> <span style="color: #660033;">-a</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'inet '</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">'127.0.0.1'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $2}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Das Gegenstück in Python <a href='http://www.datenteiler.de/wp-content/uploads/2010/04/wifishell.py_.tar.gz'>wifishell.py</a> muss auf das Handy gespielt werden. Wie alle anderen Python-Skripte auch, sollte es dort auf der Speicherkarte ins Verzeichnis <code>E:\Python\</code> kopiert werden. Sobald <em>wifishell.sh</em> auf dem Gnu/Linux-Rechner oder der Unix-Maschine nach Anfragen auf dem Port 1025 lauscht, startet man über die Python-Shell auf dem Telefon das Skript <em>wifishell.py</em>, um eine Verbindung zum Terminal auf dem Computer herzustellen. Läuft alles glatt, verwandelt sich das Terminal in eine Python-Shell auf dem Handy.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># Script:      wifishell.py</span>
<span style="color: #808080; font-style: italic;"># Object:      Starts TCP/IP Console for S60 mobiles</span>
<span style="color: #808080; font-style: italic;">#              before start console.sh on your Gnu/Linux box</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> btconsole, appuifw
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">try</span>: <span style="color: #808080; font-style: italic;"># next lines important for select_access_point()</span>
    <span style="color: #dc143c;">sys</span>.<span style="color: black;">modules</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'socket'</span><span style="color: black;">&#93;</span> = <span style="color: #008000;">__import__</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'btsocket'</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">ImportError</span>:
    <span style="color: #ff7700;font-weight:bold;">pass</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">socket</span>
&nbsp;
ip = appuifw.<span style="color: black;">query</span><span style="color: black;">&#40;</span>u<span style="color: #483d8b;">&quot;IP address:&quot;</span>, <span style="color: #483d8b;">&quot;text&quot;</span><span style="color: black;">&#41;</span>
port = <span style="color: #ff4500;">1025</span>
&nbsp;
sock=<span style="color: #dc143c;">socket</span>.<span style="color: #dc143c;">socket</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">socket</span>.<span style="color: black;">AF_INET</span>, <span style="color: #dc143c;">socket</span>.<span style="color: black;">SOCK_STREAM</span><span style="color: black;">&#41;</span>
sock.<span style="color: black;">connect</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #008000;">str</span><span style="color: black;">&#40;</span>ip<span style="color: black;">&#41;</span>, port<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
btconsole.<span style="color: black;">run_with_redirected_io</span><span style="color: black;">&#40;</span>sock,btconsole.<span style="color: black;">interact</span>,<span style="color: #008000;">None</span>,<span style="color: #008000;">None</span>,<span style="color: #008000;">locals</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
sock.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.datenteiler.de/eine-python-shell-fuers-handy-ueber-wlan/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ein kleiner Webserver mit Python</title>
		<link>http://www.datenteiler.de/ein-kleiner-webserver-mit-python/</link>
		<comments>http://www.datenteiler.de/ein-kleiner-webserver-mit-python/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 17:11:03 +0000</pubDate>
		<dc:creator>Christian Imhorst</dc:creator>
				<category><![CDATA[Gnu/Linux]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.datenteiler.de/?p=4187</guid>
		<description><![CDATA[Vielleicht kennt ihr das Problem ja auch: Da will man gerade los und denkt sich, &#8216;wäre ja schön das neu gekaufte Album unterwegs auf dem Handy zu hören&#8217;, oder &#8216;ich kann ja den Text schnell auf mein Handy laden und unterwegs lesen&#8217;, und dann weiß man nicht mehr, wo man das USB-Kabel gelassen hat, das [...]]]></description>
			<content:encoded><![CDATA[<p>Vielleicht kennt ihr das Problem ja auch: Da will man gerade los und denkt sich, &#8216;wäre ja schön das neu gekaufte Album unterwegs auf dem Handy zu hören&#8217;, oder &#8216;ich kann ja den Text schnell auf mein Handy laden und unterwegs lesen&#8217;, und dann weiß man nicht mehr, wo man das USB-Kabel gelassen hat, das Netbook hat kein Bluetooth und der Bluetooth-Adapter für den USB-Port liegt vermutlich beim verlegten USB-Kabel. Sollte WLAN vorhanden sein, ist das mit Python alles kein Problem. Der <a href="http://www.catonmat.net/blog/top-ten-one-liners-from-commandlinefu-explained/">folgende Einzeiler</a> startet einen HTTP-Server auf Port 8080 im aktuellen Verzeichnis:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">~/Musik$ python -m <span style="color: #dc143c;">SimpleHTTPServer</span> <span style="color: #ff4500;">8080</span></pre></div></div>

<p>Der Inhalt des Arbeitsverzeichnisses, in diesem Fall der Ordner <em>Musik</em>, wird über den HTTP-Server im internen Netzwerk angeboten, also nicht nur für <em>localhost</em>. Sollte sich im aktuellen Verzeichnis eine Datei wie <em>index.html</em> oder <em>index.htm</em> befinden, würde der Webbrowser ihren Inhalt anzeigen. Da sich solch eine Datei dort aber nicht aufhält, wird der Inhalt des Verzeichnisses angezeigt.</p>
<p><span id="more-4187"></span></p>
<p>Wenn der Server auf dem Netbook gestartet ist, öffnet man den Webbrowser des Handys. Bei meinem Nokia E71 musste ich dazu den Standardbrowser verwenden, da der Opera Mini sich nicht verbinden wollte. In die Adressleiste gibt man die IP-Adresse des Netbooks im internen Netzwerk gefolgt vom Port an. Die IP-Adresse wird auf jeden Fall anders sein. In meinem Fall ist das:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">http://192.168.2.105:<span style="color: #ff4500;">8080</span>/</pre></div></div>

<p><a href="http://www.datenteiler.de/wp-content/uploads/2010/04/Screenshot0037.jpg"><img src="http://www.datenteiler.de/wp-content/uploads/2010/04/Screenshot0037-300x225.jpg" alt="" title="Screenshot0037" width="300" height="225" class="aligncenter size-medium wp-image-4198" /></a></p>
<p>Wenn alles klappt, sieht man den Inhalt des Ordners auf dem Netbook präsentiert vom HTTP-Server:</p>
<p><a href="http://www.datenteiler.de/wp-content/uploads/2010/04/Screenshot0038.jpg"><img src="http://www.datenteiler.de/wp-content/uploads/2010/04/Screenshot0038-300x225.jpg" alt="" title="Screenshot0038" width="300" height="225" class="aligncenter size-medium wp-image-4196" /></a></p>
<p>Man kann sich nun durch die Ordner klicken und die einzelnen Musikstücke herunterladen, allerdings nur immer die einzelnen Dateien, keine kompletten Ordner.</p>
<p><a href="http://www.datenteiler.de/wp-content/uploads/2010/04/Screenshot0040.jpg"><img src="http://www.datenteiler.de/wp-content/uploads/2010/04/Screenshot0040-300x225.jpg" alt="" title="Screenshot0040" width="300" height="225" class="aligncenter size-medium wp-image-4201" /></a></p>
<p>In der Shell kann man dann sehr schön beobachten, mit welcher IP-Adresse das Handy auf die Ordner und Dateien des Servers zugreift:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">~<span style="color: #000000; font-weight: bold;">/</span>Musik$ python <span style="color: #660033;">-m</span> SimpleHTTPServer <span style="color: #000000;">8080</span>
Serving HTTP on 0.0.0.0 port <span style="color: #000000;">8080</span> ...
192.168.2.101 - - <span style="color: #7a0874; font-weight: bold;">&#91;</span>02<span style="color: #000000; font-weight: bold;">/</span>Apr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2010</span> <span style="color: #000000;">18</span>:<span style="color: #000000;">37</span>:<span style="color: #000000;">41</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #ff0000;">&quot;GET / HTTP/1.1&quot;</span> <span style="color: #000000;">200</span> -
192.168.2.101 - - <span style="color: #7a0874; font-weight: bold;">&#91;</span>02<span style="color: #000000; font-weight: bold;">/</span>Apr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2010</span> <span style="color: #000000;">18</span>:<span style="color: #000000;">38</span>:07<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #ff0000;">&quot;GET /The%20Avett%20Brothers/ HTTP/1.1&quot;</span> <span style="color: #000000;">200</span> -
192.168.2.101 - - <span style="color: #7a0874; font-weight: bold;">&#91;</span>02<span style="color: #000000; font-weight: bold;">/</span>Apr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2010</span> <span style="color: #000000;">18</span>:<span style="color: #000000;">38</span>:<span style="color: #000000;">16</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #ff0000;">&quot;GET /The%20Avett%20Brothers/I%20And%20Love%20And%20You/ HTTP/1.1&quot;</span> <span style="color: #000000;">200</span> -
192.168.2.101 - - <span style="color: #7a0874; font-weight: bold;">&#91;</span>02<span style="color: #000000; font-weight: bold;">/</span>Apr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2010</span> <span style="color: #000000;">18</span>:<span style="color: #000000;">38</span>:<span style="color: #000000;">23</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #ff0000;">&quot;GET /The%20Avett%20Brothers/I%20And%20Love%20And%20You/01%20-%20I%20And%20Love%20And%20You.mp3 HTTP/1.1&quot;</span> <span style="color: #000000;">200</span> -</pre></div></div>

<p>Jetzt möchte man vielleicht eine Datei schnell vom Handy zum Netbook schicken. Das ist mit einem Nokia S60-Modell und <a href="http://www.datenteiler.de/python-fuer-symbian-in-der-version-2-0/">Python for Symbian 2.0</a> kein Problem. Dazu muss <a href="http://www.digitaleschulebayern.de/dsdaten/278/19.pdf">folgendes kleine Skript</a> auf dem Telefon gestartet werden:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">BaseHTTPServer</span> <span style="color: #ff7700;font-weight:bold;">import</span> HTTPServer
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">SimpleHTTPServer</span> <span style="color: #ff7700;font-weight:bold;">import</span> SimpleHTTPRequestHandler
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
&nbsp;
<span style="color: #dc143c;">os</span>.<span style="color: black;">chdir</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;e:<span style="color: #000099; font-weight: bold;">\\</span>&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
serv = HTTPServer<span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&quot;</span>, <span style="color: #ff4500;">8080</span><span style="color: black;">&#41;</span>, SimpleHTTPRequestHandler<span style="color: black;">&#41;</span>
serv.<span style="color: black;">serve_forever</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Bevor der HTTP-Server auf Port 8080 gestartet wird, wird als Arbeitsverzeichnis &#8220;e:\\&#8221; vereinbart, was in diesem Fall die Speicherkarte ist. Bevor man den Server aber startet, sollte eine Internetverbindung über WLAN auf dem Handy schon etabliert sein. Am einfachsten surft man dazu mit dem Webbrowser irgendeine Seite an. Nach dem Start blockiert das Skripts  allerdings die Python Shell, dafür hat man jetzt die Möglichkeit, den Inhalt der Speicherkarte entlang zu surfen:</p>
<p><a href="http://www.datenteiler.de/wp-content/uploads/2010/04/simplehttpserver1.png"><img src="http://www.datenteiler.de/wp-content/uploads/2010/04/simplehttpserver1-300x199.png" alt="" title="simplehttpserver1" width="300" height="199" class="aligncenter size-medium wp-image-4208" /></a></p>
<p>Wenn man möchte, kann man einzelne Dokumente herunter laden oder vom Handy aus starten:</p>
<p><a href="http://www.datenteiler.de/wp-content/uploads/2010/04/simplehttpserver2.png"><img src="http://www.datenteiler.de/wp-content/uploads/2010/04/simplehttpserver2-300x190.png" alt="" title="simplehttpserver2" width="300" height="190" class="aligncenter size-medium wp-image-4210" /></a></p>
<p>Das alles funktioniert, weil bei neueren Python-Versionen das Standardmodul <code>SimpleHTTPServer</code> dabei ist. Da es auf dem Symbian-Handy leider keine Shell und kein Terminal gibt, kann man hier nicht mit der Option &#8220;-m&#8221; wie zum Beispiel unter Gnu/Linux auf dem Netbook arbeiten. Ein einfacher kurzer Einzeiler reicht hier nicht, man muss eben ein bisschen mehr ausholen. Es gibt übrigens auch die Möglichkeit, <a href="http://wiki.forum.nokia.com/index.php/Transferring_files_over_WiFi_with_PyS60_-_a_client/server_example">Dateien über WLAN mit einem Client- und einem Server-Programm</a> auszutauschen. Aber das ein anderes Mal.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.datenteiler.de/ein-kleiner-webserver-mit-python/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

