def DISABLED_test_natlink_timer(self):
        return

        callback_occurred = False
        def callback():
            callback_occurred = True
        ticks = 200

        import time
        import natlink
        natlink.natConnect()
        try:
            natlink.setTimerCallback(callback, ticks)
#            time.sleep(1)
            import sys
            import time
            import win32gui
            timeout = time.time() + 3
            while time.time() < timeout:
                print("Luke")
                sys.stdout.flush()
                if win32gui.PumpWaitingMessages():
                    raise RuntimeError("We got an unexpected WM_QUIT message!")
                time.sleep(1)
            natlink.setTimerCallback(None, 0)
            print("callback occurred:", callback_occurred)
        finally:
            natlink.natDisconnect()
Пример #2
0
 def cancelMode(self):
     self.curMode = None
     if self.haveCallback: 
         natlink.setTimerCallback(None,0)
         self.haveCallback = 0
     self.activateSet(['start'],exclusive=0)
     natlink.setTrayIcon()
Пример #3
0
 def gotResults_nowMousing(self,words,fullResults):
     direction = findKeyWord(words,self.listDefn['direction'])
     if direction:
         self.curDirection = direction
     elif 'stop' in words:
         self.cancelMode()
     elif 'faster' in words:
         speed = int(self.curSpeed / moveRateChange)
         pixels = self.curPixels
         while speed < 50: 
             speed = speed * 2
             pixels = pixels * 2
         if pixels > 10:
             pixels = 10
         self.curSpeed = speed
         self.curPixels = pixels
         natlink.setTimerCallback(self.onTimer,speed)
     elif 'slower' in words:
         speed = int(self.curSpeed * moveRateChange)
         pixels = self.curPixels
         while pixels > defaultMousePixels and speed >= 2*50:
             speed = speed / 2
             pixels = pixels / 2
         if speed > 2000:
             speed = 2000
         self.curSpeed = speed
         self.curPixels = pixels
         natlink.setTimerCallback(self.onTimer,speed)
Пример #4
0
    def cancelMode(self):
        debugPrint('cancelMode')
        natlink.setTrayIcon()

        if self.inTimer: 
            natlink.setTimerCallback(None,0)
            self.inTimer = 0
            if self.drag:
                debugPrint('switch of dragging')
                xPos,yPos = natlink.getCursorPos()
                if self.drag == 2:
                    natlink.playEvents([(natut.wm_rbuttonup,xPos,yPos)])
                else:
                    natlink.playEvents([(natut.wm_lbuttonup,xPos,yPos)])
                self.drag = 0
            elif self.state == 'searching':
                self.stopSearch()

        self.state = ''
        self.minorState = ''
        self.curDir = ''
        self.Count = 0
        self. mouseSteps = 10
        self.inside = 0
        self.insideCommand = 0
        self.waiting = 0
        self.drag = 0
        self.repeatFlag = 0
        self.hadRepeat = 0
        self.repeatStuff = None
        self.lastResults = []
        self.activateSet(normalSet, exclusive=0)
    def DISABLED_test_natlink_timer(self):
        return

        callback_occurred = False

        def callback():
            callback_occurred = True

        ticks = 200

        import time
        import natlink
        natlink.natConnect()
        try:
            natlink.setTimerCallback(callback, ticks)
            #            time.sleep(1)
            import sys
            import time
            import win32gui
            timeout = time.time() + 3
            while time.time() < timeout:
                print("Luke")
                sys.stdout.flush()
                if win32gui.PumpWaitingMessages():
                    raise RuntimeError("We got an unexpected WM_QUIT message!")
                time.sleep(1)
            natlink.setTimerCallback(None, 0)
            print("callback occurred:", callback_occurred)
        finally:
            natlink.natDisconnect()
Пример #6
0
 def gotResults_nowMousing(self,words,fullResults):
     direction = findKeyWord(words,self.listDefn['direction'])
     if direction:
         self.curDirection = direction
     elif 'stop' in words:
         self.cancelMode()
     elif 'faster' in words:
         speed = int(self.curSpeed / moveRateChange)
         pixels = self.curPixels
         while speed < 50: 
             speed = speed * 2
             pixels = pixels * 2
         if pixels > 10: pixels = 10
         self.curSpeed = speed
         self.curPixels = pixels
         natlink.setTimerCallback(self.onTimer,speed)
     elif 'slower' in words:
         speed = int(self.curSpeed * moveRateChange)
         pixels = self.curPixels
         while pixels > defaultMousePixels and speed >= 2*50:
             speed = speed / 2
             pixels = pixels / 2
         if speed > 2000: speed = 2000
         self.curSpeed = speed
         self.curPixels = pixels
         natlink.setTimerCallback(self.onTimer,speed)
