python - How would you design a very "Pythonic" UI framework? -
i have been playing ruby library "shoes". can write gui application in following way:
shoes.app t = para "not clicked!" button "the label" alert "you clicked button!" # when clicked, make alert t.replace "clicked!" # ..and replace label's text end end
this made me think - how design nice-to-use gui framework in python? 1 doesn't have usual tyings of being wrappers c* library (in case of gtk, tk, wx, qt etc etc)
shoes takes things web devlopment (like #f0c2f0
style colour notation, css layout techniques, :margin => 10
), , ruby (extensively using blocks in sensible ways)
python's lack of "rubyish blocks" makes (metaphorically)-direct port impossible:
def shoeless(shoes.app): self.t = para("not clicked!") def on_click_func(self): alert("you clicked button!") self.t.replace("clicked!") b = button("the label", click=self.on_click_func)
no near clean, , wouldn't nearly flexible, , i'm not sure if implementable.
using decorators seems interesting way map blocks of code specific action:
class basecontrol: def __init__(self): self.func = none def clicked(self, func): self.func = func def __call__(self): if self.func not none: self.func() class button(basecontrol): pass class label(basecontrol): pass # actual applications code (that end-user write) class myapp: ok = button() la = label() @ok.clicked def clickeryhappened(): print "ok clicked!" if __name__ == '__main__': = myapp() a.ok() # trigger clicked action
basically decorator function stores function, when action occurred (say, click) appropriate function executed.
the scope of various stuff (say, la
label in above example) rather complicated, seems doable in neat manner..
you pull off, require using metaclasses, deep magic (there dragons). if want intro metaclasses, there's series of articles ibm manage introduce ideas without melting brain.
the source code orm sqlobject might help, too, since uses same kind of declarative syntax.
Comments
Post a Comment