def createPortaudioPane(self, panel): portaudioPanel = wx.Panel(panel) portaudioPanel.SetBackgroundColour(BACKGROUND_COLOUR) gridSizer = wx.FlexGridSizer(5, 3, 5, 5) # Input textIn = wx.StaticText(portaudioPanel, 0, 'Input Device :') textIn.SetFont(self.font) availableAudioIns = [] for d in CeciliaLib.getAvailableAudioInputs(): availableAudioIns.append(CeciliaLib.ensureNFD(d)) if CeciliaLib.getAudioInput() != '': try: initInput = availableAudioIns[int(CeciliaLib.getAudioInput())] except: initInput = 'dump' else: initInput = 'dump' self.choiceInput = CustomMenu(portaudioPanel, choice=availableAudioIns, init=initInput, size=(168, 20), outFunction=self.changeAudioInput) if CeciliaLib.getAudioInput() == '' or CeciliaLib.getEnableAudioInput( ) == 0: initInputState = 0 else: initInputState = 1 self.inputToggle = Toggle(portaudioPanel, initInputState, outFunction=self.enableAudioInput) # Output textOut = wx.StaticText(portaudioPanel, 0, 'Output Device :') textOut.SetFont(self.font) availableAudioOuts = [] for d in CeciliaLib.getAvailableAudioOutputs(): availableAudioOuts.append(CeciliaLib.ensureNFD(d)) try: initOutput = availableAudioOuts[int(CeciliaLib.getAudioOutput())] except: initOutput = availableAudioOuts[0] self.choiceOutput = CustomMenu(portaudioPanel, choice=availableAudioOuts, init=initOutput, size=(168, 20), outFunction=self.changeAudioOutput) gridSizer.AddMany([ (textIn, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, PADDING), (self.inputToggle, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 45), (self.choiceInput, 0, wx.ALIGN_CENTER_VERTICAL), (textOut, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, PADDING), (wx.StaticText(portaudioPanel, -1, '', size=(65, -1)), 1, wx.EXPAND), (self.choiceOutput, 0, wx.ALIGN_CENTER_VERTICAL), ]) gridSizer.AddGrowableCol(1, 1) portaudioPanel.SetSizerAndFit(gridSizer) return portaudioPanel
def createPortaudioPane(self, panel): portaudioPanel = wx.Panel(panel) portaudioPanel.SetBackgroundColour(BACKGROUND_COLOUR) gridSizer = wx.FlexGridSizer(5, 3, 5, 5) # Input textIn = wx.StaticText(portaudioPanel, 0, 'Input Device :') textIn.SetFont(self.font) availableAudioIns = [] for d in CeciliaLib.getAvailableAudioInputs(): availableAudioIns.append(CeciliaLib.ensureNFD(d)) if CeciliaLib.getAudioInput() != '': try: initInput = availableAudioIns[int(CeciliaLib.getAudioInput())] except: initInput = 'dump' else: initInput = 'dump' self.choiceInput = CustomMenu(portaudioPanel, choice=availableAudioIns, init=initInput, size=(168,20), outFunction=self.changeAudioInput) if CeciliaLib.getAudioInput() == '' or CeciliaLib.getEnableAudioInput() == 0: initInputState = 0 else: initInputState = 1 self.inputToggle = Toggle(portaudioPanel, initInputState, outFunction=self.enableAudioInput) # Output textOut = wx.StaticText(portaudioPanel, 0, 'Output Device :') textOut.SetFont(self.font) availableAudioOuts = [] for d in CeciliaLib.getAvailableAudioOutputs(): availableAudioOuts.append(CeciliaLib.ensureNFD(d)) try: initOutput = availableAudioOuts[int(CeciliaLib.getAudioOutput())] except: initOutput = availableAudioOuts[0] self.choiceOutput = CustomMenu(portaudioPanel, choice=availableAudioOuts, init=initOutput, size=(168,20), outFunction=self.changeAudioOutput) gridSizer.AddMany([ (textIn, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, PADDING), (self.inputToggle, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 45), (self.choiceInput, 0, wx.ALIGN_CENTER_VERTICAL), (textOut, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, PADDING), (wx.StaticText(portaudioPanel, -1, '', size=(65,-1)), 1, wx.EXPAND), (self.choiceOutput, 0, wx.ALIGN_CENTER_VERTICAL), ]) gridSizer.AddGrowableCol(1, 1) portaudioPanel.SetSizerAndFit(gridSizer) return portaudioPanel
def onSavePreset(self): dlg = wx.TextEntryDialog(self, 'Enter preset name:', 'Saving Preset', self.currentPreset) if dlg.ShowModal() == wx.ID_OK: newPreset = CeciliaLib.ensureNFD(dlg.GetValue()) else: return dlg.Destroy() if newPreset == '': CeciliaLib.showErrorDialog('Failed saving preset', 'You must give a name to your preset!') return if newPreset == 'init': CeciliaLib.showErrorDialog( 'Failed saving preset', '"init" is reserved. You must give another name to your preset!' ) return if newPreset in CeciliaLib.getVar("presets").keys(): dlg2 = wx.MessageDialog( self, 'The preset you entered already exists. Are you sure you want to overwrite it?', 'Existing preset!', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_INFORMATION) if dlg2.ShowModal() == wx.ID_NO: return dlg2.Destroy() self.currentPreset = newPreset CeciliaLib.savePresetToDict(self.currentPreset) self.presetChoice.setChoice(self.orderingPresetNames(), False) self.presetChoice.setStringSelection(self.currentPreset)
def createPortmidiPane(self, panel): portmidiPanel = wx.Panel(panel) portmidiPanel.SetBackgroundColour(BACKGROUND_COLOUR) gridSizer = wx.FlexGridSizer(5, 3, 5, 5) # Input textIn = wx.StaticText(portmidiPanel, 0, 'Input Device :') textIn.SetFont(self.font) availableMidiIns = [] for d in CeciliaLib.getAvailableMidiInputs(): availableMidiIns.append(CeciliaLib.ensureNFD(d)) if availableMidiIns != [] and 'All' not in availableMidiIns: availableMidiIns.append('All') if CeciliaLib.getMidiDeviceIn() != '': try: initInput = availableMidiIns[int(CeciliaLib.getMidiDeviceIn())] except: initInput = 'dump' else: initInput = 'dump' self.midiChoiceInput = CustomMenu(portmidiPanel, choice=availableMidiIns, init=initInput, size=(168,20), outFunction=self.changeMidiInput) gridSizer.AddMany([ (textIn, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, PADDING), (wx.StaticText(portmidiPanel, -1, '', size=(74,-1)), 1, wx.EXPAND), (self.midiChoiceInput, 0, wx.ALIGN_CENTER_VERTICAL), ]) gridSizer.AddGrowableCol(1, 1) portmidiPanel.SetSizerAndFit(gridSizer) return portmidiPanel
def createPortmidiPane(self, panel): portmidiPanel = wx.Panel(panel) portmidiPanel.SetBackgroundColour(BACKGROUND_COLOUR) gridSizer = wx.FlexGridSizer(5, 3, 5, 5) # Input textIn = wx.StaticText(portmidiPanel, 0, 'Input Device :') textIn.SetForegroundColour(PREFS_FOREGROUND) textIn.SetFont(self.font) availableMidiIns = [] for d in CeciliaLib.getVar("availableMidiInputs"): availableMidiIns.append(CeciliaLib.ensureNFD(d)) try: initInput = availableMidiIns[CeciliaLib.getVar("availableMidiInputIndexes").index(CeciliaLib.getVar("midiDeviceIn"))] except: if len(availableMidiIns) >= 1: initInput = availableMidiIns[0] else: initInput = '' self.midiChoiceInput = CustomMenu(portmidiPanel, choice=availableMidiIns, init=initInput, size=(168,20), outFunction=self.changeMidiInput) gridSizer.AddMany([ (textIn, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, PADDING), (wx.StaticText(portmidiPanel, -1, '', size=(75,-1)), 1, wx.EXPAND), (self.midiChoiceInput, 0, wx.ALIGN_CENTER_VERTICAL), ]) gridSizer.AddGrowableCol(1, 1) portmidiPanel.SetSizerAndFit(gridSizer) return portmidiPanel
def onSavePreset(self): dlg = wx.TextEntryDialog(self, 'Enter preset name:','Saving Preset', self.currentPreset) if dlg.ShowModal() == wx.ID_OK: newPreset = CeciliaLib.ensureNFD(dlg.GetValue()) else: return dlg.Destroy() if newPreset == '': CeciliaLib.showErrorDialog('Failed saving preset', 'You must give a name to your preset!') return if newPreset == 'init': CeciliaLib.showErrorDialog('Failed saving preset', '"init" is reserved. You must give another name to your preset!') return if newPreset in CeciliaLib.getVar("presets").keys(): dlg2 = wx.MessageDialog(self, 'The preset you entered already exists. Are you sure you want to overwrite it?', 'Existing preset!', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_INFORMATION) if dlg2.ShowModal() == wx.ID_NO: return dlg2.Destroy() self.currentPreset = newPreset CeciliaLib.savePresetToDict(self.currentPreset) self.presetChoice.setChoice(self.orderingPresetNames(), False) self.presetChoice.setStringSelection(self.currentPreset)
def newRecent(self, file, remove=False): file = CeciliaLib.ensureNFD(file) filename = os.path.join(TMP_PATH, '.recent.txt') try: f = open(filename, "r") lines = [CeciliaLib.ensureNFD(line[:-1]) for line in f.readlines()] f.close() except: lines = [] update = False if not remove: if not file in lines and not 'Resources/modules/' in file: lines.insert(0, file) update = True else: if file in lines: lines.remove(file) update = True if update: f = open(filename, "w") if len(lines) > 10: lines = lines[0:10] for line in lines: f.write(line + '\n') f.close() subId2 = ID_OPEN_RECENT recentFiles = [] f = open(filename, "r") for line in f.readlines(): recentFiles.append(line) f.close() if recentFiles: for item in self.menubar.openRecentMenu.GetMenuItems(): self.menubar.openRecentMenu.DeleteItem(item) for file in recentFiles: try: self.menubar.openRecentMenu.Append(subId2, file) subId2 += 1 except: pass
def newRecent(self, file, remove=False): file = CeciliaLib.ensureNFD(file) filename = os.path.join(TMP_PATH,'.recent.txt') try: f = open(filename, "r") lines = [CeciliaLib.ensureNFD(line[:-1]) for line in f.readlines()] f.close() except: lines = [] update = False if not remove: if not file in lines and not 'Resources/modules/' in file: lines.insert(0, file) update = True else: if file in lines: lines.remove(file) update = True if update: f = open(filename, "w") if len(lines) > 10: lines = lines[0:10] for line in lines: f.write(line + '\n') f.close() subId2 = ID_OPEN_RECENT recentFiles = [] f = open(filename, "r") for line in f.readlines(): recentFiles.append(line) f.close() if recentFiles: for item in self.menubar.openRecentMenu.GetMenuItems(): self.menubar.openRecentMenu.DeleteItem(item) for file in recentFiles: try: self.menubar.openRecentMenu.Append(subId2, file) subId2 += 1 except: pass
def onOpenBuiltin(self, event): menu = self.GetMenuBar() id = event.GetId() file = menu.FindItemById(id) filename = file.GetLabel() filedict = self.GetMenuBar().files for key in filedict.keys(): if filename in filedict[key]: dirname = key break name = os.path.join(CeciliaLib.ensureNFD(MODULES_PATH), dirname, filename) CeciliaLib.openCeciliaFile(self, name, True) self.updateTitle()
def addPrefPath(self): currentPath = CeciliaLib.getVar("prefferedPath") path = '' dlg = wx.DirDialog(self, message="Choose a folder...", defaultPath=CeciliaLib.ensureNFD(os.path.expanduser('~'))) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() dlg.Destroy() if path and currentPath != '': path = currentPath + ';' + path elif not path: return CeciliaLib.setVar("prefferedPath", path) self.textPrefPath.SetValue(path)
def findLineError(self, csdfile, errLine=None, errText=None): f = open(csdfile, 'r') if errLine != None: line = CeciliaLib.ensureNFD(f.readlines()[errLine - 1].rstrip()) elif errText != None: line = errText.strip() f.close() ceciliaEditor = CeciliaLib.getCeciliaEditor() orchEditor = ceciliaEditor.orchestraPanels[ ceciliaEditor.activeOrchestra].editor text = orchEditor.GetText() if text.find(line) != -1: start = text.find(line) end = len(line) + start orchEditor.SetSelection(start, end) return str(orchEditor.LineFromPosition(start) + 1), line else: return '', line
def getSoundsFromList(self, pathList): soundDict = dict() for path in pathList: if os.path.isfile(path): infos = self.getSoundInfo(path) if infos != None: sndfile = os.path.split(path)[1] if sndfile not in soundDict.keys(): soundDict[CeciliaLib.ensureNFD(sndfile)] = { 'samprate': infos[1], 'chnls': infos[0], 'dur': infos[2], 'bitrate': infos[5], 'type': infos[6], 'path': path } else: print 'not a file' return soundDict
def createPortmidiPane(self, panel): portmidiPanel = wx.Panel(panel) portmidiPanel.SetBackgroundColour(BACKGROUND_COLOUR) gridSizer = wx.FlexGridSizer(5, 3, 5, 5) # Input textIn = wx.StaticText(portmidiPanel, 0, 'Input Device :') textIn.SetFont(self.font) availableMidiIns = [] for d in CeciliaLib.getAvailableMidiInputs(): availableMidiIns.append(CeciliaLib.ensureNFD(d)) if availableMidiIns != [] and 'All' not in availableMidiIns: availableMidiIns.append('All') if CeciliaLib.getMidiDeviceIn() != '': try: initInput = availableMidiIns[int(CeciliaLib.getMidiDeviceIn())] except: initInput = 'dump' else: initInput = 'dump' self.midiChoiceInput = CustomMenu(portmidiPanel, choice=availableMidiIns, init=initInput, size=(168, 20), outFunction=self.changeMidiInput) gridSizer.AddMany([ (textIn, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, PADDING), (wx.StaticText(portmidiPanel, -1, '', size=(74, -1)), 1, wx.EXPAND), (self.midiChoiceInput, 0, wx.ALIGN_CENTER_VERTICAL), ]) gridSizer.AddGrowableCol(1, 1) portmidiPanel.SetSizerAndFit(gridSizer) return portmidiPanel
def buildFileMenu(self): self.fileMenu = wx.Menu() self.fileMenu.Append(wx.ID_NEW, 'New...\tCtrl+N', 'Start a new Cecilia project (Modules)') self.frame.Bind(wx.EVT_MENU, self.ceciliaEditor.onNew, id=wx.ID_NEW) self.fileMenu.Append(wx.ID_OPEN, 'Open...\tCtrl+O', 'Open a previously saved Cecilia project') self.frame.Bind(wx.EVT_MENU, self.ceciliaEditor.onOpen, id=wx.ID_OPEN) ######## Implement the Open builtin menu ######### self.openBuiltinMenu = wx.Menu() subId1 = ID_OPEN_BUILTIN for dir in self.directories: menu = wx.Menu() self.openBuiltinMenu.AppendMenu(-1, dir, menu) for f in self.files[dir]: menu.Append(subId1, f) self.frame.Bind(wx.EVT_MENU, self.ceciliaEditor.onOpenBuiltin, id=subId1) subId1 += 1 prefPath = CeciliaLib.getPrefPath() if prefPath: for path in prefPath.split(';'): if not os.path.isdir(path): continue menu = wx.Menu(os.path.split(path)[1]) self.openBuiltinMenu.AppendMenu(-1, os.path.split(path)[1], menu) files = os.listdir(path) for file in files: if os.path.isfile(os.path.join(path, file)): ok = False try: ext = file.rsplit('.')[1] if ext == 'cec': ok = True except: ok = False if ok: menu.Append(subId1, file) self.frame.Bind(wx.EVT_MENU, self.ceciliaEditor.onOpenPrefModule, id=subId1) subId1 += 1 self.fileMenu.AppendMenu(-1, 'Modules', self.openBuiltinMenu) self.openRecentMenu = wx.Menu() subId2 = ID_OPEN_RECENT recentFiles = [] filename = CeciliaLib.ensureNFD(os.path.join(TMP_PATH,'.recent.txt')) if os.path.isfile(filename): f = codecs.open(filename, "r", encoding="utf-8") for line in f.readlines(): recentFiles.append(line.replace("\n", "")) f.close() if recentFiles: for file in recentFiles: self.openRecentMenu.Append(subId2, file) subId2 += 1 if subId2 > ID_OPEN_RECENT: for i in range(ID_OPEN_RECENT,subId2): self.frame.Bind(wx.EVT_MENU, self.ceciliaEditor.openRecent, id=i) self.fileMenu.AppendMenu(-1,'Open Recent', self.openRecentMenu, 'Access previously opened files in Cecilia') self.fileMenu.Append(wx.ID_CLOSE, 'Close\tCtrl+W', 'Close the current Interface window') self.frame.Bind(wx.EVT_MENU, self.frame.onClose, id=wx.ID_CLOSE) self.fileMenu.AppendSeparator() self.fileMenu.Append(wx.ID_SAVE, 'Save\tCtrl+S', 'Save changes made on the current module') self.frame.Bind(wx.EVT_MENU, self.ceciliaEditor.onSave, id=wx.ID_SAVE) self.fileMenu.Append(wx.ID_SAVEAS, 'Save as...\tShift+Ctrl+s', 'Save the current module as... (.cec file)') self.frame.Bind(wx.EVT_MENU, self.ceciliaEditor.onSaveAs, id=wx.ID_SAVEAS) self.fileMenu.AppendSeparator() self.fileMenu.Append(ID_UPDATE_INTERFACE, 'Reset Interface\tCtrl+R', 'Generate the interface') self.frame.Bind(wx.EVT_MENU, self.ceciliaEditor.onUpdateInterface, id=ID_UPDATE_INTERFACE) self.fileMenu.AppendSeparator() self.fileMenu.Append(ID_OPEN_CSD, "Show computed .csd file\tCtrl+T", "Shows the .csd file generated by Cecilia") self.frame.Bind(wx.EVT_MENU, self.ceciliaEditor.openCsdFile, id=ID_OPEN_CSD) self.fileMenu.Append(ID_OPEN_LOG, "Show Csound log file\tShift+Ctrl+T", "Shows the Csound log file") self.frame.Bind(wx.EVT_MENU, self.ceciliaEditor.openLogFile, id=ID_OPEN_LOG) pref_item = self.fileMenu.Append(wx.ID_PREFERENCES, 'Preferences...\tCtrl+;', 'Open Cecilia preferences pane') self.frame.Bind(wx.EVT_MENU, self.ceciliaEditor.onPreferences, id=wx.ID_PREFERENCES) self.fileMenu.AppendSeparator() quit_item = self.fileMenu.Append(wx.ID_EXIT, 'Quit\tCtrl+Q', 'Quit Cecilia') self.frame.Bind(wx.EVT_MENU, self.ceciliaEditor.onQuit, id=wx.ID_EXIT) if wx.Platform=="__WXMAC__": wx.App.SetMacExitMenuItemId(quit_item.GetId()) wx.App.SetMacPreferencesMenuItemId(pref_item.GetId())
def __init__(self, frame, mainFrame=None): wx.MenuBar.__init__(self, wx.MB_DOCKABLE) self.frame = frame if mainFrame: self.mainFrame = mainFrame else: self.mainFrame = CeciliaLib.getVar("mainFrame") inMainFrame = False if frame == mainFrame: inMainFrame = True # File Menu self.fileMenu = wx.Menu() self.fileMenu.Append(ID_OPEN, 'Open...\tCtrl+O', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.mainFrame.onOpen, id=ID_OPEN) self.fileMenu.Append(ID_OPEN_RANDOM, 'Open Random...\tShift+Ctrl+O', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.mainFrame.onOpenRandom, id=ID_OPEN_RANDOM) ######## Implement the Open builtin menu ######### self.root, self.directories, self.files = CeciliaLib.buildFileTree() self.openBuiltinMenu = wx.Menu() subId1 = ID_OPEN_BUILTIN for dir in self.directories: menu = wx.Menu() self.openBuiltinMenu.AppendMenu(-1, dir, menu) for f in self.files[dir]: menu.Append(subId1, f) self.frame.Bind(wx.EVT_MENU, self.mainFrame.onOpenBuiltin, id=subId1) subId1 += 1 prefPath = CeciliaLib.getVar("prefferedPath") if prefPath: for path in prefPath.split(';'): path = CeciliaLib.ensureNFD(path) if not os.path.isdir(path): continue menu = wx.Menu(os.path.split(path)[1]) self.openBuiltinMenu.AppendMenu(-1, os.path.split(path)[1], menu) files = os.listdir(path) for file in files: if os.path.isfile(os.path.join(path, file)): ok = False try: ext = file.rsplit('.')[1] if ext == FILE_EXTENSION: ok = True except: ok = False if ok: try: menu.Append(subId1, CeciliaLib.ensureNFD(file)) self.frame.Bind(wx.EVT_MENU, self.mainFrame.onOpenPrefModule, id=subId1) subId1 += 1 except: pass self.fileMenu.AppendMenu(-1, 'Modules', self.openBuiltinMenu) self.openRecentMenu = wx.Menu() subId2 = ID_OPEN_RECENT recentFiles = [] filename = os.path.join(TMP_PATH,'.recent.txt') if os.path.isfile(filename): f = open(filename, "r") for line in f.readlines(): try: recentFiles.append(line) except: pass f.close() if recentFiles: for file in recentFiles: try: self.openRecentMenu.Append(subId2, CeciliaLib.ensureNFD(file)) subId2 += 1 except: pass if subId2 > ID_OPEN_RECENT: for i in range(ID_OPEN_RECENT,subId2): self.frame.Bind(wx.EVT_MENU, self.mainFrame.openRecent, id=i) self.fileMenu.AppendMenu(-1,'Open Recent', self.openRecentMenu, 'Access previously opened files in Cecilia') self.fileMenu.AppendSeparator() self.fileMenu.Append(ID_SAVE, 'Save\tCtrl+S', 'Save changes made on the current module', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.mainFrame.onSave, id=ID_SAVE) self.fileMenu.Append(ID_SAVEAS, 'Save as...\tShift+Ctrl+s', 'Save the current module as... (.cec file)', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.mainFrame.onSaveAs, id=ID_SAVEAS) self.fileMenu.AppendSeparator() self.fileMenu.Append(ID_OPEN_AS_TEXT, 'Open Module as Text\tCtrl+E', '', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.mainFrame.openModuleAsText, id=ID_OPEN_AS_TEXT) self.fileMenu.Append(ID_UPDATE_INTERFACE, 'Reload module\tCtrl+R', 'Reload the current module', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.mainFrame.reloadCurrentModule, id=ID_UPDATE_INTERFACE) if CeciliaLib.getVar("systemPlatform") in ['win32', 'linux2']: self.fileMenu.AppendSeparator() pref_item = self.fileMenu.Append(wx.ID_PREFERENCES, 'Preferences...\tCtrl+,', 'Open Cecilia preferences pane', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.mainFrame.onPreferences, pref_item) if CeciliaLib.getVar("systemPlatform") in ['win32', 'linux2']: self.fileMenu.AppendSeparator() quit_item = self.fileMenu.Append(wx.ID_EXIT, 'Quit\tCtrl+Q', 'Quit Cecilia', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.mainFrame.onQuit, quit_item) # Edit Menu self.editMenu = wx.Menu() if not inMainFrame: self.editMenu.Append(ID_UNDO, 'Undo\tCtrl+Z', 'Undo the last change', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.frame.onUndo, id=ID_UNDO) self.editMenu.Append(ID_REDO, 'Redo\tShift+Ctrl+Z', 'Redo the last change', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.frame.onRedo, id=ID_REDO) self.editMenu.AppendSeparator() self.editMenu.Append(ID_COPY, 'Copy\tCtrl+C', 'Copy the current line to the clipboard', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.frame.onCopy, id=ID_COPY) self.editMenu.Append(ID_PASTE, 'Paste\tCtrl+V', 'Paste to the current line the content of clipboard', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.frame.onPaste, id=ID_PASTE) self.editMenu.AppendSeparator() self.editMenu.Append(ID_SELECT_ALL, 'Select All Points\tCtrl+A', 'Select all points of the current graph line', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.frame.onSelectAll, id=ID_SELECT_ALL) self.editMenu.AppendSeparator() self.editMenu.Append(ID_REMEMBER, 'Remember Input Sound', 'Find an expression in the text and replace it', kind=wx.ITEM_CHECK) self.editMenu.FindItemById(ID_REMEMBER).Check(CeciliaLib.getVar("rememberedSound")) self.frame.Bind(wx.EVT_MENU, self.mainFrame.onRememberInputSound, id=ID_REMEMBER) # Action Options Menu self.actionMenu = wx.Menu() self.actionMenu.Append(ID_PLAY_STOP, 'Play / Stop\tCtrl+.', 'Start and stop audio server') self.frame.Bind(wx.EVT_MENU, self.mainFrame.onShortPlayStop, id=ID_PLAY_STOP) self.actionMenu.AppendSeparator() self.actionMenu.Append(ID_BOUNCE, 'Bounce to Disk\tCtrl+B', 'Record the audio processing in a soundfile') self.frame.Bind(wx.EVT_MENU, self.mainFrame.onBounceToDisk, id=ID_BOUNCE) self.actionMenu.Append(ID_BATCH_PRESET, 'Batch Processing on Preset Sequence', '') self.frame.Bind(wx.EVT_MENU, self.mainFrame.onBatchProcessing, id=ID_BATCH_PRESET) self.actionMenu.Append(ID_BATCH_FOLDER, 'Batch Processing on Sound Folder', '') self.frame.Bind(wx.EVT_MENU, self.mainFrame.onBatchProcessing, id=ID_BATCH_FOLDER) self.actionMenu.Append(ID_USE_SOUND_DUR, 'Use Sound Duration on Folder Batch Processing', kind=wx.ITEM_CHECK) if CeciliaLib.getVar("useSoundDur") == 1: self.actionMenu.FindItemById(ID_USE_SOUND_DUR).Check(True) self.frame.Bind(wx.EVT_MENU, self.mainFrame.onUseSoundDuration, id=ID_USE_SOUND_DUR) self.actionMenu.AppendSeparator() self.actionMenu.Append(ID_SHOW_SPECTRUM, 'Show Spectrum', '', kind=wx.ITEM_CHECK) self.frame.Bind(wx.EVT_MENU, self.mainFrame.onShowSpectrum, id=ID_SHOW_SPECTRUM) if CeciliaLib.getVar('showSpectrum'): self.actionMenu.FindItemById(ID_SHOW_SPECTRUM).Check(True) self.actionMenu.AppendSeparator() self.actionMenu.Append(ID_USE_MIDI, 'Use MIDI', 'Allow Cecilia to use a midi device.', kind=wx.ITEM_CHECK) if CeciliaLib.getVar("useMidi") == 1: midiCheck = True else: midiCheck = False self.actionMenu.FindItemById(ID_USE_MIDI).Check(midiCheck) self.actionMenu.FindItemById(ID_USE_MIDI).Enable(False) self.frame.Bind(wx.EVT_MENU, self.mainFrame.onUseMidi, id=ID_USE_MIDI) windowMenu = wx.Menu() windowMenu.Append(ID_MARIO, 'Eh Oh Mario!\tShift+Ctrl+E', '', kind=wx.ITEM_CHECK) self.frame.Bind(wx.EVT_MENU, self.marioSwitch, id=ID_MARIO) helpMenu = wx.Menu() helpItem = helpMenu.Append(wx.ID_ABOUT, '&About %s %s' % (APP_NAME, APP_VERSION), 'wxPython RULES!!!') self.frame.Bind(wx.EVT_MENU, self.mainFrame.onHelpAbout, helpItem) infoItem = helpMenu.Append(ID_MODULE_INFO, 'Show Module Info\tCtrl+I', '') self.frame.Bind(wx.EVT_MENU, self.mainFrame.onModuleAbout, infoItem) docItem = helpMenu.Append(ID_DOC_FRAME, 'Show API Documentation\tCtrl+D', '') self.frame.Bind(wx.EVT_MENU, self.mainFrame.onDocFrame, docItem) self.Append(self.fileMenu, '&File') self.Append(self.editMenu, '&Edit') self.Append(self.actionMenu, '&Action') self.Append(windowMenu, '&Window') self.Append(helpMenu, '&Help')
def __init__(self, frame, mainFrame=None): wx.MenuBar.__init__(self, wx.MB_DOCKABLE) self.frame = frame if mainFrame: self.mainFrame = mainFrame else: self.mainFrame = CeciliaLib.getVar("mainFrame") inMainFrame = False if frame == mainFrame: inMainFrame = True # File Menu self.fileMenu = wx.Menu() self.fileMenu.Append(ID_OPEN, 'Open...\tCtrl+O', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.mainFrame.onOpen, id=ID_OPEN) self.fileMenu.Append(ID_OPEN_RANDOM, 'Open Random...\tShift+Ctrl+O', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.mainFrame.onOpenRandom, id=ID_OPEN_RANDOM) ######## Implement the Open builtin menu ######### self.root, self.directories, self.files = CeciliaLib.buildFileTree() self.openBuiltinMenu = wx.Menu() subId1 = ID_OPEN_BUILTIN for dir in self.directories: menu = wx.Menu() self.openBuiltinMenu.AppendMenu(-1, dir, menu) for f in self.files[dir]: menu.Append(subId1, f) self.frame.Bind(wx.EVT_MENU, self.mainFrame.onOpenBuiltin, id=subId1) subId1 += 1 prefPath = CeciliaLib.getVar("prefferedPath") if prefPath: for path in prefPath.split(';'): path = CeciliaLib.ensureNFD(path) if not os.path.isdir(path): continue menu = wx.Menu(os.path.split(path)[1]) self.openBuiltinMenu.AppendMenu(-1, os.path.split(path)[1], menu) files = os.listdir(path) for file in files: if os.path.isfile(os.path.join(path, file)): ok = False try: ext = file.rsplit('.')[1] if ext == FILE_EXTENSION: ok = True except: ok = False if ok: try: menu.Append(subId1, CeciliaLib.ensureNFD(file)) self.frame.Bind( wx.EVT_MENU, self.mainFrame.onOpenPrefModule, id=subId1) subId1 += 1 except: pass self.fileMenu.AppendMenu(-1, 'Modules', self.openBuiltinMenu) self.openRecentMenu = wx.Menu() subId2 = ID_OPEN_RECENT recentFiles = [] filename = os.path.join(TMP_PATH, '.recent.txt') if os.path.isfile(filename): f = open(filename, "r") for line in f.readlines(): try: recentFiles.append(line) except: pass f.close() if recentFiles: for file in recentFiles: try: self.openRecentMenu.Append(subId2, CeciliaLib.ensureNFD(file)) subId2 += 1 except: pass if subId2 > ID_OPEN_RECENT: for i in range(ID_OPEN_RECENT, subId2): self.frame.Bind(wx.EVT_MENU, self.mainFrame.openRecent, id=i) self.fileMenu.AppendMenu(-1, 'Open Recent', self.openRecentMenu, 'Access previously opened files in Cecilia') self.fileMenu.AppendSeparator() self.fileMenu.Append(ID_SAVE, 'Save\tCtrl+S', 'Save changes made on the current module', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.mainFrame.onSave, id=ID_SAVE) self.fileMenu.Append(ID_SAVEAS, 'Save as...\tShift+Ctrl+s', 'Save the current module as... (.cec file)', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.mainFrame.onSaveAs, id=ID_SAVEAS) self.fileMenu.AppendSeparator() self.fileMenu.Append(ID_OPEN_AS_TEXT, 'Open Module as Text\tCtrl+E', '', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.mainFrame.openModuleAsText, id=ID_OPEN_AS_TEXT) self.fileMenu.Append(ID_UPDATE_INTERFACE, 'Reload module\tCtrl+R', 'Reload the current module', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.mainFrame.reloadCurrentModule, id=ID_UPDATE_INTERFACE) if CeciliaLib.getVar("systemPlatform") in ['win32', 'linux2']: self.fileMenu.AppendSeparator() pref_item = self.fileMenu.Append(wx.ID_PREFERENCES, 'Preferences...\tCtrl+,', 'Open Cecilia preferences pane', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.mainFrame.onPreferences, pref_item) if CeciliaLib.getVar("systemPlatform") in ['win32', 'linux2']: self.fileMenu.AppendSeparator() quit_item = self.fileMenu.Append(wx.ID_EXIT, 'Quit\tCtrl+Q', 'Quit Cecilia', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.mainFrame.onQuit, quit_item) # Edit Menu self.editMenu = wx.Menu() if not inMainFrame: self.editMenu.Append(ID_UNDO, 'Undo\tCtrl+Z', 'Undo the last change', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.frame.onUndo, id=ID_UNDO) self.editMenu.Append(ID_REDO, 'Redo\tShift+Ctrl+Z', 'Redo the last change', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.frame.onRedo, id=ID_REDO) self.editMenu.AppendSeparator() self.editMenu.Append(ID_COPY, 'Copy\tCtrl+C', 'Copy the current line to the clipboard', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.frame.onCopy, id=ID_COPY) self.editMenu.Append( ID_PASTE, 'Paste\tCtrl+V', 'Paste to the current line the content of clipboard', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.frame.onPaste, id=ID_PASTE) self.editMenu.AppendSeparator() self.editMenu.Append(ID_SELECT_ALL, 'Select All Points\tCtrl+A', 'Select all points of the current graph line', kind=wx.ITEM_NORMAL) self.frame.Bind(wx.EVT_MENU, self.frame.onSelectAll, id=ID_SELECT_ALL) self.editMenu.AppendSeparator() self.editMenu.Append(ID_REMEMBER, 'Remember Input Sound', 'Find an expression in the text and replace it', kind=wx.ITEM_CHECK) self.editMenu.FindItemById(ID_REMEMBER).Check( CeciliaLib.getVar("rememberedSound")) self.frame.Bind(wx.EVT_MENU, self.mainFrame.onRememberInputSound, id=ID_REMEMBER) # Action Options Menu self.actionMenu = wx.Menu() self.actionMenu.Append(ID_PLAY_STOP, 'Play / Stop\tCtrl+.', 'Start and stop audio server') self.frame.Bind(wx.EVT_MENU, self.mainFrame.onShortPlayStop, id=ID_PLAY_STOP) self.actionMenu.AppendSeparator() self.actionMenu.Append(ID_BOUNCE, 'Bounce to Disk\tCtrl+B', 'Record the audio processing in a soundfile') self.frame.Bind(wx.EVT_MENU, self.mainFrame.onBounceToDisk, id=ID_BOUNCE) self.actionMenu.Append(ID_BATCH_PRESET, 'Batch Processing on Preset Sequence', '') self.frame.Bind(wx.EVT_MENU, self.mainFrame.onBatchProcessing, id=ID_BATCH_PRESET) self.actionMenu.Append(ID_BATCH_FOLDER, 'Batch Processing on Sound Folder', '') self.frame.Bind(wx.EVT_MENU, self.mainFrame.onBatchProcessing, id=ID_BATCH_FOLDER) self.actionMenu.Append(ID_USE_SOUND_DUR, 'Use Sound Duration on Folder Batch Processing', kind=wx.ITEM_CHECK) if CeciliaLib.getVar("useSoundDur") == 1: self.actionMenu.FindItemById(ID_USE_SOUND_DUR).Check(True) self.frame.Bind(wx.EVT_MENU, self.mainFrame.onUseSoundDuration, id=ID_USE_SOUND_DUR) self.actionMenu.AppendSeparator() self.actionMenu.Append(ID_SHOW_SPECTRUM, 'Show Spectrum', '', kind=wx.ITEM_CHECK) self.frame.Bind(wx.EVT_MENU, self.mainFrame.onShowSpectrum, id=ID_SHOW_SPECTRUM) if CeciliaLib.getVar('showSpectrum'): self.actionMenu.FindItemById(ID_SHOW_SPECTRUM).Check(True) self.actionMenu.AppendSeparator() self.actionMenu.Append(ID_USE_MIDI, 'Use MIDI', 'Allow Cecilia to use a midi device.', kind=wx.ITEM_CHECK) if CeciliaLib.getVar("useMidi") == 1: midiCheck = True else: midiCheck = False self.actionMenu.FindItemById(ID_USE_MIDI).Check(midiCheck) self.actionMenu.FindItemById(ID_USE_MIDI).Enable(False) self.frame.Bind(wx.EVT_MENU, self.mainFrame.onUseMidi, id=ID_USE_MIDI) windowMenu = wx.Menu() windowMenu.Append(ID_MARIO, 'Eh Oh Mario!\tShift+Ctrl+E', '', kind=wx.ITEM_CHECK) self.frame.Bind(wx.EVT_MENU, self.marioSwitch, id=ID_MARIO) helpMenu = wx.Menu() helpItem = helpMenu.Append(wx.ID_ABOUT, '&About %s %s' % (APP_NAME, APP_VERSION), 'wxPython RULES!!!') self.frame.Bind(wx.EVT_MENU, self.mainFrame.onHelpAbout, helpItem) infoItem = helpMenu.Append(ID_MODULE_INFO, 'Show Module Info\tCtrl+I', '') self.frame.Bind(wx.EVT_MENU, self.mainFrame.onModuleAbout, infoItem) docItem = helpMenu.Append(ID_DOC_FRAME, 'Show API Documentation\tCtrl+D', '') self.frame.Bind(wx.EVT_MENU, self.mainFrame.onDocFrame, docItem) self.Append(self.fileMenu, '&File') self.Append(self.editMenu, '&Edit') self.Append(self.actionMenu, '&Action') self.Append(windowMenu, '&Window') self.Append(helpMenu, '&Help')