Question

I want to get myself into programming some serious GUI based applications, but when I look at things like Swing/SWT from Java, I can't help but HATE programming a GUI interface by creating "widget" objects and populating them and calling methods on them.

I think GUI design should be done in a separate text-based file in some markup format, which is read and rendered (e.g. HTML), so that the design of the interface is not tightly coupled with the rest of the code.

I've seen HTMLayout and I love the idea, but so far it seems be only in C++.

I'm looking for a python library (or even a WIP project) for doing markup-based gui.

UPDATE

The reason I can't accept QT's xml is the same reason I hate the programatic approach; you're assembling each widget separately, and specifying each property of it on a separate line. It doesn't provide any advantage over doing it the programatic way.

Was it helpful?

Solution

You can try Mozilla's XUL. It supports Python via XPCOM.

See this project: pyxpcomext

XUL isn't compiled, it is packaged and loaded at runtime. Firefox and many other great applications use it, but most of them use Javascript for scripting instead of Python. There are one or 2 using Python though.

OTHER TIPS

You should look into Qt, which you can use from Python using the excellent PyQt interface (why they didn't name it QtPy --- cutiepie, get it ? --- I will never understand).

With Qt, you can have the choice of constructing your GUI's programmatically (which you don't want), or using XML markup. This XML file can either be compiled to code beforehand, or loaded with a short command. The latter is the normal way to work using PyQt.

Qt is versatile, high-quality, cross-platform, and you're likely using it already without knowing it. The official Skype client application is written in Qt if I remember correctly.

Edit: Just adding some links so the OP get get some feel for it ...

How about wxPython? I'm just now beginning to work with it, but there's a tool -- XRC Resource Editor -- that allows you to assemble your GUI, which is then written to an XML file. As I understand it, your Python application loads the XML file, rather than having a whole bunch of GUI-layout code mixed in with your Python code.

If you choose a language like Tcl or Python and Tk for your application development it becomes fairly trivial to write your own DSL for describing the interface. You can, for instance, write a DSL that lets you create menus like this:

menubar {
    File => {
        Open => cmd.open
        Save => cmd.save
        Exit => cmd.exit
    }
    Edit => {
        Cut => cmd.cut
        Copy => cmd.copy
        Paste => cmd.paste
    }
}

... and your main GUI forms like this:

form PropertiesForm {
          Font: [fontchooser]
    Foreground: [foregroundChooser]
    Background: [backgroundChooser]
}
form NewUserForm {
    username [_____________________]
    [] administrator
    enable the following features:
    () feature 1
    () feature 2
    () feature 3
}
notebook {
   Properties => PropertiesForm
   New User => NewUserForm
}

... and so on. Tcl really excels at letting you write DSLs like this. Note that this capability isn't built in to Tcl per se, but the language makes DSLs trivial. Some of this type of thing exists on the Tcler's wiki, for example there's code to create menus similar to what I described at Menus Made Easy.

I think, though, that after a while you'll find it really, really hard to make professional grade UIs in this manner.

If you use GTK, you can use Glade, which is an XML file.

As a GUI programmer who has gained some experience, you should probably just roll your own sweet little toolkit for automating tasks you find yourself doing over and over again.

It's XML, not Python, but look at Open Laszlo

windows?

you can use the WinForms editor in Visual Studio and then talk to the assembly from IronPython.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top