Python declarative

Frank Millman frank at chagford.com
Sat Jan 25 02:18:44 EST 2014


"Chris Angelico" <rosuav at gmail.com> wrote in message 
news:CAPTjJmpi-kvJAVs2gK+nH5n6q3REkJaKR=CZeRfzUgDk8_VLGw at mail.gmail.com...
> On Fri, Jan 24, 2014 at 11:49 PM, Frank Millman <frank at chagford.com> 
> wrote:
>>
>

[...]

I have realised that we unlikely to come to an agreement on this in the near 
future, as our philosophies are completely different.

You have stated that your objective is to express as much as possible in 
Python code.

I have stated that my objective is to express as little as possible in 
Python code.

We would have to resolve that difference of opinion first, before discussing 
our respective approaches in detail, and that is way beyond the scope of 
this thread.

As a brief example of my approach, here is how I would write your simple 
'About' box.

Here is your version -

mainwindow = GTK2.Window(0)->add(GTK2.Vbox(0,0)
    ->add(GTK2.Label("About Gypsum: big long multi-line string"))
    ->add(GTK2.HbuttonBox()
        ->add(GTK2.Button("Close"))
        ->add(GTK2.Button("Foobar"))
    )
);

Here is my version -

<form name="ChrisAbout_form">
  <data_objects/>
  <input_params/>
  <output_params/>
  <rules/>
  <frame>
    <body>
      <block/>  <!-- an html div -->
      <panel/>  <!-- an html table -->
      <row/>
      <col/>
      <text value="This is line one of a multi-line string"/>
      <row/>
      <col/>
      <text value="This is line two of a multi-line string"/>
      <row/>
      <col/>
      <text value="This is line three of a multi-line string"/>
    </body>
    <button_row>  <!-- an html div -->
      <button btn_id="btn_close" btn_label="Close" len="60"
          btn_enabled="true" btn_validate="false" btn_default="true">
        <end_form state="completed"/>
      </button>
      <button btn_id="btn_foo" btn_label="Foobar" len="60"
          btn_enabled="true" btn_validate="false" btn_default="false">
        <pyfunc name="path1.path2.foobar"/>
      </button>
    </button_row>
    <frame_methods>
      <method name="on_req_close">  <!-- user clicked [X] or pressed 
Shift_F4 -->
        <end_form state="completed"/>
      </method>
      <method name="on_req_cancel">  <!-- user pressed Escape -->
        <end_form state="completed"/>
      </method>
    </frame_methods>
  </frame>
</form>

Currently I do not have a widget for a multi-line label, so I just show 
three separate lines. If I ever needed one, it would not take long to 
create.

I took two screenshots, but I don't know the best way to upload and share 
them. I found a site called tinypic, which works, but the screen is 
cluttered with a lot of other stuff. Still, it shows what I want.

First, here is the screen as rendered in Internet Explorer (it works in 
other browsers as well - even on my smart phone, though I have not done any 
optimising for mobile devices yet) -

http://tinypic.com/r/ip15xx/5



Second, here is the screen designer, showing a portion of the screen 
definition - one of the buttons. As you can see, the designer does not have 
to worry about XML at all -


http://tinypic.com/r/1j7sdh/5



I am not claiming that I am 'right', or that this is a perfect solution. It 
is just 'where I am' right now, after quite a long period of evolution, and 
it is achieving a large portion of what I am aiming for, so I will press on 
with my current approach for now.



Hopefully it will not take *too* long before I am in a position to release 
something, and then I will be very interested in any feedback.



Thanks for the interesting discussion.



Frank








More information about the Python-list mailing list