Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #64165

Re: Python declarative

Newsgroups comp.lang.python
Date 2014-01-17 06:22 -0800
References <mailman.5529.1389805825.18130.python-list@python.org>
Message-ID <9ccc7180-3ebd-4976-b2e3-3013ca6569b0@googlegroups.com> (permalink)
Subject Re: Python declarative
From Francesco Bochicchio <bieffe62@gmail.com>

Show all headers | View raw


Some time ago I played with Tkinter trying a more declarative way of coding the GUI building part and I come out with this:

       top = Tk( 'top' ).add (
             Frame( 'frame' ).add (
                Pack( side = 'top' ),
                Frame ( 'panel1' ).add (
                    Pack( side='left'),
                    Label ( 'label', text="Entry 1 : " ),
                    Entry ( 'entry' )  
                ),
                Frame( 'panel2' ).add (
                    Pack( side='left'),
                    Label ( 'label', text="Entry 2 : " ),
                    Entry( 'entry' ) 
                ),
                Pack( side = 'bottom' ), # packing change 
                Button( 'button', 
                    text='Click Me' ))
             )

        top.frame.button["command"] = functools.partial(button_cb, top)
        top.realize().mainloop()

which, without changing the underlying plumbing, may also be written this way, which avoid nesting but still looks  declarative-ish :

   top = Tk( 'top' )
    top.add( Frame( 'frame' ) )
    top.frame.add (
        Pack( side = 'top' ),
        Frame ( 'panel1' ),
        Frame( 'panel2' ),
        Pack( side = 'bottom' ), # packing change 
        Button( 'button', 
                text='Click Me',
                command = functools.partial(button_cb, top) ) )
            
    top.frame.panel1.add(
        Pack( side='left'),
        Label ( 'label', text="Entry 1 : " ),
        Entry ( 'entry' ) ) 

    top.frame.panel2.add(
        Pack( side='left'),
        Label ( 'label', text="Entry 1 : " ),
        Entry( 'entry' )  ) 
   
    top.realize().mainloop()


The underlying plumbing for those two examples is just two classes amounting to about fifty lines of code, plus one-liner wrappers for each kind of widgets/geometry

This just to tell you that yes, with python you can write declarative-looking code ... if you don't mind parenthesis :-)

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Python declarative Sergio Tortosa Benedito <sertorbe@gmail.com> - 2014-01-15 18:02 +0100
  Re: Python declarative Francesco Bochicchio <bieffe62@gmail.com> - 2014-01-17 06:22 -0800
    Re: Python declarative Francesco Bochicchio <bieffe62@gmail.com> - 2014-01-19 23:25 -0800
  Re: Python declarative sertorbe@gmail.com - 2014-01-17 06:47 -0800
    Re: Python declarative Tim Roberts <timr@probo.com> - 2014-01-18 13:13 -0800
  Re: Python declarative sertorbe@gmail.com - 2014-01-19 02:27 -0800
  Re: Python declarative sertorbe@gmail.com - 2014-01-22 12:38 -0800
  Re: Python declarative Asaf Las <roegltd@gmail.com> - 2014-01-22 13:16 -0800
    Re: Python declarative Chris Angelico <rosuav@gmail.com> - 2014-01-23 13:29 +1100
    Re: Python declarative Terry Reedy <tjreedy@udel.edu> - 2014-01-22 23:08 -0500
    Re: Python declarative "Frank Millman" <frank@chagford.com> - 2014-01-24 11:21 +0200
      Re: Python declarative Rustom Mody <rustompmody@gmail.com> - 2014-01-24 01:53 -0800
        Re: Python declarative "Frank Millman" <frank@chagford.com> - 2014-01-24 15:06 +0200
    Re: Python declarative Chris Angelico <rosuav@gmail.com> - 2014-01-24 22:18 +1100
    Re: Python declarative "Frank Millman" <frank@chagford.com> - 2014-01-24 14:49 +0200
    Re: Python declarative Burak Arslan <burak.arslan@arskom.com.tr> - 2014-01-24 15:40 +0200
    Re: Python declarative Chris Angelico <rosuav@gmail.com> - 2014-01-25 00:55 +1100
    Re: Python declarative Matěj Cepl <mcepl@redhat.com> - 2014-01-24 17:28 +0100
    Re: Python declarative Chris Angelico <rosuav@gmail.com> - 2014-01-25 03:33 +1100
      Re: Python declarative sertorbe@gmail.com - 2014-01-24 10:51 -0800
    Re: Python declarative "Frank Millman" <frank@chagford.com> - 2014-01-25 09:18 +0200
      Re: Python declarative Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-26 02:33 +0000
        Re: Python declarative Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-26 02:45 +0000
          Re: Python declarative Asaf Las <roegltd@gmail.com> - 2014-02-02 18:17 -0800
        Re: Python declarative Chris Angelico <rosuav@gmail.com> - 2014-01-26 14:38 +1100
        Re: Python declarative Chris Angelico <rosuav@gmail.com> - 2014-01-26 15:06 +1100
          Re: Python declarative Rustom Mody <rustompmody@gmail.com> - 2014-01-25 20:47 -0800
            Re: Python declarative Chris Angelico <rosuav@gmail.com> - 2014-01-26 16:23 +1100
              Re: Python declarative Rustom Mody <rustompmody@gmail.com> - 2014-01-26 00:05 -0800
                Re: Python declarative "Frank Millman" <frank@chagford.com> - 2014-01-26 11:12 +0200
                Re: Python declarative Rustom Mody <rustompmody@gmail.com> - 2014-01-26 06:36 -0800
          Re: Python declarative Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-26 12:05 +0000
        Re: Python declarative "Frank Millman" <frank@chagford.com> - 2014-01-26 08:03 +0200
          Re: Python declarative Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-26 12:21 +0000
    Re: Python declarative Chris Angelico <rosuav@gmail.com> - 2014-01-25 18:33 +1100
    Re: Python declarative matej@ceplovi.cz (Matěj Cepl) - 2014-01-25 12:23 +0100
  Re: Python declarative Asaf Las <roegltd@gmail.com> - 2014-01-24 04:04 -0800

csiph-web