<?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>Ben Jao Ming &#187; Python</title>
	<atom:link href="http://overtag.dk/wordpress/category/computers/python-computers/feed/" rel="self" type="application/rss+xml" />
	<link>http://overtag.dk/wordpress</link>
	<description>101% objective... always</description>
	<lastBuildDate>Fri, 02 Apr 2010 23:50:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9-rare</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Django localized date template filter</title>
		<link>http://overtag.dk/wordpress/2009/07/django-localized-date-template-filter/</link>
		<comments>http://overtag.dk/wordpress/2009/07/django-localized-date-template-filter/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 22:24:13 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[template filter]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=155</guid>
		<description><![CDATA[UPDATE! This is going to be redundant in Django 1.2, in which you can add DATE_FORMAT to your django.po files.
I&#8217;ve often been frustrated that using settings.DATE_FORMAT does not give a localized date. Granted that the name of a month may be localized, but the format string does not change. So let&#8217;s start out by modifying [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE!</strong> This is going to be redundant in Django 1.2, in which you can add DATE_FORMAT to your django.po files.</p>
<p>I&#8217;ve often been frustrated that using <strong>settings.DATE_FORMAT</strong> does not give a localized date. Granted that the name of a month may be localized, but the format string does not change. So let&#8217;s start out by modifying <strong>settings.py</strong>. We wrap our default date format in a <b>ugettext</b> so the makemessages command will detect it, and we need to make it a dummy function, because the i18n library cannot be imported in settings.py due to circularity (it depends on settings.py).</p>

<div class="wp_syntax"><div class="code"><pre class="python">ugettext = <span style="color: #ff7700;font-weight:bold;">lambda</span> s: s
DATE_FORMAT = ugettext<span style="color: black;">&#40;</span><span style="color: #483d8b;">'N j, Y'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Run compilemessages and type in your localized date formats. Now we need a template filter that uses a localized format for calling the Django date format function. This is really simple:</p>

<div class="wp_syntax"><div class="code"><pre class="python"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">template</span>.<span style="color: black;">defaultfilters</span> <span style="color: #ff7700;font-weight:bold;">import</span> stringfilter
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">utils</span> <span style="color: #ff7700;font-weight:bold;">import</span> dateformat
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">utils</span>.<span style="color: black;">translation</span> <span style="color: #ff7700;font-weight:bold;">import</span> ugettext
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">conf</span> <span style="color: #ff7700;font-weight:bold;">import</span> settings
&nbsp;
@register.<span style="color: #008000;">filter</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> localdate<span style="color: black;">&#40;</span>value<span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;Format date with localized date format&quot;</span><span style="color: #483d8b;">&quot;&quot;</span>
    format = ugettext<span style="color: black;">&#40;</span>settings.<span style="color: black;">DATE_FORMAT</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> dateformat.<span style="color: black;">format</span><span style="color: black;">&#40;</span>value, format<span style="color: black;">&#41;</span></pre></div></div>

<p>And done. Using the filter is straight forward:</p>
<p><code><br />
Date: {{ my_date|localdate }}<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2009/07/django-localized-date-template-filter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Presenting: django-simple-wiki</title>
		<link>http://overtag.dk/wordpress/2009/04/presenting-django-simple-wiki/</link>
		<comments>http://overtag.dk/wordpress/2009/04/presenting-django-simple-wiki/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 23:52:57 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[django application]]></category>
		<category><![CDATA[django-simple-wiki]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[wiki]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=142</guid>
		<description><![CDATA[It was bothering me that all the wikis I tried, all had either errors, feature lacks, too many dependencies or were simply unmaintained. So I decided to create yet another one. Curiously, the third hit when googling &#8216;django wiki&#8217; is Create a wiki in 20 minutes. Luckily that&#8217;s not really true, so all the PHP [...]]]></description>
			<content:encoded><![CDATA[<p>It was bothering me that all the wikis I tried, all had either errors, feature lacks, too many dependencies or were simply unmaintained. So I decided to create yet another one. Curiously, the third hit when googling &#8216;django wiki&#8217; is <a href="http://showmedo.com/videotutorials/video?name=1100000">Create a wiki in 20 minutes</a>. Luckily that&#8217;s not really true, so all the PHP guys and MediaWiki can continue breathing. This took me several days.</p>
<blockquote style="font-size: 150%;"><p><strong><a href="http://code.google.com/p/django-simple-wiki/">Google Code project page</a></strong></p></blockquote>
<blockquote style="font-size: 150%;"><p><strong><a href="http://wikidemo.overtag.dk/">Demo website</a></strong></p></blockquote>
<p><strong>Hierarchy and relations</strong><br />
First of all, as in the Trac wiki system, I chose to create a system for hierarchy, meaning that it&#8217;s possible to create an article and then create sub-articles. The hierarchy does not support multiple inheritance, because it needs to be basis for the permission system. That&#8217;s where the relation system comes in place: All articles can contain symmetrical relations to any other articles in the hierarchy.</p>
<p><strong>Parsing</strong><br />
Python and Django supports Markdown pretty much out of the box, so it&#8217;s an obvious choice to use this for parsing. The HTML features of normal Markdown have been removed, so all HTML is escaped in django-simple-wiki. And parsing is static, so every time a revision is created, the contents are passed and stored. This means that the contents of the article itself are not supposed to be dynamic. On the other hand, it is desirable to avoid parsing contents for every page hit. The parsing area of the application is only a few lines of code, and can be expanded if further parsing needs to be done, or someone wants to replace Markdown completely. For instance, if no parsing is done and HTML escaping is disabled, the wiki becomes a very simple CMS.</p>
<p><strong>Curious issues</strong><br />
There are a few out standing problems:</p>
<ul>
<li>Permission system is related to User entries in the Django auth system. But maybe this is too much of an annoyance, if the project already has groups setup in the existing auth system. On the other hand, other users would be bothered to setup both wiki groups and user groups, if the permission system was linked to user groups. And directly linking articles to user groups would require wiki-related groups to be created directly in the auth system.</li>
<li>Since relations are symmetrical, what should happen if one article is locked, but a user modifies it&#8217;s relations by deleting them from related articles?</li>
<li>Title editing: The title can only be created once, since it is coupled to the &#8217;slug&#8217; of the article. A user can deliberately create a completely different title, which is fine, but should subsequent editing be allowed, which would add complexity to the revision system?</li>
<li>Article deletion: When an article is deleted from the backend it shouldn&#8217;t worry anyone. But if the feature is added to the frontend, we would want to handle maliciousness etc. But should we really store all these files and revisions? Should we alert admins, so they can do the final cleanup?</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2009/04/presenting-django-simple-wiki/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GTK and scrolling without scrollbars</title>
		<link>http://overtag.dk/wordpress/2009/01/gtk-and-scrolling-without-scrollbars/</link>
		<comments>http://overtag.dk/wordpress/2009/01/gtk-and-scrolling-without-scrollbars/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 19:09:39 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[full screen]]></category>
		<category><![CDATA[gtk]]></category>
		<category><![CDATA[gtk.Layout]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[rhythmbox]]></category>
		<category><![CDATA[scrolling]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=114</guid>
		<description><![CDATA[There&#8217;s still some work to do on the full screen plugin for Rhythmbox, but the current version is very usable indeed. The latest addition is scrolling by hovering the track list.
I changed the display from a normal fixed table with 3 tracks to a gtk.Layout with a gtk.VBox containing n tracks. In a Layout widget [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s still some work to do on the full screen plugin for Rhythmbox, but the current version is very usable indeed. The latest addition is scrolling by hovering the track list.</p>
<p>I changed the display from a normal fixed table with 3 tracks to a <strong>gtk.Layout</strong> with a <strong>gtk.VBox</strong> containing <em>n</em> tracks. In a Layout widget it&#8217;s possible to freely place and move child widgets, so by detecting motion events on the edges of the Layout you can emulate scrolling by moving a child widget accordingly with <strong>Layout.move(widget, x, y)</strong>. Unfortunately I get a rather nasty blinking effect when scrolling too fast, and I don&#8217;t have an explanation for this, so I&#8217;d be glad to hear from anyone who can help.</p>

<div class="wp_syntax"><div class="code"><pre class="python"><span style="color: #ff7700;font-weight:bold;">def</span> track_layout_scroll<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, widget, event<span style="color: black;">&#41;</span>:
    time_step = <span style="color: #ff4500;">10</span> <span style="color: #808080; font-style: italic;">#msecs</span>
    ycoord = event.<span style="color: black;">y</span>
    accel_factor = <span style="color: #ff4500;">10</span> <span style="color: #808080; font-style: italic;">#how many pixels to scroll at the edge</span>
    edge_distance = <span style="color: #ff4500;">100.0</span> <span style="color: #808080; font-style: italic;">#pixels</span>
    layout_size = widget.<span style="color: black;">get_size</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    top_dist = edge_distance - ycoord
    bot_dist = edge_distance - layout_size<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> + ycoord
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> top_dist <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span>:
        accel = <span style="color: #ff4500;">-1</span> - <span style="color: black;">&#40;</span>top_dist / edge_distance<span style="color: black;">&#41;</span> <span style="color: #66cc66;">*</span> accel_factor
    <span style="color: #ff7700;font-weight:bold;">elif</span> bot_dist <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span>:
        accel =  <span style="color: #ff4500;">1</span> + <span style="color: black;">&#40;</span>bot_dist / edge_distance<span style="color: black;">&#41;</span> <span style="color: #66cc66;">*</span> accel_factor
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        accel = <span style="color: #ff4500;">0.0</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">self</span>.<span style="color: black;">scroll_event_id</span>:
        gobject.<span style="color: black;">source_remove</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">scroll_event_id</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> accel == <span style="color: #ff4500;">0.0</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">scroll_event_id</span> = gobject.<span style="color: black;">timeout_add</span><span style="color: black;">&#40;</span>time_step, <span style="color: #008000;">self</span>.<span style="color: black;">do_scrolling</span>, accel, widget<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> do_scrolling<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, accel, layout_widget<span style="color: black;">&#41;</span>:
    step = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: #66cc66;">*</span>accel<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> step == <span style="color: #ff4500;">0</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span>
    vbox_size = <span style="color: #008000;">self</span>.<span style="color: black;">vbox</span>.<span style="color: black;">size_request</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    layout_size = layout_widget.<span style="color: black;">get_size</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    scroll_height = vbox_size<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>-layout_size<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">self</span>.<span style="color: black;">scroll_y</span> + step <span style="color: #66cc66;">&lt;</span> <span style="color: #ff4500;">0</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">scroll_y</span> = <span style="color: #ff4500;">0</span>
    <span style="color: #ff7700;font-weight:bold;">elif</span> <span style="color: #008000;">self</span>.<span style="color: black;">scroll_y</span> + step <span style="color: #66cc66;">&gt;</span> scroll_height:
        <span style="color: #008000;">self</span>.<span style="color: black;">scroll_y</span> = scroll_height
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">scroll_y</span> += step
&nbsp;
    <span style="color: #008000;">self</span>.<span style="color: black;">track_layout</span>.<span style="color: black;">move</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">vbox</span>, <span style="color: #ff4500;">0</span>, -<span style="color: #008000;">self</span>.<span style="color: black;">scroll_y</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.<span style="color: black;">scroll_y</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #008000;">self</span>.<span style="color: black;">scroll_y</span> <span style="color: #66cc66;">&lt;</span> scroll_height</pre></div></div>

<p>The code is related to my Rhythmbox plugin, but I&#8217;m sure you get the idea. Also please note, that track_layout_scroll has to receive notify_motion_event from the Layout widget, and that you have to set a size for the Layout widget with set_size().</p>
<p><strong>Update:</strong> By playing around with time_step (lowering it to be more exact) and slowing down the acceleration, I managed to almost make the white flashes disappear.</p>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2009/01/gtk-and-scrolling-without-scrollbars/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
