#!/usr/bin/env perl use Data::Dumper; use threads; use Thread::Queue::Any; use strict; use warnings; my $thread_queue = Thread::Queue::Any->new; async { \&testThread($thread_queue) }; async { \&_thread_for_images($thread_queue) }; while (1) { sleep 1; } sub testThread { my $queue = shift; while (1) { $queue->enqueue("something"); sleep 2; } } sub _thread_for_images { my $queue = shift; my $pid; while (1) { my ($full_path) = $thread_queue->dequeue; print $full_path . "\n"; sleep 2; #if ($oid) { # print "KILL!\n"; # $oid->kill(); #} #sleep 2; $pid = fork(); if ($pid) { print "Parent\n"; waitpid($pid,0); } elsif (defined ($pid)) { print "Child\n"; &mainloop2(); exit; } #$app->MainLoop; } } sub mainloop2 { if (-e "imageHandling.pl") { my $app = do "imageHandling.pl"; if (!defined($app)) { die "imageHandling not loaded.\n"; } } else { print "imageHandling.pl not found.\n"; exit; } my $app = MyApp->new(); # create $app->newImageFrame("L:/02.jpg", 200, 500); $app->newImageFrame("I:/34.jpg", 400, 500); #print Dumper($app); $app->MainLoop; $app->Destroy; }
package MyApp; use strict; use vars qw(@ISA); use Wx qw(:everything); @ISA=qw(Wx::App); #use Wx::Event qw( EVT_MOTION EVT_LEFT_DOWN ); use Data::Dumper; sub new { my $class = shift; my $this = $class->SUPER::new(@_); return $this; } sub OnInit { return 1; } sub newImageFrame { #my $this = @_; my $this = shift; my $file = shift; my $x = shift; my $y = shift; #wxFrame(wxWindow* parent, wxWindowID id, const wxString& titl +e, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDef +aultSize, long style = wxDEFAULT_FRAME_STYLE, const wxString& name = +"frame") my $frame = MyFrame->new( "Image View", [-1,-1], [-1,-1], $fil +e); unless ($frame) {print "unable to create frame -- exiting."; r +eturn undef} push(@{$this->{Frame}}, $frame); #EVT_LEFT_DOWN ($this, \&evtLeftDown); #$frame->SetSize(0,0, 210, 210); $frame->SetSize(0,0, 200, 200); $frame->Move($x, $y); $frame->Show( 1 ); return 1; } package MyFrame; use vars qw(@ISA); use strict; # # All we load here are constants used # to keep the image stretched to the dimensions of the window. # use Wx qw( wxWidth wxHeight wxLeft wxTop wxDefaultPosition wxDefau +ltSize wxID_CANCEL wxCentreX wxCentreY wxFRAME_NO_TASKBAR); use Wx::Event qw(:everything); # # Wx::Image loads the Image control and all of the Image handler +s. # use IO::File; use Wx::Event qw( EVT_LEFT_DOWN EVT_LEFT_DCLICK EVT_MOTION EVT_RIG +HT_DOWN ); @ISA=qw(Wx::Frame); #use Image::Magick; #use MIME::Base64; use Data::Dumper; sub new { my $class = shift; my $title = shift; my $pos = shift; my $size = shift; my $filename = shift; #wxFrame(wxWindow* parent, wxWindowID id, const wxString& titl +e, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDef +aultSize, long style = wxDEFAULT_FRAME_STYLE, const wxString& name = +"frame") my $this = $class->SUPER::new( undef, -1, $title, $pos, $size, + wxFRAME_NO_TASKBAR ); my $file = IO::File->new( $filename, "r" ); unless ($file) {print "Can't load file."; return undef}; binmode $file; my $handler = Wx::JPEGHandler->new(); my $imgdata = Wx::Image->new(); $handler->LoadFile( $imgdata, $file ); # ?????????? # my $imgquick = Image::Magick->new(); #open(IMAGE, 'quote.png'); #binmode(IMAGE); #my $imageData = $img->Read(file=>\*IMAGE); # my $imageData = $imgquick->Read('K:\222.jpg'); #close(IMAGE); # $imgquick->BlobToImage($imageData); # $imgquick->set(magick=>'bmp'); # $imgquick->Scale(geometry=>'200x200'); # my $imgdata2 = $imgquick->ImageToBlob(); #$imgdata->SetData($imgdata); my $a = $imgdata->Rescale(200,200); #print Dumper($imgquick); my $bmp = Wx::Bitmap->new($imgdata); if( $bmp->Ok() ) { # create a static bitmap called ImageViewer that displays + the # selected image. my $img = Wx::StaticBitmap->new($this, -1, $bmp); my $size = $img->GetSize(); $img->SetBitmap($bmp); #if ($parent->{ScaleImage}){$img->SetSize($size)}; #$parent->Clear(); $img->Refresh; EVT_LEFT_DOWN ($img, sub { &evtLeftDown($this, @_) } ); EVT_RIGHT_DOWN ($img, sub { &evtRightDown($this, @_) } ); EVT_LEFT_DCLICK ($img, sub { &evtRightDown($this, @_) } ); EVT_MOTION ($this, \&evtMotion); $this->{'ScaleImage'} = 0; $this->SetAutoLayout( 1 ); # allow wxperl to manage contr +ol sizing & placement } #EVT_MOTION ($this, \&evtMotion); return $this; # return the frame object to the calling applic +ation. } sub evtLeftDown { my ($this, $img, $event) = @_; if ($event->LeftIsDown()) { my ($x, $y) = $event->GetPositionXY(); $this->{'mouse_x'} = $x; $this->{'mouse_y'} = $y; } } sub evtMotion { my ($this, $event) = @_; if ($event->LeftIsDown()) { my ($real_x, $real_y) = $this->GetPositionXY(); my ($x, $y) = $event->GetPositionXY(); my $old_x = $this->{'mouse_x'}; my $old_y = $this->{'mouse_y'}; my $x_diff = $x - $old_x; my $y_diff = $y - $old_y; $this->Move($real_x + $x_diff, $real_y + $y_diff); } } sub evtRightDown { my ($this, $img, $event) = @_; $this->Destroy(); }
In reply to ReShow images without user interact with the GUI. by Ace128
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |