Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl -w use strict; use Gtk2 -init; my $window = Gtk2::Window->new; $window->set_default_size( 650, 650 ); # the ListStore model that actually holds the # data ..a picture and a filename my $model = Gtk2::ListStore->new ('Gtk2::Gdk::Pixbuf', 'Glib::String') +; my @files = <*.jpg *.png *.gif>; #print "@files\n"; foreach my $file (@files){ my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file_at_scale($file,100,10 +0,1); my $iter = $model->append; $model->set($iter, 0, $pixbuf, 1, $file, ); } # now make the actual treeview renderer my $treeview = Gtk2::TreeView->new ($model); $treeview->set_headers_visible (0); $treeview->insert_column_with_attributes( -1, # append "", # this won't be visible because we turned off headings Gtk2::CellRendererPixbuf->new, # the renderer pixbuf => 0); # get the pixbuf property from model col 0 $treeview->insert_column_with_attributes( -1, # append "", # this won't be visible because we turned off headings Gtk2::CellRendererText->new(), # the renderer text => 1); # get the property from model col 1 $treeview->get_selection->signal_connect (changed => sub { my $treeselection = $treeview->get_selection; #print "$treeselection\n"; $treeselection->selected_foreach (sub{ #this sub wil receive the following: my ($model,$path,$iter) =@_; #we want data at the model's column 1 #where the iter is pointing my $value = $model->get($iter,1); #print $value."\n"; load_image( "./$value" ); }); }); my $hbox = Gtk2::HBox->new (0, 4); my $scwin = Gtk2::ScrolledWindow->new(); $scwin->set_size_request( 250, 250 ); $scwin->add_with_viewport($treeview); $scwin->set_policy('always', 'always'); $hbox->pack_start($scwin,0,1,1); my $vp = Gtk2::Viewport->new( undef, undef ); my $scwin1 = Gtk2::ScrolledWindow->new( undef, undef ); $scwin1->set_policy( 'automatic', 'automatic' ); $scwin1->add( $vp ); $hbox->pack_start($scwin1,1,1,1); my $image = Gtk2::Image->new(); $vp->add($image); $window->add ($hbox); $window->show_all; $window->signal_connect (destroy => sub {Gtk2->main_quit}); Gtk2->main; ################################### sub load_image { my $file = shift or warn "$!\n"; $image->set_from_file ($file); $window->show_all(); }

In reply to Gtk2 ListStore Thumbnail/Image Viewer by zentara

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-20 01:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found