def killNatspeakOrDragonPad(self):
     natqh.SetForegroundWindow(self.DragonPadHndle)
     mod, title, hndle = natlink.getCurrentModule()
     self.assert_(mod == self.DragonPadMod and hndle == self.DragonPadHndle,
                  "could not get back to Natspeak/DragonPad window")
     actions.killWindow()
     mod, title, hndle = natlink.getCurrentModule()
     self.failIf(mod == self.DragonPadMod and hndle == self.DragonPadHndle,
                 "did not kill Natspeak/DragonPad window")
Exemple #2
0
    def changeCallback(type, args):
        global userName, DNSuserDirectory, language, BaseModel, BaseTopic, DNSmode, changeCallbackUserFirst, shiftkey
        if debugCallback:
            print 'changeCallback, type: %s, args: %s' % (type, args)
        if type == 'mic' and args == 'on':
            if debugCallback:
                print 'findAndLoadFiles...'
            moduleInfo = natlink.getCurrentModule()
            findAndLoadFiles()
            beginCallback(moduleInfo, checkAll=1)
            loadModSpecific(moduleInfo)
        if type == 'user' and userName != args[0]:
            userName, DNSuserDirectory = args
            moduleInfo = natlink.getCurrentModule()
            if debugCallback:
                print "---------changeCallback, User changed to", userName
            elif not changeCallbackUserFirst:
                # first time, no print message, but next time do...
                print "\n------ user changed to: %s\n" % userName

            unloadEverything()
            ## this is not longer needed here, as we fixed the userDirectory
            ##        changeUserDirectory()
            status.setUserInfo(args)
            language = status.getLanguage()
            shiftkey = status.getShiftKey(language)
            print 'setting shiftkey to: %s (language: %s)' % (shiftkey,
                                                              language)

            if debugCallback:
                print 'usercallback, language: %s' % language
            if changeCallbackUserFirst:
                natlinkstartup.start()
                changeCallbackUserFirst = 0
            # changed next two lines QH:
            findAndLoadFiles()
            beginCallback(moduleInfo, checkAll=1)
            loadModSpecific(moduleInfo)
            # give a warning for BestMatch V , only for Dragon 12:
            BaseModel, BaseTopic = status.getBaseModelBaseTopic()
            if DNSVersion == 12 and BaseModel.find("BestMatch V") > 0:
                print '\n--- WARNING: Speech Model BestMatch V is used for this User Profile'
                print 'The performance of many NatLink grammars is not good with this model.'
                print 'Please choose another User Profile with for example Speech Model BestMatch IV.'
                print 'See http://unimacro.antenna.nl/installation/speechmodel.html\n----'

        #ADDED BY BJ, possibility to finish exclusive mode by a grammar itself
        # the grammar should include a function like:
        #def changeCallback():
        #    if thisGrammar:
        #        thisGrammar.cancelMode()
        # and the grammar should have a cancelMode function that finishes exclusive mode.
        # see _oops, _repeat, _control for examples
        changeCallbackLoadedModules(type, args)
Exemple #3
0
def anchor(kind=None):
    left, top = 0, 0
    if kind:
        if kind == "absolute":
            left, top = 0, 0
        elif kind == "window":
            name, title, hwnd = natlink.getCurrentModule()
            left, top, right, bottom = win32gui.GetWindowRect(hwnd)
        elif kind == "interior":
            name, title, hwnd = natlink.getCurrentModule()
            left, top = win32gui.ClientToScreen(hwnd, (0, 0))
        elif kind == "relative":
            left, top = position()
    return left, top
Exemple #4
0
def changeCallback(type,args):
    global userName, DNSuserDirectory, language, BaseModel, BaseTopic, DNSmode, changeCallbackUserFirst
    if debugCallback:
        print 'changeCallback, type: %s, args: %s'% (type, args)
    if type == 'mic' and args == 'on':
        if debugCallback:
            print 'findAndLoadFiles...'
        moduleInfo = natlink.getCurrentModule()
        findAndLoadFiles()
        beginCallback(moduleInfo, checkAll=1)
        loadModSpecific(moduleInfo)
    if type == 'user' and userName != args[0]:
        userName, DNSuserDirectory = args
        moduleInfo = natlink.getCurrentModule()
        if debugCallback:
            print "---------changeCallback, User changed to", userName
        elif changeCallbackUserFirst:
            # first time, no print message, but next time do...
            changeCallbackUserFirst = 0
        else:
            print "\n------ user changed to: %s\n"% userName

        unloadEverything()
