tags:

views:

43

answers:

1

In my frame constructor I have a function that easily makes a menu bar for me.

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;
}
[...]

Unfortunately, it doesn't work. After putting in a print in the SetupMenu() function, it did not print. On the other hand, when I put it a warn, it warned.

What's worse is that even if I put in a print in the new() function, it still doesn't print. What is going on?

+1  A: 

Yakov, I'll take a stab at this in the absence of other answers, but take this with a grain of salt since I'm not a wxPerl expert.

Your description sounds like printing to STDERR works, since that's where warn goes, whereas printing to STDOUT does not.

Try doing print STDERR $mbar instead - I'm fairly sure it will work.

UPDATE: As per daotoad's excellent suggestion, this could also be attributed to lack of flush - if so, then setting autoflush on STDOUT would solve it. Whether it's one or the other, depends on what the OP tries. I added it to my answer since daotoad only posted a comment and didn't add his own separate answer yet - I will remove once he does that.

DVK
Could be he's suffering from buffering. IIRC STDERR is set to autoflush by default, but STDOUT is set to buffer output.
daotoad
@daotoad - very plausible... that'd have been my next guess... you might want to turn this into an answer so OP sees it.
DVK
Thanks for the autoflush suggestion! Adding `$|=1` at the top of the file did `print` when needed. However, the bar still doesn't display, although that just might be my program.
Yakov Lipkovich