tags:

views:

790

answers:

8

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 sepcifying each property of it on a separate line. It doesn't provide any advantage over doing it the programatic way.

A: 

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

Charlie Martin
+2  A: 

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 ...

harms
I've been exposed to Qt before, although not in depth at all, it would help if you add a link to something related to the xml-markup-thing :)
hasen j
I use QT/PyQT at work and love using them. Keep in mind that while you're learning, they are both free as in GPL open source license, but as soon as you start selling your work you need to buy commercial developer licenses one per developer.
Chris Cameron
The XML markup is the format of the .ui files used. These can probably be written by hand, or you could use the Qt Designer to create them.
gnud
hasen: The first of the three links includes a sample .ui file: http://sector.ynet.sk/qt4-tutorial/tutorial/my-first-qt-gui-application/my_first_qt_app/myqtapp.ui
harms
By the way, note that the third link is on PyQt version 3, so it's probably not 100% applicable anymore.
harms
hmm, seeing that example file, this format is too complicated, no where near HTML, it's organized in more or less the same way one would organize code that creates and places widget objects manually
hasen j
Any particular reason you wouldn't want to use the Qt Designer application, or equivalent tools for other systems, to generate this markup for you? At least when I was touching this stuff (a year ago) I found myself doing all of it in Qt Designer, and really only just "looking over" the XML output.
harms
Well I could use Visual Studio with C# for that matter and I wouldn't have to ask the question ...
hasen j
The VS IDE comes with a widget toolkit. Qt is separate from your IDE. Qt Designer lets you lay out your design in a .ui XML file. The XML is converted to python code using pyuic4. You control your laid out widgets with Python. Any more HTML and you're talking about designing a webapp, no?
Chris Cameron
Sorry for double-wide comment but I wanted to mention that pyuic4 is a utility that comes with the PyQt library for Python.
Chris Cameron
Chris, look at HTMLayout, it's not a browser, and it doesn't implement all of html spec
hasen j
Just felt like saying that Qt is now LGPL.
Nailer
A: 

windows?

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

Dustin Getz
Downvoted because it's for Windows? I don't get it. +1 to offset.
orip
Downvote because "talk to the assembly" does not equal "markup based UI", additionally, even if it is successfully argued that it /is/ markup based, albiet with a fancy windows-IDE-specific "assembly library", it suffers the same issues the OP has with QT.
Arafangion
The winforms editor produces code. Particularly ugly code in some cases. Also, IronPython is an implementation of the Python language on top of the .NET runtime. This means you lose a lot of CPython modules.
Kevin Thiart
+1  A: 

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.

Mark42
+1. Probably the best option for Python. I prefer this approach to the one I suggested. A guide to XML resource files: http://wiki.wxpython.org/UsingXmlResources
Kevin Thiart
+1  A: 

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

Bernard
+5  A: 

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.

Kevin Thiart
A: 

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.

Seun Osewa
+2  A: 

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.

Bryan Oakley