## this is not longer needed here, as we fixed the userDirectory
##        changeUserDirectory()
        status.setUserInfo(args)
        language = status.getLanguage()
        if debugCallback:
            print 'usercallback, language: %s'% language
        # changed next two lines QH:
        findAndLoadFiles()        
        beginCallback(moduleInfo, checkAll=1)
        loadModSpecific(moduleInfo)
        # give a warning for BestMatch V 
        BaseModel, BaseTopic = status.getBaseModelBaseTopic()
        if BaseModel.find("BestMatch V") > 0:
            print '\n--- WARNING: Speech Model BestMatch V is used for this User Profile'
            print 'The performance of many NatLink grammars is not good with this model.'
            print 'Please choose another User Profile with for example Speech Model BestMatch IV.'
            print 'See http://unimacro.antenna.nl/installation/speechmodel.html\n----'


    #ADDED BY BJ, possibility to finish exclusive mode by a grammar itself
    # the grammar should include a function like:
    #def changeCallback():
    #    if thisGrammar:
    #        thisGrammar.cancelMode()
    # and the grammar should have a cancelMode function that finishes exclusive mode.
    # see _oops, _repeat, _control for examples
    changeCallbackLoadedModules(type,args)
Exemple #5
0
    def gotResults_namephrase(self,words,fullResults):
        # list of words that can be combined in a double christian name
        #  eg Jan Jaap or Jan-Marie 
        voornamenList = ['Jan', 'Jaap', 'Peter', 'Louise', 'Anne'
                         ]
        modInfo = natlink.getCurrentModule()
        action("CLIPSAVE")
        keystroke("{Ctrl+c}")

        # do contents of clipboard:
        t = string.strip(natlink.getClipboard())
        if not t:
            modInfo = natlink.getCurrentModule()
            if natqh.matchModule('natspeak', 'spell', modInfo):
                keystroke("{ExtHome}{Shift+ExtEnd}{Ctrl+x}")
                natqh.Wait(0.5)
                t = string.strip(natlink.getClipboard())
                if not t:
                    action("CLIPRESTORE")
                    return
            else:
                if self.language == 'nld':
                    com = "Selecteer dat"
                else:
                    com  = "Select That"
                if natqh.getDNSVersion() >= 7:
                    com = com.lower()
                action("HW %s"%com)
                natqh.Wait(0.5)
                keystroke("{Ctrl+c}")
                
                t = string.strip(natlink.getClipboard())
                if not t:                    
                    self.DisplayMessage("select a text first")
                    action("CLIPRESTORE")
                    return
        if self.hasCommon(words, ['naam', 'Name']):
            result = namelist.namelistUnimacro(t, ini=self.ini)
            print 'result of namelistUnimacro function: %s'% result
            for r in result:
                print 'adding part: %s'% r
                natqh.addWordIfNecessary(t)
            keystroke(r)
        else: # zonder naam in words, a normal phrase:
            print 'adding phrase %s'% t
            natqh.addWordIfNecessary(t)
            keystroke(t)
        action("CLIPRESTORE")
Exemple #6
0
def mouse_set_scaled(position):
    x, y = position.split(",")
    name, title, hwnd = natlink.getCurrentModule()
    left, top, right, bottom = win32gui.GetWindowRect(hwnd)
    x = int(int(x) * 1.0 / 100 * (right - left - 1))
    y = int(int(y) * 1.0 / 100 * (bottom - top - 1))
    VocolaUtils.call_Dragon("SetMousePosition", "iii", [1, x, y])
Exemple #7
0
def mouse_set_local(position):
    x, y = position.split(",")
    name, title, hwnd = natlink.getCurrentModule()
    #    left,top,right,bottom = win32gui.GetWindowRect(hwnd)
    #    x += left
    #    y += top
    VocolaUtils.call_Dragon("SetMousePosition", "iii", [1, x, y])
 def gotResults_copy(self,words,fullResults):
     global sourceHandle, nsHandle
     modInfo = natlink.getCurrentModule()
     if natut.matchWindow(modInfo, self.startProgram, self.startProgram):
         self.DisplayMessage('Do not use "'+self.fullText+'" in '+self.startProgram)
         return 
     # get Handle of this window:
     sourceHandle = modInfo[2]
     
     ##  If "edit all" is said, first select whole document
     if (self.hasCommon(words, ['all'])):
         action('<<selectall>>')
         natqh.Wait(0.2)
     if (self.hasCommon(words, ['messages'])):
         natqh.switchToWindowWithTitle('messages from python macros')
         action('<<selectall>>')
         natqh.Wait(0.2)
     # copy and goto NatSpeak
     #  clear clipboard, copy and goto DragonPad
     natqh.saveClipboard()
     if (self.hasCommon(words, ['copy'])):
         action('<<copy>>')
     elif (self.hasCommon(words, ['cut'])):
         action('<<cut>>')
     else:
         print 'no copy or cut in words: %s'% words
         return
     natqh.rememberWindow()
     if self.startEditProgram():
         if natqh.getClipboard():
                 keystroke('{Ctrl+ExtEnd}{Enter}{Ctrl+v}')
         natqh.returnToWindow(20,0.2, winHandle=sourceHandle)
     natqh.restoreClipboard()
    def lookForNatspeakOrDragonPad(self):

        # This should find the NatSpeak window.  If the NatSpeak window is not
        # available (because, for example, NatSpeak was not started before
        # running this script) then we will get the error:
        #   NatError: Error 62167 executing script execScript (line 1)

        try:
            natlink.execScript('AppBringUp "NatSpeak"')
        except natlink.NatError:
            raise TestError, 'The NatSpeak user interface is not running'
        try:
            natlink.execScript('Start "DragonPad"')
        except natlink.NatError:
            raise TestError, 'The DragonPad window cannot be started'

        # This will make sure that the NatSpeak window is empty.  If the NatSpeak
        # window is not empty we raise an exception to avoid possibily screwing
        # up the users work.

        if self.getWindowContents():
            raise TestError, 'The NatSpeak/DragonPad window is not empty'
        mod, title, hndle = natlink.getCurrentModule()
        self.DragonPadMod = mod
        self.DragonPadHndle = hndle
