Sizing Widgets

I’m new to Ruby/Gtk and find it, so far, exactly what I want for a GUI.
However, I have one problem that I can’t seem to figure out and that
has to do with setting sizes of widgets. For example, I want to
create a status bar with four display areas. I can use an HBox for
the container and use four status bars for the info. Works great.
I can set the first three to be small for position data and the fourth
one to be long for general messages. Done all the time. (there may
be a better way to do this, but it works)

However, if the user resizes the main window, the statusbars stretch in
all directions, including height. I want only the last area to
stretch and it only in width. Setting height and width_requests seem
to only affect shrinking the window.

I’m having the same problem with my menubar - it stretches in height
when the window is resized. There has to be an easy fix to this, but
so far it eludes me.

Bill

Can not help you but I would like to say that I am interested in an easy
solution as well, using ruby-gtk/gnome myself quite a lot.

On Fri, 2006-10-20 at 03:35 +0900, WoodHacker wrote:

all directions, including height. I want only the last area to
stretch and it only in width. Setting height and width_requests seem
to only affect shrinking the window.

I’m having the same problem with my menubar - it stretches in height
when the window is resized. There has to be an easy fix to this, but
so far it eludes me.

Bill

http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ABox

see section on child props

On Fri, 2006-10-20 at 03:35 +0900, WoodHacker wrote:

all directions, including height. I want only the last area to
stretch and it only in width. Setting height and width_requests seem
to only affect shrinking the window.

I’m having the same problem with my menubar - it stretches in height
when the window is resized. There has to be an easy fix to this, but
so far it eludes me.

Bill

alternatively, use glade-2 and ruby-glade-create-template.

Gen the user interface with glade, setting props to expand/not expand
X/Y directions etc, then use ruby-glade-create-template to gen the
framework code.

WoodHacker wrote:

