2005-03-09 23:59

Data-aware widgets in PyQt

Here's the challenge: a nicer version of Qt's data-aware widgets, using PyQt.

Did I succeed? Probably not, but it was interesting to do. Maybe it will be interesting to read about ;-)

2005-03-08 23:59

Trac is cool. Cherrypy is cooler.

Trac is cool. Easy to set up, easy to run, low maintenance, and you get:

  • A ticketing system
  • Milestones
  • A webcvs-like thing for subversion
  • A wiki (I mean,. what doesn't provide a wiki nowadays?)
  • Bug reporting tool
  • The bug reporting tool and the subversion changesets can be linked using Wiki markup (now that's cooler than it sounds ;-)
  • You don't need to be root to set it up, and you don't need apache or anything else, really.

Really, really nice stuff.

On the other hand, CherryPy is a tool that lets you "publish your python objects on the web", which doesn't really mean much, but here's what I figured out:

Cherrypy is the first way I have seen to write a useful web-based app in a reasonable amount of time and pain.

Example, I wrote a frontend to clamav (allowing me to remotely trigger scans of individual nodes on a network) using Cherrypy and pyclamav in about 200 lines of code.

It works like a charm, it's robust, it even can be made to look nice using some sort of templating engine (haven't bothered yet).

And of course, I control that baby using a Trac project :-)

2005-03-07 23:59

Breaking radio silence

The main bad thing about PyDS is that you need your own computer, and you need it to be connected to the nets.

I had my own box, but since I changed employment, it was a lonely disconnected box, until this week.

So, what happened in the last few months...

  • I am coding some little stuff, as usual
  • I am gonna get married
  • I moved with Rosario (rather both of us moved into a new place)

Read The Confusion and The system of the world so I can print that "I survived the baroque cycle" T-shirt Lots and lots of other things. Mostly good, too :-)

2005-03-07 23:59

Ok, so not **everyone** read my calculator rant

First of all, a note: I intend all this post as encouragement to Emiliano, the author of Kalcoolus.

You see, he turned bc into a on-screen keyboard thing . I don't like that UI much .

I can't post comments on kde-look (forgot my id, or maybe never registered), and I am not going to register just for this, but it's interesting to see how the same idea is recycled over and over and over.

This app seems to be a conflation of the following:

  • Writing frontends is good, because you don't need to write the hard part
  • A GUI calculator has to look like the real thing, in the name of usability

Well, the bad news is: writing frontends is fragile. What you want are libraries. And if GUIs had to look like the real thing, the UI to Skype would be a numpad, the UI to Amarok would look like an Ipod, and the UI to KWord would look different .

So, please, Emiliano, put a CLI in it. Pretty please? :-)

2004-12-23 12:19

Why equation evolution and religion is wrong

Be it evolution in general, micro-evolution or macro-evolution.

Let's start with Gervase's three points:

  • It's a basic position that you hold about the nature of reality that's not provable - it's a faith position.
  • It's something that you put your trust in, and live your life on the basis of.
  • It's something you urge others to believe as the truth.

Perhaps the third applies to evolution, The other two are garbage.

Let's start with the first one. There's this nifty concept called falsifiability (sorry about the spelling). Something is falsifiable if it can be proven false.

Things that are unfalsifiable are not apt for rational discussion, since the truth value behind the proposition is unknowable.

Here's an example of something that's unfalsifiable: there is a supreme being that commands the whole universe, yet is not part of it, and can not be contacted.

Here's something that's not: random mutations get selected by the environment to prosper.

That is, because it can be proven false. If there were no mutations, it would be false. If exposing diferent breeds to environments causes no differential in survival rate, it is proven false.

Yes, this is the micro-evolution Gervase accepts. Macro-evolution simply extrapolates from this generally accepted theory into a larger one. Is it the right one? Not sure.

There is no imaginable experiment that can prove the inexistence of god. That's why god's existence is a religious matter, and not a scientific one. The existence of microevolution can be seen, and even experimented (ask any guy that happens to have a few hundred fruit flies in a bottle).

