Exemple #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)
Exemple #2
0
 def openRecent(self, event):
     menu = self.GetMenuBar()
     id = event.GetId()
     file = menu.FindItemById(id).GetLabel().replace("\n", "").strip()
     if os.path.isfile(file):
         CeciliaLib.openCeciliaFile(self, file)
     else:
         CeciliaLib.showErrorDialog("Error while trying to open a file!", "No such file : %s" % file[:-1])
         self.newRecent(file, remove=True)
Exemple #3
0
 def MouseRightDown(self, evt):
     if self._enable:
         rec = wx.Rect(5, 13, 45, 45)
         pos = evt.GetPosition()
         if rec.Contains(pos):
             if evt.ShiftDown():
                 self.setMidiCtl(None)
             else:
                 if CeciliaLib.getVar("useMidi"):
                     CeciliaLib.getVar("audioServer").midiLearn(self)
                     self.inMidiLearnMode()
                 else:
                     CeciliaLib.showErrorDialog("Midi not initialized!",
                         "There is no Midi interface connected!")
     evt.Skip()
 def OnClose(self):
     self.Destroy()
     if not CeciliaLib.getUseMidi():
         CeciliaLib.showErrorDialog("Midi not initialized!", 
                                    "If you want to use Midi, please connect your interface and restart Cecilia")    
