菜单栏出现50%的时间,wxPython,Ubuntu 11.10,Python 2.7,wxPython 2.8 GTK2

时间:2012-04-03 20:40:31

标签: wxpython

我这里有一个非常不稳定的问题。运行时,菜单栏随机出现。我已经多次尝试在整个程序中重复使用self.SetMenuBar(self.menuBarr),但它似乎不会影响成功率。有没有人知道任何类型的触发器的位置,它指示菜单栏是否已经显示,以便我可以在需要时自动重新加载它?

或者,我已经看过一些类似(但不同)的帖子herehere,所以如果它与所提到的错误相关,那么有人知道我如何调整黑客(在第一个链接)为一个简单的菜单栏工作?

在初始wx.Frame构造函数中,对menu()方法的调用已从创建序列的开头移动到结尾也可能是有用的信息,但它也没有影响到的可靠性。菜单栏项目。没有例外。

提前感谢您提供的任何帮助!

代码:

#!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))

更新 现在这开始变得非常奇怪。我通过使用管理员权限执行程序解决了这个问题。我的任何脚本都不会删除shell命令,所以我完全不知道为什么会这样。

1 个答案:

答案 0 :(得分:0)

菜单是否出现在任务栏区域,就像Mac一样?我认为在较新的Ubuntu版本中有一些禁用菜单的设置。我不记得它现在叫什么,但我认为你必须安装一个插件,否则它会被禁用,具体取决于主题。另请参阅http://wxpython-users.1045709.n5.nabble.com/help-no-show-menubar-in-ubuntu-td3292261.html

你没有提到你正在使用哪种wxPython。如果它不是2.8.12,请尝试升级到它并查看它是否已修复:https://groups.google.com/forum/?fromgroups#!topic/wxpython-users/7tx9i1TpfZc