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

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
  • Comment on Re^5: WxPerl and drag and dropping files

Replies are listed 'Best First'.
Re^6: WxPerl and drag and dropping files
by Anonymous Monk on Jun 20, 2014 at 07:31 UTC

    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...

      here you go, a working drag and drop implementation. thank you very much for your dedicated patience with me mr monk :) i can finally finish this little tool...
      $frame->DragAcceptFiles(1); EVT_DROP_FILES( $frame, \&ondrop ); sub ondrop { my ($self, $this) = @_; Wx::DropFilesEvent::GetFiles($this); our $dropfile = $this->GetFiles(); extract($dropfile); # or i can assign a button to +do the subroutine :) #print "$dropfile"; <----prints the filepath/name }
      once again thank you very much anonymous monk. Also, do you see anything wrong with using the our statement here? is there a better way of doing it?

      See, the contents of the file will always be the same, but the filenames are usually different because of the methods used to obtain this data. and the reason i needed it to do drag and drop was because staticallly setting a filename in the open statement wouldnt have worked to well. i would have had to rename the file to that statically assigned filename for it to work. but now it works great so far :)

      But dont get to comfortable because i will probably have more questions lol

        Use meaningful variable names ($this is traditional for instance ... the docs can't guess what varname you're using)

        Don't use global variables, you already have $frame , the globalest of the global things of your GUI application and all you could need or want, use it for storage

        Invoke methods like methods not functions

        Like this

        $frame->DragAcceptFiles(1); EVT_DROP_FILES( $frame, \&ondrop ); EVT_BUTTON( $frame, $ButExtract, \&onExtract ); ## its like ## EVT_BUTTON( $parent, $child, \&callback ); ## EVT_BUTTON( $parent, $child->GetId, \&callback ); ... sub ondrop { my( $frame, $wxDropFilesEvent ) = @_; my @files = $wxDropFilesEvent->GetFiles; $frame->{you_chose_these_files} = \@files; ## extract( $files[0] ); ## or whatever } sub onExtract { my( $frame, $extractBut ) = @_; my( $firstFile ) = @{ $frame->{you_chose_these_files} }; extract( $firstFile ); ... }

        But dont get to comfortable because i will probably have more questions lol

        I'm standing right now, but my laptop isn't high enough, so neck/back a little more stiff than usual ... still better than unadjustable hard dining room chair ... I'm done buying furniture :)

        im back, can you point me in the right direction of how i would also get the directory of said dropped file? let me be a little more specific. the program outputs to the root directory in which the gui program is in. if i make me a link in the taskbar for the program and run it, then just start dropping files, it still puts the output into the gui programsd directory and not the directory in which the dropped file came from.
        im also trying to figure out how to return the md5 from the subroutine to the listbox. ill make another thread later if i cant figure it out myself :)