in reply to WxPerl and drag and dropping files

$file $x $y are three undefined variables -- wx will complain

This works for me on windows

$frame->DragAcceptFiles(1); EVT_DROP_FILES( $frame, \&doit ); sub doit { warn "@_\n" }

Why that?

Read these links (and what they link) Re^3: WxPerl DnD , Re^3: WxPerl DnD

Also for reference :) my wxWidgets / wxPerl / wxGlade tutorial and there also exists https://github.com/jmlynesjr/wxPerl-wxBook-Examples/ and it probably has drag drop example, just like wxperl_demo --show "Drag and drop"

Also, interleaving code and subs is bad :)

use ... Main( @ARGV ); exit( 0 ); ... sub
see Re: No such file or directory error/No such file or directory error, see template at (tye)Re: Stupid question (and see one discussion of that template at Re^2: RFC: Creating unicursal stars

Another thing i am trying to figure out is how to share a variable from a subroutine and pass it to print in the listbox?

What "subroutine", what variable where and for what purpose? The same principles apply to wxPerl, see write Tk callbacks all lexically scoped and not-memory leaking with no nested subs ever :) avoid nested subs and closures because nested named subs because they're closures

You register event handlers UPON widget objects (wxWindow a wxObject), so each event handler gets as first argument that wxObject ... there is even a global Wx::wxTheApp() which you can also use as a stash (better if the frames keep track of their own data) ... more words and/or more code gets more clear answer

Replies are listed 'Best First'.
Re^2: WxPerl and drag and dropping files
by james28909 (Deacon) on Jun 03, 2014 at 09:26 UTC
    i cant believe it was that easy, i was so close lol. let me read those links you posted, and thanks for pointing this out :)
Re^2: WxPerl and drag and dropping files
by james28909 (Deacon) on Jun 13, 2014 at 06:54 UTC
    You have to forgive me. I havent got around to actually testing this until just now. Now the problem seems to be me not being able to actually associate the dropped file with a filehandle.
    I tried the following code :
    $frame->DragAcceptFiles(1); EVT_DROP_FILES( $frame, \&doit ); sub doit { #warn "@_\n" open ( our $file, '<', @_ ) or die "$!"; \&otherSub($file); }
    And ofcourse it didnt work and has sent me into a downwards spiral of searching in google and trying everything i could find lol, but i still couldnt find an example that made me have that "ah-ha" moment.
    I use the our statement so the dropped file will be available throught the script. would this be the correct concept? I understand the way i am trying to associate the dropped file with the filehandle isnt correct and any insight will be very much appreciated :)

      So, how did it not work?

      Also, what are the contents of @_ in sub doit?

      Also, what is this code supposed to do:

      \&otherSub($file);

      Maybe you just want to call othersub?

      otherSub($file);

      If you are passing $file as parameter already, there is no need to make it into a global variable. Just use my $file and pass the filehandle around as a parameter.

      ... jokes ...

      I like you, you're a funny human, and we seem to visit at same time of day :)

      See your problem is you're making stuff up and expecting the computer to know what you mean; stop that please

      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.