Exemple #5
0
def buildTogglePopupBox(parent, list):
    mainBox = wx.BoxSizer(wx.VERTICAL)
    outBox = wx.BoxSizer(wx.VERTICAL)
    objects = []

    widgetlist = [
        widget for widget in list
        if widget['type'] in ['cpopup', 'ctoggle', 'cbutton']
    ]
    widgetCecList = [widget for widget in list if widget['type'] == 'cgen']
    widgetpoly = [widget for widget in list if widget['type'] == 'cpoly']

    for i, widget in enumerate(widgetlist):
        if widget['type'] == 'cpopup':
            tooltip = widget.get('help', '')
            name = widget['name']
            label = widget.get('label', '')
            values = widget.get('value')
            init = widget.get('init', values[0])
            rate = widget.get('rate', 'k')
            if rate == 'k':
                col = widget.get('col', '')
                if col == '':
                    col = random.choice(list(COLOUR_CLASSES.keys()))
                elif col not in COLOUR_CLASSES.keys():
                    CeciliaLib.showErrorDialog(
                        'Wrong colour!',
                        '"%s"\n\nAvailable colours for -col flag are:\n\n%s.' %
                        (col, ', '.join(COLOUR_CLASSES.keys())))
                    col = random.choice(list(COLOUR_CLASSES.keys()))
                colour = CeciliaLib.chooseColourFromName(col)
            else:
                colour = CeciliaLib.chooseColourFromName("grey")
            cpopup = CECPopup(parent, label, values, init, rate, name, colour)
            box = wx.FlexGridSizer(1, 2, 2, 10)
            box.AddMany([(cpopup.label, 0, wx.TOP | wx.ALIGN_RIGHT, 2),
                         (cpopup.popup, 0, wx.TOP | wx.ALIGN_LEFT, 2)])
            mainBox.Add(box, 0, wx.TOP | wx.BOTTOM, 1)
            objects.append(cpopup)

        elif widget['type'] == 'ctoggle':
            tooltip = widget.get('help', '')
            name = widget['name']
            label = widget.get('label', '')
            stack = widget.get('stack', False)
            init = widget.get('init', 0)
            rate = widget.get('rate', 'k')
            if rate == 'k':
                col = widget.get('col', '')
                if col == '':
                    col = random.choice(list(COLOUR_CLASSES.keys()))
                elif col not in COLOUR_CLASSES.keys():
                    CeciliaLib.showErrorDialog(
                        'Wrong colour!',
                        '"%s"\n\nAvailable colours for -col flag are:\n\n%s.' %
                        (col, ', '.join(COLOUR_CLASSES.keys())))
                    col = random.choice(list(COLOUR_CLASSES.keys()))
                colour = CeciliaLib.chooseColourFromName(col)
            else:
                colour = CeciliaLib.chooseColourFromName("grey")
            ctoggle = CECToggle(parent, label, init, rate, name, colour,
                                tooltip, stack)
            if stack and label != '':
                labelBox = wx.FlexGridSizer(1, 1, 2, 10)
                labelBox.Add(ctoggle.label, 0, wx.EXPAND | wx.TOP, 2)
                mainBox.Add(labelBox, 0, wx.TOP | wx.BOTTOM, 1)
                stackBox = wx.FlexGridSizer(1, 8, 2, 7)
                stackBox.Add(ctoggle.toggle, 0, wx.TOP, 2)
                mainBox.Add(stackBox, 0, wx.TOP | wx.BOTTOM, 1)
            elif stack:
                stackBox.Add(ctoggle.toggle, 0, wx.TOP | wx.ALIGN_LEFT, 2)
            else:
                box = wx.FlexGridSizer(1, 2, 2, 10)
                box.AddMany([(ctoggle.label, 0, wx.TOP | wx.ALIGN_RIGHT, 2),
                             (ctoggle.toggle, 0, wx.TOP | wx.ALIGN_LEFT, 2)])
                mainBox.Add(box, 0, wx.TOP | wx.BOTTOM, 1)
            objects.append(ctoggle)

        elif widget['type'] == 'cbutton':
            tooltip = widget.get('help', '')
            name = widget['name']
            label = widget.get('label', '')
            col = widget.get('col', '')
            if col == '':
                col = random.choice(list(COLOUR_CLASSES.keys()))
            elif col not in COLOUR_CLASSES.keys():
                CeciliaLib.showErrorDialog(
                    'Wrong colour!',
                    '"%s"\n\nAvailable colours for -col flag are:\n\n%s.' %
                    (col, ', '.join(COLOUR_CLASSES.keys())))
                col = random.choice(list(COLOUR_CLASSES.keys()))
            colour = CeciliaLib.chooseColourFromName(col)
            cbutton = CECButton(parent, label, name, colour, tooltip)
            box = wx.FlexGridSizer(1, 2, 2, 10)
            box.AddMany([(cbutton.label, 0, wx.TOP | wx.ALIGN_RIGHT, 2),
                         (cbutton.button, 0, wx.TOP | wx.ALIGN_LEFT, 2)])
            mainBox.Add(box, 0, wx.TOP | wx.BOTTOM, 1)
            objects.append(cbutton)

    for i, widget in enumerate(widgetCecList):
        tooltip = widget.get('help', '')
        name = widget['name']
        init = widget.get('init', '1')
        label = widget.get('label', '')
        rate = widget.get('rate', 'k')
        if rate == 'k':
            col = widget.get('col', '')
            if col == '':
                col = random.choice(list(COLOUR_CLASSES.keys()))
            elif col not in COLOUR_CLASSES.keys():
                CeciliaLib.showErrorDialog(
                    'Wrong colour!',
                    '"%s"\n\nAvailable colours for -col flag are:\n\n%s.' %
                    (col, ', '.join(COLOUR_CLASSES.keys())))
                col = random.choice(list(COLOUR_CLASSES.keys()))
            colour = CeciliaLib.chooseColourFromName(col)
        else:
            colour = CeciliaLib.chooseColourFromName("grey")
        popup = widget.get("popup", None)
        ok = False
        if popup is not None:
            for obj in objects:
                if obj.name == popup[0]:
                    popup = (obj, popup[1])
                    ok = True
                    break
        if not ok: popup = None
        clist = CECGen(parent, label, init, rate, name, popup, colour, tooltip)
        box = wx.FlexGridSizer(1, 2, 2, 10)
        box.AddMany([(clist.label, 0, wx.TOP | wx.ALIGN_RIGHT, 2),
                     (clist.entry, 0, wx.ALIGN_LEFT | wx.TOP, 2)])
        mainBox.Add(box, 0, wx.TOP | wx.BOTTOM, 1)
        objects.append(clist)

    for i, widget in enumerate(widgetpoly):
        tooltip = widget.get('help', '')
        name = widget['name']
        minvoices = widget.get('min', 1)
        maxvoices = widget.get('max', 10)
        values = [str(voice) for voice in range(minvoices, maxvoices + 1)]
        init = widget.get('init', values[0])
        label = widget.get('label', '')
        colour = [CPOLY_COLOUR, CPOLY_COLOUR]
        cpoly = CECPoly(parent, label, name, values, init, colour, tooltip)
        box = wx.FlexGridSizer(0, 2, 2, 10)
        box.AddMany([(cpoly.popup.label, 0, wx.TOP | wx.ALIGN_RIGHT, 2),
                     (cpoly.popup.popup, 0, wx.ALIGN_LEFT | wx.TOP, 2),
                     (cpoly.chord.label, 0, wx.TOP | wx.ALIGN_RIGHT, 2),
                     (cpoly.chord.popup, 0, wx.ALIGN_LEFT | wx.TOP, 2)])
        mainBox.Add(box, 0, wx.TOP | wx.BOTTOM, 1)
        objects.append(cpoly.popup)
        objects.append(cpoly.chord)

    outBox.Add(mainBox, 0, wx.ALL, 5)
    return outBox, objects