One thing that's always bugged me about Python GUIs is that they're  
always so damned verbose to declare. Some way more than others. Here's  
a little random thought that I freely license anyone currently  
developing a GUI to run with, using the "with" statement to clean  
things up. The folllowing is a simple "application" which gathers some  
information in a manner similar to HTML forms.

gui = withgui.Window()
with gui.vertical:
   gui.label('My awesome GUI', halign=gui.CENTER)
   with gui.form:
     gui.label('Name')
     gui.text()
     gui.help('Enter the name of your character in the game')
     gui.label('Skill level')
     gui.selection(['Awesome', 'Radical', 'Understated'])
     gui.help('''This selection will determine the level of challenge
         in the game''')
     @gui.submit('Go!').on_click
     def go(form):
        # "form" contains the form widget
        name_text = form[0].value
        if error_with_data:
           form[1].has_error()
           success = False
        if success:
           gui.stop(collected_data)
     @gui.cancel('No stop!').on_click
     def stop(form):
         gui.stop()

collected_data = gui.run()
if collected_data is not None:
    ...

Just in case it's not clear, gui.vertical would be a property that  
generates a context manager which performs a vertical layout of the  
contents. gui.form is similar except that it lays out rows with  
optional label, widget contents and help (starting a new row when you  
add a new label, widget or help item) and has a special gui.submit  
button just like HTML form's submit button is special. gui.help would  
render somehow in the GUI (could be a context-sensitive help display  
under the form, or could be a clickable "?" button, or...)

The gui.vertical property return value would be callable so it could  
modify the vertical box's parameters, ie. "gui.vertical(padding=8)"

When the context manager exits at the end of the "with" block the  
contents are laid out.

gui.run() would open the window and invoke pyglet.app.run() - of  
course there'd be alternative top-level containers which would be  
usable in existing windows (with gui.show(window) and gui.hide() which  
would manage events and gui.draw())

We could even lose the gui.run() line if we have a separate program  
which defines a top-level Window called "gui" and invokes run() on it  
and then you just execfile() the gui "app" code to fill in the details.


     Richard


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to