<?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>meh &#187; python</title>
	<atom:link href="http://www.bonf.net/category/coding/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bonf.net</link>
	<description>-__-</description>
	<lastBuildDate>Sun, 11 Jul 2010 17:51:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>&#8220;Oh Crap It&#8217;s Morning&#8221; &#8211; Alpha Version</title>
		<link>http://www.bonf.net/2009/06/29/oh-crap-its-morning-alpha-version/</link>
		<comments>http://www.bonf.net/2009/06/29/oh-crap-its-morning-alpha-version/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 19:14:15 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[proof-of-concept]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.bonf.net/?p=82</guid>
		<description><![CDATA[If you&#8217;ve been saying the above statement before, this program is for you. It&#8217;s an alarm clock application for S60 phones (more specifically Nokia 5800) written in Python The code is NOWHERE near what you&#8217;d expect of released code to be &#8211; this is NOT a release, rather a preview This is my first piece [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve been saying the above statement before, this program is for you.</p>
<p>It&#8217;s an alarm clock application for S60 phones (more specifically Nokia 5800) written in Python<br />
<span id="more-82"></span></p>
<p><strong>The code is NOWHERE near what you&#8217;d expect of released code to be &#8211; this is NOT a release, rather a preview <img src='http://www.bonf.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </strong></p>
<p>This is my first piece of code written in S60 Python. The code is not pretty, not well designed, not nothing &#8211; it&#8217;s just a proof of concept; helping me get to know the S60 python modules, and wake up on time.</p>
<p>The main feature of this program, that I could not find a ready-made S60 application that already accomplishes this, is the use of a random tune for every alarm.<br />
Don&#8217;t you hate it when you choose a song for an alarm clock, and find yourself hating the song ever after? Spazzing just a little bit every time you hear it?<br />
By choosing a random song every morning, you get to hear many of your favorite songs, without slowly developing hate towards them.</p>
<p>The second feature, is &#8220;fade in&#8221;. The song is initially played in low volume, which is gradually turned up.</p>
<p>Don&#8217;t rely on this code to wake you up for important meetings, it is probably full of bugs. It can&#8217;t save your last alarm properly (even though it tries to), but it will save your songs path.<br />
It is also semi-automatic, meaning you&#8217;ll have to set the alarm every night, it won&#8217;t do so automatically (yet!).<br />
It won&#8217;t survive phone shutdown either.<br />
It seems like python can&#8217;t overcome these obstacles easily, but I&#8217;ll try to improve it in the future. If I tried to code it with the bare Symbian API, it wouldn&#8217;t have reached the somewhat functional state it is in today&#8230;</p>
<p>I only post it here because I have started using it almost daily, and that both lowered my motivation to work for a more complete solution, and urged me to post the code somewhere, as other people may find it useful.<br />
It can also serve as a demo for S60 Python API use.</p>
<p>I have only tested it on Nokia 5800 which is S60 5th edition, with python 1.9.4.<br />
Other configurations may cause nuclear fusion.</p>
<p>Feel free to do whatever you want with the code.</p>
<p><a href="http://bonf.net/wp-content/uploads/2009/06/alarm.py">The Code</a></p>
<p>As a side note, during development I have used <a href="http://sourceforge.net/projects/pys60-compat/">pys60-compat</a> which is a wxPython based implementation of portions of the S60 python framework &#8211; meaning it let&#8217;s you run python code written for s60 in a testing environment on your desktop.<br />
It is somewhat outdated, and I have added some extensions of my own, which I may release in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bonf.net/2009/06/29/oh-crap-its-morning-alpha-version/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>So&#8230;</title>
		<link>http://www.bonf.net/2007/05/18/so/</link>
		<comments>http://www.bonf.net/2007/05/18/so/#comments</comments>
		<pubDate>Fri, 18 May 2007 20:36:38 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.bonf.net/?p=3</guid>
		<description><![CDATA[Yeah, well, it&#8217;s my blog. Hi. So, hmm, basically, I&#8217;m not really that much of a writer. I think I just started this blog because it happens to me quite often that when I search stuff on google, I find useful information on personal blogs, of all places. Solutions to coding problems (yes, I&#8217;m a [...]]]></description>
			<content:encoded><![CDATA[<p>Yeah, well, it&#8217;s my blog. Hi.</p>
<p>So, hmm, basically, I&#8217;m not really that much of a writer. I think I just started this blog because it happens to me quite often that when I search stuff on google, I find useful information on personal blogs, of all places.  Solutions to coding problems (yes, I&#8217;m a coder) , interesting reviews and recommendations, and articles.</p>
<p>I thought that I should give back to the web, publish more code that I write, and help others with problems that I have solved. The hosting plan and domain were purchased about 2 months ago, and only now I write my first post, well, I&#8217;m a busy man XD</p>
<p>There&#8217;s more to come next. I don&#8217;t want to put too much effort to the first posts, as there&#8217;s a high chance that I will abandon this blog quickly, and no one will ever read them.</p>
<p>Anyway, I&#8217;ll post something small and quick that I had coded some days ago in 10 minutes.</p>
<p>Some weeks ago I&#8217;ve been contacted by an online buddy to whom I didn&#8217;t  speak in 2 or 3 years. It was a period during which I was highly enthusiastic about 3d and animation, and he was one of the experts in the forum where I used to &#8220;hang&#8221; <img src='http://www.bonf.net/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  . The short conversation with him inspired me to do some 3d modeling, and I came up with something (quite lame) for a quick modeling challenge in some forum.</p>
<p>So, I had a time limit, and I wanted to keep measure of time as I was modeling. The right thing to do was certainly to program a stopwatch in python using pygame ! I&#8217;ll just post the code now, and will look for a code highlighting plug-in for wordpress later.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> pygame,pygame.<span style="color: black;">font</span>
<span style="color: #ff7700;font-weight:bold;">from</span> pygame.<span style="color: #008000;">locals</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#yuck, global vars ^_^</span>
font=<span style="color: #008000;">None</span>
surface=<span style="color: #008000;">None</span>
<span style="color: #dc143c;">time</span>=<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> <span style="color: #808080; font-style: italic;"># an array to keep the current time measurement which is being rendered</span>
start_state=<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> <span style="color: #808080; font-style: italic;">#the time measurement from which to start counting</span>
start_tick=<span style="color: #ff4500;">0</span> <span style="color: #808080; font-style: italic;"># the number of ticks when we began counting</span>
on=<span style="color: #008000;">False</span> <span style="color: #808080; font-style: italic;">#wheter the stopwatch should be running or not</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">global</span> font,surface,on
&nbsp;
    video_flags = DOUBLEBUF
    pygame.<span style="color: black;">init</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#initialize pygame</span>
    surface = pygame.<span style="color: black;">display</span>.<span style="color: black;">set_mode</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">200</span>,<span style="color: #ff4500;">100</span><span style="color: black;">&#41;</span>, video_flags<span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#create our main window SDL surface</span>
    surface.<span style="color: black;">fill</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">255</span>,<span style="color: #ff4500;">255</span>,<span style="color: #ff4500;">255</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#fill with white</span>
&nbsp;
    font = pygame.<span style="color: black;">font</span>.<span style="color: black;">Font</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'INK2SCRI.TTF'</span>,<span style="color: #ff4500;">60</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#load up a ttf font</span>
    last_tick = pygame.<span style="color: #dc143c;">time</span>.<span style="color: black;">get_ticks</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>	<span style="color: #808080; font-style: italic;"># initialize the tick count</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #ff4500;">1</span>: <span style="color: #808080; font-style: italic;">#do forever</span>
        event = pygame.<span style="color: black;">event</span>.<span style="color: black;">poll</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> event.<span style="color: #008000;">type</span> == QUIT:
            <span style="color: #ff7700;font-weight:bold;">break</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> event.<span style="color: #008000;">type</span> == KEYUP <span style="color: #ff7700;font-weight:bold;">and</span> event.<span style="color: black;">key</span>==<span style="color: #ff4500;">32</span>: <span style="color: #808080; font-style: italic;"># if the space bar was pushed</span>
            <span style="color: #ff7700;font-weight:bold;">if</span><span style="color: black;">&#40;</span>on<span style="color: black;">&#41;</span>: <span style="color: #808080; font-style: italic;"># if currently running</span>
                <span style="color: #808080; font-style: italic;">#prepare start_state for future use, save current time</span>
                start_state<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span> = <span style="color: #dc143c;">time</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>
                start_state<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> = <span style="color: #dc143c;">time</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
                start_state<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> = <span style="color: #dc143c;">time</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
            <span style="color: #ff7700;font-weight:bold;">else</span>:
                <span style="color: #808080; font-style: italic;">#starting the timer, so set the tick count reference to the current tick count</span>
                start_tick = pygame.<span style="color: #dc143c;">time</span>.<span style="color: black;">get_ticks</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
            on = <span style="color: #ff7700;font-weight:bold;">not</span> on <span style="color: #808080; font-style: italic;">#toggle on</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">if</span><span style="color: black;">&#40;</span>on<span style="color: black;">&#41;</span>:
            a = <span style="color: black;">&#40;</span>pygame.<span style="color: #dc143c;">time</span>.<span style="color: black;">get_ticks</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> - start_tick<span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># get the amount of ticks(miliseconds) that passed from when the stopwatch was last run</span>
&nbsp;
            <span style="color: #dc143c;">time</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span> = start_state<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>+ <span style="color: black;">&#40;</span>a / <span style="color: #ff4500;">1000</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">%</span> <span style="color: #ff4500;">60</span> <span style="color: #808080; font-style: italic;">#seconds</span>
            <span style="color: #dc143c;">time</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> = start_state<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>+<span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>a / <span style="color: #ff4500;">1000</span><span style="color: black;">&#41;</span> / <span style="color: #ff4500;">60</span> <span style="color: #66cc66;">%</span> <span style="color: #ff4500;">60</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#minutes</span>
            <span style="color: #dc143c;">time</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> = start_state<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>+<span style="color: black;">&#40;</span>a / <span style="color: #ff4500;">1000</span><span style="color: black;">&#41;</span> / <span style="color: #ff4500;">3600</span> <span style="color: #808080; font-style: italic;">#hours</span>
&nbsp;
        draw<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
        pygame.<span style="color: black;">display</span>.<span style="color: black;">flip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> draw<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">global</span> surface,font
&nbsp;
<span style="color: #808080; font-style: italic;">#render the time, by converting each array member to a string, and concating with ':' in between time components. render in black on a white background.</span>
    tempsurface=font.<span style="color: black;">render</span><span style="color: black;">&#40;</span><span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">time</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>+<span style="color: #483d8b;">':'</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">time</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>+<span style="color: #483d8b;">':'</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">time</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>,<span style="color: #ff4500;">1</span>,<span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>,<span style="color: black;">&#40;</span><span style="color: #ff4500;">255</span>,<span style="color: #ff4500;">255</span>,<span style="color: #ff4500;">255</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
    surface.<span style="color: black;">fill</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">255</span>,<span style="color: #ff4500;">255</span>,<span style="color: #ff4500;">255</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#fill the screen with white, to erase the previous time</span>
    surface.<span style="color: black;">blit</span><span style="color: black;">&#40;</span>tempsurface,<span style="color: black;">&#40;</span><span style="color: #ff4500;">10</span>,<span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># blit the temporary surface to the screen</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span><span style="color: black;">&#40;</span>__name__==<span style="color: #483d8b;">'__main__'</span><span style="color: black;">&#41;</span>:
    main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Check out the screenshot:</p>
<p><a href="http://www.bonf.net/wp-content/uploads/2007/05/screen.PNG" title="screen.PNG"><img src="http://www.bonf.net/wp-content/uploads/2007/05/screen.thumbnail.PNG" alt="screen.PNG" /></a></p>
<p>And here&#8217;s the model that I used it for:</p>
<p><a href="http://www.bonf.net/wp-content/uploads/2007/05/hook.jpg" title="Hook"><img src="http://www.bonf.net/wp-content/uploads/2007/05/hook.thumbnail.jpg" alt="Hook" /></a></p>
<p>I&#8217;m happy to finally start this blog, hope I will manage to keep writing, and that people will actually read it some time in the future.</p>
<p>Ben.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bonf.net/2007/05/18/so/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
