示例#1
0
    def getPrevNotes(self, n=1):
        if self.justLeft is None:
            self.getPrevNext()
        if self.prevchars is None:
            self.prevchars = self.frescobaldi.getPrevLine()
        if self.inMiddleOfWord:
            print 'inMiddleOfWord %s' % self.inMiddleOfWord
            lastWord = self.prevchars.split()[-1]
            numcharsleft = len(lastWord)
            print 'go left %s characters' % numcharsleft
            keystroke("{left %s}" % numcharsleft)
            self.justLeft, self.justRight = self.prevchars[
                -numcharsleft - 1], self.prevchars[-numcharsleft]
            print 'after go left: justLeft: %s, justRight: %s' % self.justLeft, self.justRight
            self.getPrevNextVariables(self, self.justLeft, self.justRight)
            self.prevchars = self.prevchars[:-numcharsleft]
            print 'prevchars after go left to beginning of note: %s' % repr(
                self.prevchars)

        print 'prevchars: %s' % repr(self.prevchars)
        wordsList, notesIndexes = analyseString(self.prevchars)
        print 'wordsList: %s, notesIndexes: %s' % (wordsList, notesIndexes)
        notesFound = len(notesIndexes)

        if notesFound <= n:
            moreLines = 5
            print 'get %s more lines' % moreLines
            prevchars = self.frescobaldi.getPrevLine(moreLines)
            if prevchars == self.prevchars:
                raise Exception(
                    "getPrevNotes, not enough notes found: %s, wanted: %s" %
                    (notesFound, n))
            print '%s more lines prev:\n%s' % (moreLines, repr(prevchars))
            self.prevchars = prevchars

            wordsList, notesIndexes = analyseString(self.prevchars)
            notesFound = len(notesIndexes)
            print '----prevchars: %s' % repr(self.prevchars)
            if notesFound < n:
                print 'notesFound: %s' % notesFound
                print 'wordsList: %s, notesIndexes: %s' % (wordsList,
                                                           notesIndexes)
                raise Exception(
                    "too little notes caught in %s lines up: %s, wanted: %s" %
                    (moreLines, notesFound, n))
        else:
            self.hasAllInfoPrev = True  ## know enough

        wordsList, notesIndexes, afterNotes, beforeNotes, beforeNoteComplete = \
                              getNotesFromWordsList(n, wordsList, notesIndexes, reverse=True)
        beforeNoteComplete = beforeNoteComplete or self.hasAllInfoPrev
        return wordsList, notesIndexes, afterNotes, beforeNotes, beforeNoteComplete
示例#2
0
    def getNextNotes(self, n=1):
        if self.nextchars is None:
            self.nextchars = self.frescobaldi.getNextLine()
        print 'nextchars: |%s|' % self.nextchars
        if self.justLeft is None:
            self.getPrevNext()
        if self.inMiddleOfWord:
            print 'inMiddleOfWord %s' % self.inMiddleOfWord
            if not self.prevchars:
                self.prevchars = self.frescobaldi.getPrevLine()
            lastWord = self.prevchars.split()[-1]
            numcharsleft = len(lastWord)
            print 'go left %s characters' % numcharsleft
            keystroke("{left %s}" % numcharsleft)
            self.getPrevNext()
            self.nextchars = self.frescobaldi.getNextLine()

        print 'nextchars: %s' % repr(self.nextchars)
        wordsList, notesIndexes = analyseString(self.nextchars)
        print 'wordsList: %s, notesIndexes: %s' % (wordsList, notesIndexes)
        notesFound = len(notesIndexes)

        if notesFound <= n:
            moreLines = 5
            print 'get %s more lines' % moreLines
            nextchars = self.frescobaldi.getNextLine(moreLines)
            # nextcharsplit = self.nextchars.split('\n\n') # double empty line ends the search
            # if len(nextcharsplit) > 1:
            #     self.hasAllInfoNext = True
            # self.nextchars = nextcharsplit[0]
            if nextchars == self.nextchars:
                raise Exception(
                    "getNextNotes, not enough notes found: %s, wanted: %s" %
                    (notesFound, n))
            self.nextchars = nextchars
            wordsList, notesIndexes = analyseString(self.nextchars)
            notesFound = len(notesIndexes)
            print '----nextchars: %s' % repr(self.nextchars)
            if notesFound < n:
                print 'notesFound: %s' % notesFound
                print 'wordsList: %s, notesIndexes: %s' % (wordsList,
                                                           notesIndexes)
                raise Exception(
                    "too little notes caught in %s lines down: %s, wanted: %s"
                    % (moreLines, notesFound, n))
        else:
            self.hasAllInfoNext = True
        wordsList, notesIndexes, beforeNotes, afterNotes, afterNoteComplete = \
                              getNotesFromWordsList(n, wordsList, notesIndexes)
        afterNoteComplete = afterNoteComplete or self.hasAllInfoNext
        return wordsList, notesIndexes, beforeNotes, afterNotes, afterNoteComplete
