in reply to Re^2: WxPerl and drag and dropping files
in thread WxPerl and drag and dropping files

finally got back around to it this evening >:D
but still no drag and drop joy for me :(

here is what i am trying to do:
use diagnostics; use warnings; use Wx; use Wx::Event qw(EVT_BUTTON); use Wx::Event qw(EVT_DROP_FILES); use File::Slurp; use Digest::MD5; use File::Path; ###################################################################### +######### my $app = Wx::SimpleApp->new; my $frame = Wx::Frame->new( undef, -1, 'test tool', wxDefaultPosition, Wx::Size->new(700,400), wxDEFAULT_DIALOG_STYLE|wxSTAY_ON_TOP ); $frame->DragAcceptFiles(1); EVT_DROP_FILES( $frame, \&extract ); ###################################################################### +######### my $noteBook = Wx::Notebook->new($frame, -1, wxDefaultPosition +, wxDefaultSize); my $window1 = Wx::Panel->new($noteBook, wxID_ANY); my $window2 = Wx::Panel->new($noteBook, wxID_ANY); my $window3 = Wx::Panel->new($noteBook, wxID_ANY); $noteBook->AddPage($window1, "First", 1, 0); $noteBook->AddPage($window2, "Second", 0, 1); $noteBook->AddPage($window3, "Third", 0, 2); $frame->Show(1); $app->SetTopWindow($frame); $app->MainLoop; ###################################################################### +######### sub extract { $_= shift; print "@_\n"; #<------- prints: "Wx::DropFilesEvent=SCALAR(0x3131024) +" #please read below the code for the question pertaining + to this. open (my $data, '<', "@_") or die "cannot open $data $!"; my $fileLocation = ''; my $fileSize = ''; my $fileName = ''; my $chunk = ''; seek ( $data, 0x04, 0 ); read ( $data, my $count, 0x04 ); $count =~ s/(.)/sprintf("%02x",ord($1))/egs; my $entryCount = hex($count); print "\nEntry count in file is: $entryCount\n\n"; seek ( $data, 0x00, 0 ); seek( $data, 0x10, 0 ) or die "cannot seek $data $!"; for (my $i=1; $i <= $entryCount; $i++) { read( $data, $fileLocation, 0x08 ); read( $data, $fileSize, 0x08 ); read( $data, $fileName, 0x20 ); $fileLocation =~ s/(.)/sprintf("%02x",ord($1))/egs; $fileSize =~ s/(.)/sprintf("%02x",ord($1))/egs; $fileName =~ s/\0+$//; open( my $extractedData, '>', "extracted/$fileName" ) or die "Cann +ot open $fileName $!"; sysseek( $data, hex($fileLocation), 0 ); sysread( $data, $chunk, hex($fileSize) ); syswrite( $extractedData, $chunk ); close( $extractedData ); } my $dirname = "extracted/"; my @md5s = read_file("md5"); my $md5s = join( '', @md5s ); my $filesize = ''; open( my $buf, '<', "extracted/sdk_version" ) or die "cannot open $buf + $!"; seek( $buf, 0x00, 0 ); read( $buf, my $sdk, 0x03 ); foreach my $file (<$dirname/*>) { next if -d $file; open( my $FILE, $file ); binmode($FILE); $filesize = -s $FILE; $file =~ s{.*/}{}; my $md5 = Digest::MD5->new->addfile($FILE)->hexdigest; if ( $md5s =~ $md5 ) { print "$md5 Match! $sdk $file $filesize\n"; } else { print "WARNING !\n"; } } }
The problem i am having is what you said in your earlier post anonomous monk, it does print what you said, but i cannot for the life of me figure out why it is not working. i get "Use of uninitialized value $data", or "trying to seek closed filehandle" and its because its not associating the dropped file with anything and thus not even opening the file.

Ive tried to assign it a variable as you can see in open statement, but that does not work for some reason, and its because it does not have the filepath or filename of the file, instead $data has "Wx::DropFilesEvent=SCALAR(0x3131024)" inside of it and that ofcourse is not going to work and is why it is giving me these errors.

I also have a very hard time understanding wxperl and wxwidgets in general especially when it comes to certain functions/events, tho i did get buttons figured out sort of. I have gotten very busy recently and havent really had time to delve into it like i should, but i have searched the modules inside of WX but everything in there is like ancient egyptian hieroglyphics. if you could school me at what i am doing wrong, and maybe show me an example i would greatly appreciate it. This is just a small personal project i am working on and it will help me finish certain tasks quicker if i could get this working :)

p.s. This is just one revision, ive tried abunch of different things to no avail and always end up with the same error as no such file or directory, or use of uninitialized value.

Replies are listed 'Best First'.
Re^4: WxPerl and drag and dropping files
by Anonymous Monk on Jun 20, 2014 at 06:54 UTC
      the contents of "@_" are "Wx::DropFilesEvent=SCALAR(0x3131024)" and i do not have a file named that.
      and actually now that you mentioned that, i remember using some code from wxDND demo modules that would list the file path of the dropped file in a list box. Let me see if i can make something happen with that. i really hope i can figure this out :l

        Hmm, read Re^4: WxPerl and drag and dropping files, call the GetFiles method on the wxDropFilesEvent, get a list of paths ...

        You have objects, call methods on objects, all GUI toolkits everywhere are about "object" on which you call methods, like wxDropFilesEvent...