Beispiel #1
0
    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:
            newPreset = ''
        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
        ok = True
        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:
                ok = False
            dlg2.Destroy()

        if ok:
            self.currentPreset = newPreset
            CeciliaLib.savePresetToDict(self.currentPreset)
            self.presetChoice.setChoice(self.orderingPresetNames(), False)
            self.presetChoice.setStringSelection(self.currentPreset)
            CeciliaLib.saveCeciliaFile(self, showDialog=False)
Beispiel #2
0
    def newRecent(self, file, remove=False):
        if ".cecilia5" in file:
            return

        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 file not in lines and 'Resources/modules/' not 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.Delete(item)
            for file in recentFiles:
                try:
                    self.menubar.openRecentMenu.Append(subId2, file)
                    subId2 += 1
                except:
                    pass
Beispiel #3
0
 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)
Beispiel #4
0
    def makePanel(self, obj=None):
        panel = wx.Panel(self, -1)
        panel.isLoad = False
        if self.needToParse:
            if obj == "Intro":
                if BUILD_RST:
                    create_api_doc_index()
                panel.win = stc.StyledTextCtrl(panel, -1, size=(600, 480), style=wx.BORDER_SUNKEN)
                panel.win.SetUseHorizontalScrollBar(False)
                panel.win.SetUseVerticalScrollBar(False)
                panel.win.SetText(_INTRO_TEXT)
            elif "Example" in obj:
                panel.win = stc.StyledTextCtrl(panel, -1, size=(600, 480), style=wx.BORDER_SUNKEN)
                panel.win.SetUseHorizontalScrollBar(False)
                panel.win.SetUseVerticalScrollBar(False)
                if "1" in obj:
                    panel.win.SetText(_EXAMPLE_1)
                elif "2" in obj:
                    panel.win.SetText(_EXAMPLE_2)
            else:
                var = eval(obj)
                if isinstance(var, str):
                    panel.win = stc.StyledTextCtrl(panel, -1, size=(600, 480), style=wx.BORDER_SUNKEN)
                    panel.win.SetUseHorizontalScrollBar(False)
                    panel.win.SetUseVerticalScrollBar(False)
                    if "Interface_API" in var:
                        if BUILD_RST:
                            create_interface_api_index()
                        for word in _KEYWORDS_LIST:
                            lines = eval(word).__doc__.splitlines()
                            line = "%s : %s\n" % (word, lines[1].replace('"', '').strip())
                            var += line
                        var += _COLOUR_TEXT
                        var += _COLOURS
                    else:
                        if BUILD_RST:
                            create_base_module_index()
                    panel.win.SetText(var)
                else:
                    text = var.__doc__
                    if BUILD_RST:
                        create_api_doc_page(obj, text)
                    panel.win = stc.StyledTextCtrl(panel, -1, size=(600, 480), style=wx.BORDER_SUNKEN)
                    panel.win.SetUseHorizontalScrollBar(False)
                    panel.win.SetUseVerticalScrollBar(False)
                    panel.win.SetText(text.replace(">>> ", ""))

            panel.win.SaveFile(CeciliaLib.ensureNFD(os.path.join(DOC_PATH, obj)))
        return panel
Beispiel #5
0
    def getPage(self, word):
        if word == self.oldPage:
            self.fromToolbar = False
            return
        page_count = self.GetPageCount()
        for i in range(page_count):
            text = self.GetPageText(i)
            if text == word:
                self.oldPage = word
                if not self.fromToolbar:
                    self.sequence = self.sequence[0:self.seq_index + 1]
                    self.sequence.append(i)
                    self.seq_index = len(self.sequence) - 1
                    self.history_check()
                self.parent.setTitle(text)
                self.SetSelection(i)
                panel = self.GetPage(self.GetSelection())
                if not panel.isLoad:
                    panel.isLoad = True
                    panel.win = stc.StyledTextCtrl(panel, -1, size=panel.GetSize(), style=wx.BORDER_SUNKEN)
                    panel.win.SetUseHorizontalScrollBar(False)
                    panel.win.LoadFile(os.path.join(CeciliaLib.ensureNFD(DOC_PATH), word))
                    panel.win.SetMarginWidth(1, 0)
                    if self.searchKey is not None:
                        words = complete_words_from_str(panel.win.GetText(), self.searchKey)
                        _ed_set_style(panel.win, words)
                    else:
                        _ed_set_style(panel.win)
                    panel.win.SetSelectionEnd(0)

                    def OnPanelSize(evt, win=panel.win):
                        win.SetPosition((0, 0))
                        win.SetSize(evt.GetSize())

                    panel.Bind(wx.EVT_SIZE, OnPanelSize)
                self.fromToolbar = False
                return
        try:
            win = self.makePanel(CeciliaLib.getVar("currentCeciliaFile"))
            self.AddPage(win, word)
            self.getPage(word)
        except:
            pass
