Nikolaus Rath wrote:
> Neil Dugan <py...@butterflystitches.com.au> writes:
>> Nikolaus Rath wrote:
>>> Hello,
>>>
>>> For some reason I'm just not able to figure out how use the packing
>>> parameters in the right way to get the layout that I want.
>>>
>>> Can someone help me out? What I want is this:
>>>
>>>   - In the first row, the label and spin button should be centered and
>>>     right next to each other (no space in between).
>>>
>>>   - In the second row, all buttons should have the same size with 10px
>>>     spacing between them. The set of buttons should again be centered.
>>>
>>>   - In the third line, the one button should be just as large as the 4
>>>     buttons in the previous line (and also centered).
>>>
>>>   - The text area should fill the rest of the window
>>>
>>> Here is the code that I am using right now:
>>>
>>>
>> I don't know if this is the most effect way of doing what you want.
>> fixed a couple of minor other problems the lambda for the 
>> 'delete_event' need arguments and the Control.blub() function need 
>> some as well.
> 
> That already looks almost perfect, thank you so much!
> 
> (The only problem left is that the buttons grow when the window is
> resized and that the last button is not as wide as the buttons in the
> next-to-last line all together).

If you don't want to have the button grow you will need to put another 
HBox() around the current HBox() and add some empty labels each side 
to center it in the window.
All the widgets are the same size on my layout.

> 
> 
> But could you comment on a couple of your changes? I'd very much like to
> understand what I was doing wrong, so that next time I don't have to ask
> but can create the layout myself...
> 
> ,----
> | $ diff -u -w box.py box_new.py 
> | --- box.py  2010-03-13 14:06:12.020104562 -0500
> | +++ blub.py 2010-03-13 10:36:00.940105089 -0500
> | @@ -10,70 +10,69 @@
> |  
> |      def __init__(self):
> |          self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
> | -        self.window.connect("delete_event", lambda: False)
> | +         self.window.connect("delete_event", lambda x,y: False)
> |          self.window.connect("destroy", gtk.main_quit)
> |          self.window.set_border_width(10)
> |          self.window.set_title('Dispatch Control')
> |  
> |          vbox = gtk.VBox(False, 10)
> | -        vbox.pack_start(self.make_shot_box(), False)
> | +         vbox.pack_start(self.make_shot_box(), False, False)
> 
> Isn't the third parameter to pack_start ignored anyway if the second one
> is False?

No!  the prototype is :
def pack_start(child, expand=True, fill=True, padding=0)
So to set 'fill' to False you need at least 3 arguments.  I find it 
easier to understand the code if I as a rule set at least the first 3 
arguments.

> 
> |          vbox.pack_start(self.make_button_box(), False)
> |          vbox.pack_start(self.make_textarea(), True, True)
> | -        vbox.show()
> |          self.window.add(vbox)
> | -        self.window.show()
> | +         self.window.show_all()
> |  
> 
> I guess the removal of the .show() calls in favor of the
> window.show_all() call does not have an effect on the layout, right?
Yes!  I prefer just using a show_all(), unless I want a particular 
widget not to be shown initially.

> 
>    
> |      def make_shot_box(self):
> | -        box = gtk.HBox(True, 10)
> | +         box = gtk.HBox(False, 10)
> 
> 
> This seems to get rid of the spacing between the label and spin
> button -- but why?

It doesn't.  It just sets the spacing of the widgets.
The code "box = gtk.HBox(spacing = 10)" would do the same thing.

> 
> |  
> | +         box.pack_start(gtk.Label(''), True, True, 0)
> 
> What is this for?

It (and its mate further along) are there to use up the available 
space in 'box' to make the other widgets as small as possible, and to 
thereby cause them to be centralized.

> 
> |          label = gtk.Label("Create shot:")
> |          label.set_justify(gtk.JUSTIFY_RIGHT)
This line does nothing.  The label is minimum sized so justification 
is meaningless.
> |          label.show()
This line also does nothing (now).
> |          box.pack_start(label, False, False, 0)
This could be replaced by :
box.pack_start(gtk.Label("Create shot:"), False, False, 0)
> |  
> |          cur_shot = 42
> | -        self.shotno = gtk.Adjustment(value=cur_shot+1, lower=1, 
> upper=cur_shot+1,
> | +         self.shotno = gtk.Adjustment(value=cur_shot+1, lower=1,
> | +                                      upper=cur_shot+1,
> |                                       step_incr=1)
> |          button = gtk.SpinButton(adjustment=self.shotno, digits=0)
> |          button.set_numeric(True)
> | -        button.show()
> |          box.pack_start(button, False, False, 0)
> | +         box.pack_start(gtk.Label(''), True, True, 0)
> 
> Again, why the empty label?
See previous note.

> 
> 
>      
> Thanks!
> 
>    -Nikolaus
> 

As another thing, there is an easier way to create the buttons in the 
make_button_box() function.
          for (name,number) in [
                  ('INIT',1),
                  ('PULSE ON',2),
                  ('STORE',3),
                  ('ANALYSIS',4)] :
             button = gtk.Button(name)
             button.connect('clicked', self.blub, number)
             box.pack_start(button, True, True)

_______________________________________________
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to