Re: [pygtk] Help with box layout

2010-03-15 Thread Nikolaus Rath
 | -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 don't understand.

http://www.pygtk.org/pygtk2tutorial/sec-DetailsOfBoxes.html:

The fill argument to the pack methods control whether the extra space
 is allocated to the objects themselves (True), or as extra padding in
 the box around these objects (False). It only has an effect if the
 expand argument is also True.

In the above line you set expand to False, so you don't have to provide
a value for fill, IMO.

 |  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.

The spacing is the same in both versions, you changed the 'homogenous'
parameter.

 | + 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.

Uh, I think I see. So the only way to center something in a box is to
add an empty element on both sides with expand=True?

 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)

The buttons of course call different functions in the real code, this
was just to simplify the example.


Best,

   -Nikolaus

-- 
 »Time flies like an arrow, fruit flies like a Banana.«

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C

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

Re: [pygtk] Help with box layout

2010-03-15 Thread Timo
On 15-03-10 15:30, Nikolaus Rath wrote:
 | + 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.
  
 Uh, I think I see. So the only way to center something in a box is to
 add an empty element on both sides with expand=True?



Try using a gtk.HButtonBox instead (see the reference manual for info). 
This is excatly what you need to layout buttons.

Cheers,
Timo

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


Re: [pygtk] Help with box layout

2010-03-15 Thread Neil Dugan
Nikolaus Rath wrote:
 | -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 don't understand.
 
 http://www.pygtk.org/pygtk2tutorial/sec-DetailsOfBoxes.html:
 
 The fill argument to the pack methods control whether the extra space
  is allocated to the objects themselves (True), or as extra padding in
  the box around these objects (False). It only has an effect if the
  expand argument is also True.
 
 In the above line you set expand to False, so you don't have to provide
 a value for fill, IMO.
 

That appears to be the fact.  But I still prefer to specify both 
'expand' and 'fill'.


 |  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.
 
 The spacing is the same in both versions, you changed the 'homogenous'
 parameter.
 

No!  The default is for 'homogenous' is False.  So technically you 
don't need to specify it.

 | + 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.
 
 Uh, I think I see. So the only way to center something in a box is to
 add an empty element on both sides with expand=True?

It is the only way I have found.

 
 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)
 
 The buttons of course call different functions in the real code, this
 was just to simplify the example.
 
Ok!  but you could put in a function like.
for (name,function) in [('INIT',self.on_init_clicked),
('PULSE ON',self.on_pulse_clicked)] :
button = gtk.Button(name)
button.connect('clicked', function)
box.pack_start(button, True, True)

Its just a coding preference, instead of have many pieces of code 
almost the same.

 
 Best,
 
-Nikolaus
 

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


Re: [pygtk] Help with box layout

2010-03-14 Thread Neil Dugan
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),
  

Re: [pygtk] Help with box layout

2010-03-13 Thread Nikolaus Rath
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).


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.py2010-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?

|  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?

   
|  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?

|  
| + box.pack_start(gtk.Label(''), True, True, 0)

What is this for?

|  label = gtk.Label(Create shot:)
|  label.set_justify(gtk.JUSTIFY_RIGHT)
|  label.show()
|  box.pack_start(label, 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?


 
Thanks!

   -Nikolaus

-- 
 »Time flies like an arrow, fruit flies like a Banana.«

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C

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

Re: [pygtk] Help with box layout

2010-03-13 Thread Paul Malherbe




On 13/03/10 21:25, 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).


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?

|  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?

   
|  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?

|  
| + box.pack_start(gtk.Label(''), True, True, 0)

What is this for?

|  label = gtk.Label("Create shot:")
|  label.set_justify(gtk.JUSTIFY_RIGHT)
|  label.show()
|  box.pack_start(label, 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?


 
Thanks!

   -Nikolaus
  

#box.pack_start(gtk.Label(''), True, True)
button = gtk.Button("Full Cycle")
button.connect('clicked', self.blub, 5)
box.pack_start(button, True, True)
#box.pack_start(gtk.Label(''), True, True)

Should give you what you want :-)
-- 







Regards 

Paul
Malherbe

+27
(0) 21 6711866
+27
(0) 82 9005260 


-- 
This message has been scanned for viruses and
dangerous content by
MailScanner, and is
believed to be clean.

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

Re: [pygtk] Help with box layout

2010-03-12 Thread Neil Dugan
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.


#!/usr/bin/env python

from __future__ import print_function, absolute_import

import pygtk
pygtk.require('2.0')
import gtk

class Control(object):

 def __init__(self):
 self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
 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, False)
 vbox.pack_start(self.make_button_box(), False)
 vbox.pack_start(self.make_textarea(), True, True)
 self.window.add(vbox)
 self.window.show_all()

 def make_shot_box(self):
 box = gtk.HBox(False, 10)

 box.pack_start(gtk.Label(''), True, True, 0)
 label = gtk.Label(Create shot:)
 label.set_justify(gtk.JUSTIFY_RIGHT)
 label.show()
 box.pack_start(label, False, False, 0)

 cur_shot = 42
 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)
 box.pack_start(button, False, False, 0)
 box.pack_start(gtk.Label(''), True, True, 0)

 return box

 def make_button_box(self):
 box = gtk.HBox(True, 10)

 button = gtk.Button(INIT)
 button.connect('clicked', self.blub, 1)
 box.pack_start(button, True, True, 0)

 button = gtk.Button(PULSE ON)
 button.connect('clicked', self.blub, 2)
 box.pack_start(button, True, True, 0)

 button = gtk.Button(STORE)
 button.connect('clicked', self.blub, 3)
 box.pack_start(button, True, True, 0)

 button = gtk.Button(ANALYSIS)
 button.connect('clicked', self.blub, 4)
 box.pack_start(button, True, True, 0)


 vbox = gtk.VBox(True, 10)
 vbox.pack_start(box, False, False)

 box = gtk.HBox()
 vbox.pack_start(box, False, False)

 box.pack_start(gtk.Label(''), True, True)
 button = gtk.Button(Full Cycle)
 button.connect('clicked', self.blub, 5)
 box.pack_start(button, False, False)
 box.pack_start(gtk.Label(''), True, True)

 return vbox

 def make_textarea(self):

 textview = gtk.TextView()
 textview.set_editable(True)
 textview.set_wrap_mode(gtk.WRAP_WORD)
 self.comment = textview.get_buffer()

 sw = gtk.ScrolledWindow()
 sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
 sw.set_border_width(5)
 sw.add(textview)

 frame = gtk.Frame('Shot Comment')
 frame.add(sw)

 return frame

 def blub(self, widget, number):
 print('Click! %d' % (number))

if __name__ ==  '__main__':
 control = Control()
 gtk.main()

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