Tao of the Machine

Programming, Python, my projects, card games, books, music, Zoids, bettas, manga, cool stuff, and whatever comes to mind.

Content management, part 4

Kaa has just grown an interesting feature, a step closer to the "content management" ideal (or nightmare ;-). For those who know Python, it is now possible to generate custom pages.

How does this work? You inherit from the CM class, and override a few choice methods, like get_entries, which obviously lets you select the entries you want. If you have a separate template file, you can point page_template or entry_template to them; or just set page_html or entry_html as a Python string. You set the target attribute to the filename you want, and voila!

Right now it isn't perfect yet, and this addition revealed a few other problems that need to be resolved, and some fine refactorings. :) I will also need to add a similar feature to generate a series of pages, sort of like the categories or the archives now.

This new version cannot be downloaded yet. When it's ready, I'll upload it... but not just yet.

Posted by Hans Nowak on 2002-09-03 00:12:02   {link}
Categories: Kaa

Import anything

I don't know how others do it, maybe they don't need this (often). But I found myself wanting to import any Python file, no matter where it's located. So I wrote this function:
def import_path(fullpath):
    """ Import a file with full path specification. Allows one to
        import from anywhere, something __import__ does not do. 
    path, filename = os.path.split(fullpath)
    filename, ext = os.path.splitext(filename)
    module = __import__(filename)
    del sys.path[-1]
    return module
I post it here because it might be useful to others as well. Kaa needs it to import a configuration file. (Of course, I could have written an __init__ file, and then the db_ directory could be considered a package...)

Posted by Hans Nowak on 2002-09-03 00:09:29   {link}
Categories: Python

Old cake

Introducing a new category: games.

I will not bother the reader with reviews of the latest uninspiring 3D shooter, or Command & Conquer clones. I don't play those games anyway. No, I like old games, original games, creative games, etc. If I find noteworthy links, I'll put them here. And maybe I'll do an occasional review of an ancient game myself.

These guys are reviving Archon. For those who don't know the game: it's a bit like chess, but instead of regular chess pieces, you play with fantasy creatures, like a dragon, a phoenix, a valkyrie, a golem, trolls, etc. The light/white side has different creatures than the dark/black side. As in chess, these creatures come with their own special movements; some fly, etc. Aside from that, they also have special abilities. Where in chess one piece would capture another, in Archon the two will duke it out on a separate, arcade-like screen.

That's not all. There's a wizard (or witch) with special powers, like regenerating a creature that was removed from the board earlier. And there are white, black and grey squares on the board. White creatures get a bonus (when fighting) on the white ones, black on the black ones, and the grey ones change color over time, making for an interesting strategy twist... a field that is currently in your favor will not be so later in the game, and vice versa.

Archon is dope; I had a version for DOS (Archon Ultra) in the middle 90s (which unfortunately stopped working on Windows 2K/XP, though); there's also versions for the Commodore 64, Amiga and Atari. You should be able to find PC versions on some abandonware sites. I'm still looking for a Mac version...

On a totally unrelated note, here's Kultpower, a site with stuff from some ancient (80s) German computer magazines.

Posted by Hans Nowak on 2002-09-02 13:04:45   {link}
Categories: games

Building Python

They claim that Python on the Mac builds right out of the box. And they are right. :-) Of course, it took me (being a Mac newbie) a little while to figure out the Right Way to do this, but still...

Yesterday I downloaded the latest CVS source on Windows (Cygwin), tarred & gzipped it, transferred it on a zip disk, and tried it on the Mac. Just to find out that the Mac didn't like the line endings... I didn't know that that was a problem for tools like shell and make also. The configure script wouldn't run properly, and when I fixed it in vi, some makefiles barfed, etc. So it was clear that this was not the way to do it. :-)

So today I tried downloading the CVS source on the Mac, in Terminal of course. To my surprise, that worked without problems. More surprises followed when the configure script ran without a problem (it usually doesn't on Cygwin), and I could build Python. (Not sure why the executable is called Python.exe, though... is that a Mac extension too?)

And what's more: Tkinter actually seems to work and uses Carbon...? I haven't been able to try this very well, since I have nothing to drop a Python script on (how that is made is something I have to learn some other day); but when I did root = Tkinter.Tk(), a Tkinter/Carbon window showed up. Running Kaa this way shows such a window too, but it hangs; I read somewhere that you're not supposed to use this from the shell? Anyway, we'll see when Python 2.3 comes out, which should fix the line ending problem as well.

Kaa does work, more or less, on some of the pre-compiled Pythons I've tried, although not very well on any of them. The test blog I made is stored somewhere, I have yet to find out where, but it's not in the Kaa directory where it would be created on Windows. Also, it crashes when you open the bloginfo dialog.

For now, I'll just resume development of Python stuff on Windows; it will be a while before I can do anything sensible on a Mac, or know how to make things portable so that they run on either machine.

Posted by Hans Nowak on 2002-09-01 15:18:39   {link}
Categories: switch

Running Python on the Mac

At first, I was greatly confused by the appearance of some Python files... some would have a special icon and start with the PythonInterpreter when double-clicked, others would have no icon at all and would not be recognized. When I dragged & dropped these files on the interpreter, it would produce a message "This is not a script." This was very puzzling; the script was perfectly valid (there's not really much you can do wrong in a "Hello, world" :-) yet it was refused.
So I tried a few things... writing the file with vi in Terminal, with a GUI vim, with TextEdit. To no avail. I tried setting permissions in the shell, making it executable etc... didn't work either.
Eventually I read something in documentation (Using Python 2.0 on the Macintosh)... "If you create your script with the correct creator and type, creator 'Pyth' and type 'TEXT', you can double-click your script and it will automatically invoke the interpreter". How to set those though? It's not obvious. I'm currently using the fixfiletypes.py script, but I sure hope there's a better way.

More alarming news is that porting Kaa to the Mac doesn't turn out to be that easy. First, the date.py module gave three syntax (!) errors... turned out to be a problem with lines ending in a backslash and Windows line endings; the Mac didn't like the ^M after the backslash. So I fixed that, and tried again, just to watch the program crash gratuitously. :-) With a MemoryError, of all exceptions! In Gadfly. No clue what's wrong. Maybe this is a known problem, maybe not, maybe I can actually contribute something already.

I do pine for that Python where line endings don't matter though... when is it coming out? :-}

Another lesson learned: when copying files with a zip disk, store them in a zip file or something first, because some short names will be converted to ALL UPPERCASE. And since OS X has a case sensitive filesystem, Python will not find DIALOG.PY if it expects dialog.py.

Posted by Hans Nowak on 2002-08-31 22:11:04   {link}
Categories: Kaa, switch

Bro, this Mac is dope

Some stuff I learned today:
  • You can use "virtual disk images" (.dmg files). These are files that work like they're a separate disk drive.
  • You can eject a disk (CD, zip disk, virtual disk) by dragging it to the Trash icon.
  • LiteSwitch X enables me to alternate between windows like I'm used to. ^_^
  • The Gameboy Advance (GBA) emulator works. :) The N64 emulator doesn't, though; maybe I can find other/better ones on the Net. This is not a top priority, but I have these Pokemon ROMs, and...
More to come later. Let's see what I can do with Java. I don't really want to do lots of programming in it (after all, I have Python, although a better integrated version of MacPython has yet to be made), but a working Java means that I can use Jython.

Posted by Hans Nowak on 2002-08-31 19:22:04   {link}
Categories: switch


Mac OS may look like Windows (or is it the other way around?), but their interfaces are not exactly the same. Here are some of the differences I've noticed so far:
  • Home and End keys have different meaning. I repeatedly found myself pressing these in edit boxes, to no avail. The Mac uses Ctrl-Left and Ctrl-Right for this (moving to the beginning or end of a line). In some programs (like ProjectBuilder's editor), Home and End move to the beginning and end of the document. In some other programs, like Acrobat Reader, they don't seem to do anything.
  • Clicking a window's "close" button (which is in the upper left corner on the Mac, by the way) does not automatically close the application as well. To do so, you have to press Apple-Q. (What is the name of the key with the Apple and the funny token on it? Cmd?) If you don't, the program stays in the "dock".
  • Where Windows uses Alt-Tab, the Macintosh uses Cmd-Tab. This works roughly the same as on Windows. The difference is that on the Mac, that keystroke just moves you one position forward to the next active program on the dock. (For non-Mac readers, the dock is a toolbar at the bottom of the screen, with icons that you can click to start a program quickly. A bit like the "quick launch" bar on modern Windows.) On Windows, repeatedly pressing Alt-Tab alternates between two programs or windows. The latter is very handy if alternating is indeed what you need to do, e.g. when you are looking things up in documentation or tutorial, and type text in an editor. This feature is missing on the Mac, or at least I don't know yet how to do it. Where's that mac-beginners mailing list...
These are some of the differences that are biting me (a bit) right now, simply because I'm used to other conventions. It's more of a problem that I don't have a good workspace for the Mac right now; the keyboard is positioned too high and the mouse doesn't have enough space, which is cumbersome and doesn't invite to a lot of hacking.

There was some more progress too. I managed to compile "hello world" in two environments; first, the canonical C file in Terminal, compiled with cc; later, a more complex hello world file using Carbon, compiled with ProjectBuilder. I also managed to hook up my Zip drive without problems. The zip disk can now function as a way to quickly copy files from the PC to the Mac and vice versa. ^_^

Some interesting links:

  • Marc Liyanage's Mac OS X packages -- containing docs and tips, some software (including vim for OSX), and links.
  • Tracker-Tracker, a site to search for Hotline servers. (Hotline is a file sharing program; look for it on download.com or elsewhere. Hotline servers often contain Mac software.)
  • Another MacVim page (courtesy of Kow Kuroda).
  • And here are some programs that I haven't tested yet but that look interesting:
  • LiteSwitch X (a keyboard application switcher)
  • Silk (enable font smoothing in all apps)
  • TinkerTool (utility for hidden GUI options)

Posted by Hans Nowak on 2002-08-31 00:32:00   {link}
Categories: switch

Generated by Firedrop2.