【问题标题】:OnDropFiles starts long-lasting functionOnDropFiles 启动持久功能
【发布时间】:2014-04-16 13:27:04
【问题描述】:

使用 wxperl 我想在将文件拖到我的窗口后启动一个持久的功能。这是我的 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;
}

这个模块通过

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

(OnDropFiles 调用函数 &runner() 并将删除的文件作为参数。) 一切都很好,除了 Windows 上的拖动源窗口在函数 &runner() 工作时被阻止,这可能是一个长期的操作。在OnDropFiles 返回 1 后,拖动源窗口再次可用,因此在 &runner() 准备好之后。

是否有机会在 &runner() 完成之前解除对拖动源的阻塞?

【问题讨论】:

    标签: drag-and-drop wxwidgets wxperl


    【解决方案1】:

    不要立即调用该函数,而是将其推迟到下一次事件循环迭代。如果 3.x CallAfter() 被 wxPerl 包裹,你应该使用它。如果没有,请使用通常的 wxEVT_IDLE 技巧手动模拟它:让此事件的处理程序检查标志并在已设置(并重置它)时调用您的函数,然后在您的 OnDropFiles() 中设置此标志。

    【讨论】:

      猜你喜欢
      • 2021-10-29
      • 1970-01-01
      • 1970-01-01
      • 2018-04-29
      • 1970-01-01
      • 1970-01-01
      • 2019-02-05
      • 1970-01-01
      • 2022-07-05
      相关资源
      最近更新 更多