Hacker News new | past | comments | ask | show | jobs | submit login
Python Universal GUI (tkinter, wxwidgets, winforms with shoes-like syntax) (alcidesfonseca.com)
12 points by Alcides on Aug 22, 2008 | hide | past | favorite | 4 comments



Some discussion:

1. Python's object-oriented syntax makes it tedious to hand-code a complete GUI app. Instantiate a container, add a label, set the label text, add button, add a button -- without special hackmagic (e.g. fussing with __dict__ and __getattr__), it's very repetitive and not particularly readable. Basically, it looks like Java. Special hacks can cut the redundancy, but then, simple GUI layout code shouldn't be that conceptually tricky.

When I started using Glade alongside GTK, life improved dramatically. Separating the layout from the controlling methods seems to be part of it, and that works fine in web apps, so it's nicely familiar. But XML sucks for simply storing and retrieving data within an app, and I don't think the layout and logic need to be written in different languages necessarily. XML and HTML work for layout because the code physically looks like the layout it describes -- angle brackets don't matter; parentheses would be fine too.

In short, I think the syntax we want for GUI layout should be declarative, not object-oriented. Ruby's blocks make it work for Shoes, and I'm suspicious that converting that style to Python's OOP syntax without understanding the need for a sort of declarative mini-language will lead to... let's say, a confusing and ugly API.

2. Is this (a) a library that's either pre-installed on the user's machine or included with the distributed code, (b) a framework that generates code for the target platform during design, or (c) a preprocessor that generates the right platform-specific code before/during packaging?

3. I understood that Clutter was the new hotness in GUI creation these days. Any interaction there?


1. The example of the working syntax right now would be:

a = App("test", width=200, height=400) a.insert(Button("close",a.quit)) a.run()

Should give you an idea of what I am thinking of.

I actually have working with wxGlade for a while, and it generates wxPython code, but I am not happy with that.

Another solution is to make windows like Django models.

2. this a python module that you can include with your app, that just calls the specific gui binginds on real time.

3. No relation with Clutter. The idea is to be gui tookit agnostic.


The thing that I've idly wished would work in PyGTK and wxWidgets (the ones I've used and liked) has these features:

- takes full advantage of data-type literals like dictionaries and lists

- allows method chaining -- I think this implies mywgt.add(NewWidget(), callback, data) must return a new modified object, rather than modifying mywgt in-place and returning None.

So I can build an app the clean way (generated XML or Django-style models), and then if I need to whip up a simple dialog in straight Python, I can do it like this:

    import gui
    myframe = gui.Frame(
                    title="Password",
                    width=300,
                    modal=True,
                    ).add(gui.Col([
                        gui.Label("""Enter the password to enable
                                  this feature:"""),
                        gui.Password(),
                        gui.HRule(),
                        gui.Row([
                           gui.Button("OK", self.accept),
                           gui.Button("No!", self.cancel)])
                        ]))
    myframe[3][1] += gui.Image("images/hellno.png")
Not sure if it's possible to use dictionaries as part of the toolkit since ordering is lost, but you see the idea: let container widgets like HBox and VBox accept literals instead of requiring repeated foo.insert() calls; have different methods for in-place modification and returned values; implement container widget's magic attributes like __getitem__ to allow semi-obscure shorthand (since the inline Python form is mostly for simple throwaway/prototype code). There are probably a lot more shortcuts I'm missing; I haven't had my coffee yet and I'm no guru to begin with.


I see what you mean, and I agree. In other words, we need a "wxQuery" library.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: