0

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

或者,我在这里这里看到了一些类似(但不同)的帖子,所以如果它与注意到的错误有关,那么有人知道我将如何调整黑客(在第一个链接中)以适用于简单的菜单栏吗?

在初始 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 命令,所以我完全不知道为什么会发生这种情况。

4

1 回答 1

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

于 2012-04-17T16:15:24.277 回答