Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Hi,

To amplify on what Anonymous Monk said, here is how to do it. You do not want to rebuild the $hbox, only the image. I also cleaned up your code, you had many useless lines. The script below will cycle thru all jpg's in the script's directory for the demo. I improved on your use of "cat" to load the file, that code looked familiar to me, and is not very advanced. :-) The code below is much better, and it can be improved a bit, but it does show you the idea.

#!/usr/bin/perl -w use Glib qw/TRUE FALSE/; use Gtk2 '-init'; use strict; # load all jpgs in directory for this demo my @files = <*.jpg>; #print "@files\n"; my $window = Gtk2::Window->new('toplevel'); $window->signal_connect(delete_event => sub { Gtk2->main_quit; return +FALSE; }); $window->set_title("Test set up"); $window->set_border_width(0); # create your first image and pass it to $hbox my $img1 = load_first_image(); my $hbox = &make_gui_frame($img1); $window->add($hbox); Glib::Timeout->add(1000, \&update_image); $window->show; Gtk2->main; 0; sub load_first_image{ my $file = $files[0]; my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file_at_scale($file,300,3 +00,1); return Gtk2::Image->new_from_pixbuf($pixbuf); } sub update_image { # circular list of images just for demo push (@files,shift(@files)); my $file = $files[0]; my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file_at_scale($file,300,300 +,1); $img1->set_from_pixbuf ($pixbuf); $window->show_all(); return 1; } sub make_gui_frame { my $img1 = shift; ## MAIN HBOX $hbox = Gtk2::HBox->new(FALSE, 20); my $frame = Gtk2::Frame->new('Data control'); $frame->set_shadow_type ('out'); #method of Gtk2::Container $frame->set_border_width(5); my $box1 = Gtk2::VBox->new(FALSE, 10); my $box2 = Gtk2::VBox->new(FALSE, 10); $box2->set_border_width(10); $box1->pack_start($box2, TRUE, TRUE, 0); my $button = Gtk2::Button->new("close"); $button->signal_connect(clicked => sub { Gtk2->main_quit; }); $box2->pack_start($button, TRUE, TRUE, 0); $button->can_default(TRUE); $frame->add($box1); $hbox->pack_start($frame, FALSE, FALSE,0); $frame = Gtk2::Frame->new('Data output and Overlay'); $frame->set_shadow_type ('out'); #method of Gtk2::Container $frame->set_border_width(5); my $vbox_image = Gtk2::VBox->new(FALSE, 10); $vbox_image->pack_start($img1,FALSE,FALSE,0); $frame->add($vbox_image); $hbox->pack_start($frame, FALSE, FALSE,0); $hbox->show_all(); return $hbox; }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: GTK2 - Load updated image file into a frame by zentara
in thread GTK2 - Load updated image file into a frame by seoseoboyle

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (8)
    As of 2014-10-21 06:36 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (97 votes), past polls