Posts about programming (old posts, page 2)

2004-02-02 20:34

And so does uqbar

It's better than I remember. Specially because the SF CVS version is newer than all the copies I had on disk (I wonder how that happened).

In fact, it has a nice trick to create error dialogs from any exception I am lifting right away for other apps :-)

The only problem it does have is that python's urllib and urllib2 support for FTP seems to suck.

You can't choose the username and password?

Sailor (Gutenberg's main server) is picky about the password you send, and [email protected], which urllib insist on using ([email protected]) doesn't pass muster.

And ftplib, which can do the right thing, doesn't let me give progress of the download, which would make the program awful.

Oh, well.

2004-01-27 13:34

Screenshot of Notty today

Since I uploaded Notty to Sourceforge (get it from CVS), I thought it would be nice to show what it looks like nowadays.

So here's a screenshot. If that link doesn't work, try this one.

It is mostly a working app, although still pretty basic. You can use it, you can create notes, you can even export them to HTML (working fairly well, except for links to other notes, which don't get fixed).

I am even using it to document itself (see docs/help.notty in the sources, it's a notty file)

Specially nice is Silvercity's code-block directive, which you can see used in the screenshot (look at the yellow fragment).

I'd say it is right now a pretty decent documentation writing tool, although the editor component is too featureless.

2004-01-24 11:36

Neat stuff

This is a recipe at the Python CookBook showing how to add a new directive to reStructuredText, called code-block, which syntax-highlights the block!

I just implemented it in Notty, and now you can have the neatest code snippets. I did have to hack the output a fair bit since the displaying widget doesn´t support <span> (or CSS for that matter), so I had to do massive search-replaces on the output, to convert to <font>. But it took only half an hour to do, since SilverCity´s output is very regular.

I think I will suggest this to Hugo for PyDS, considering the density of programmers among its users :-)

2004-01-10 13:06

Whoa. Hits!

Looks like the programming tutorial was well received. About 5000 hits in 12 hours :-)

Today´s ranings:

Lateral Opinion (link) 2355 SPE - Stani's Python Editor (link) 86

If it continues, Lateral Opinion will reach 50K hits today. I´ll have a beer for that!

2004-01-05 19:01

Using linux without the CLI (Newsforge)

Nice article by Robin Miller at Newsforge.

I agree with most of it, except for one thing.

The author says "I always considered the "scratch your own itch" hacker ethos an essentially masturbatory thing. It would be like me writing articles I want to read instead of articles I think you want to read."

Well, Robin, articles and code are extremely different things. For one thing, articles are 100% useles for the author, unless someone else reads them, whicle code can be 100% useful for the author even if noone else has tried it.

I would say it´s like comparing apples and oranges, except... well, both are fruits and we compare them whenever we choose what fruit to buy. This is a less comparable pair.

For example, I am probably the only user of KRsN in the world. But it is useful for me. It saves me almost an hour a day, so I wrote it.

On the other hand, I will contradict myself: articles almost noone reads (like this one ;-) are useful for shaping one´s mind, although that´s not a frequent goal.

On the gripping hand[1], masturbation is good, dude. Don´t slam it unless you have never done it. And if you have never done it, don´t slam what you don´t know ;-)

In fact, programming because it itches is... well, it´s like scratching. It may even be bad for you, but don´t tell me it doesn´t feel good.

[1] One geek credit to the one who catches the reference.

2003-11-04 20:06

Confused by QMimeSourceFactory

Ok, here it goes. If you are not fluent in Qt programming the following entry will make no sense whatsoever :-)

If you set the contents of a QTextBrowser, and the content is HTML, it will call its QMimeSourceFactory's data() method to get MimeObjects representing, for example, images in the HTML.

So far so good.

However, I am mistified by this: While it's doing that, you can change the contents, and it will go along it's merry way, except that old data() calls are still in progress.

In other words, it acts as if it's multithreaded. Usually, in Qt, this is because someone is calling QApp::processEvents, and then you have multiple functions running and yielding to each other in the Qt event loop.

That is surely what's happeneing, but... how the hell does one stop the old data() calls????

The processEvents call is not made by me, it's done internally by some method in the QTextBrowser.... so, right now, in KRsN, sometimes you are downloading images for old stuff you saw minutes ago!

2003-10-27 17:33

Post-facto inheritance

Now, I didn't expect this to work at all!

A QlistView is a sort of tree widget, and is drag&drop enabled.

The trick is, you have to reimplement dragObject() so it returns a draggable thingie after you drag something.

But, since I am using designer to draw the forms, I have to use a real QListView, not a child class.

Conundrum? Custom widget in designer? Not with python!

def myDragObject(self):
return QTextDrag("something",self)


And that works! I know it should work in python, but QListView is implemented in a C++ module!

The guys that did PyQt really made it well.

2003-10-09 19:41

Nifty python/xmlrpc thing

Using python, it's trivial to turn any module into a XMLRPC server. So, if you are careful writing your app in a modular way, you can move the backend elsewhere in very little code.

For example, if I had a module that has some functionality, like this (

#Stupid simple module

def add(a,b):
        return a+b

A program would use it like this:

import module
print module.add(2,4)

Now, if I move the module to a remote box (server), create this xmlrpc server program in the server (and run it ;-):

#!/usr/bin/env python

#Simple generic XML-RPC server

import module

import SimpleXMLRPCServer

server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 800


And this bridge module in the client (

import xmlrpclib

server = xmlrpclib.Server('')

Now this very slightly modified version of our program works in exactly the same way as the original:

from clientmodule import server as module

print module.add(2,4)

Of course this has issues:

  • It has no security
  • XMLRPC could introduce errors and the program doesn't catch them.
  • It could be made even more transparent with some more pythoning

But anyway, I think it's cute.

2003-09-30 21:52

Baby steps

Implementing proper updating is simple in that sending stuff to PyDS is simple. However, having the GUI do the right thing is tricky:

When you modify an entry and switch to another, you have to offer a chance to save or discard.

If the user discards, you have to go back to the original data, so it must be saved somewhere else. And remember this:

>>> a={}
>>> b=a
>>> a['x']=1
>>> b['x']

Yeah, obvious python semantics. Lost an hour, though ;-)

What you want to do instead is:


If he saves, you have to upload.

Also, when he modifies, you have to update the post list realtime, so you see a coherent entity. Not too hard, but it forces you to despaghettize code somewhat.

Contents © 2000-2018 Roberto Alsina