1

在我的框架构造函数中,我有一个函数可以轻松地为我创建一个菜单栏。

package Routines;

#This function will set up a menu
#REQUIRED: entries
#RETURNS:  id, menu
sub SetupMenu {
    $menuItemCount = 0;                     #Element number under the same menu
    $subMenuCount  = 0;                     #Number of menus
    $mbar          = Wx::MenuBar->new();    #Menu bar constructor
    for ($totalCount = 0; $totalCount < scalar($_[1]); $totalCount++) {    #Loop for each entry
        if ($menuItemCount == 0) {                                         #If this is the first entry in the menu
            $menuList[$subMenuCount] = Wx::Menu->new($_[$totalCount]);     #Construct a menu and make this the title
        } elsif ($_[$totalCount] == "---") {                               #If the entry is ---
                                                                           #Treat it as a separator, skip ID
        } elsif ($_[$totalCount] == "***") {                               #If the entry is ***
            $mbar->Append($menuList[$subMenuCount]);                       #Add the menu to the bar
            $menuItemCount = 0;                                            #Reset the number of elements
            $subMenuCount++;                                               #Increment the number of menus
        } else {                                                           #On normal operation
            $menuList[$subMenuCount]->Append($id[$totalCount], $_[$totalCount]);    #Add the element to the menu and assign it an ID
        }
    }
    #print $mbar;
    return (@id, $mbar);
}

#This package puts crap in the main window
package mehFrame;
use base qw(Wx::Frame);

sub new {
    #Preparation
    $class = shift;
    $self  = $class->SUPER::new(@_);

    #Place the panel
    $pan = Wx::Panel->new($self, -1);

    #Set up menus
    (@mehId, $mehBar) = Routines::SetupMenu("File", "Open ROM", "Save ROM", "Save ROM As", "---", "Close ROM", "Exit");

    #Return
    return $self;
}
[...]

不幸的是,它不起作用。print在函数中放入a后SetupMenu(),它没有打印。另一方面,当我把它 a 时warn,它发出警告。

更糟糕的是,即使我在print函数中输入了a new(),它仍然不打印。到底是怎么回事?

4

2 回答 2

1

Yakov,在没有其他答案的情况下,我会对此进行尝试,但是由于我不是 wxPerl 专家,因此请谨慎对待。

您的描述听起来像是打印到 STDERR 有效,因为那是warn可行的,而打印到 STDOUT 则不行。

尝试print STDERR $mbar改为 - 我很确定它会起作用。

更新:根据 daotoad 的优秀建议,这也可能是由于缺乏刷新 - 如果是这样,那么在 STDOUT 上设置 autoflush 可以解决它。无论是一种还是另一种,都取决于 OP 的尝试。我将它添加到我的答案中,因为 daotoad 只发表了评论并且还没有添加他自己的单独答案 - 一旦他这样做,我将删除。

于 2010-07-24T13:25:43.033 回答
0

打印在 Wx 下有时是异步的,除非你添加一个“\n”

于 2010-12-22T01:12:17.300 回答