As for macroevolution, well, as mpyne says, there is a thnkable experiment. And even if it isn't technically feasible, there can be a rational discussion, regarding the recombination sppeds, and radiation levels producing mutations, and volumes, and timescales.

So, discussing it is a rational process.

As for the second point: I doubt anyone lives his life based on evolution, although it can provide some reasonable tips about how to expect things to happen, but that's mostly reasoning by analogy.

Now religion.. one of its purposes is usually to describe how you should live.

So, what Gervase is describing is religion. And by his definition, evolution ain't.

Evolution theory may be wrong. That's ok. It happens to almost all theories in one way or another, usually they end replaced by a slightly evolved new version.

But religion? Well, dude, that's just another name for who the hell knows. If you accept religion as a premise, you are into voodoo land.

Maybe the universe only exists since 1987, and everything earlier is a thought in god's mind. Who knows? Presummably only him.

Maybe he's cranky and we all die and go to hell tomorrow. He's many things but not reasonable, as evidenced by his alleged handywork.

So, what's the point in arguing a subject where no rational discourse is appropiate, a subject which is the very basis of irrational discourse?

I have no idea. That's why I'm an agnostic.

2004-12-22 18:58

Games using PyQt

As some may remember, a long time ago I started writing a Bejeweled! lookalike using PyQt.

While that game is actually playable, it mostly showed me I had no idea how to write a decent game ;-)

So, I have been for a couple of weeks trying to create a high level package for creating games, specifically board games (yes, I classify Bejeweled as a board game).

Well, it's working. I am writing a few libraries, and I am writing three games using it.

  • Scroogle: a dumb boggle/scrabble mixture
  • Nameless1: The bejeweled clone
  • Nameless2: A crafty-compatible chessboard

Since I have abstracted stuff like pieces, squares, and such, these games are quite small in size, which means easy to implement!

For example, scroogle can keep score, use a dictionary for word validation, replace used tiles with new ones, so it's basically complete.

It's under 200 lines of code.