Exemple #10
0
    def rule_taskaction(self, words):
        '(<taskswitch> | <subtask> | task)({taskaction}| "give name" <dgndictation>|<closemultiple>)'

        # do a taskaction to the current task, or one of the
        # numbered/named tasks or task back
        #print 'got taskaction: %s'% words
        actions = self.ini.get('taskaction')
        act = self.hasCommon(words, actions)
        giveName = self.hasCommon(words, "give name")
        #if self.app == "messages":
        #    print 'action for messages: %s'% act
        #    if act == 'refresh':
        #        self.doTaskAction('close')
        #        print 'new messages window'
        #        return
        if giveName:
            hndle = natlink.getCurrentModule()[2]
            self.giveName = hndle
        elif act:
            self.doTaskAction(act)
        else:
            print 'thistask in _general, no valid action', words

        prog, title, topchild, windowHandle = natqh.getProgInfo()
        if prog == 'explorer' and not title:
            return  # no centermouse!

        if self.centerMouse:
            natqh.doMouse(1, 5, 0.3, 0.3, 0, 0)
Exemple #11
0
    def xxxxtestKeystrokesGrammarEnx(self):
        """test the keystrokes grammar

        with language english (this grammar must be in the Unimacro directory)
        the inactive mode seemed not to be working. Deactivate was not enough. Hard to test.
        But hopefully solved, Quintijn, September 26, 2013...

        !!Enable ONLY this test function, disable NatLink (leaving Unimacro and possibly Vocola enabled)
        !!enable the "start_natlink" line in def connect and
        then restart Dragon and run this module.
        
        Note the test function writes the number into this file, so leave the cursor here or after a comment
        before running the function!! Or you comment out the line self.outputNumber() (line 99) in _number simple.py.

        """
        natlinkmain.start_natlink()
        print 'started natlink (Unimacro)'
        import _keystrokes
        kgrammar = _keystrokes.thisGrammar

        # the Backspace gives an error:
        words = ['Backspace']
        fullResults = [('Backspace', 'repkey')]
        seqsAndRules = [(['Backspace'], 'repkey')]

        # now call the different functions in the resultsCallback procedure:
        moduleInfo = natlink.getCurrentModule()
        # initialise things in gotBegin
        kgrammar.callIfExists('gotBegin', (moduleInfo, ))
        # and run the rules:
        kgrammar.callIfExists('gotResultsInit', (words, fullResults))
        kgrammar.callRuleResultsFunctions(seqsAndRules, fullResults)
        kgrammar.callIfExists('gotResults', (words, fullResults))
        pass
Exemple #12
0
    def gotResults_browsewith(self, words, fullResults):
        """show page in another browser"""
        m = natlink.getCurrentModule()
        prog, title, topchild = natqh.getProgInfo(modInfo=m)
        Iam2x = prog == '2xexplorer'
        IamExplorer = prog == 'explorer'
        browser = prog in ['iexplore', 'firefox', 'opera', 'netscp', 'chrome']
        if not browser:
            self.DisplayMessage('command only for browsers')
            return
        print 'words:', words
        natqh.saveClipboard()
        action(
            '<<addressfield>>; {extend}{shift+exthome}{ctrl+c};<<addressfieldclose>>'
        )
        askedBrowser = self.getFromInifile(words, 'browsers')
        if askedBrowser == prog:
            self.DisplayMessage('command only for another browser')
            return
        print 'try to bring up browser: |%s|' % askedBrowser
        action('RW')
        action('AppBringUp "%s"' % askedBrowser)
        action('WTC')
        action('<<addressfield>>; {ctrl+v}{enter}')

        natqh.restoreClipboard()
Exemple #13
0
    def startNow(self):
        self.moduleInfo = natlink.getCurrentModule()
        k = self.state + self.minorState
        s = self.curSpeed + 2  # very slow =2 -->> 0
        if self.waiting:
            natlinktimer.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))
            natlinktimer.setTimerCallback(self.onTimer, speed)
            self.mouseSteps = steps
        elif k in SPEED:
            debugPrint('starting with speed: %s' % SPEED[k][s])
            natlinktimer.setTimerCallback(self.onTimer, SPEED[k][s], debug=1)
        else:
            debugPrint(
                "timer starting with unknown speed for state/minorstate: %s" %
                k)
            natlinktimer.setTimerCallback(self.onTimer, defaultSpeed)

        self.inTimer = 1
