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()印刷されませんでした。一方、 を入れると、warn警告が表示されました。

さらに悪いことprintに、new()関数に a を入れても、まだ印刷されません。何が起こっている?

4

2 に答える 2

1

Yakov、他に答えがない場合はこれを試してみますが、私は wxPerl の専門家ではないので、これは一粒の塩で考えてください。

あなたの説明は、STDERRへの印刷が機能するように聞こえwarnますが、STDOUTへの印刷はそうではありません。

代わりにやってみてくださいprint STDERR $mbar- 私はそれがうまくいくと確信しています。

更新: daotoad の優れた提案によると、これはフラッシュの不足に起因する可能性もあります。そうであれば、STDOUT で autoflush を設定すると解決します。それがどちらであるかは、OPが何を試みるかによって異なります。daotoadはコメントを投稿しただけで、彼自身の別の回答をまだ追加していないため、回答に追加しました-彼がそれをしたら削除します。

于 2010-07-24T13:25:43.033 に答える
0

「\ n」を追加しない限り、Wxで印刷が非同期になることがあります

于 2010-12-22T01:12:17.300 に答える