示例#3
0
    def doTestGetNotesFromWordsList(self,
                                    maxWords,
                                    wordsList,
                                    notesIndexes,
                                    expWords,
                                    expNotesIndexes,
                                    expBeforeNotes,
                                    expAfterNotes,
                                    expAfterNoteComplete,
                                    reverse=False):
        """test the variants for the getting of notes from a wordslist
        
        normal, for next notes and reverse, for previous notes.
        
        is called from routines below. several notes are tested in one run
        
        """
        for expName in 'expWords', 'expNotesIndexes', 'expBeforeNotes', 'expAfterNotes', 'expAfterNoteComplete':
            exp = locals()[expName]
            self.assertEqual(
                maxWords, len(exp),
                'doTestGetNotesFromWordsList, %s should be sequence of length %s, not %s\nwordsList: %s'
                % (expName, maxWords, len(expWords), repr(wordsList)))

        if reverse:
            # setting expBeforeNoteComplete:
            expBeforeNoteComplete = expAfterNoteComplete

        for i in range(maxWords):
            numWords = i + 1
            print '---testing %s words from %s' % (numWords, wordsList)

            if reverse:
                # tricky with calling names:
                gotWordsList, gotNotesIndexes, afterNotes, beforeNotes, beforeNoteComplete = \
                        lynote.getNotesFromWordsList(numWords, wordsList, notesIndexes, reverse=reverse)
            else:
                gotWordsList, gotNotesIndexes, beforeNotes, afterNotes, afterNoteComplete = \
                        lynote.getNotesFromWordsList(numWords, wordsList, notesIndexes)
            gotWords = [str(a) for a in gotWordsList]

            self.assertEqual(
                expWords[i], gotWords,
                'words of getNotesFromWordsList (%s) not as expected\nexpected: %s\ngot: %s'
                % (numWords, expWords[i], gotWords))
            self.assertEqual(
                expNotesIndexes[i], gotNotesIndexes,
                'noteIndexes of getNotesFromWordsList (%s) not as expected\nexpected: %s\ngot: %s'
                % (numWords, expNotesIndexes[i], gotNotesIndexes))
            if reverse:
                # for previous words:
                self.assertEqual(
                    expBeforeNotes[i], beforeNotes,
                    'REVERSE: beforeNotes of getNotesFromWordsList (%s) not as expected\nexpected: %s\ngot: %s'
                    % (numWords, repr(expBeforeNotes[i]), repr(beforeNotes)))
                self.assertEqual(
                    expAfterNotes[i], afterNotes,
                    'REVERSE: afterNotes of getNotesFromWordsList (%s) not as expected\nexpected: %s\ngot: %s'
                    % (numWords, repr(expAfterNotes[i]), repr(afterNotes)))
                self.assertEqual(
                    expBeforeNoteComplete[i], beforeNoteComplete,
                    'REVERSE beforeNoteCompleteof getNotesFromWordsList (%s) not as expected\nexpected: %s\ngot: %s'
                    % (numWords, expBeforeNoteComplete[i], beforeNoteComplete))
            else:
                # normal case, next words:
                self.assertEqual(
                    expBeforeNotes[i], beforeNotes,
                    'beforeNotes of getNotesFromWordsList (%s) not as expected\nexpected: %s\ngot: %s'
                    % (numWords, repr(expBeforeNotes[i]), repr(beforeNotes)))
                self.assertEqual(
                    expAfterNotes[i], afterNotes,
                    'afterNotes of getNotesFromWordsList (%s) not as expected\nexpected: %s\ngot: %s'
                    % (numWords, repr(expAfterNotes[i]), repr(afterNotes)))
                self.assertEqual(
                    expAfterNoteComplete[i], afterNoteComplete,
                    'afterNoteCompleteof getNotesFromWordsList (%s) not as expected\nexpected: %s\ngot: %s'
                    % (numWords, expAfterNoteComplete[i], afterNoteComplete))