Exemple #14
0
    def xxxxtestControlGrammarNld(self):
        """test the reload of the control grammar
        
        The obsolete words seem to be reversed.

        !!Enable ONLY this test function, disable NatLink (leaving Unimacro and possibly Vocola enabled)
        !!enable the "start_natlink" line in def connect and
        then restart Dragon and run this module.
        
        Note the test function writes the number into this file, so leave the cursor here or after a comment
        before running the function!! Or you comment out the line self.outputNumber() (line 99) in _number simple.py.Zwitserland kiest Rooks hallo

        This test was because at reload time the self.gramSpec instance variable was used for translation instead of
        self.__class__.gramSpec.
        
        Next lines of test are not very sensible. Problem was at natlinkutilsbj line 2324, QH sept 2013

        """
        natlinkmain.start_natlink()
        print 'started natlink (Unimacro)'
        import _control
        cgrammar = _control.utilGrammar  # why this name?
        print 'gramSpec: %s' % cgrammar.gramSpec
        words = ['schakel', 'in', 'toetsen']
        fullResults = [('schakel', 'switch'), ('in', 'switch'),
                       ('toetsen', 'switch')]
        seqsAndRules = [(['schakel', 'in', 'toetsen'], 'switch')]

        moduleInfo = natlink.getCurrentModule()
        cgrammar.checkInifile()

        # now call the different functions in the resultsCallback procedure:
        print 'after second initialise gramSpec: %s' % cgrammar.gramSpec
        pass
    def assert_mod(self, expMod, text=''):
        """check module name with expected

        """
        mod, title, hndle = natlink.getCurrentModule()
        baseOfMod = natlinkutils.getBaseName(mod).lower()
        self.assert_equal(expMod, baseOfMod, "module unequal " + text)
Exemple #16
0
    def rule_taskaction(self, words):
        '(<taskswitch> | <subtask> | task)({taskaction}| "give name" <dgndictation>|<closemultiple>)'
        
        # do a taskaction to the current task, or one of the
        # numbered/named tasks or task back
        #print 'got taskaction: %s'% words
        actions = self.ini.get('taskaction')
        act = self.hasCommon(words, actions)
        giveName = self.hasCommon(words, "give name")
        #if self.app == "messages":
        #    print 'action for messages: %s'% act
        #    if act == 'refresh':
        #        self.doTaskAction('close')
        #        print 'new messages window'
        #        return
        if giveName:
            hndle = natlink.getCurrentModule()[2]
            self.giveName = hndle
        elif act:
            self.doTaskAction(act)
        else:
            print 'thistask in _general, no valid action', words

        prog, title, topchild, windowHandle = natqh.getProgInfo()
        if prog == 'explorer' and not title:
            return # no centermouse!
        
        if self.centerMouse:
            natqh.doMouse(1, 5, 0.3, 0.3, 0, 0)
Exemple #17
0
    def gotResults_namephrase(self, words, fullResults):
        # list of words that can be combined in a double christian name
        #  eg Jan Jaap or Jan-Marie
        voornamenList = ['Jan', 'Jaap', 'Peter', 'Louise', 'Anne']
        modInfo = natlink.getCurrentModule()
        action("CLIPSAVE")
        keystroke("{Ctrl+c}")

        # do contents of clipboard:
        t = string.strip(natlink.getClipboard())
        if not t:
            modInfo = natlink.getCurrentModule()
            if natqh.matchModule('natspeak', 'spell', modInfo):
                keystroke("{ExtHome}{Shift+ExtEnd}{Ctrl+x}")
                natqh.Wait(0.5)
                t = string.strip(natlink.getClipboard())
                if not t:
                    action("CLIPRESTORE")
                    return
            else:
                if self.language == 'nld':
                    com = "Selecteer dat"
                else:
                    com = "Select That"
                if natqh.getDNSVersion() >= 7:
                    com = com.lower()
                action("HW %s" % com)
                natqh.Wait(0.5)
                keystroke("{Ctrl+c}")

                t = string.strip(natlink.getClipboard())
                if not t:
                    self.DisplayMessage("select a text first")
                    action("CLIPRESTORE")
                    return
        if self.hasCommon(words, ['naam', 'Name']):
            result = namelist.namelistUnimacro(t, ini=self.ini)
            print 'result of namelistUnimacro function: %s' % result
            for r in result:
                print 'adding part: %s' % r
                natqh.addWordIfNecessary(t)
            keystroke(r)
        else:  # zonder naam in words, a normal phrase:
            print 'adding phrase %s' % t
            natqh.addWordIfNecessary(t)
            keystroke(t)
        action("CLIPRESTORE")
    def failIf_mod(self, expMod, text=''):
        """check module name with expected, should be UNEQUAL

        """
        mod, title, hndle = natlink.getCurrentModule()
        baseOfMod = natlinkutils.getBaseName(mod).lower()
        self.failIf(
            expMod == baseOfMod,
            "modules %s and %s are equal, should be unequal " %
            (expMod, baseOfMod) + text)
    def gotResults(self, words, fullResults):
        """perform the resulting actions
        """
        self.collectNumber()
        if self.debug:
            print 'collected: %s'% self.inwindow
        #
        if self.taskbar:
            #asked for a taskbar number...
            cmd = 'DOACTIONTRAY=(%s, %s)'% (self.taskbar, self.clicktype)
            self.command(cmd)
            # see if stacked tray shows up
            className = natqh.getClassName()
            #print 'className: %s'% className
            if className == "TaskListThumbnailWnd":
                if self.debug:
                    print 'stacked taskbar, display numbers again'
                cmd = 'SHOWNUMBERS'
                self.command(cmd)
                natqh.visibleWait()
            self.mode = None

        if self.inwindow:
            # intercept when you are in the stacked explorer (taskbar) windows:
            className = natqh.getClassName()
            #print 'classname: %s'% className
            if className == "TaskListThumbnailWnd":
                self.doAlternativeClick(className, self.inwindow)
            else:
                cmd = 'DOACTIONSHOWNUMBERS=(%s, %s)'% (self.inwindow, self.clicktype)
                if self.debug:
                    print 'inwindow cmd: %s'% cmd
                self.command(cmd)
        if self.action:
            action("VW") # visible wait
            if self.debug:
                print 'shownumbers plus action: %s'% self.action
            action(self.action)

        if self.centerMouse:
            if self.debug:
                print 'center mouse'
            natqh.Wait()
            natqh.doMouse(1, 5, 0.3, 0.3, 0, 0)  # relative in client area, no clicking           
        # must check this:
        if self.mode == 'continue':
            hndle = natlink.getCurrentModule()[2]
            if hndle != self.prevHndle:
                self.mode = '' # new window
                return
            if self.debug:
                print 'continuous, show numbers again'
            action("VW")
            cmd = 'SHOWNUMBERS'
            self.command(cmd)
