I was clicking and viewing a bunch of JPEG's, and my hand became really tied... so I treated myself with this little Tk tool, which shows all JPEG's in a folder one by one, like a slide show, and it is only < 20 lines long. One really nice feature is that it even handles broken JPEG's (see inline comment):

use Tk; use Tk::JPEG; use File::Glob ':glob'; my @jpgs = bsd_glob('*.jpg'); my $index = 0; my $mw = MainWindow->new(title => "JPEG"); my $b = $mw->Button()->pack(); $mw->after(1000, \&next_image); MainLoop; sub next_image { #the eval was not there at the beginning, but then I had some brok +en image, and the application stoped... eval {$b->configure(-image => $mw->Photo('-format' => 'jpeg', -fil +e => $jpgs[$index])); $mw->configure(-title => $jpgs[$index]) }; $mw->after(1000, \&next_image) if (++$index <= $#jpgs); }

Replies are listed 'Best First'.
Re: slide view of a folder a JPEG's
by pg (Canon) on Oct 25, 2004 at 16:00 UTC

    Several changes:

    1. Thanks, and your two suggestions were implemented.
    2. In the old version, it waits even after failed to load the image; in this new version, it no longer waits in this situation.
    3. The time dealyed is now a constant, for better coding style.
    use Tk; use Tk::JPEG; use File::Glob ':glob'; use constant DELAY => 1000; my @jpgs = bsd_glob("*.jpg"); my $index = 0; my $mw = MainWindow->new(title => "JPEG"); my $image = $mw->Photo(); $mw->Button(-image => $image)->pack(); $mw->after(DELAY, \&next_image); MainLoop; sub next_image { $image->blank(); if (eval {$image->read($jpgs[$index]); 1}) { $mw->configure(-title => $jpgs[$index]); $mw->after(DELAY, \&next_image) if (++$index <= $#jpgs); } else { $mw->after(0, \&next_image) if (++$index <= $#jpgs); } }
Re: slide view of a folder a JPEG's
by zentara (Cardinal) on Oct 25, 2004 at 13:33 UTC
    It runs, but there are 2 problems.

    1. It eats memory, it's not a big problem if you are just quickly viewing 10 or 20 small jpgs, but memory is constatntly climbing. You can reuse Photo objects with $photo->blank and $photo->read, so you only need to create 1 Photo object.

    2. The photos jump around on the screen if they are not the same size, that is pretty annoying.


    I'm not really a human, but I play one on earth. flash japh
Re: slide view of a folder a JPEG's
by thor (Priest) on Oct 25, 2004 at 18:39 UTC
    Only one reason that I can think of to be clicking on a directory full of JPEGS...but then again, I have a dirty mind. ;) Cool stuff.

    thor

    Feel the white light, the light within
    Be your own disciple, fan the sparks of will
    For all of us waiting, your kingdom will come

      Gives a whole new meaning to "my hand became really tired".
Re: slide view of a folder of JPEG's
by zentara (Cardinal) on Oct 26, 2004 at 13:15 UTC
    Looks good now. :-) By the way, you can include gifs and pngs too, by just adding "use Tk::PNG;" at the top and adjusting your glob. Gifs are built into Tk.

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

      That's right. Actually one thing I forgot to mention is that, in my second version, when I new Photo, -format is no longer specified as "jpeg", and it is simply missing. I intentionally dropped the format.

Re: slide view of a folder of JPEG's
by eyepopslikeamosquito (Archbishop) on Oct 27, 2004 at 06:51 UTC
    I was clicking and viewing a bunch of JPEG's, and my hand became really tired...
    I suppose you could try swapping hands periodically. :-) Seriously, thankyou for creating this handy tool.