Tao of the MachineProgramming, Python, my projects, card games, books, music, Zoids, bettas, manga, cool stuff, and whatever comes to mind. |
Front page Last 10 archives 2002-07-27 2002-08-03 2002-08-10 2002-08-17 2002-08-24 Category archives bettas books CCGs Charm esoterica Firedrop games general ideas internet Kaa linkstuffs Lisp manga music Mygale Nederland nostalgia programming Python SGI switch Wax Zoids :: Search All posts ...by category ...by date :: About me :: Oasis Digital :: Resume :: GeoURL :: RSS :: Atom |
Content management, part 4Kaa 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. Import anythingI 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) sys.path.append(path) module = __import__(filename) del sys.path[-1] return moduleI 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...) Old cakeIntroducing 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. Building PythonThey 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. Running Python on the MacAt 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. Bro, this Mac is dopeSome stuff I learned today:
DifferencesMac 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:
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:
|