Beispiel #6
0
    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)
Beispiel #7
0
        display = wx.Display()
        numDisp = display.GetCount()
        if CeciliaLib.getVar("DEBUG"):
            print('Numbers of displays:', numDisp)
        displays = []
        displayOffset = []
        displaySize = []
        for i in range(numDisp):
            displays.append(wx.Display(i))
            offset = displays[i].GetGeometry()[:2]
            size = displays[i].GetGeometry()[2:]
            if CeciliaLib.getVar("DEBUG"):
                print('display %d:' % i)
                print('    pos =', offset)
                print('    size =', size)
                print()
            displayOffset.append(offset)
            displaySize.append(size)
    except:
        numDisp = 1
        displayOffset = [(0, 0)]
        displaySize = [(1024, 768)]

    CeciliaLib.setVar("numDisplays", numDisp)
    CeciliaLib.setVar("displayOffset", displayOffset)
    CeciliaLib.setVar("displaySize", displaySize)

    sp = CeciliaSplashScreen(None, img=CeciliaLib.ensureNFD(SPLASH_FILE_PATH), callback=onStart)

    app.MainLoop()
Beispiel #8
0
        if CeciliaLib.getVar("DEBUG"):
            print 'Numbers of displays:', numDisp
        displays = []
        displayOffset = []
        displaySize = []
        for i in range(numDisp):
            displays.append(wx.Display(i))
            offset = displays[i].GetGeometry()[:2]
            size = displays[i].GetGeometry()[2:]
            if CeciliaLib.getVar("DEBUG"):
                print 'display %d:' % i
                print '    pos =', offset
                print '    size =', size
                print
            displayOffset.append(offset)
            displaySize.append(size)
    except:
        numDisp = 1
        displayOffset = [(0, 0)]
        displaySize = [(1024, 768)]

    CeciliaLib.setVar("numDisplays", numDisp)
    CeciliaLib.setVar("displayOffset", displayOffset)
    CeciliaLib.setVar("displaySize", displaySize)

    sp = CeciliaSplashScreen(None,
                             img=CeciliaLib.ensureNFD(SPLASH_FILE_PATH),
                             callback=onStart)

    app.MainLoop()