Exemple #20
0
 def setUp(self):
     self.connect()
     self.thisHndle = natlink.getCurrentModule()[2]
     self.org_text = "Xyz"*3
     natlinkclipboard.Clipboard.set_system_text(self.org_text)
     # self.setupWindows()
     # self.setupTextFiles() # should be done "by hand"
     print('thisHndle: %s'% self.thisHndle)
     # take txt files from test_clipboardfile subdirectory, a sorted list of txt files, see at bottom of module
     # take docx files etc. 
     self.allWindows = {}
Exemple #21
0
 def onTimer(self):
     if natlink.getMicState() != 'on':
         print 'mic switched off, cancel timer'
         self.cancelMode()
         return
     modInfo = natlink.getCurrentModule()
     if modInfo[2] != self.prevHandle:
         print 'window handle changed, cancel timer'
         self.cancelMode()
         return
     print 'in onTimer: %.1f' % time.clock()
     self.rule_newcard([])
Exemple #22
0
   def gotResultsObject(self,recogType,resObj):
       global logFile
       currentUser=natlink.getCurrentUser()[0]
       if recogType == 'reject':
           message = "*REJECT*"
       else:
           message = resObj.getWords(0)

       currentModule=natlink.getCurrentModule()
       windowTitle =string.replace(currentModule[1],"\t"," ")
       message ="%s\t%s\t%s"% (currentModule[0],windowTitle,message)
       logMessageToFile (logFile, "%s\t%s" % (currentUser, message))
Exemple #23
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)
    def assert_mod_partoftitle(self, expMod, expPartOfTitle=None, text=''):
        """check module and optional part of the window title with the actual

        """
        mod, title, hndle = natlink.getCurrentModule()
        baseOfMod = natlinkutils.getBaseName(mod).lower()
        self.assert_equal(expMod, baseOfMod, "module unequal " + text)
        if expPartOfTitle:
            self.assert_(
                title.find(expPartOfTitle) >= 0,
                'part of title "%s" does not match title "%s" in module "%s" " + text'
                % (expPartOfTitle, title, mod))
Exemple #25
0
 def onTimer(self):
     if natlink.getMicState() != 'on':
         print 'mic switched off, cancel timer'
         self.cancelMode()
         return
     modInfo = natlink.getCurrentModule()
     if modInfo[2] != self.prevHandle:
         print 'window handle changed, cancel timer'
         self.cancelMode()
         return
     print 'in onTimer: %.1f'% time.clock()
     self.rule_newcard([])
Exemple #26
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)
Exemple #27
0
    def gotResultsObject(self, recogType, resObj):
        global logFile
        currentUser = natlink.getCurrentUser()[0]
        if recogType == 'reject':
            message = "*REJECT*"
        else:
            message = resObj.getWords(0)

        currentModule = natlink.getCurrentModule()
        windowTitle = string.replace(currentModule[1], "\t", " ")
        message = "%s\t%s\t%s" % (currentModule[0], windowTitle, message)
        logMessageToFile(logFile, "%s\t%s" % (currentUser, message))
