Exemplo n.º 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!
Exemplo n.º 2
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
Exemplo n.º 3
0
 def getInputcontrol(self):
     """get the Click by Voice input control"""
     keystroke("{shift+ctrl+space}")
     unimacroutils.Wait()  ## longer: unimacroutils.Wait(visiblePause)
     for i in range(10):
         progInfo = unimacroutils.getProgInfo()
         if progInfo.topchild == 'child':
             if i: print('found input window after %s steps' % i)
             break
         unimacroutils.Wait()
     else:
         print("_clickbyvoice failed to reach input window")
     # print("found input window of clickbyvoice")
     unimacroutils.visibleWait()
Exemplo n.º 4
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
Exemplo n.º 5
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)
Exemplo n.º 6
0
    def doAction(self):
        ##         debugPrint('start doAction state: %s, dir: %s, count: %s'% \
        ##                   (self.state, self.curDir, self.Count))
        if self.state in ['moving', 'selecting', 'searching']:
            if not self.curDir:
                debugPrint('do action, no direction specified')
                return
            key = 'ext' + self.curDir
            if self.minorState == 'page':
                if self.curDir == 'down':
                    key = 'extpgdn'
                elif self.curDir == 'up':
                    key = 'extpgup'
                else:
                    debugPrint('invalid direction for minorState page: %s' %
                               self.curDir)
            elif self.minorState in ['word', 'paragraph']:
                key = 'ctrl+' + key

            if self.waiting and self.Count:
                nowCount = " " + repr(self.Count)
            else:
                nowCount = ""

        if self.state == 'moving':
            if self.startScroll:
                keyBefore = ''
                if self.curDir == 'up': keyBefore = 'extpgup'
                elif self.curDir == 'down': keyBefore = 'extpgdn'
                elif self.curDir == 'left': keyBefore = 'ctrl+extpgdn'
                elif self.curDir == 'right': keyBefore = 'ctrl+extpgup'
                else:
                    debugPrint('invalid direction in scrollcommand: %s' %
                               self.curDir)
                if keyBefore:
                    natlinkutils.playString("{" + keyBefore + "}")
                self.startScroll = 0
            self.setTrayIcon(1)
            natlinkutils.playString("{" + key + nowCount + "}")

        elif self.state == 'selecting':
            self.setTrayIcon(1)
            natlinkutils.playString("{shift+" + key + nowCount + "}")
        elif self.state == 'repeating':
            self.setTrayIcon(1)
            self.repeatNow()
        elif self.state == 'searching':
            self.setTrayIcon(1)
            if not self.curDir:
                print('searching, no current direction: %s, assume down' %
                      self.curDir)
                self.curDir = self.getLastSearchDirection() or 'down'
            self.insideCommand = 1
            count = self.Count or 1
            for i in range(count):
                res = self.searchForText(self.curDir)
                self.curDir = self.getLastSearchDirection()
                if res == -2:
                    # missing search, did cancel mode
                    return
            unimacroutils.visibleWait()
            self.insideCommand = 0
        elif self.state == 'mousing':
            self.setTrayIcon(1)
            if self.Count:
                self.moveMouse(self.curDir, self.Count * self.mouseJumps)
            else:
                self.moveMouse(self.curDir, self.mouseSteps)
        elif self.state == 'dragging':
            self.setTrayIcon(1)
            if self.Count:
                self.moveMouse(self.curDir, self.Count * self.mouseJumps)
            else:
                self.moveMouse(self.curDir, self.mouseSteps)
        else:
            return

        self.lastClock = time.time()
        return 1  # good exit
Exemplo n.º 7
0
 def gotResults_lastkey(self, words, fullResults):
     self.flush()
     self.flushAll()
     unimacroutils.visibleWait()
Exemplo n.º 8
0
 def finishInputControl(self):
     """press enter, after a little bit of waiting
     """
     unimacroutils.visibleWait()
     unimacroutils.visibleWait()
     keystroke("{enter}")