Пример #7
0
 def cancelMode(self):
     self.curMode = None
     if self.haveCallback: 
         natlink.setTimerCallback(None,0)
         self.haveCallback = 0
     self.activateSet(['start'],exclusive=0)
     natlink.setTrayIcon()
Пример #8
0
def DisplayTextToCorrect():
    if getattr(_globals, "lastSavedResults", None) is None:
        print "No results to correct..."
    if hasattr(_globals, "lastSavedResults") and _globals.lastSavedResults is not None:
        results = _globals.lastSavedResults
        words = results.getWords(0)
        recognized_phrase = " ".join(words)
        glib.LaunchExeAsyncWithArgList("C:\\Python27_32bit\\python.exe", ["C:\\NatLink\\NatLink\\MacroSystem\\DragonCorrectionDialog.py", recognized_phrase])
        natlink.setTimerCallback(check_for_correction_response, 1000)
Пример #9
0
 def rule_newcard(self, words):
     "'new card'|next|continue"
     self.moveTo(firstrowpos(1))
     natqh.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
Пример #10
0
 def rule_newcard(self, words):
     "'new card'|next|continue"
     self.moveTo(firstrowpos(1))
     natqh.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
Пример #11
0
 def gotResults_startMousing(self,words,fullResults):
     self.cancelMode()
     direction = findKeyWord(words,self.listDefn['direction'])
     self.curMode = 2
     self.curDirection = direction
     self.curSpeed = defaultMouseSpeed
     self.curPixels = defaultMousePixels
     self.lastClock = time.clock()
     natlink.setTimerCallback(self.onTimer,defaultMouseSpeed)
     self.haveCallback = 1
     self.activateSet(['nowMousing'],exclusive=1)
Пример #12
0
 def gotResults_startMousing(self,words,fullResults):
     self.cancelMode()
     direction = findKeyWord(words,self.listDefn['direction'])
     self.curMode = 2
     self.curDirection = direction
     self.curSpeed = defaultMouseSpeed
     self.curPixels = defaultMousePixels
     self.lastClock = time.time()
     natlink.setTimerCallback(self.onTimer,defaultMouseSpeed)
     self.haveCallback = 1
     self.activateSet(['nowMousing'],exclusive=1)
Пример #13
0
 def gotResults_startMoving(self,words,fullResults):
     self.cancelMode()
     direction = findKeyWord(words,self.listDefn['direction'])
     self.curMode = 1
     self.curDirection = direction
     self.setTrayIcon(0)
     self.moduleInfo = natlink.getCurrentModule()
     self.curSpeed = defaultMoveSpeed
     self.lastClock = time.clock()
     natlink.setTimerCallback(self.onTimer,defaultMoveSpeed)
     self.haveCallback = 1
     self.activateSet(['nowMoving'],exclusive=1)
Пример #14
0
 def __init__(self, engine_type):
     EngineBase.__init__(self)
     self.__loaded_grammars = []
     if engine_type == "natlink":
         from dragonfire.engines.backend_natlink import get_engine
         self._wrapped_engine = get_engine()
         natlink.setTimerCallback(self.client_work, int(0.025 * 1000))
     if engine_type == "sapi5":
         from dragonfire.engines.backend_sapi5 import get_engine
         self._wrapped_engine = get_engine()
         threading.Timer(self.client_work, 0.025 * 1000).start()
     ClientEngine.DictationContainer = self._wrapped_engine.DictationContainer
Пример #15
0
 def gotResults_startMoving(self,words,fullResults):
     self.cancelMode()
     direction = findKeyWord(words,self.listDefn['direction'])
     self.curMode = 1
     self.curDirection = direction
     self.setTrayIcon(0)
     self.moduleInfo = natlink.getCurrentModule()
     self.curSpeed = defaultMoveSpeed
     self.lastClock = time.clock()
     natlink.setTimerCallback(self.onTimer,defaultMoveSpeed)
     self.haveCallback = 1
     self.activateSet(['nowMoving'],exclusive=1)