Exemple #28
0
    def gotResultsObject(self, recogType, resObj):
        if natbj.IsDisplayingMessage:
            debugPrint('displaying message, ignoring generic movement')
            return

        if recogType == 'reject':
            return
        handle = natlink.getCurrentModule()[2]
        if handle != self.prevHandle:
            # new window, empty lastResults list:
            self.lastResults = []
            self.prevHandle = handle
            self.repeatFlag = 0
        words = resObj.getWords(0)[:]
        if recogType == 'other':
            #print 'resultObject, %s,  repeatFlag: %s' % (words, self.repeatFlag)
            if self.repeatFlag:
                if words != self.repeatStuff:
                    self.cancelMode()
            elif self.inTimer:
                self.cancelMode()
            elif natlink.getCallbackDepth() < 3:
                if self.lastResults and words == self.lastResults[-1]:
                    pass
                else:
                    self.lastResults.append(words)
                    if len(self.lastResults) > 6:
                        self.lastResults = self.lastResults[1:]
                #debugPrint('lastResults: %s' % `self.lastResults`)
            else:
                debugPrint('callbackdepth %s, words: %s' %
                           (natlink.getCallbackDepth(), words))
            self.inside = 0
            return
##        skipped this, because it interferes with _message:
##        elif recogType == 'reject':
##            if self.inTimer and self.missed:
##                self.doAction()
##                self.startNow()
        elif recogType == 'self':
            self.nDir = ''
            self.Count = 0
            self.nSpeed = None
            self.dirState = ''
            debugPrint('---starting phrase')
            debugPrint('callbackdepth %s, words: %s' %
                       (natlink.getCallbackDepth(), words))
            if showAll:
                self.DisplayMessage('<%s>' % ' '.join(words))
        else:
            print('recogtype: %s' % recogType)
        self.inside = 0
    def window_info(self):
        """find the window id, title, and module of the current window

        **INPUTS**

        *none*

        **OUTPUTS**

        *(INT, STR, STR)* -- the window id, title, and module name.  The
        module name should be converted to all lowercase
        """
        return self.parse_module_info(natlink.getCurrentModule())
    def window_info(self):
        """find the window id, title, and module of the current window

        **INPUTS**

        *none*

        **OUTPUTS**

        *(INT, STR, STR)* -- the window id, title, and module name.  The
        module name should be converted to all lowercase
        """
        return self.parse_module_info(natlink.getCurrentModule())
Exemple #31
0
 def onTimer(self):
     if self.lastClock:
         diff = int( (time.clock() - self.lastClock) * 1000 )
         self.lastClock = time.clock()
     if self.curMode == 1:
         moduleInfo = natlink.getCurrentModule()
         if natlink.getMicState() == 'on' and moduleInfo == self.moduleInfo:
             self.setTrayIcon(1)
             # Note: it is often during a playString operation that the
             # "stop moving" command occurs
             natlink.playString('{'+self.curDirection+'}')
         else:
             self.cancelMode()
     elif self.curMode == 2:
         self.moveMouse(self.curDirection,self.curPixels)
Exemple #32
0
 def onTimer(self):
     if self.lastClock:
         diff = int( (time.time() - self.lastClock) * 1000 )
         self.lastClock = time.time()
     if self.curMode == 1:
         moduleInfo = natlink.getCurrentModule()
         if natlink.getMicState() == 'on' and moduleInfo == self.moduleInfo:
             self.setTrayIcon(1)
             # Note: it is often during a playString operation that the
             # "stop moving" command occurs
             natlink.playString('{'+self.curDirection+'}')
         else:
             self.cancelMode()
     elif self.curMode == 2:
         self.moveMouse(self.curDirection,self.curPixels)
    def onTimer(self):
##        if self.lastClock:
##            diff = int((time.clock() - self.lastClock) * 1000 )
        if natbj.IsDisplayingMessage:
            debugPrint('in timer, displaying message, returning')
            return
        moduleInfo = natlink.getCurrentModule()
        if natlink.getMicState() == 'on' and moduleInfo[2] == self.moduleInfo[2]:
            if self.inside or self.insideCommand:
                self.setTrayIcon(1)
                return
            elif self.waiting:
                self.setTrayIcon(1) 
                return
            elif self.doAction():
                return   # this is the only good exit from onTimer!!!!
        self.cancelMode()
Exemple #34
0
    def gotResults_comment(self, words, fullResults):
        name = nameList[words[-1]]
        if name:
            ts = time.strftime("%d%m%Y", time.localtime(time.time()))
        else:
            ts = time.strftime("%d%m%y_", time.localtime(time.time()))

        m = natlink.getCurrentModule()
        if natqh.matchModule('pythonwin', modInfo=m):
            com = "#" + name + ts
        elif natqh.matchModule('textpad', 'html', modInfo=m):
            com = "<!--" + name + ts + "-->"
        elif natqh.matchModule(m, 'textpad', '.c', modInfo=m):
            com = "$$$$" + name + ts + "$$$$"
        elif natqh.matchModule(m, 'textpad', '.py', modInfo=m):
            com = "#" + name + ts
        else:
            com = name + ts
        keystroke(com + "\n")
