#!/usr/bin/perl -w use strict; use Tk; use Tk::WinPhoto; use Tk::JPEG; #Global variables my $img_count = 0; #number of images displayed my @mini; #array of frames created when image is grabbed #Main window parameters my $mw = MainWindow->new(); $mw->minsize(qw(670 510)); $mw->configure(-background=>'gray'); $mw->title("Screen Capture GUI"); my $but_capture = $mw->Button( -text => "Capture Screen", -command => sub { \&Grab() } ); $but_capture -> place(-x=>10,-y=>5, -width=>650); my $exit = $mw->Button( -text => "Exit", -command => sub { exit } ); $exit -> place(-x=>560,-y=>460, -width=>100); my $frame2_1 = $mw->Scrolled('Frame',-scrollbars=> "e"); $frame2_1 -> place(-x=>10,-y=>50, -width=>650, -height=>400 ); MainLoop(); ########################################################################## ########################################################################## sub Grab(){ #Takes picture and makes thumbnail to display in mini frame ########################################################################## #Creating file handle and taking picture my $tim = time(); my $fname = "/tmp/".$tim.".jpg"; #print "$fname\n"; system("import -frame $fname"); #resize to display in window my $fname2=$fname."sm.jpg"; system("convert -size 230X230 $fname -resize 230x230 $fname2"); ########################################################################## $img_count++; #Frame packed in scrolling Frame $mini[$img_count] = $frame2_1->Frame(-background=>'#3300ff'); $mini[$img_count] -> configure(-relief => 'groove', -borderwidth => 2); $mini[$img_count] ->pack(); #need to create new frame to hold contents #stupid pack needs to create area to display things, this works but not quite right? my $dummy = $mini[$img_count]->Canvas(); $dummy -> create('rectangle', 0,0,500,300, -fill=>"black"); $dummy -> pack(); #items for mini frame my $img_label = $mini[$img_count]->Label(-text=>"Image $img_count"); $img_label -> place(-x=>5,-y=>5); my $pic_location = $mini[$img_count]->Label(-text=>"Pathname:"); $pic_location -> place(-x=>5,-y=>25 ); my $pic_fname = $mini[$img_count]->Entry(-width=>50,-textvariable=>"$fname"); $pic_fname -> place(-x=>70,-y=>25 ); my $pic = $mini[$img_count]->Photo( -file =>"$fname2"); my $f =$mini[$img_count]->Label(-image => $pic); $f -> place(-x=>5,-y=>50 ); my $i = $img_count; my $but_delete = $mini[$img_count] ->Button( -text => "Delete Image", -command => sub { \&Delete($mini[$i], $i) } ); $but_delete -> place(-x=>5,-y=>240 ); my $blank1 = $frame2_1->Label(-text=>""); $blank1 ->pack(); #Removes items from scrolling frame and replaces them with most recent frame created at top ################################################ my $k = $img_count-1; if($img_count>=2){ while($k!=0){ $mini[$k]->packForget; $k--; } $k=$img_count; while($k!=0){ $mini[$k]->pack(); $k--; } } ################################################ #print "i =$img_count :: mini is $mini[$img_count]\n"; } #close Grab() ########################################################################## ########################################################################## sub Delete(){ my ($fn, $i) =@_; #if only one image displayed if ($img_count == 1){$fn ->destroy; $img_count--; return;} #print "Image $i deleted is $fn\n"; $fn ->destroy; #Deleted image now need to reorder array @mini[] splice(@mini,$i,1); $img_count--; }