Question

using wxperl I want to start a long-lasting function after dragging files to my window. Here is my code for the DropTarget:

package FilesDropTarget;

use strict;
use Wx qw[:allclasses];
use base qw(Wx::FileDropTarget);

sub new {
  my $class = shift;
  my $caller = shift;
  my $fref = shift;
  my $this = $class->SUPER::new( @_ );
  $this->{caller} = $caller;
  $this->{fref} = $fref;
  return $this;
}

sub OnDropFiles {
  my( $this, $x, $y, $files ) = @_;

  &{$this->{fref}}($this->{caller},@$files);

  return 1;
}

This module is used via

$frame->{TextControl}->SetDropTarget( FilesDropTarget->new($frame,\&runner) );

(OnDropFiles calls the function &runner() with the dropped files as parameter.) Everything is fine, except that the drag-source window on Windows is blocked while function &runner() is working, which potentially is a long-lasting operation. The drag-source window becomes useable again after OnDropFiles returns 1, hence after &runner() is ready.

Are there chances to get the drag-source unblocked before &runner() has been finished?

Was it helpful?

Solution

Don't call the function immediately, but postpone doing this until the next event loop iteration. If 3.x CallAfter() is wrapped by wxPerl, you should use it. If not, emulate it manually by using the usual wxEVT_IDLE trick: have a handler for this event checking a flag and calling your function if it's set (and resetting it) and just set this flag in your OnDropFiles().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top