Exemple #35
0
    def gotResults_comment(self,words,fullResults):
        name = nameList[words[-1]]
        if name:
            ts = time.strftime("%d%m%Y", time.localtime(time.time()))
        else:
            ts = time.strftime("%d%m%y_", time.localtime(time.time()))

        m = natlink.getCurrentModule()
        if natqh.matchModule('pythonwin', modInfo=m):
            com = "#" + name + ts
        elif natqh.matchModule('textpad', 'html', modInfo=m):
            com = "<!--" + name + ts + "-->"
        elif natqh.matchModule(m,'textpad', '.c', modInfo=m):
            com = "$$$$" + name + ts + "$$$$"
        elif natqh.matchModule(m,'textpad', '.py', modInfo=m):
            com = "#" + name + ts
        else:
            com = name + ts
        keystroke(com+"\n")
    def is_active(self):
        """indicates whether dictation into the SpeechBuffer is currently 
        active (activated globally, or activated with the current
        window)

        **INPUTS**

        *none*

        **OUTPUTS**

        *BOOL* -- returns true iff dictation into the buffer is 
        currently active.
        """
        if self.is_activated():
            if is_global():
                return 1
            app_and_window = natlink.getCurrentModule()
            if app_and_window[2] == self.window_handle:
                return 1
        return 0
    def is_active(self):
        """indicates whether dictation into the SpeechBuffer is currently 
        active (activated globally, or activated with the current
        window)

        **INPUTS**

        *none*

        **OUTPUTS**

        *BOOL* -- returns true iff dictation into the buffer is 
        currently active.
        """
        if self.is_activated():
            if is_global():
                return 1
            app_and_window = natlink.getCurrentModule()
            if app_and_window[2] == self.window_handle:
                return 1
        return 0
Exemple #38
0
    def test_KW(self):
        """ kill window testing
        """
        # setup, bringing Dragonpad with open dialog in front:
        action("BRINGUP dragonpad")
        action("testing KW actions")
        action("W 1")
        action("{ctrl+o}")  # open dialog dragonpad
        action("W 0.5")
        modInfo = natlink.getCurrentModule()
        handle = modInfo[2]
        self.assert_(not unimacroutils.isTopWindow(handle),
                     "dialog should be open now")

        # do Notepad and kill, without text in it, so NO SaveAs dialog:
        action("BRINGUP Notepad")
        action("W 0.5")
        action("KW")
        action("W 0.5")
        # now NO kill letter should be printed, because it is again in the
        # DragonPad open dialog:  It
        self.doTestWindowIsEmpty("line in dialog box should be empty now")

        # this is the case in which the kill letter is done inside the SaveAs dialog
        # of Notepad:
        action("BRINGUP Notepad")
        action("abacadabra")
        action("W 0.5")
        action("KW")
        action("W 0.5")
        self.doTestWindowIsEmpty("line in dialog box should still be empty")

        # close DragonPad dialog, leave DragonPad open (if needed)
        action("{esc}")
        action("<<selectall>><<delete>>")
        action("W 0.5")
        self.doTestWindowIsEmpty(
            "should leave DragonPad empty after testing Kill Window (KW)")
    def activate(self, dict_globally=0):
        """activates the speech buffer for dictation, either globally or
        tied to the current window.

        **INPUTS**

        *BOOL* dict_globally -- if true, activate globally, otherwise
        note the current window and activate only when it is the active window.
        Additional conditions can be placed on the activation by
        activating or deactivating manually or on recognition starting
        (see SpeechBufferRecogStart below)

        **OUTPUTS**

        *none*
        """
        #        Note: NaturallySpeaking's window-specific dictation is
        #        more general, but requires specifying a MS Windows window
        #        handle, and I haven't figured out yet how to abstract the window
        #        ID to handle other operating systems or speech engines which
        #        may specify the window differently, so I figured that the
        #        current window would be good enough to start.
        #
        #        Also note that, for the same reason, the default behavior
        #        activate is different from that of NaturallySpeaking (either
        #        Natlink DictObj, or SDK CDgnDictCustom)

        window_handle = 0
        if (not dict_globally):
            app_and_window = natlink.getCurrentModule()
            window_handle = app_and_window[2]
        self.window_handle = window_handle
        self.dict_globally = dict_globally
        self.underlying.activate(window_handle)
        self.was_activated = 1
        self.activated = 1
    def activate(self, dict_globally = 0):
        """activates the speech buffer for dictation, either globally or
        tied to the current window.

        **INPUTS**

        *BOOL* dict_globally -- if true, activate globally, otherwise
        note the current window and activate only when it is the active window.
        Additional conditions can be placed on the activation by
        activating or deactivating manually or on recognition starting
        (see SpeechBufferRecogStart below)

        **OUTPUTS**

        *none*
        """
