예제 #1
0
    def rule_figure(self, words):
        """here figure {figures}+"""
        # start with the pointer in the music pane
        # always click
        unimacroutils.buttonClick()
        unimacroutils.visibleWait()
        self.hadFigure = 1

        selection = self.getFigurePart()
        if not selection:
            print 'rule_figure, no selection found, stop macro'
            return

        # print 'figurepart: %s'% selection
        L = []
        previous = None
        for w in words:
            figure = self.getFromInifile(w, 'figures')
            # print 'figure: %s, result: %s'% (w, figure)
            if figure:
                if previous and self.isFigure(
                        previous) and not self.isFigure(figure):
                    if figure.startswith("_"):
                        figure = figure.lstrip("_")
                    L[-1] = L[-1] + figure
                else:
                    L.append(figure)
                previous = figure
        self.keystroke("<" + ' '.join(L) +
                       ">")  # allow for { , not being a control character!
예제 #2
0
    def rule_cardnumto(self, words):
        "[card] {cnum} to ((stack {snum})|{cnum})"
        #card with number to a stack or another card column
        #
        #the first word is optional,and is recognised with the function
        #self.hasCommon, which can handle translations or synonyms
        print('cardnumto: %s' % words)
        unimacroutils.rememberMouse()
        if self.hasCommon(words[0], ['card']):
            ww = words[1:]
        else:
            ww = words[:]

        # go to numbered card with mouse:
        From = self.getNumberFromSpoken(words[0])
        self.moveTo(cardpos(From))

        unimacroutils.rememberMouse()
        to = self.getNumberFromSpoken(words[-1])

        # check if you go to a stack or another card column:
        if self.hasCommon(words, 'stack'):
            to = firstrowpos(to + 3)
        else:
            to = cardpos(to)
        self.dragTo(to)
        unimacroutils.cancelMouse()
        unimacroutils.buttonClick()
예제 #3
0
 def rule_newcard(self, words):
     "'new card'|next|continue"
     self.moveTo(firstrowpos(1))
     unimacroutils.buttonClick()
     self.moveTo(firstrowpos(2))
     if self.hasCommon(words, 'continue'):
         timeEachMilliseconds = max(1, self.pauseTime) * 500
         print('set the timer to %s' % timeEachMilliseconds)
         natlink.setTimerCallback(self.onTimer, timeEachMilliseconds)
         self.inTimer = 1
예제 #4
0
    def gotResults_click(self, words, fullResults):
        """do click, with mouse, rule
        
        modifiers can be set
        """
        # print 'click rule: %s (modifiers: %s), prevrule: %s'% (words, self.mod, self.prevRule)
        self.flush()
        if self.key:
            self.flushAll()
        if self.prevRule is None or self.prevRule in [
                'startrule', 'modifiers'
        ]:
            if not self.doWaitForMouseToStop():
                print('_keystrokes, click, cancel command')
                return
        else:
            if not self.doMouseMoveStopClick():
                print("you should move the mouse a bit at least!")
                return
        possibleButtons = unimacroutils.joelsButtons
        possibleClicks = ['1', '2', '3']
        clickrules = self.getFromInifile(words[0], 'click')
        #print 'clickrules: %s'% clickrules
        if not clickrules:
            print('_keystrokes: no valid clickrule')
            return
        parts = [s.strip() for s in clickrules.split(',')]
        button = parts[0]
        if not button in possibleButtons:
            print('button should be one of %s' % possibleButtons)
            return
        if len(parts) > 1:

            if parts[1] not in possibleClicks:
                print('number of clicks (%s) should be one of %s' %
                      (parts[1], possibleClicks))
                return
            nClick = int(parts[1])
        else:
            nClick = 1

        if len(parts) > 2:
            print(
                'currently only (button, clicks) allowed in clickrule, not: %s'
                % clickrules)
            return

        if self.nextRule == 'contextmenu' and nClick == 1:
            button = 'right'
        unimacroutils.buttonClick(button, nClick, modifiers=self.mod)
        unimacroutils.visibleWait()
        self.hadClick = button
예제 #5
0
    def rule_to(self, words):
        "to ((stack {snum})|{cnum})"

        to = self.getNumberFromSpoken(words[-1])
        unimacroutils.rememberMouse()

        if self.hasCommon(words, 'stack'):
            to = firstrowpos(to + 3)
        else:
            to = cardpos(to)
        self.dragTo(to)
        unimacroutils.cancelMouse()
        unimacroutils.buttonClick()
