Sizing Widgets

W

WoodHacker

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
 
M

Marc Heiler

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

Reid Thompson

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
http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk::Box

see section on child props
 
R

Reid Thompson

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

WoodHacker

Reid said:

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

Reid Thompson

WoodHacker said:
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.
what are the values of:

|query_child_packing(child)|
<http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk::Box#query_child_packing>
Returns information about how child is packed into box.

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

WoodHacker

Reid said:
WoodHacker said:
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.
what are the values of:

|query_child_packing(child)|
<http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk::Box#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)
 
R

Reid Thompson

WoodHacker said:
Reid said:
what are the values of:

|query_child_packing(child)|
<http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk::Box#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.
* 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"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">

<glade-interface>

<widget class="GtkWindow" id="window1">
<property name="visible">True</property>
<property name="title" translatable="yes">window1</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>

<child>
<widget class="GtkTable" id="table1">
<property name="visible">True</property>
<property name="n_rows">3</property>
<property name="n_columns">3</property>
<property name="homogeneous">False</property>
<property name="row_spacing">0</property>
<property name="column_spacing">0</property>

<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>
</child>
</widget>

</glade-interface>
 
W

WoodHacker

Reid said:
WoodHacker said:
Reid said:
WoodHacker wrote:
Reid Thompson wrote:

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

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



http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk::Box

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.



what are the values of:

|query_child_packing(child)|
<http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk::Box#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.
* 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"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">

<glade-interface>

<widget class="GtkWindow" id="window1">
<property name="visible">True</property>
<property name="title" translatable="yes">window1</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>

<child>
<widget class="GtkTable" id="table1">
<property name="visible">True</property>
<property name="n_rows">3</property>
<property name="n_columns">3</property>
<property name="homogeneous">False</property>
<property name="row_spacing">0</property>
<property name="column_spacing">0</property>

<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>
</child>
</widget>

</glade-interface>

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

WoodHacker

Reid said:
WoodHacker said:
Reid said:
WoodHacker wrote:
Reid Thompson wrote:

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

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



http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk::Box

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.



what are the values of:

|query_child_packing(child)|
<http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk::Box#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.
* 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"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">

<glade-interface>

<widget class="GtkWindow" id="window1">
<property name="visible">True</property>
<property name="title" translatable="yes">window1</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>

<child>
<widget class="GtkTable" id="table1">
<property name="visible">True</property>
<property name="n_rows">3</property>
<property name="n_columns">3</property>
<property name="homogeneous">False</property>
<property name="row_spacing">0</property>
<property name="column_spacing">0</property>

<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>
</child>
</widget>

</glade-interface>

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

Reid Thompson

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

WoodHacker

Reid said:
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.
 
W

WoodHacker

WoodHacker said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top