#        Note: NaturallySpeaking's window-specific dictation is 
#        more general, but requires specifying a MS Windows window
#        handle, and I haven't figured out yet how to abstract the window
#        ID to handle other operating systems or speech engines which
#        may specify the window differently, so I figured that the
#        current window would be good enough to start.
#
#        Also note that, for the same reason, the default behavior
#        activate is different from that of NaturallySpeaking (either
#        Natlink DictObj, or SDK CDgnDictCustom)
    
        window_handle = 0
        if (not dict_globally):
            app_and_window = natlink.getCurrentModule()
            window_handle = app_and_window[2]
        self.window_handle = window_handle 
        self.dict_globally = dict_globally
        self.underlying.activate(window_handle)
        self.was_activated = 1
        self.activated = 1
Exemple #41
0
 def gotResults_browsewith(self,words,fullResults):
     """show page in another browser"""
     m = natlink.getCurrentModule()
     prog, title, topchild = natqh.getProgInfo(modInfo=m)
     Iam2x = prog == '2xexplorer'
     IamExplorer = prog == 'explorer'
     browser = prog in ['iexplore', 'firefox','opera', 'netscp', 'chrome']
     if not browser:
         self.DisplayMessage ('command only for browsers')
         return
     print 'words:', words
     natqh.saveClipboard()
     action('<<addressfield>>; {extend}{shift+exthome}{ctrl+c};<<addressfieldclose>>')
     askedBrowser = self.getFromInifile(words, 'browsers')
     if askedBrowser == prog:
         self.DisplayMessage('command only for another browser')
         return
     print 'try to bring up browser: |%s|'% askedBrowser
     action('RW')
     action('AppBringUp "%s"'% askedBrowser)
     action('WTC')
     action('<<addressfield>>; {ctrl+v}{enter}')
     
     natqh.restoreClipboard()
Exemple #42
0
 def gotBegin(self,moduleInfo):
     if self.sawBegin > nTries:
         self.error = 'Command grammar called gotBegin twice'
     self.sawBegin += 1
     if moduleInfo != natlink.getCurrentModule():
         self.error = 'Invalid value for moduleInfo in GrammarBase.gotBegin'
Exemple #43
0
    def gotResults_info(self,words,fullResults):
        """display in a message box information about the window, user or unimacro

        """
        T = []
        extra = []
        if self.hasCommon(words,'window'):
            m = natlink.getCurrentModule()
            hwnd = m[2]
            p = natqh.getProgInfo(m)
            toporchild = p[2]
            T.append('---from natqh.getProgInfo:')
            T.append('0 program: %s'% p[0])
            T.append('1 window title: %s'% p[1])
            T.append('2 toporchild: %s'% p[2])
            T.append('3 window handle: %s'% p[3])
            if toporchild == 'top':
                overrule = actions.topWindowBehavesLikeChild(m)
                if overrule:
                    T.append('\t*** but should be treated as child window according to actions.topWindowBehavesLikeChild')
            else:
                overrule = actions.childWindowBehavesLikeTop(m)
                if overrule:
                    T.append('\t*** but should be treated as top window according to actions.childWindowBehavesLikeTop')
            T.append('')
            T.append('---from getCurrentModule:')
            T.append('0 program path: %s'% m[0])
            T.append('1 window title: %s'% m[1])
            T.append('2 window handle: %s'% m[2])
            T.append('')
            T.append('---from GetClassName:')
            T.append('class name: %s'% win32gui.GetClassName(hwnd))
        elif self.hasCommon(words,'user'):
            T.append('user:\t%s'% natqh.getUser())
            T.append('language:\t%s'% self.language)
            bm = natqh.getBaseModel()
            bt = natqh.getBaseTopic()
            T.append('BaseModel:\t%s'% bm)
            T.append('BaseTopic:\t%s'% bt)
            T.append('')
            T.append('see messages window for trainuser info')
            extra = ['lines for making a new user:'******'cd d:\natlink\miscscripts   (or different folder)')
            extra.append(r'python trainuser.py d:\natlink\recordings\recordingcode "user name" "%s" "%s"'%\
                         (bm, bt))
            extra.append('change folders, recording code and user name of course')
            
        elif self.hasCommon(words,'unimacro'):
            T.append('DNSVersion:\t%s'% natqh.getDNSVersion())
            T.append('WindowsVersion:\t%s'% natqh.getWindowsVersion())
            T.append('Natlink/Unimacro userDirectory:\t%s'% natqh.getUserDirectory())
            T.append('(Unimacro) UserIniFilesDirectory:\t%s'% natqh.getUnimacroUserDirectory())
            T.append('DNSuserDirectory:\t%s'% natqh.getDNSuserDirectory())
        elif self.hasCommon(words,'path'):
        	  T.append('the python path:')
        	  T.append(pprint.pformat(sys.path))
        elif self.hasCommon(words, "class"):
            T.append()
        else:
            T.append('no valid keyword found')

        s = '\n'.join(T)
        self.DisplayMessage(s)
        print s
        print
        for e in extra:
            print e