The chess game is, again, almost complete, except for stuff like saving games, or board edition, but you can play ( it can't tell if you win or lose and has no timer, though ;-)

It's 210 lines of code (the crafty interface is 70).

Why am I mentioning this? Well, I think that if I ever make this good enough to release it, developing simple games for KDE will become much easier.

And those games will be a 80KB download, including art.

That would be good, wouldn't it? But...

... if you are thinking of writing a game, I need your help. I want you to try using this, so I can figure out if it's good or how it should be changed!

Please contact me if you know a little PyQt and want to write games!

2004-12-19 21:10

I don't have a feminine side. And neither do you, girlie man!

Yesterday I was talking with Rosario, and we had a strange argument. She said I was not in touch with my feminine side, and that she didn't like that.

To which I replied I don't have a feminine side.

Of course that caused a reply of "you do, but you are not in touch with it" and whatever. I asked her what my feminine side is supposed to be, and she mentioned that it was the part of me where I could find my feelings and some other things.

To that, I say, nyah nyah!

The idea that just because I have a certain kind of chromosomes, in order to find my feelings I must have a side that's "feminine", I say that's just propaganda.

I am a guy. I am masculine. I cry whenever I watch the end of Forrest Gump, The part of me that's crying is not some feminine side. It's my masculine side. I cry masculine tears, because a movie triggers some response in my very masculine feelings.

If I were to tell a woman that she has to get in touch with her masculine side so she can, say, drive a car better, I would be called a chauvinist pig. And correctly.

The idea, I suppose, is that her feminine side can drive just fine. Well, my masculine side can cry on movies, and fall in love, and miss my mom, and pet my cat just fine, thank you very much.

So, I don't have a feminine side Rosario, it's just my other masculine side, and he loves you too.

2004-12-14 19:00

This is why dynamic languages are cool

I wrote a little spreadsheet thingie a few days ago. [1]

Of course, it's a toy, not the real thing at all, but it was a nice hack, since it is a real, recalculating, extensible, dependency-checking, loop-avoiding spreadsheet engine in about 50 lines of code.

That's because I was using Python, which is a seriously cool language to write that kind of thing in, since all you have to do to evaluate an expression is call eval() on it.

Sure, that's nice, but the real core of the spreadsheet engine was that you could also create a dictionary-like object that recalculated on-demand its contents.

That way, when you ask for sheet['a1'], custom code goes to see what a1 has in it (a formula), calculates it if needed, and maybe trigger a few extra recalculations if another cell depends on a1. [2]

But as anyone who uses spreadsheets can tell you, weird things exist in ssheet land.

For example, if you copy something, then you paste it, it gets modified in the process.

What other app does that???

Here's an example you can check in any spreadsheet:

  • In A1, type "1".
  • In B1, type "A1+1" (should display 2)
  • In A2, type 2
  • Copy B1 to B2, and it will display 3

Further, if you look at the formula in B2, it says A2+1 now.

That's called relative cellnames (I think).

In order to do that trick, you have to parse the formula in B1, and then, when you paste it into B2, take into account the displacement and modify accordingly. Usually, if you want absolute names, you use $ A1 instead, and that would stay unmodified.

Now, that throws a nice monkeywrench into my neat little spreadsheet [3] because now it suddenly looks not like a spreadsheet at all!

So, I started thinking, how the hell could this be done? The whole advantage of a python sheet is using eval(), so switching to a parser (like if this were a C[++] sheet) would be silly.

I delved into the python standard lib. As every python programmer knows, almost everyhting is there. If you write python, you read the library reference every day, and memorize chunks of it, because it's one of the things that make python cool. It's just chockfull of useful stuff!

And here I was reading about the compiler module, and the parser module, which can be used to do wondrous stuff with python code. But I couldn't understand jackshit about them. I'm a simple coder.

And just as I was going to say, let's write instead about the connection between free software and the sex life of frogs [4] I found tokenize.

Tokenize is a module that parses python and turns it into tokens. Here's how a+2 looks after you tokenize it:

1,0-1,1:        NAME    'a'
1,1-1,2:        OP      '+'
1,2-1,3:        NUMBER  '2'
2,0-2,0:        ENDMARKER       ''

The numbers on the left side are positions in the text stream where the tokens were.

It has just enough information that you can tokenize a piece of code, and then reassemble it. There's code to do just that, it's called regurgitate and it's written by Ka-Ping Yee.

So, the solution is obvious. When copying a formula:

  • Tokenize the formula to be copied
  • Look for tokens of type NAME
  • See if it looks like a cellname, or _cellname
  • If it's _cellname, leave as is. That will be our notation for absolute cells
  • If it's cellname, displace it nicely
  • Regurgitate it

Later, when evaluating a formula, if someone asks for cell _a1 give him cell a1.

And voilà, relative cells.

This works, and it works well (ok, I had to introduce some ugly globals, I need to learn more stuff), and it is guaranteed to tokenize in the same way python does it. It's not even really slow [5]

I touched a bunch of other things, including support for all the functions in python's math module so you can use them in cells. Here's the code to do that:

for name in dir(math):
        if name[0]<>"_":
                self.tools[name]=eval('math.'+name)

Freaky stuff, isn't it?

What's the main issue? Performance. To put it simply, I seriously doubt a sheet written in python can be fast enough for general use. But hey, it's extensible, it's nice, and depending on what you are trying to do, it may be good enough.

And here's today's version of StupidSheet including relative cells. Don't worry, it's a small download ;-)

[1] And almost noone noticed ;-)
[2] That triggering is the only part I wrote myself, the rest is from ASPN's cookbook.
[3] I call it StupidSheet.
[4] I did write that anyway
[5] I don't advice you to copy a formula and paste it into a 10000x200 selection. It will never end. Optimization for this is unexistant. And unlikely.

2004-12-13 14:55

What do you get...

...If you make ESR argue with a anarcho-libertarian-freemarketer-progressive (or whatever?)

A lot of hot gas!

It's a pity George Staikos' reasonable comments are in this piece, but hey, who could have guessed.

Anyway: the writer is the most annoying essayist I've ever read. And he goes and has en email exchange with ESR (the previous holder of the crown). And half-quotes it at length. Sigh. A trainwreck.

We are all now slightly dumber if we read this piece.

Contents © 2000-2019 Roberto Alsina