one to be long for general messages. Done all the time. (there may

you quote. And I get the
status boxes to remain stable in the x direction. In other words, the
first three boxes stay in their fixed size and the fourth one enlarges.
The problem is with the y direction. All the boxes grow in the y
direction. This also happens with my menubar. And I believe the
menubar doesn’t allow you to use pack - it wants append, which gives
you no control at all.

what are the values of:

|query_child_packing(child)|
http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ABox#query_child_packing
Returns information about how child is packed into box.

    * Returns: [expand, fill, padding, pack_type]

Reid T. wrote:

I can set the first three to be small for position data and the fourth
so far it eludes me.
In the statusbar code, I’m using pack_start as defined in the section
what are the values of:

|query_child_packing(child)|
http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ABox#query_child_packing
Returns information about how child is packed into box.

    * Returns: [expand, fill, padding, pack_type]

I get false, false, 0, and a pack_type of 0 (start)

Reid T. wrote:

However, if the user resizes the main window, the statusbars stretch in

http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ABox

see section on child props

In the statusbar code, I’m using pack_start as defined in the section
you quote. And I get the
status boxes to remain stable in the x direction. In other words, the
first three boxes stay in their fixed size and the fourth one enlarges.
The problem is with the y direction. All the boxes grow in the y
direction. This also happens with my menubar. And I believe the
menubar doesn’t allow you to use pack - it wants append, which gives
you no control at all.

WoodHacker wrote:

the container and use four status bars for the info. Works great.
when the window is resized. There has to be an easy fix to this, but
In the statusbar code, I’m using pack_start as defined in the section
what are the values of:

    * Returns: [expand, fill, padding, pack_type]

A glade file that gives the effect that you want ( i believe -->
resizing the main window does not affect the size of the status bars in
cell 1 and 2 either way, the status bar in cell 3 will expand in
direction X)
A window with a 3x3 table.
row 3’s cells each contain an Hbox
cell 1 and 2’s Hbox’s have explicitly set Height an Width
each hbox contains a status bar
properties of the hbox control the expansion of the cell see the packing
settings for the boxes below

<?xml version="1.0" standalone="no"?> True window1 GTK_WINDOW_TOPLEVEL GTK_WIN_POS_NONE False True False True False False GDK_WINDOW_TYPE_HINT_NORMAL GDK_GRAVITY_NORTH_WEST True False True 3 3 False 0 0
  <child>
<widget class="GtkHBox" id="hbox2">
  <property name="width_request">103</property>
  <property name="height_request">16</property>
  <property name="visible">True</property>
  <property name="homogeneous">False</property>
  <property name="spacing">0</property>

  <child>
    <widget class="GtkStatusbar" id="statusbar2">
      <property name="visible">True</property>
      <property name="has_resize_grip">True</property>
    </widget>
    <packing>
      <property name="padding">0</property>
      <property name="expand">True</property>
      <property name="fill">True</property>
    </packing>
  </child>
</widget>
<packing>
  <property name="left_attach">1</property>
  <property name="right_attach">2</property>
  <property name="top_attach">2</property>
  <property name="bottom_attach">3</property>
  <property name="x_options">fill</property>
  <property name="y_options"></property>
</packing>
  </child>

  <child>
<widget class="GtkHBox" id="hbox1">
  <property name="width_request">103</property>
  <property name="height_request">16</property>
  <property name="visible">True</property>
  <property name="homogeneous">False</property>
  <property name="spacing">0</property>

  <child>
    <widget class="GtkStatusbar" id="statusbar1">
      <property name="visible">True</property>
      <property name="has_resize_grip">True</property>
    </widget>
    <packing>
      <property name="padding">0</property>
      <property name="expand">True</property>
      <property name="fill">True</property>
    </packing>
  </child>
</widget>
<packing>
  <property name="left_attach">0</property>
  <property name="right_attach">1</property>
  <property name="top_attach">2</property>
  <property name="bottom_attach">3</property>
  <property name="x_options">fill</property>
  <property name="y_options"></property>
</packing>
  </child>

  <child>
<widget class="GtkHBox" id="hbox3">
  <property name="visible">True</property>
  <property name="homogeneous">False</property>
  <property name="spacing">0</property>

  <child>
    <widget class="GtkStatusbar" id="statusbar3">
      <property name="visible">True</property>
      <property name="has_resize_grip">True</property>
    </widget>
    <packing>
      <property name="padding">0</property>
      <property name="expand">True</property>
      <property name="fill">True</property>
    </packing>
  </child>
</widget>
<packing>
  <property name="left_attach">2</property>
  <property name="right_attach">3</property>
  <property name="top_attach">2</property>
  <property name="bottom_attach">3</property>
  <property name="y_options"></property>
</packing>
  </child>
</widget>

Reid T. wrote:

create a status bar with four display areas. I can use an HBox for
I’m having the same problem with my menubar - it stretches in height

0, 1(start) for the last one.
cell 1 and 2’s Hbox’s have explicitly set Height an Width
True
GDK_GRAVITY_NORTH_WEST
0




2
0



I am sure this will work, but I would rather not use glade. It seems
rather bloated to add an XML layer to what should easily be done in
straight Ruby. I notice that in the glade code you use a
height_request property, which I have done in Ruby, but this only sets
up the initial height (and the minimal height) and does not seem to
effect enlarging the toplevel window. Why would the code work in
glade and not in Ruby?

Reid T. wrote:

create a status bar with four display areas. I can use an HBox for
I’m having the same problem with my menubar - it stretches in height

0, 1(start) for the last one.
cell 1 and 2’s Hbox’s have explicitly set Height an Width
True
GDK_GRAVITY_NORTH_WEST
0




2
0



One other comment…

I am getting the same result with a menubar, which in affect is much
simpler than the statusbar we have been talking about. I have never
seen a menubar enlarge in height in any GUI system I have ever used,
and I have used a LOT of them. Unfortunately, the only examples of a
menubar I can find are done with glade. Shouldn’t fixing the hight of
a menubar be part of the Gtk creation of a menubar? I’m confused.

Reid T. wrote:

I can set the first three to be small for position data and the fourth
so far it eludes me.
In the statusbar code, I’m using pack_start as defined in the section
what are the values of:

|query_child_packing(child)|
http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ABox#query_child_packing
Returns information about how child is packed into box.

I should have said:

I get false, false, 0, 1 (start) fror the first three and true, true,
0, 1(start) for the last one.

Reid T. wrote:

understood – my hope was that looking at the glade generated framework
it might show a parameter/value setting, or slightly different way of
building the GUI that would allow you to achieve the results you wanted.

I plan to do exactly that. (I have been travelling and unable to
really get into it)
As I’ve said all along, there has to be some simple thing I’m missing.
Prehaps it’s in your code.
Thanks for posting it.

On Mon, 2006-10-23 at 22:40 +0900, WoodHacker wrote:

I am sure this will work, but I would rather not use glade. It
seems
rather bloated to add an XML layer to what should easily be done in
straight Ruby. I notice that in the glade code you use a
height_request property, which I have done in Ruby, but this only sets
up the initial height (and the minimal height) and does not seem to
effect enlarging the toplevel window. Why would the code work in
glade and not in Ruby?

understood – my hope was that looking at the glade generated framework
it might show a parameter/value setting, or slightly different way of
building the GUI that would allow you to achieve the results you wanted.

WoodHacker wrote:

understood – my hope was that looking at the glade generated framework
it might show a parameter/value setting, or slightly different way of
building the GUI that would allow you to achieve the results you wanted.

I plan to do exactly that. (I have been travelling and unable to
really get into it)
As I’ve said all along, there has to be some simple thing I’m missing.
Prehaps it’s in your code.

Why is it that when you figure a problem out the solution is always so
obvious? I was looking at the menubar and that statusbar (an HBox)
for the problem when issue was with packing them into their container.
I was using add when I should have been using pack_start. Add was
left over from a very early example I was using as a starter.

Thank you very much for all the time you’ve spent on this.

Bill

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs