Esempio n. 1
0
 def _getCount(self, termObj):
     """get number of pitches to read interactively"""
     query = 'number of pitches?'
     while 1:
         usrStr = dialog.askStr(query, termObj)
         if usrStr == None: return None
         num = drawer.strToNum(usrStr, 'int')
         if num != None and num != 0: return num
         else:
             dialog.msgOut(('%senter a positive or negative integer.\n' % 
                 lang.TAB), termObj)          
Esempio n. 2
0
def getPitch(termObj=None, read=None):
    while 1:
        if read != None:
            usrStr = read
        else:
            usrStr = dialog.askStr("enter a pitch or note name:", termObj)
            if usrStr == None:
                return None
        usrStr = usrStr.lower()  # make sure lower case
        try:
            obj = pitchTools.Pitch(usrStr)
        except error.PitchSyntaxError:
            if read != None:
                return None  # failure
            dialog.msgOut('%sno such pitch exists.\n' % lang.TAB, termObj)
            continue
        return obj
Esempio n. 3
0
def getPitch(termObj=None, read=None):
    while 1:
        if read != None:
            usrStr = read
        else:
            usrStr = dialog.askStr("enter a pitch or note name:", termObj)
            if usrStr == None:
                return None
        usrStr = usrStr.lower() # make sure lower case
        try:
            obj = pitchTools.Pitch(usrStr)
        except error.PitchSyntaxError: 
            if read != None:    
                return None # failure
            dialog.msgOut('%sno such pitch exists.\n' % lang.TAB, termObj)
            continue
        return obj
Esempio n. 4
0
    def _makeObj(self, ao=None, read=None):
        """ returns sc, pcset, trans from 0=C, and inv
        read arg allows non-interactive use: provide data as arg
        can be used to replace calls to getSet
        pass an ao to get references and termObj
        """
        if ao != None:
            termObj = ao.termObj
            dlgVisMet = ao.external.getPref('athena', 'dlgVisualMethod')
            fpLastDir = ao.aoInfo['fpLastDir']
        else:  # get defaults
            termObj = None
            dlgVisMet = 'txt'
            fpLastDir = ''

        attempts = 0
        usrStrType = None  # not yet known what format user provided
        while 1:
            if read != None:  # method must return result, not interactive
                if attempts > 0:
                    return None  # dont run more than once when reading
                usrStr = read  # assign to usrStr for parsing
            else:
                usrStr = dialog.askStr(lang.msgSCgetSet, termObj)
                if usrStr == None: return None
            attempts = attempts + 1
            usrStrType = self._parseSetInputType(usrStr, termObj)
            # may get one or the other of these as input values
            scFound = None
            psSet = None
            try:
                if usrStrType == 'forte':
                    scFound = self._parseForte(usrStr)
                elif usrStrType == 'psName':
                    psSet = self._parsePsName(usrStr)
                elif usrStrType == 'psReal':
                    psSet = self._parsePsReal(usrStr)
                elif usrStrType == 'sieve':
                    psSet = self._parseSieve(usrStr)
                elif usrStrType == 'midi':
                    psSet = self._parseMidi(usrStr)
                elif usrStrType == 'fq':
                    psSet = self._parseFq(usrStr)
                elif usrStrType == 'txt':
                    psSet = self._parseTxt(usrStr)
                # import will get a file dialog
                elif usrStrType == 'import':
                    msg, ok = dialog.promptGetFile(lang.msgSCgetAudacity,
                                                   fpLastDir, 'file',
                                                   dlgVisMet, termObj)
                    count = self._getCount(
                        termObj)  # count may be equal to None
                    # call parse text after getting file path
                    if ok: psSet = self._parseTxt(msg, count)
                    else: return None  # cancel
                else: return None
            except error.MultisetError:
                dialog.msgOut(lang.msgSCnoSuchSet, termObj)
                continue
            try:
                obj = Multiset(psSet, scFound)
            except error.MultisetError:
                return None  # will be understood as error

            if read == None:  # dont check response
                sc = obj.repr('sc')
                ps = obj.repr('psName')
                query = lang.TAB + 'SC %s as %s? ' % (sc, ps)
                ok = dialog.askYesNoCancel(query, 1, termObj)
                if ok != -1 and ok != 1: continue  # return to top
                elif ok == -1: return None  # destroy obj
            return obj
Esempio n. 5
0
    def _makeObj(self, ao=None, read=None):
        """ returns sc, pcset, trans from 0=C, and inv
        read arg allows non-interactive use: provide data as arg
        can be used to replace calls to getSet
        pass an ao to get references and termObj
        """
        if ao != None:
            termObj = ao.termObj
            dlgVisMet = ao.external.getPref('athena', 'dlgVisualMethod')
            fpLastDir = ao.aoInfo['fpLastDir']
        else: # get defaults
            termObj = None
            dlgVisMet = 'txt'
            fpLastDir = ''
        
        attempts = 0
        usrStrType = None # not yet known what format user provided
        while 1:
            if read != None: # method must return result, not interactive
                if attempts > 0: return None # dont run more than once when reading
                usrStr = read # assign to usrStr for parsing
            else:
                usrStr = dialog.askStr(lang.msgSCgetSet, termObj)
                if usrStr == None: return None
            attempts = attempts + 1
            usrStrType = self._parseSetInputType(usrStr, termObj)
            # may get one or the other of these as input values
            scFound = None
            psSet = None
            try:
                if usrStrType == 'forte':
                    scFound = self._parseForte(usrStr)
                elif usrStrType == 'psName':
                    psSet = self._parsePsName(usrStr)
                elif usrStrType == 'psReal':
                    psSet = self._parsePsReal(usrStr)
                elif usrStrType == 'sieve':
                    psSet = self._parseSieve(usrStr)
                elif usrStrType == 'midi':
                    psSet = self._parseMidi(usrStr)
                elif usrStrType == 'fq':
                    psSet = self._parseFq(usrStr)
                elif usrStrType == 'txt':
                    psSet = self._parseTxt(usrStr)
                # import will get a file dialog
                elif usrStrType == 'import':
                    msg, ok = dialog.promptGetFile(lang.msgSCgetAudacity, 
                                             fpLastDir, 'file', dlgVisMet, termObj)
                    count = self._getCount(termObj) # count may be equal to None
                    # call parse text after getting file path
                    if ok: psSet = self._parseTxt(msg, count)
                    else: return None # cancel
                else: return None
            except error.MultisetError:
                dialog.msgOut(lang.msgSCnoSuchSet, termObj)
                continue
            try:
                obj = Multiset(psSet, scFound)
            except error.MultisetError:
                return None # will be understood as error

            if read == None: # dont check response
                sc = obj.repr('sc')
                ps = obj.repr('psName')
                query = lang.TAB + 'SC %s as %s? ' % (sc, ps)
                ok = dialog.askYesNoCancel(query, 1, termObj)               
                if ok != -1 and ok != 1:  continue  # return to top
                elif ok == -1: return None # destroy obj    
            return obj