Tim Roberts wrote:
Yang Zhang wrote:
Are there any libraries for wxPython that make GUI construction/layout
more streamlined? I'm imagining a set of context managers that take
advantage of Python 2.5's with statement. (I miss this from more
structure-declarative UI languages like Laszlo/JavaFX.) At the very
least, the indentation `with` affords could make code easier to
read/group together.
The problem is that the context manager concept doesn't fit all that
well with the GUI models. In most cases, when you are constructing a
user interface, you call a "create" routine that creates all of the user
interface components. Those components live on well beyond the "create"
routine. The context manager concept works really well when you have a
resource that will be consumed within a well-define block of code and
then destroyed. That's not how the UI models work.
The "create my UI components" routine tends to be the ugliest in a UI
app. That's one reason, for example, why Visual Studio hides the
component creation routine in a C# program by default. You only see it
if you go out of your way to look for it.
I understand what you mean. What I'm interested in is something that lets me write stuff like the following (not real code, but at least very similar). The structure of the code reflects the structure of the GUI elements.
XHTML:
<form method="..." action="...">
<p>
Choose an option:
<select size="5">
...
</select>
</p>
<p>
Enter word:
<input type="text" name="..."/>
<input type="submit" value="Submit"/>
</p>
</form>
JavaFX:
FlowLayout {
alignment: VERTICAL
contents: [
FlowLayout {
alignment: HORIZONTAL
contents: [
Label { text: "Enter word:" },
TextField {},
Button { text: "Submit" }
]
}
]
}
Laszlo:
<vbox>
<listbox values="..." />
<hbox>
<label text="Enter word:"/>
<textedit width="100%"/>
<button text="Submit"/>
</hbox>
<vbox>
My imagined wx API for Python:
with form.add(VBox()) as vbox:
vbox.add(ListBox(options=...), 1, EXPAND)
with vbox.add(HBox()) as hbox:
hbox.add(StaticText(label='Enter word:'), 0, EXPAND)
hbox.add(TextCtrl(), 1, EXPAND)
hbox.add(Button(label='Submit'), 0, EXPAND)
or:
with form.vbox() as vbox:
vbox.listbox(1, EXPAND, options=...)
with vbox.hbox() as hbox:
hbox.statictext(0, EXPAND, label='Enter word:')
hbox.textctrl(1, EXPAND)
hbox.button(0, EXPAND, label='Submit')
···
--
Yang Zhang
http://www.mit.edu/~y_z/