Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Tk::Thumbnail --> callback help

by zzspectrez (Hermit)
callback help NODE.owner = 36692 N.title = monktitlebar sitedoclet N.owner = 17342 -->
on Apr 14, 2005 at 04:39 UTC ( [id://447644]=note: print w/replies, xml ) Need Help??


in reply to Tk::Thumbnail --> callback help

I guess TK isn't that popular!

I hate to be the first to respond to my own thread, but here goes.

I stole borrowed some code from the Tk::Thumbnail module and came up with an immature solution. However, 1) I hate reinventing the wheel 2) My hack of the original code is not as elegant.

Seems like there should be an easier way to do this that utilizes the existing Tk::Thumbnail.. My thought is that I need to subclass this module.. Tk::Thumbnail::Select but am unsure how I would do this.. The whole TK arena is still confusing to me and I am not very OOP literate.

Ohhh... Saints of Perl Wisdom, please bless this humble monk with guidance

zzSPECTREz



CODE

use Tk; use TK::JPEG; use Tk::Photo; use strict; use warnings; sub mk_thumbnail { my $win = shift; my $img = shift; my $photo = $win->Photo( -file => $img ); my $thumb = $win->Photo; my $w = $photo->width; my $h = $photo->height; $w = ( $w /60 ); $h = ( $h /60 ); $thumb->copy( $photo, -subsample => ( $w, $h ) ); $photo->delete; return $thumb; } my $mw = MainWindow->new; my %images; my ($row, $col) = ( 0,0 ); foreach my $img ( <*.jpg>, <*.bmp> ) { my $thumb = mk_thumbnail ( $mw, $img ); $images{$img}=undef; my $frame = $mw->Labelframe( -text => $img)->grid( -row => $row, - +column => $col); my $lb1 = $frame->Label ( -image => $thumb)->pack; my $chk = $frame->Checkbutton ( -variable => \$images{$img} )->pac +k; $col++; if ($col == 4) { $col = 0; $row++; } } MainLoop; foreach my $k ( keys %images ){ print "$k:"; if ($images{$k} ) { print " selected.\n"; }else{ print " not selected.\n"; } }

Replies are listed 'Best First'.
Re^2: Tk::Thumbnail --> callback help
by zentara (Archbishop) on Apr 14, 2005 at 13:14 UTC
    I guess TK isn't that popular

    Now, now, don't starting yelling things that are not true, just because someone dosn't give you an instant answer. You have asked a question, about doing something "the hard way", and most Tk programmers would not try to do it your way, by manipulating the Tk::Thumbnail module.

    I probably would not use Tk::Thumbnail(as you have discovered), and instead make the thumbnails yourself, with Imager or ImageMagick. Then take the thumbnails and display them in an HList or TableMatrix, etc. I would prefer an HList in a left-frame, and the main display in the right frame. You can put as much as you want in an Hlist entry, thumbnails, checkboxes, selection highlighting, etc.

    In your second example, you seem to have found a way, (although there is no TK::JPEG), so what do you want to know? If you are looking for an example the way I would do it, look at ztkdb . Here is a screenshot . Now all you need to do is make the -selection option of the HList to be "multiple", and strip off all the database junk which you don't need, and display all selected thumbails in the right frame.


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

      >> I guess TK isn't that popular

      > Now, now, don't start yelling things that are not true...

      Oh... Just ignore that.. I sometimes forget sarcasm does not translate the same when written as opposed to spoken... It was ment more to be humourous... Usually responses on perlmonks seem to appear before I even submit the question.. :)

      > In your second example, you seem to have found a way, ( although there is no TK::JPEG)...

      TK::JPEG must be a windows Activestate thing. If I remove that use, the code will die with an error stating:

       couldn't recognize data in image file "???@@@" at c:/Perl/site/lib/Tk/Image.pm line 21."
      So logicly you think I just need to send the -format option... You add the -format option then get an error:
      image file format "JPEG" is not supported at C:/Perl/site/lib/Tk/Image.pm line 21.
      Why this is the case I do not know... But add the use TK::JPEG and everything works fine not -format required. I'm really new to Tk so am just figuring things out.

      > so what do you want to know?

      EVERYTHING!! :) I'm just looking for ideas on how others would deal with the situation. It's not hard to steal acquire some code from a module and make it do what you want.. However, the all knowing powers that be will usually chastise you for reinventing the wheel and poorly at that. (Rightfully so).

      So Im trying to see if there is a way to reuse Tk::Thumbnail but add the features I need to it. Seems like I should be able to make use of the label -command to just visually make it apparent which image was selected. Or even better, would be to make it do something like my second example and add checkboxes. I would think you would have to make a subclass of the initial module. I have not been able to figure out how to go about either of these ways. Maybee, I am going about it wrong, and just need to reinvent the whole thing like Im doing in my second example.

      Thank you for your response and your suggestions! I wil have to look at your code ztkdb...

      zzSPECTREz

        Well, on Linux, it's Tk::JPEG, notice the small k. Maybe windows ignores cpaitalization.

        If you want to "customize" Tk::Thumbnails, you should read "perldoc Tk::Derived". It shows you how to do it. There is also a good article by Steven Lidie at Custom Widgets . And as always, goggle for "Tk derived widget" and "Tk custom widget", for examples.


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://447644]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-26 07:57 GMT
Sections?
callback help NODE.owner = 36692 N.title = Sections sitedoclet N.owner = 17342 -->
Information?
callback help NODE.owner = 36692 N.title = Information sitedoclet N.owner = 17342 -->
Find Nodes?
callback help NODE.owner = 36692 N.title = Find Nodes sitedoclet N.owner = 17342 -->
Leftovers?
    callback help NODE.owner = 36692 N.title = Leftovers sitedoclet N.owner = 17342 -->
    Voting Booth?

    No recent polls found