Resizing the mainwindow and displaying SVG's
- From: zentara <zentara zentara net>
- To: gtk-perl-list gnome org
- Subject: Resizing the mainwindow and displaying SVG's
- Date: Mon, 30 Jan 2006 12:53:01 -0500
Hi,
I've been playing around with the recently announced
Gnome2::Rsvg module, and tried to make a script that
would automatically resize the svg after the mainwindow
is resized.
I've come up with the following script, which I need to
somehow speed up. The script works, but it seems to hesitate
as the configure event goes through each of it's calls
as the window is resized with a corner drag.
Is there some way, to detect when the resize has finished?
So that I can only do the reloading of the svg after the
corner-drag has ended?
P.S. An interesting effect of auto-expansion occurs if you
don't take a fraction < 1 on the size request.
$vp->set_size_request(.9*$x,.9*$y);
#!/usr/bin/perl
use warnings;
use strict;
use Glib qw(TRUE FALSE);
use Gnome2::Rsvg;
Gtk2->init;
my $file = shift || die "Need an svg file $!\n";
my $img;
my $mw = Gtk2::Window->new;
$mw->signal_connect (delete_event => sub { Gtk2->main_quit });
my $vbox = Gtk2::VBox->new (FALSE, 4);
$vbox->set_border_width (4);
$vbox->show;
# Create the main box
my $vp = Gtk2::Viewport->new(undef, undef);
# Layout the stuff
$vbox->pack_start ($vp, TRUE, TRUE, 0);
$vp->show;
$mw->add( $vbox );
get_svg(400,400);
$mw->signal_connect (event_after => \&event_after);
$mw->show;
Gtk2->main;
################################################################3
sub get_svg {
my ($x,$y) = @_;
$vp->remove($img) if defined $img;
#use the max specs to resize to window size, so make zoom huge
my $pb = Gnome2::Rsvg->pixbuf_from_file_at_zoom_with_max($file,15,15,$x,$y);
# ($file, x_zoom, y_zoom, max_x, max_y )
$img = Gtk2::Image->new_from_pixbuf($pb);
$vp->add($img);
$img->show;
#will auto expand ????
#$vp->set_size_request($x,$y);
$vp->set_size_request(.9*$x,.9*$y);
$vp->show;
}
#####################################################################
sub event_after {
my ($mw, $event) = @_;
return FALSE unless $event->type eq 'configure';
my ($x, $y) = $mw->get_size;
print "$x $y\n";
get_svg($x,$y);
return FALSE;
}
__END__
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]