#! / usr / bin / perl -w
Use tk; user; use tk :: message; use dirhandle; use cwd;
MY $ srcpath = cwd (); My $ dstpath = cwd ();
$ mw = mainwindow -> new (-title => "auto red eye removal);
$ srcframe = $ mw -> frame (-width => 600, -Height => 10); $ srcframe -> label (-width => 10) -> Pack (-SIDE => 'Left'; $ srcframe - > Label (-text => "source file path:") -> Pack (-Side => 'Left'); $ srcentry = $ srcframe -> PathenTry (-TextVariable => / $ srcpath, -width => 70) $ Srcframe -> label (-width => 10) -> Pack (-SIDE => 'Right'); $ srcentry -> Pack (-SIDE => 'Right');
$ dstframe = $ mw -> frame (-width => 600, -Height => 10); $ dstframe -> label (-width => 10) -> Pack (-Side => 'left'; $ dstframe - > Label (-Text => "target file path:") -> Pack (-SIDE => 'Left'); $ dstentry = $ dstframe -> PathenTry (-TextVariable => / $ dstpath,, -width => 70 ); $ Dstframe -> label (-width => 10) -> Pack (-SIDE => 'Right'); $ dstentry -> Pack (-SIDE => 'Right');
$ cmdframe = $ mw -> frame (-width => 600, -Height => 35); $ cmdframe -> label (-width => 25) -> Pack (-fill => 'x', -Side => 'Left'); $ cmdframe -> label (-width => 25) -> Pack (-fill => 'x', -side => 'right'); $ runbutton = $ cmdframe -> button (-Text = > "Run", -height => 1, -width => 8, -command => / & run; $ exitButton = $ cmdframe -> button (-text => "exit", -height => 1, -WIDTH => 8, -command => Sub {EXIT}, -default => 'Active'); $ Runbutton -> Pack (-Side => 'Left'); $ EXITBUTTON -> PACK (-SIDE => 'Right' $ outputframe = $ mw -> frame (-width => 600, -Height => 400); $ outputtext = $ outputframe -> text (-width => 80, -Height => 25, -wrap => ' Word ', -Background =>' Gray ', -font =>' Normal '); $ OTPUTTEXT -> Pack (-SIDE =>' Left ', -fill =>' Y ');
$ ScrollBar = $ outputFrame -> Scrollbar (-command => [ 'yview' => $ outputText]); $ outputText -> configure (-yscrollcommand => [ 'set' => $ scrollBar]); $ scrollBar -> pack (-SIDE => 'Right', -fill => 'Y');
$ srcframe -> Pack (-SIDE => 'TOP', -FILL => 'Both'); $ dstframe -> Pack (-SIDE => 'top', -fill => 'Both'); $ cmdframe -> Pack (-SIDE => 'top', -fill => 'Both'); $ OUTPUTFRAME -> PACK (-SIDE => 'TOP'); $ MW -> ResizAble (0, 0); mainloop;
Sub run () {MY $ SRC_PATH = $ srcpath. "/"; My $ dst_path = $ dstpath. "/";
IF ($ SRC_PATH EQ '|| $ mw -> messagebox (-type => "-", -title => "Error", -message => "Please enter the target file path or source File path !! "); Die;} Elsif ($ src_path eq '' || $ dst_path eq '') {$ mw -> messagebox (-type => 'OK', -title =>" Error ", -message => "Please enter the target file path or source file path !!"); Die;} $ src_path = & trim ($ src_path); $ dst_path = & trim ($ dst_path); my @ArrayFiles; if (& IsFolder ($ src_path)) {@ArrayFiles = & getjpgfiles ($ src_path);} else {$ mw -> messagebox (-type => 'OK', -title => "Error", -message => "source folder path does not exist, please enter the correct Folder path! "); Die;} if (& isfolder ($ dst_path)) {} else {$ mw -> messagebox (-type => 'ok', -title =>" Error ", -message =>" The target folder path does not exist, please enter the correct folder path! "); Die;} Foreach my $ file (@ArrayFiles) {$ OUTPUTTEXT -> Insert ('end'," source file is: ". $ Src_path. $ file. "/ n". "$ dst_path. $ file." / n "); $ outputtext -> insert ('end'," current redeye is detected: "); $ comMand =" Demo $ SRC_PATH "." $ file "." $ dst_path "." $ f ILE 1 1 0 "; Eval {Open (FD," $ Command 2> & 1 | "); while ($ line =
Sub getjpgfiles () {MY $ TMPPATH = $ _ [0]; $ tmpath = $ tmpath. "/"; my $ dh = new Dirhandle ("$ tmpath"); @files = dirhandle :: read ($ DH); Undef $ dh; @files = sort (@files); shift (@files); shift; f (@files == 0) {$ mw -> messagebox (-type => 'OK', -TITLE => "Error", -Message => "Current Folder is empty, please check!"); Die;} my @tempfiles; foreach my $ f (@files) {if ($ f = ~ /( (.jpg) $ / || $ f = ~ /(.jpg) $ /) {push @tempfiles, $ f;}} f (@tempfiles == 0) {$ mw -> messagebox (-type => 'ok', Title => "error", -Message => "There is no JPG file in the current folder!"); Die;} @files = @TempFiles;} @files;}
Sub isfolder () {$ TMP = $ _ [0]; My $ DH = New Dirhandle ("$ TMP"); if (! (DEfined $ DH)) {Return 0;} UNDEF $ DH; RETURN 1;}