How would you design a very “Pythonic” UI framework?

后端 未结 15 1983
日久生厌
日久生厌 2021-02-02 01:29

I have been playing with the Ruby library \"shoes\". Basically you can write a GUI application in the following way:

Shoes.app do
  t = para \"Not clicked!\"
  b         


        
15条回答
  •  青春惊慌失措
    2021-02-02 01:49

    If you use PyGTK with glade and this glade wrapper, then PyGTK actually becomes somewhat pythonic. A little at least.

    Basically, you create the GUI layout in Glade. You also specify event callbacks in glade. Then you write a class for your window like this:

    class MyWindow(GladeWrapper):
        GladeWrapper.__init__(self, "my_glade_file.xml", "mainWindow")
        self.GtkWindow.show()
    
        def button_click_event (self, *args):
            self.button1.set_label("CLICKED")
    

    Here, I'm assuming that I have a GTK Button somewhere called button1 and that I specified button_click_event as the clicked callback. The glade wrapper takes a lot of effort out of event mapping.

    If I were to design a Pythonic GUI library, I would support something similar, to aid rapid development. The only difference is that I would ensure that the widgets have a more pythonic interface too. The current PyGTK classes seem very C to me, except that I use foo.bar(...) instead of bar(foo, ...) though I'm not sure exactly what I'd do differently. Probably allow for a Django models style declarative means of specifying widgets and events in code and allowing you to access data though iterators (where it makes sense, eg widget lists perhaps), though I haven't really thought about it.

提交回复
热议问题