Beispiel #9
0
    def createMidiPanel(self, panel):
        midiParamPanel = wx.Panel(panel)
        midiParamPanel.SetBackgroundColour(BACKGROUND_COLOUR)

        box = wx.BoxSizer(wx.VERTICAL)

        driverbox = wx.BoxSizer(wx.HORIZONTAL)

        # Midi driver
        textInOutConfig = wx.StaticText(midiParamPanel, 0, 'Midi Driver :')
        textInOutConfig.SetForegroundColour(PREFS_FOREGROUND)
        textInOutConfig.SetFont(self.font)
        self.midiDriverChoice = CustomMenu(
            midiParamPanel,
            choice=['PortMidi'],
            size=(150, 20),
            init='PortMidi',
            outFunction=self.onMidiDriverPageChange)

        driverbox.Add(textInOutConfig, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL,
                      5)
        driverbox.AddStretchSpacer(1)
        driverbox.Add(self.midiDriverChoice, 0,
                      wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, PADDING)

        # Input
        textIn = wx.StaticText(midiParamPanel, 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(midiParamPanel,
                                          choice=availableMidiIns,
                                          init=initInput,
                                          size=(150, 20),
                                          outFunction=self.changeMidiInput)

        inbox = wx.BoxSizer(wx.HORIZONTAL)
        inbox.Add(textIn, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 5)
        inbox.AddStretchSpacer(1)
        inbox.Add(self.midiChoiceInput, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT,
                  PADDING)

        textAutoBinding = wx.StaticText(midiParamPanel, 0,
                                        'Automatic Midi Bindings :')
        textAutoBinding.SetForegroundColour(PREFS_FOREGROUND)
        textAutoBinding.SetFont(self.font)
        self.autoMidiToggle = Toggle(midiParamPanel,
                                     CeciliaLib.getVar("automaticMidiBinding"),
                                     size=(19, 19),
                                     outFunction=self.enableAutomaticBinding)

        autobox = wx.BoxSizer(wx.HORIZONTAL)
        autobox.Add(textAutoBinding, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 5)
        autobox.AddStretchSpacer(1)
        autobox.Add(self.autoMidiToggle, 0,
                    wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, PADDING + 1)

        box.Add(
            Separator(midiParamPanel, size=(350, 1), colour=BACKGROUND_COLOUR))
        box.Add(driverbox, 0, wx.EXPAND | wx.BOTTOM, 7)
        box.Add(inbox, 0, wx.EXPAND | wx.BOTTOM, 7)
        box.Add(autobox, 0, wx.EXPAND | wx.BOTTOM, 7)

        midiParamPanel.SetSizerAndFit(box)

        return midiParamPanel
Beispiel #10
0
    def createAudioPanel(self, panel):
        audioParamPanel = wx.Panel(panel)
        audioParamPanel.SetBackgroundColour(BACKGROUND_COLOUR)

        box = wx.BoxSizer(wx.VERTICAL)

        driverbox = wx.BoxSizer(wx.HORIZONTAL)

        # Audio driver
        textInOutConfig = wx.StaticText(audioParamPanel, 0, 'Audio Driver :')
        textInOutConfig.SetForegroundColour(PREFS_FOREGROUND)
        textInOutConfig.SetFont(self.font)
        self.driverChoice = CustomMenu(audioParamPanel,
                                       choice=AUDIO_DRIVERS,
                                       init=CeciliaLib.getVar("audioHostAPI"),
                                       size=(150, 20),
                                       outFunction=self.onDriverPageChange)

        driverbox.Add(textInOutConfig, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL,
                      5)
        driverbox.AddStretchSpacer(1)
        driverbox.Add(self.driverChoice, 0,
                      wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, PADDING)

        # Audio driver panels
        # Input
        textIn = wx.StaticText(audioParamPanel, 0, 'Input Device :')
        textIn.SetForegroundColour(PREFS_FOREGROUND)
        textIn.SetFont(self.font)
        availableAudioIns = []
        for d in CeciliaLib.getVar("availableAudioInputs"):
            availableAudioIns.append(CeciliaLib.ensureNFD(d))
        try:
            initInput = availableAudioIns[CeciliaLib.getVar(
                "availableAudioInputIndexes").index(
                    CeciliaLib.getVar("audioInput"))]
        except:
            if len(availableAudioIns) >= 1:
                initInput = availableAudioIns[0]
            else:
                initInput = ''
        self.choiceInput = CustomMenu(audioParamPanel,
                                      choice=availableAudioIns,
                                      init=initInput,
                                      size=(150, 20),
                                      outFunction=self.changeAudioInput)
        if CeciliaLib.getVar("enableAudioInput") == 0:
            initInputState = 0
        else:
            initInputState = 1
        self.inputToggle = Toggle(audioParamPanel,
                                  initInputState,
                                  size=(19, 19),
                                  outFunction=self.enableAudioInput)

        # Output
        textOut = wx.StaticText(audioParamPanel, 0, 'Output Device :')
        textOut.SetForegroundColour(PREFS_FOREGROUND)
        textOut.SetFont(self.font)
        availableAudioOuts = []
        for d in CeciliaLib.getVar("availableAudioOutputs"):
            availableAudioOuts.append(CeciliaLib.ensureNFD(d))
        try:
            initOutput = availableAudioOuts[CeciliaLib.getVar(
                "availableAudioOutputIndexes").index(
                    CeciliaLib.getVar("audioOutput"))]
        except:
            if len(availableAudioOuts) >= 1:
                initOutput = availableAudioOuts[0]
            else:
                initOutput = ''
        self.choiceOutput = CustomMenu(audioParamPanel,
                                       choice=availableAudioOuts,
                                       init=initOutput,
                                       size=(150, 20),
                                       outFunction=self.changeAudioOutput)

        inbox = wx.BoxSizer(wx.HORIZONTAL)
        inbox.Add(textIn, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 5)
        inbox.AddStretchSpacer(1)
        inbox.Add(self.inputToggle, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 5)
        inbox.Add(self.choiceInput, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT,
                  PADDING)

        outbox = wx.BoxSizer(wx.HORIZONTAL)
        outbox.Add(textOut, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 5)
        outbox.AddStretchSpacer(1)
        outbox.Add(self.choiceOutput, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT,
                   PADDING)

        # Sample precision
        textSamplePrecision = wx.StaticText(audioParamPanel, 0,
                                            'Sample Precision :')
        textSamplePrecision.SetForegroundColour(PREFS_FOREGROUND)
        textSamplePrecision.SetFont(self.font)
        self.choiceSamplePrecision = CustomMenu(
            audioParamPanel,
            choice=['32 bit', '64 bit'],
            init=CeciliaLib.getVar("samplePrecision"),
            size=(150, 20),
            outFunction=self.changeSamplePrecision)

        # Bit depth
        textBufferSize = wx.StaticText(audioParamPanel, 0, 'Buffer Size :')
        textBufferSize.SetForegroundColour(PREFS_FOREGROUND)
        textBufferSize.SetFont(self.font)
        self.choiceBufferSize = CustomMenu(
            audioParamPanel,
            choice=BUFFER_SIZES,
            init=CeciliaLib.getVar("bufferSize"),
            size=(150, 20),
            outFunction=self.changeBufferSize)

        # Number of channels
        textNCHNLS = wx.StaticText(audioParamPanel, 0,
                                   'Default # of channels :')
        textNCHNLS.SetForegroundColour(PREFS_FOREGROUND)
        textNCHNLS.SetFont(self.font)
        self.choiceNCHNLS = CustomMenu(audioParamPanel,
                                       choice=[str(x) for x in range(1, 37)],
                                       init=str(
                                           CeciliaLib.getVar("defaultNchnls")),
                                       size=(150, 20),
                                       outFunction=self.changeNchnls)

        # Sampling rate
        textSR = wx.StaticText(audioParamPanel, 0, 'Sample Rate :')
        textSR.SetForegroundColour(PREFS_FOREGROUND)
        textSR.SetFont(self.font)
        self.comboSR = CustomMenu(audioParamPanel,
                                  choice=SAMPLE_RATES,
                                  init=str(CeciliaLib.getVar("sr")),
                                  size=(150, 20),
                                  outFunction=self.changeSr)

        # First physical input
        textFPI = wx.StaticText(audioParamPanel, 0, 'First Physical Input :')
        textFPI.SetForegroundColour(PREFS_FOREGROUND)
        textFPI.SetFont(self.font)
        self.choiceFPI = CustomMenu(
            audioParamPanel,
            choice=[str(x) for x in range(36)],
            init=str(CeciliaLib.getVar("defaultFirstInput")),
            size=(150, 20),
            outFunction=self.changeFPI)

        # First physical output
        textFPO = wx.StaticText(audioParamPanel, 0, 'First Physical Output :')
        textFPO.SetForegroundColour(PREFS_FOREGROUND)
        textFPO.SetFont(self.font)
        self.choiceFPO = CustomMenu(
            audioParamPanel,
            choice=[str(x) for x in range(36)],
            init=str(CeciliaLib.getVar("defaultFirstOutput")),
            size=(150, 20),
            outFunction=self.changeFPO)

        sampbox = wx.BoxSizer(wx.HORIZONTAL)
        sampbox.Add(textSamplePrecision, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL,
                    5)
        sampbox.AddStretchSpacer(1)
        sampbox.Add(self.choiceSamplePrecision, 0,
                    wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, PADDING)
        bufbox = wx.BoxSizer(wx.HORIZONTAL)
        bufbox.Add(textBufferSize, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 5)
        bufbox.AddStretchSpacer(1)
        bufbox.Add(self.choiceBufferSize, 0,
                   wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, PADDING)
        chnlbox = wx.BoxSizer(wx.HORIZONTAL)
        chnlbox.Add(textNCHNLS, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 5)
        chnlbox.AddStretchSpacer(1)
        chnlbox.Add(self.choiceNCHNLS, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT,
                    PADDING)
        srbox = wx.BoxSizer(wx.HORIZONTAL)
        srbox.Add(textSR, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 5)
        srbox.AddStretchSpacer(1)
        srbox.Add(self.comboSR, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT,
                  PADDING)
        finbox = wx.BoxSizer(wx.HORIZONTAL)
        finbox.Add(textFPI, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 5)
        finbox.AddStretchSpacer(1)
        finbox.Add(self.choiceFPI, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT,
                   PADDING)
        foutbox = wx.BoxSizer(wx.HORIZONTAL)
        foutbox.Add(textFPO, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 5)
        foutbox.AddStretchSpacer(1)
        foutbox.Add(self.choiceFPO, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT,
                    PADDING)

        box.Add(
            Separator(audioParamPanel, size=(350, 1),
                      colour=BACKGROUND_COLOUR))
        box.Add(driverbox, 0, wx.EXPAND | wx.BOTTOM, 7)
        box.Add(inbox, 0, wx.EXPAND | wx.BOTTOM, 7)
        box.Add(outbox, 0, wx.EXPAND | wx.BOTTOM, 7)
        box.Add(sampbox, 0, wx.EXPAND | wx.BOTTOM, 7)
        box.Add(bufbox, 0, wx.EXPAND | wx.BOTTOM, 7)
        box.Add(chnlbox, 0, wx.EXPAND | wx.BOTTOM, 7)
        box.Add(srbox, 0, wx.EXPAND | wx.BOTTOM, 7)
        box.Add(finbox, 0, wx.EXPAND | wx.BOTTOM, 7)
        box.Add(foutbox, 0, wx.EXPAND | wx.BOTTOM, 7)

        audioParamPanel.SetSizerAndFit(box)

        return audioParamPanel
Beispiel #11
0
        display = wx.Display()
        numDisp = display.GetCount()
        if CeciliaLib.getVar("DEBUG"):
            print 'Numbers of displays:', numDisp
        displays = []
        displayOffset = []
        displaySize = []
        for i in range(numDisp):
            displays.append(wx.Display(i))
            offset = displays[i].GetGeometry()[:2]
            size = displays[i].GetGeometry()[2:]
            if CeciliaLib.getVar("DEBUG"):
                print 'display %d:' % i
                print '    pos =', offset
                print '    size =', size
                print
            displayOffset.append(offset)
            displaySize.append(size)
    except:
        numDisp = 1
        displayOffset = [(0, 0)]
        displaySize = [(1024, 768)]

    CeciliaLib.setVar("numDisplays", numDisp)
    CeciliaLib.setVar("displayOffset", displayOffset)
    CeciliaLib.setVar("displaySize", displaySize)

    sp = CeciliaSplashScreen(None, img=CeciliaLib.ensureNFD(SPLASH_FILE_PATH), callback=onStart)

    app.MainLoop()
Beispiel #12
0
    def makePanel(self, obj=None):
        panel = wx.Panel(self, -1)
        panel.isLoad = False
        if self.needToParse:
            if obj == "Modules":
                if BUILD_RST:
                    create_modules_index()
                panel.win = stc.StyledTextCtrl(panel, -1, size=(600, 480), style=wx.BORDER_SUNKEN)
                panel.win.SetUseHorizontalScrollBar(False)
                panel.win.SetUseVerticalScrollBar(False)
                text = ""
                for cat in _MODULE_CATEGORIES:
                    l = _CATEGORY_OVERVIEW[cat].splitlines()[1].replace('"', '').strip()
                    text += "# %s\n    %s\n" % (cat, l)
                panel.win.SetText(_MODULES_TEXT + text)
            elif obj in _MODULE_CATEGORIES:
                if BUILD_RST:
                    create_category_index(obj, _CATEGORY_OVERVIEW[obj], self.files[obj])
                panel.win = stc.StyledTextCtrl(panel, -1, size=(600, 480), style=wx.BORDER_SUNKEN)
                panel.win.SetUseHorizontalScrollBar(False)
                panel.win.SetUseVerticalScrollBar(False)
                text = _CATEGORY_OVERVIEW[obj]
                for file in self.files[obj]:
                    text += "# %s\n" % file
                    with open(os.path.join(self.root, obj, file), "r") as f:
                        t = f.read()
                        first = t.find('"""')
                        if first != -1:
                            newline = t.find("\n", first)
                            second = t.find('\n', newline + 2)
                            text += t[newline + 1:second].replace('"', '')
                            text += "\n"
                panel.win.SetText(text)
            elif os.path.isfile(obj):
                with open(obj, "r") as f:
                    text = f.read()
                    first = text.find('"""')
                    if first != -1:
                        newline = text.find("\n", first)
                        second = text.find('"""', newline)
                        text = text[newline + 1:second]
                    else:
                        text = '"Module not documented..."'
                    if BUILD_RST:
                        create_module_doc_page(obj, text)
                obj = os.path.split(obj)[1]
                panel.win = stc.StyledTextCtrl(panel, -1, size=(600, 480), style=wx.BORDER_SUNKEN)
                panel.win.SetUseHorizontalScrollBar(False)
                panel.win.SetUseVerticalScrollBar(False)
                panel.win.SetText(text)
            else:
                var = eval(obj)
                if isinstance(var, str):
                    panel.win = stc.StyledTextCtrl(panel, -1, size=(600, 480), style=wx.BORDER_SUNKEN)
                    panel.win.SetUseHorizontalScrollBar(False)
                    panel.win.SetUseVerticalScrollBar(False)
                    panel.win.SetText(var)
                else:
                    text = var.__doc__
                    panel.win = stc.StyledTextCtrl(panel, -1, size=(600, 480), style=wx.BORDER_SUNKEN)
                    panel.win.SetUseHorizontalScrollBar(False)
                    panel.win.SetUseVerticalScrollBar(False)
                    panel.win.SetText(text)

            panel.win.SaveFile(CeciliaLib.ensureNFD(os.path.join(DOC_PATH, obj)))
        return panel
Beispiel #13
0
    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.Append(-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.Append(-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.Append(-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).replace("\n", ""))
                    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.Append(-1, 'Open Recent', self.openRecentMenu,
                             'Access previously opened files in Cecilia')
        self.fileMenu.Append(wx.ID_SEPARATOR, kind=wx.ITEM_SEPARATOR)
        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.Append(wx.ID_SEPARATOR, kind=wx.ITEM_SEPARATOR)
        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").startswith(
                "linux") or CeciliaLib.getVar("systemPlatform") == 'win32':
            self.fileMenu.Append(wx.ID_SEPARATOR, kind=wx.ITEM_SEPARATOR)
        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").startswith(
                "linux") or CeciliaLib.getVar("systemPlatform") == 'win32':
            self.fileMenu.Append(wx.ID_SEPARATOR, kind=wx.ITEM_SEPARATOR)
        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.Append(wx.ID_SEPARATOR, kind=wx.ITEM_SEPARATOR)
            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.Append(wx.ID_SEPARATOR, kind=wx.ITEM_SEPARATOR)
            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.Append(wx.ID_SEPARATOR, kind=wx.ITEM_SEPARATOR)
        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.Append(wx.ID_SEPARATOR, kind=wx.ITEM_SEPARATOR)
        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.Append(wx.ID_SEPARATOR, kind=wx.ITEM_SEPARATOR)
        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.Append(wx.ID_SEPARATOR, kind=wx.ITEM_SEPARATOR)
        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)
        graphItem = helpMenu.Append(ID_GRAPH_FRAME,
                                    'Show Grapher Help\tCtrl+G', '')
        self.frame.Bind(wx.EVT_MENU, self.mainFrame.onGraphFrame, graphItem)

        self.Append(self.fileMenu, '&File')
        self.Append(self.editMenu, '&Edit')
        self.Append(self.actionMenu, '&Action')
        self.Append(windowMenu, '&Window')
        self.Append(helpMenu, '&Help')