예제 #6
0
 def rule_notesinsert(self, words):
     """[here] insert [<sequence>]"""
     ###
     ### position at correct position, possibly put a space.
     if self.hasCommon(words, 'here'):
         unimacroutils.buttonClick()
     self.getPrevNext()
     # position at left of word
     while self.inMiddleOfWord:
         keystroke("{left}")
         self.getPrevNext()
     # and put a space:
     keystroke("{space}{left}")
     self.getPrevNext()
예제 #7
0
    def gotResults(self, words, fullResults):

        #  see if something selected, leaving the clipboard intact
        #  keystroke('{ctrl+x}')  # try to cut the selection
        if self.between:
            cb = Clipboard(save_clear=True)
            action('<<cut>>')
            text = cb.get_text(waiting_interval=0.1, waiting_iterations=3)
        else:
            text = ""

        if self.here:
            unimacroutils.buttonClick('left', 1)
            unimacroutils.visibleWait()

        leftText = rightText = leftTextDict = rightTextDict = ""
        if text:
            # strip from clipboard text:
            text, leftText, rightText = stripFromBothSides((text))

        if self.dictated.strip():
            text, leftTextDict, rightTextDict = stripFromBothSides(self.dictated)
        elif self.dictated:
            # the case of only a space-bar:
            leftTextDict = self.dictated


        lSpacing = leftText + leftTextDict
        rSpacing = rightTextDict + rightText

        if lSpacing:
            keystroke(lSpacing)

        action(self.pleft)
        unimacroutils.visibleWait()
        if text:
            #print 'text: |%s|'% repr(text)
            keystroke(text)
        unimacroutils.visibleWait()
        action(self.pright)
        unimacroutils.visibleWait()

        if rSpacing:
            keystroke(rSpacing)

        if not text:
            # go back so you stand inside the (brackets):
            nLeft = len(self.pright) + len(rSpacing)
            keystroke('{left %s}'% nLeft)
예제 #8
0
 def gotResults_before(self, words, fullResults):
     """optional for here or keystroke multiple words even allowed"""
     if not self.hasCommon(words, 'here'):
         print('got words in "before" rule, but not "here": %s' % words)
         return
     # do a click, or (if next rule == contextmenu) a right click.
     button, nClick = 'left', 1
     if self.nextRule == 'contextmenu':
         button = 'right'
     #print '_keystrokes, do a "%s" mouse click'% button
     if not self.doWaitForMouseToStop():
         raise Exception("_keystrokes, mouse did not stop")
     unimacroutils.buttonClick(button, nClick)
     unimacroutils.visibleWait()
     self.hadClick = button
예제 #9
0
    def rule_cardto(self, words):
        "card to ((stack {snum})|{cnum})"
        #drag the last drawn card to a stack or to a pile
        print('cardto: %s' % words)

        unimacroutils.rememberMouse()
        self.moveTo(firstrowpos(2))
        to = self.getNumberFromSpoken(words[-1])

        if self.hasCommon(words, 'stack'):
            to = firstrowpos(to + 3)
        else:
            to = cardpos(to)
        self.dragTo(to)
        unimacroutils.cancelMouse()
        unimacroutils.buttonClick()
예제 #10
0
 def subrule_notesnavigate(self, words):
     "here | [here] [next] (note | {n2-20} notes)"
     # leave next|previous for the moment, assume always count from the beginning
     DIR = 'right'
     if self.hasCommon(words, 'here'):
         unimacroutils.buttonClick()
     try:
         nStr = self.getNumbersFromSpoken(words)[
             0]  # returns a string or None
         n = int(nStr)
     except IndexError:
         n = 1
     if n == 1:
         gotoNext = self.hasCommon(words, 'next')
         if gotoNext:
             print 'move right one note! Todo'
     self.notesWanted = n
     print 'get %s notes' % n
     self.getNextNotes(n)
     print 'notesNavigate, wordsList: %s' % self.wordsList
예제 #11
0
 def gotResults_before(self, words, fullResults):
     if self.hasCommon(words, 'here'):
         if not self.doWaitForMouseToStop():
             print('excel, mouse does not stop, cancel command')
             return
         unimacroutils.buttonClick()
예제 #12
0
 def rule_card(self, words):
     "card {cnum}"
     k = self.getNumberFromSpoken(words[-1])
     self.moveTo(cardpos(k))
     unimacroutils.buttonClick()