Menu Bar Appears 50% of the Time, wxPython, Ubuntu 11.10, Python 2.7, wxPython 2.8 GTK2

Go To StackoverFlow.com

0

I'm having a very erratic issue here. The menubar appears randomly when run. I have tried several times to repeat the use of self.SetMenuBar(self.menuBarr) throughout the program but it does not appear to affect the success rate. Does anybody know of the location of any kind of trigger which indicates whether or not the menu bar has been shown so that I can automatically re-load it when needed?

Alternatively, I've seen some similar (but different) posts here and here, so if it's related to the noted bug then does anybody know how I'd adjust the hack (in the first link) to work for a simple menu bar?

It may also be of useful information that the call to the menu() method has been moved from the beginning to the end of the creation sequence in the initial wx.Frame constructor, but it also did not affect the reliability of the menu bar item. No exception is called.

Thanks in advance for any help you can offer!

Code:

#!usr/bin/python
#Window Manager - Owned by Main


import wx, os, EmptyTestClass, isolationboard, controlpanel, logger, configmenu


ID_BUTTON=100
ID_EXIT=200
ID_SPLITTER=300

class WindowMan(wx.Frame):
    def __init__(self, parent, gsettings):
        logprefix='WindowMan Entry: '
        self.width=gsettings['width']
        self.height=gsettings['height']
        self.title=gsettings['title']
        self.dirname='~/'
        self.main=parent
        self.logman=logger.logg(logprefix)
        self.app=wx.App(False)
        super(WindowMan, self).__init__(None, title=self.title, size=(int(self.width), int(self.height)))
        try:
            self.menu()
        except Exception, e:
            self.logman.error("error creating file menu: "+str(e))
            print e
        self.splitter=wx.SplitterWindow(self, ID_SPLITTER, style=wx.SP_3D)
        self.testnames, self.testclasses=self.gettestnames(gsettings['tests'])
        self.sashpos=32
        self.InitTests()
        self.InitUI()
        self.show1()



    def gettestnames(self, tests): #Helper which parses the test settings array
        testnames=[]
        testclasses=[]
        testarr=tests.split(',')
        for currtest in testarr:
            temp=currtest.split(';')
            if temp==None:
                self.logman.error("Unable to load test "+currtest)
            else:
                testnames.append(temp[0])
                testclasses.append(temp[1])
        return testnames, testclasses

    def menu(self):
        #Create the Menu
        filemenu= wx.Menu()
        menuOpen = filemenu.Append(wx.ID_OPEN, "&Open"," Open a file to edit")
        menuAbout= filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")
        menuExit = filemenu.Append(wx.ID_EXIT,"E&xit"," Terminate the program")
        menuDConfig=filemenu.Append(wx.ID_PROPERTIES, "&Configuration", "Edit Configuration")
        self.menuBarr = wx.MenuBar()
        self.menuBarr.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar
        print self.SetMenuBar(self.menuBarr)
        # Events.
        self.Bind(wx.EVT_MENU, self.OnOpen, menuOpen)
        self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
        self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)
        self.Bind(wx.EVT_MENU, self.OnConfig, menuDConfig)


    def OnConfig(self, e):
        self.logman.debug("Config menu called")
        self.configframe=configmenu.configmenu(self)

    def InitUI(self): 
        try:
            self.panel=controlpanel.controlpanel(self.splitter, self, self.testnames) #splitter must be parent
            self.splitter.SplitHorizontally(self.panel, self.test[0],self.sashpos) #Splitter function, 40 specifies size of top section
            self.splitter.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED,self.fixsash)
            self.splitter.SetMinimumPaneSize(20)
            self.currwindow=self.test[0] #Start with first test as default window
            self.logman.info("Main UI Constructed Successfully")
        except Exception, e:
            self.logman.error("Error creating control panel object: "+str(e))



    def InitTests(self):
        self.test=[]
        for classtorun in self.testclasses:
            try:
                if classtorun=="isolation":
                    self.test.append(isolationboard.isolation(self.splitter))
                elif classtorun=="emptytest":
                    self.test.append(EmptyTestClass.emptytest(self.splitter))
                else:
                    self.logman.error("Encountered unknown test class reference: "+str(classtorun)+". Please check config file.")
                    raise Exception('Unknown Test Class Implemented In Config File: '+str(classtorun))
            except Exception as inst:
                self.logman.error(inst)
        self.logman.info("Main UI Constructed Successfully")

    def show1(self): #Shows and starts app
        self.Centre()
        self.Show()
        self.app.MainLoop()

    def OnAbout(self,e):
        # Create a message dialog box
        dlg = wx.MessageDialog(self, "blahblahblah")
        dlg.ShowModal() # Shows it
        dlg.Destroy() # finally destroy it when finished.

    def OnExit(self,e):
        self.Close(True)  # Close the frame.

    def OnOpen(self,e): #Not used yet, taken from wxPython example for convenience
        """ Open a file"""
        dlg = wx.FileDialog(self, "Choose a file", self.dirname, "", "*.*", wx.OPEN)
        if dlg.ShowModal() == wx.ID_OK:
            self.filename = dlg.GetFilename()
            self.dirname = dlg.GetDirectory()
            f = open(os.path.join(self.dirname, self.filename), 'r')
            self.control.SetValue(f.read())
            f.close()
        dlg.Destroy()

    def fixsash(self, event):  #Fixes splitter window if accidentally resized.
        self.splitter.SetSashPosition(self.sashpos) 

    def switchpanel(self, event):
        try:
            button=event.GetEventObject()
            #self.Hide()
            self.logman.debug("pressed button: "+button.GetLabel())
            testtoswitch=self.testnames.index(button.GetLabel())
            self.splitter.Unsplit(self.currwindow)
            self.currwindow=self.test[testtoswitch]
            self.splitter.SplitHorizontally(self.panel, self.test[testtoswitch],self.sashpos)
            self.splitter.SetMinimumPaneSize(20)
            self.splitter.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED,self.fixsash)
            #self.Show()
        except Exception, e:
            self.logman.error("Error in Panel switch: "+str(e))

UPDATE Now this is starting to get REALLY weird. I have solved the problem by executing the program with admin privileges. At no point do any of my scripts drop shell commands, so I'm completely stumped as to why this is happening.

2012-04-03 20:40
by Charles H


0

Does the menu appear up in the taskbar area, like a Mac? I'm thinking there's some setting in the newer Ubuntu releases that disable menus. I can't remember what it's called now, but I think you have to install an addon or it just gets disabled depending on the theme. See also http://wxpython-users.1045709.n5.nabble.com/help-no-show-menubar-in-ubuntu-td3292261.html

You don't mention which wxPython you're using. If it's not 2.8.12, try upgrading to that and see if it's fixed: https://groups.google.com/forum/?fromgroups#!topic/wxpython-users/7tx9i1TpfZc

2012-04-17 16:15
by Mike Driscoll
Ads