Пример #16
0
 def startNow(self):
     self.moduleInfo = natlink.getCurrentModule()
     k = self.state + self.minorState
     s = self.curSpeed + 2  # very slow =2 -->> 0
     if self.waiting:
         natlink.setTimerCallback(self.onTimer, waitingSpeed)
     elif k == 'mousing' or self.state == 'dragging':
         speed = SPEED[k][s]
         steps = defaultMousePixels
         print 'mousing/dragging, speed: %s, steps: %s'% (speed, steps) 
         if s < minSpeed:
             steps = (minSpeed//speed) + 1
             speed = steps*speed
             if steps < defaultMousePixels:
                 steps = defaultMousePixels
                 speed = speed*defaultMousePixels/steps
                 print 'enlarge steps: %s, new speed: %s'% (steps, speed)
         else:
             speed = s
         debugPrint('mouse starting with speed: %s, steps: %s'% (speed, steps))
         natlink.setTimerCallback(self.onTimer, speed)
         self.mouseSteps = steps
     elif SPEED.has_key(k):
         debugPrint('starting with speed: %s'% SPEED[k][s])
         natlink.setTimerCallback(self.onTimer, SPEED[k][s])
     else:
         debugPrint("timer starting with unknown speed for state/minorstate: %s"%k)
         natlink.setTimerCallback(self.onTimer, defaultSpeed)
         
     self.inTimer = 1
Пример #17
0
    def gotResults_trayicon(self, words, fullResults):

        #iconDir = r'D:\natlink\unimacro\icons'
        #for name in ['repeat', 'repeat2', 'waiting', 'waiting2']:
        #    iconPath = os.path.join(iconDir, name+'.ico')
        #    print 'iconPath', iconPath
        #    natlink.setTrayIcon(iconPath)
        #    time.sleep(0.5)
        #
        ## remove the icon:
        #natlink.setTrayIcon()
        self.stopShowing = 0  # can be used for interrupt by clicking on the tray icon...
        self.directions = ['right', 'down', 'up', 'left']
        self.loops = 12
        self.currentLoop = 0
        self.currentDirection = 0
        natlink.setTimerCallback(self.doNextIcon, 500)  # each 500 milliseconds
Пример #18
0
 def doNextIcon(self):
     if self.stopShowing:
         print 'caught callback, stop the looping'
         natlink.setTrayIcon()
         natlink.setTimerCallback(None)
         return
     if self.currentLoop >= self.loops:
         self.currentLoop = 0
         self.currentDirection += 1
         if self.currentDirection >= len(self.directions):
             print 'ready all done, remove the icon and stop the timercallback'
             natlink.setTrayIcon()
             natlink.setTimerCallback(None)
     if self.currentLoop % 2:
         iconName = '%s2' % self.directions[self.currentDirection]
     else:
         iconName = '%s' % self.directions[self.currentDirection]
     print 'set trayIcon: %s' % iconName
     natlink.setTrayIcon(iconName, 'test also click on icon %s' % iconName,
                         self.onTrayIcon)
Пример #19
0
 def gotResults_nowMoving(self,words,fullResults):
     direction = findKeyWord(words,self.listDefn['direction'])
     if direction:
         self.curDirection = direction
         self.setTrayIcon(0)
     elif 'stop' in words:
         self.cancelMode()
     elif 'faster' in words:
         speed = int(self.curSpeed / moveRateChange)
         if 'much' in words:
             speed = int(speed / (moveRateChange*moveRateChange))
         if speed < 50: speed = 50
         self.curSpeed = speed
         natlink.setTimerCallback(self.onTimer,speed)
     elif 'slower' in words:
         speed = int(self.curSpeed * moveRateChange)
         if 'much' in words:
             speed = int(speed * (moveRateChange*moveRateChange))
         if speed > 4000: speed = 4000
         self.curSpeed = speed
         natlink.setTimerCallback(self.onTimer,speed)
Пример #20
0
 def gotResults_nowMoving(self,words,fullResults):
     direction = findKeyWord(words,self.listDefn['direction'])
     if direction:
         self.curDirection = direction
         self.setTrayIcon(0)
     elif 'stop' in words:
         self.cancelMode()
     elif 'faster' in words:
         speed = int(self.curSpeed / moveRateChange)
         if 'much' in words:
             speed = int(speed / (moveRateChange*moveRateChange))
         if speed < 50: speed = 50
         self.curSpeed = speed
         natlink.setTimerCallback(self.onTimer,speed)
     elif 'slower' in words:
         speed = int(self.curSpeed * moveRateChange)
         if 'much' in words:
             speed = int(speed * (moveRateChange*moveRateChange))
         if speed > 4000: speed = 4000
         self.curSpeed = speed
         natlink.setTimerCallback(self.onTimer,speed)
Пример #21
0
def check_for_correction_response():
    global TRIES
    correction = "-1"
    try:
        correction = xmlrpclib.ServerProxy("http://127.0.0.1:" + str(1338)).get_message()
        print "xmlprclib correction =", correction
    except:
        print "xmlrpclib exception"
        TRIES+=1
        if TRIES>29:
            TRIES=0
            #TIMER_MANAGER.remove_callback(check_for_correction_response)
            natlink.setTimerCallback(None, 0)
            return
    
    if correction == "-1":
        return
    
    if hasattr(_globals, "lastSavedResults") and _globals.lastSavedResults is not None:
        results = _globals.lastSavedResults
        corrected_words = correction.split()
        status = results.correction(corrected_words)
        print "Correction status is", status
        natlink.setTimerCallback(None, 0)        
    else:
        #TIMER_MANAGER.remove_callback(check_for_correction_response)
        natlink.setTimerCallback(None, 0)
        return   
Пример #22
0
 def remove_callback(self, function):
     for c in self.callbacks:
         if c.function == function: self.callbacks.remove(c)
     if len(self.callbacks) == 0:
         natlink.setTimerCallback(None, 0)
Пример #23
0
 def add_callback(self, function, interval):
     self.callbacks.append(self.Callback(function, interval))
     if len(self.callbacks) == 1:
         natlink.setTimerCallback(self.callback, int(self.interval * 1000))
Пример #24
0
 def unload(self):
     if self.haveCallback: 
         natlink.setTimerCallback(None,0)
         self.haveCallback = 0
     GrammarBase.unload(self)
Пример #25
0
 def cancelMode(self):
     #self.setExclusive(0)
     if self.inTimer:
         print 'cancel timer'
         natlink.setTimerCallback(None, 0)
         self.inTimer = 0
Пример #26
0
 def unload(self):
     if self.haveCallback: 
         natlink.setTimerCallback(None,0)
         self.haveCallback = 0
     GrammarBase.unload(self)
Пример #27
0
	def add_callback(self, function, interval):
		self.callbacks.append(self.Callback(function, interval))
		if len(self.callbacks) == 1:
			natlink.setTimerCallback(self.callback, int(self.interval * 1000))
Пример #28
0
def shutdown():
    print "shutting down"
    natlink.setTimerCallback(None)
    for g in grammars:
        grammars[g].unload()
    natlink.natDisconnect()
Пример #29
0
    grammars[grammar_name].setExclusive(exclusive)
    return "done"


@rpc
def activate(grammar_name, rule_name):
    grammars[grammar_name].activate(rule_name, 0)
    return "done"


@rpc
def deactivate(grammar_name, rule_name):
    grammars[grammar_name].deactivate(rule_name)
    return "done"


#@rpc
#def updateList(grammar_name, list_name, elements): Pass

try:
    print "loading"
    natlink.natConnect(1)
    natlink.openUser("Michael")
    natlink.setMicState("on")
    natlink.setTimerCallback(drainRequests, 100)
    natlink.waitForSpeech(0)
except Exception as e:
    print e
finally:
    shutdown()
Пример #30
0
 def cancelMode(self):
     #self.setExclusive(0)
     if self.inTimer:
         print 'cancel timer'
         natlink.setTimerCallback(None,0)
         self.inTimer = 0
Пример #31
0
	def remove_callback(self, function):
		for c in self.callbacks:
			if c.function == function: self.callbacks.remove(c)
		if len(self.callbacks) == 0:
			natlink.setTimerCallback(None, 0)