Suggestion for Perl/GTk packing



Hello,

I have had a long weekend and have read the gtk tutorial. It gave me
some ideas of how to merge some of the ideas from Tk together with
the Perl/Gtk.

1. First of all I think that the idea of creating a method of Widget 
  called new_child("widget name") like in
  
      $window->new_child( Gtk::Button, -label => "the label");
      
  is a very good one. With such a function it should be easy to create
  some AUTOLOAD magic so that:
  
      $window->Button(-label=>"the label")
  
  will work as well.
  
2. Gtk::Widget should be given a new method called pack() which 
  encapsulates the the three functions gtk_box_pack_start(),
  gtk_box_pack_end() and questionably gtk_container_add() . As each
  widget knows who its parent is (a consequence of 1 above) it can
  check if it is hbox, a vbox, or a frame and do the relevent function
  call.
  
  start/end, padding, filling, and, expanding should be specified as
  named parameters to pack() .
  
  Here is an example of how clean the corresponding C code becomes in
  Perl with this syntax:
  
       hbox = gtk_hbox_new();
       button = gtk_button_new_with_label("a box");
       gtk_box_pack_end(GTK_BOX(box), button, 0, 1, 0);
       gtk_widget_show(button); 
       
  becomes
  
       $hbox = $widget->HBox();
       $button = $hbox->Button(-label=>"a box");
       $button->pack(-fill=>1, -end => 1)->show();
       
  which imho is much cleaner. The -end=>1 may be -side=>'end' or
  something similar. It really doesn't matter.
  
3. Similarly a method attach() is used to place a widget inside a
   table(). Actually pack() could be overloaded to do this as it
   is always known what the parent widget is.
   
Reading through the tutorial I really had a feeling that it is a shame
that the underlying C-Code wasn't build around varargs and named 
parameters. There are lots of strange functions like
gtk_table_attach() vs. gtk_table_attach_with_defaults(),
gtk_box_pack_start() vs. gtk_box_pack_end() that would be unnecessary
had this be done. Not to speak about the consequences of adding a new
parameter in the future to the latter pack functions... E.g. an 
-anchor parameter. There is no room for it without changing all the 
existing code. But this critique obviously doesn't belong to the 
Perl interface.

Regards,
--
                                                                    ___
Dov Grobgeld                        | Email: dov@orbotech.co.il    /+  \  PCB
Algorithms Department, Orbotech     | Phone: +972-8-9423882        \  +/  AOI
Yavne 70651, Israel                 | Fax:   +972-8-9423775       __| |
               Disclaimer: All views above are mine alone.        ____|



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]