This question Tk::Adjuster, how to keep proportions got me thinking about how to do it in Perl/Gtk2. In this demo, I set it up to resize only after the drag-resize is finished (which is the best way). It demonstrates how you can use the signaling mechanism, which is far more important in Gtk2, than in Tk.
#!/usr/bin/perl use warnings; use strict; use Glib qw/TRUE FALSE/; use Gtk2 '-init'; my $resize_flag = 0; #global for detecting a resize my $ratio = .5; #global to store the adjustment setting #start centered my $window = Gtk2::Window->new('toplevel'); $window->set_title('Adjustment Demo'); $window ->signal_connect( 'destroy' => \&delete_event ); $window->set_border_width(10); $window->set_default_size(400,400); my $vbox = Gtk2::VBox->new( FALSE, 6 ); $vbox->set_size_request(0,0); $window->add($vbox); $vbox->set_border_width(2); my $hbox= Gtk2::HBox->new( FALSE, 6 ); $vbox->pack_end($hbox,FALSE,FALSE,0); $hbox->set_border_width(2); $vbox->pack_end (Gtk2::HSeparator->new, FALSE, FALSE, 0); my $button = Gtk2::Button->new_from_stock('gtk-quit'); $hbox->pack_end( $button, FALSE, FALSE, 0 ); $button->signal_connect( clicked => \&delete_event ); # HPaned or VPaned are just types of Gtk2::Paned # add to them with add1 and add2 my $hpaned = Gtk2::HPaned->new; $hpaned->set_border_width (5); my $frame = Gtk2::Frame->new("Foo Label"); my $label = Gtk2::Label->new("This is a foo Label"); $frame->add($label); $hpaned->add1($frame); $vbox->pack_start ($hpaned, TRUE, TRUE, 0); my $frame1 = Gtk2::Frame->new("Bar Label"); my $label1 = Gtk2::Label->new("This is a bar Label"); $frame1->add($label1); $hpaned->add2($frame1); $window->show_all(); #setup as centered set_position_by_ratio($hpaned); $window->signal_connect (event_after => \&event_after); $hpaned->signal_connect( event_after => \&set_ratio ); Gtk2->main; ##################################### sub delete_event { Gtk2->main_quit; return FALSE; } ####################################### sub event_after { my ($mw, $event) = @_; # print $event->type,"\n"; # this tests so that the reconfiguring only occurs once after # the resize is finished if( ($event->type eq 'configure') or ($event->type eq 'expose' ) ){ $resize_flag = 1 }else{ $resize_flag = 0 } if( ($event->type eq 'enter-notify') or ($event->type eq 'leave-notify' ) or ( $resize_flag == 1 ) ){ return FALSE } # print $event->type,"\n"; set_position_by_ratio($hpaned); return FALSE; } ########################################## sub set_ratio{ # done only after an adjustment slide my ($pane, $event) = @_; if($event->type eq 'button-release'){ my $rect = $pane->allocation; my ($x, $y, $width, $height) = $rect->values; my $new_width = $width -2*$x; my $pos = $pane->get_position; $ratio = $pos/$new_width; #print "$ratio\n"; } return FALSE; } ############################################# sub set_position_by_ratio{ my $pane = shift; my $rect = $pane->allocation; my ($x, $y, $width, $height) = $rect->values; my $pos = ($width -2*$x) * $ratio; $pane->set_position($pos); #print "$ratio\n"; }

In reply to Gtk2-maintaining-pane-proportion by zentara

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.