up with PyGUI!

Hans Nowak hans at zephyrfalcon.org
Wed Sep 22 19:35:00 CEST 2004


Nicolas Fleury wrote:
> Hans Nowak wrote:
> 
>> Zooko O'Whielacronx wrote:
>>
>>> I'm a fan of Greg Ewing's PyGUI [1].  I used it to code a simple game 
>>> for my son [2], and enjoyed it.  Programming with wxPython feels like 
>>> programming with a C++ tool that has been wrapped in Python.  
>>
>> This problem is addressed by Wax:
> 
> 
> I think it doesn't go far enough.  Wouldn't it better to hide the 
> concept of wxPython ownership by now passing the parent in the 
> constructor, but instead create the wxPython widget when it is finally 
> added to its parent?  

I'm not sure what you mean.  One known issue is, that there is some redundancy 
when creating a control and adding it to its parent:

   b = Button(parent, ...)
   parent.AddComponent(b, ...)

I am thinking of ways to make this simpler.  One possible solution would be to 
accept a 'layout' parameter:

   b = Button(parent, ..., layout={'expand': 'both', 'border': 2})

...but I'm not sure that actually makes things simpler or more readable.

It's also possible to do something like this:

   parent.Add(some_control, parameters_for_control, parameters_for_layout)

I think this is rather ugly, and I don't like the mixing of control constructor 
parameters and layout parameters.  Aside from that, it's sometimes useful or 
necessary to use the control before it's added to the parent.  Consider:

from wax import *

class MainFrame(Frame):

     def Body(self):
         b1 = Button(self, text="b1")
         b1.Size = (40, 40)
         self.AddComponent(b1)

         b2 = Button(self, text="b2")
         self.AddComponent(b2)
         b2.Size = (40, 40)

         self.Pack()

app = Application(MainFrame)
app.Run()

> It could also be a good idea to take the occasion 
> to respect PEP8.  

Which recommendations of the style guide does the Wax code violate?

> Note also that "import wax" would be better than "from 
> wax import *".

I'm considering it.  This way, it would also be possible to import things on 
demand.  On the other hand, I don't like to write 'wax.' before everything.

--
Hans Nowak (hans at zephyrfalcon.org)
http://zephyrfalcon.org/




More information about the Python-list mailing list