Beispiel #1
0
    def execute(self):
        mT = archyState.mainText
        foSel = mT.getSelection('first old selection')
        oSel = mT.getSelection('old selection')
        sel = mT.getSelection('selection')

        self.origSel = sel
        self.origCursor = mT.getCursorPos()

        searchTerm = mT.textArray.getSubString(*foSel)
        replacement = mT.textArray.getSubString(*oSel)

        pos = mT.textArray.find(searchTerm, sel[0])
        if pos < sel[1] and pos > 0:
            mT.setSelection('selection', pos, pos+len(searchTerm)-1)
            mT.setCursor(pos+len(searchTerm))
            
            FindNextCommand.searchEnd = sel[1]
            FindNextCommand.searchTerm = searchTerm
            AcceptReplaceCommand.replacement = replacement

            archyState.commandMap.unregisterCommand(AcceptReplaceCommand())
            archyState.commandMap.unregisterCommand(FindNextCommand())
            archyState.commandMap.unregisterCommand(EndReplaceCommand())
            
            archyState.commandMap.registerCommand(AcceptReplaceCommand())
            archyState.commandMap.registerCommand(FindNextCommand())
            archyState.commandMap.registerCommand(EndReplaceCommand())

            messages.queue("command-space: change\ncommand-tab: find next\nEND - Exit REPLACE", "persistant")

        else:
            raise commands.AbortCommandException('\"%s\" was not found in the selection.' % (searchTerm))
Beispiel #2
0
    def execute(self):
        import email.Message
        selRange = archyState.mainText.getSelection('selection')
        text, style = archyState.mainText.getStyledText(*selRange)
        text = filter(lambda x: x <> '~', text)
        
        serverForm = getEmailServerInformation()
        emailForm = EmailForm()
        emailForm.parse(text)

        bodyTag = 'Body:'
        bodyStart = text.find(bodyTag)
        text[bodyStart+len(bodyTag):]
        msg = email.Message.Message()
        msg.set_payload( text[bodyStart+len(bodyTag):] )
        msg['To'] = emailForm['To']
        msg['CC'] = emailForm['CC']
        msg['Subject'] = emailForm['Subject']

        newServerInfo = { 'server': serverForm['Outgoing Server'], 'authentication':serverForm['Outgoing Authentication'] , 'From':serverForm['Email Address'], 'password':serverForm['Outgoing Password'], 'user':serverForm['Outgoing User'], 'TLS':serverForm['TLS']}
        email_thread.outgoing_servers_lock.acquire()
        email_thread.outgoing_servers = [ newServerInfo ]
        email_thread.outgoing_servers_lock.release()

        email_thread.outgoing_email_lock.acquire()
        email_thread.outgoing_email.append( msg )
        email_thread.is_outgoing_mail.set()
        email_thread.outgoing_email_lock.release()
        
        messages.queue('Email sent successfully', 'normal')
Beispiel #3
0
    def cleanupExample(self):
        global START_TAG, END_TAG

        keyboard.resetModifiers()
        archyState.keyState.setToTextEntry()
        commands.cursor.LeapBackwardCommand(START_TAG).execute()
        commands.cursor.LeapForwardCommand(END_TAG).execute()
        for i in range(len(END_TAG)-1):
            commands.cursor.CreepRightCommand().execute()
        commands.text_editing.SelectCommand().execute()

        deleteCmd = commands.text_editing.DeleteTextCommand()
        deleteCmd.setinfo(useDeletionsDocument = 0)
        deleteCmd.execute()
        
        self.start_leap.undo()

        mv = archyState.mainTextViewer
        try:
            mv.recenterOnCursor()
        except:
            print "Thread Failure: Attempting to recenter the screen at an inappropriate time"
        self.soundtrack.stop()
        archyState.commandHistory._history = archyState.commandHistory._history[:self.original_command_history_length]
        archyState.commandHistory._lastCommandIndex = self.original_command_history_length-1

        messages.queue('Example '+self.name+' Finished', 'instant')
Beispiel #4
0
 def lastLeapForward(self):
     try:
         archyState.commandHistory.repeatLastLeapForward()
     except commands.AbortCommandException, e:
         messages.hide()
         messages.queue("%s: %s" % ("LEAP Forward again", e.getExplanation()))
         messages.display()
Beispiel #5
0
    def cleanupExample(self):
        global START_TAG, END_TAG

        keyboard.resetModifiers()
        archyState.keyState.setToTextEntry()
        commands.cursor.LeapBackwardCommand(START_TAG).execute()
        commands.cursor.LeapForwardCommand(END_TAG).execute()
        for i in range(len(END_TAG) - 1):
            commands.cursor.CreepRightCommand().execute()
        commands.text_editing.SelectCommand().execute()

        deleteCmd = commands.text_editing.DeleteTextCommand()
        deleteCmd.setinfo(useDeletionsDocument=0)
        deleteCmd.execute()

        self.start_leap.undo()

        mv = archyState.mainTextViewer
        try:
            mv.recenterOnCursor()
        except:
            print "Thread Failure: Attempting to recenter the screen at an inappropriate time"
        self.soundtrack.stop()
        archyState.commandHistory._history = archyState.commandHistory._history[:
                                                                                self
                                                                                .
                                                                                original_command_history_length]
        archyState.commandHistory._lastCommandIndex = self.original_command_history_length - 1

        messages.queue('Example ' + self.name + ' Finished', 'instant')
Beispiel #6
0
 def doInit(self):
     messages.queue('Leap Backward\n', 'leap')
     self.leapCommand = archyState.commandMap.findSystemCommand( 'LEAP backward to:' )
     try:
         archyState.commandHistory.executeCommand(self.leapCommand)
     except commands.AbortCommandException:
         pass
    def execute(self):
        mT = archyState.mainText

        self.origSel = mT.getSelection('selection')
        if mT.textArray.getSubString(
                *self.origSel).lower() <> FindNextCommand.searchTerm.lower():
            raise commands.AbortCommandException(
                "Current selection is not \"%s\". Use command-tab to find the next instantance."
                % (FindNextCommand.searchTerm))

        self.origSearchEnd = FindNextCommand.searchEnd
        FindNextCommand.searchEnd += len(self.replacement) - len(
            FindNextCommand.searchTerm)

        self.delText = DeleteTextCommand()
        self.addText = AddTextCommand(self.replacement)
        self.findNext = FindNextCommand()

        self.delText.execute()
        self.addText.execute()
        try:
            self.findNext.execute()
        except commands.AbortCommandException, e:
            self.findNext = None
            messages.queue(e.getExplanation())
Beispiel #8
0
    def cleanupExample(self):
        archyState.commandMap.findCommand("CLEAR UNDO HISTORY").execute()

        mv = archyState.mainTextViewer
        mv.recenterOnCursor()
        
        import messages
        messages.queue('Test '+self.name+' Finished', 'instant')
    def undo(self):
        archyState.commandMap.registerCommand(EndReplaceCommand())
        archyState.commandMap.registerCommand(AcceptReplaceCommand())
        archyState.commandMap.registerCommand(FindNextCommand())

        messages.queue(
            "command-space: change\ncommand-tab: find next\nEND - Exit REPLACE",
            "persistant")
Beispiel #10
0
    def cleanupExample(self):
        archyState.commandMap.findCommand("CLEAR UNDO HISTORY").execute()

        mv = archyState.mainTextViewer
        mv.recenterOnCursor()

        import messages
        messages.queue('Test ' + self.name + ' Finished', 'instant')
Beispiel #11
0
    def execute(self):
        mT = archyState.mainText

        storage = self.getStorage(archyState.mainText)
        if not storage:
            return

        word = storage.getWord()

        if storage.getSuggestions() <> []:
            suggestions = storage.getSuggestions()
        else:
            c = getSpellChecker()
            suggestions = c.suggest(word.lower())[:8]
            storage.setSuggestions(suggestions)

        suggestions = filter(lambda c: c[0].islower(), suggestions)[:8]

        if word[0].isupper():
            suggestions = map(lambda w: w.title(), suggestions)

        numberedSuggestions = zip(range(1, len(suggestions) + 1), suggestions)

        for num, sug in numberedSuggestions:
            replaceCommand = AbstractReplaceCommand()

            replaceCommand.setName(num)
            replaceCommand.setSuggestion(sug)
            replaceCommand.setRange(self.findExtent(mT))

            archyState.commandMap.unregisterCommand(replaceCommand)
            archyState.commandMap.registerCommand(replaceCommand)

        replaceCommand = AbstractReplaceCommand()
        replaceCommand.setName("K")
        replaceCommand.setSuggestion(word)
        replaceCommand.setRange(self.findExtent(mT))

        archyState.commandMap.unregisterCommand(replaceCommand)
        archyState.commandMap.registerCommand(replaceCommand)

        learnCommand = AbstractLearnCommand()
        learnCommand.setName("LEARN")
        learnCommand.setWord(word)
        learnCommand.setWordRange(self.findExtent(mT))

        archyState.commandMap.unregisterCommand(learnCommand)
        archyState.commandMap.registerCommand(learnCommand)

        message = ' '.join(
            map(lambda ns: '%s-%s' % (ns[0], ns[1]), numberedSuggestions))
        message += '\n%s - %s' % ("K", "Keeps the word")
        message += '\n%s - %s' % ("LEARN", "Learns word")
        messages.queue(message, 'persistant')
        messages.display()
Beispiel #12
0
    def execute(self):
        mT = archyState.mainText
    
        storage = self.getStorage(archyState.mainText)
        if not storage:
            return

        word = storage.getWord()
        
        if storage.getSuggestions() <> []:
            suggestions = storage.getSuggestions()
        else:
            c = getSpellChecker()
            suggestions = c.suggest(word.lower())[:8]
            storage.setSuggestions(suggestions)

        
        suggestions = filter(lambda c:c[0].islower(), suggestions)[:8]

        if word[0].isupper():
            suggestions = map(lambda w:w.title(), suggestions)

        numberedSuggestions = zip(range(1, len(suggestions)+1), suggestions)
        
        for num, sug in numberedSuggestions:
            replaceCommand = AbstractReplaceCommand()
            
            replaceCommand.setName(num)
            replaceCommand.setSuggestion(sug)
            replaceCommand.setRange( self.findExtent(mT) )
            
            archyState.commandMap.unregisterCommand(replaceCommand)
            archyState.commandMap.registerCommand(replaceCommand)
        
        replaceCommand = AbstractReplaceCommand()   
        replaceCommand.setName("K")
        replaceCommand.setSuggestion(word)
        replaceCommand.setRange( self.findExtent(mT) )
            
        archyState.commandMap.unregisterCommand(replaceCommand)
        archyState.commandMap.registerCommand(replaceCommand)
        
        learnCommand = AbstractLearnCommand()
        learnCommand.setName("LEARN")
        learnCommand.setWord(word)
        learnCommand.setWordRange( self.findExtent(mT) )

        archyState.commandMap.unregisterCommand(learnCommand)
        archyState.commandMap.registerCommand(learnCommand)

        message = ' '.join(map(lambda ns:'%s-%s' % (ns[0], ns[1]), numberedSuggestions))
        message += '\n%s - %s' % ("K", "Keeps the word")
        message += '\n%s - %s' % ("LEARN", "Learns word")
        messages.queue(message, 'persistant')
        messages.display()
Beispiel #13
0
 def _executeCommand(self, command, clearDisplay):
     try:
         archyState.commandHistory.executeCommand(command)
         if clearDisplay:
             messages.hide()
     except SystemExit:
         raise
     except commands.AbortCommandException, e:
         messages.hide()
         messages.queue("%s: %s" % (command.name(), e.getExplanation()))
         messages.display()
Beispiel #14
0
    def onExit(self):
        self.onAbort()

        commandName = self.commandText+self.suggestText
        if commandName == '':
            return
        try:
            command_object = archyState.commandMap.findCommand(commandName)
        except commands.CommandNotFoundError:
            messages.queue("Command %s not found" % commandName, 'instant')
            return

        self.runCommand(command_object)
Beispiel #15
0
 def onExit(self):
     self.parent.hideWhitespace()
     self.parent.hidePreselection()
     messages.unqueue('leap')
     messages.hide()
     if self.leapCommand.status() == 1:
         archyState.commandHistory.addToHistory(self.leapCommand)
         archyState.commandHistory.setLastCommand(self.leapCommand)
     else:
         self.restoreViewSettings()
         if  self.leapCommand.status() == 0:
             pass
         else:
             messages.queue(self.info, 'instant')
             self.playFailedLeapSound()
Beispiel #16
0
    def execute(self):
        self.origCursor = archyState.mainText.getCursorPos()
        moveOver = 0
        self.history = []

        startPos, endPos = self.findExtent(archyState.mainText)

        if self.origCursor == startPos:
            moveOver = 1
            archyState.mainText.setCursor(startPos)
        else:
            archyState.mainText.setCursor(endPos + 1)

        if moveOver:
            archyState.mainText.setSelection('selection', startPos, startPos)
            theAction = behavior_editing.RemoveActionCommand(
                self.behaviorName())
            addText = archyState.commandMap.findSystemCommand("AddText")
            addText.setinfo(self.newText, self.newTextStyle)
            theStyle = archyState.commandMap.findSystemCommand("Style")
            theStyle.setinfo(backgroundColor=(255, 255, 255),
                             foregroundColor=(0, 0, 0))

            theAction.execute()
            addText.execute()
            theStyle.execute()

            self.history.append(theAction)
            self.history.append(addText)
            self.history.append(theStyle)

            selStart, selEnd = archyState.mainText.getSelection('selection')
            archyState.mainText.setSelection('selection', selEnd + 1,
                                             selEnd + 1)
            self.theAction = behavior_editing.AddActionCommand(
                self.behaviorName())
            self.theAction.execute()
            self.history.append(self.theAction)

            archyState.mainText.setSelection('selection', selStart, selEnd)
        else:
            addText = archyState.commandMap.findSystemCommand("AddText")
            addText.setinfo(self.newText, self.newTextStyle)
            addText.execute()
            self.history.append(addText)
            messages.queue('You cannot type in Locked text.')
            messages.display()
Beispiel #17
0
    def onEnter(self):
        self.parent.showWhitespace()
        self.parent.showPreselection()
        
        message = ''
        if archyState.commandHistory._lastCommand <> None:
            message += 'Last Command: '+ archyState.commandHistory._lastCommand.name() + '\n'
        message += 'Command\n'
        messages.queue(message, 'command')
        self.commandText = ''
        self.suggestText = ''

        import platform_specific
        suggestStyle = platform_specific.Quasimode_Font
        suggestStyle['foregroundColor'] = 90,90,0
        suggestStyle['outline'] = 0
        pool = archyState.stylePool
        self.suggestStyle = pool.newStyle(**suggestStyle)
Beispiel #18
0
 def execute(self):
     self.origCursor = archyState.mainText.getCursorPos()
     moveOver = 0
     self.history = []
     
     startPos, endPos = self.findExtent(archyState.mainText)
     
     if self.origCursor == startPos:
         moveOver = 1
         archyState.mainText.setCursor(startPos)
     else:
         archyState.mainText.setCursor(endPos+1)
     
     if moveOver:
         archyState.mainText.setSelection('selection', startPos, startPos)
         theAction = behavior_editing.RemoveActionCommand(self.behaviorName())
         addText = archyState.commandMap.findSystemCommand("AddText")
         addText.setinfo(self.newText, self.newTextStyle)
         theStyle = archyState.commandMap.findSystemCommand("Style")
         theStyle.setinfo(backgroundColor = (255,255,255), foregroundColor = (0,0,0))
         
         theAction.execute()
         addText.execute()
         theStyle.execute()
         
         self.history.append(theAction)
         self.history.append(addText)
         self.history.append(theStyle)
         
         selStart, selEnd = archyState.mainText.getSelection('selection')
         archyState.mainText.setSelection('selection', selEnd+1, selEnd+1)
         self.theAction = behavior_editing.AddActionCommand(self.behaviorName())
         self.theAction.execute()
         self.history.append(self.theAction)
         
         archyState.mainText.setSelection('selection', selStart, selEnd)
     else:
         addText = archyState.commandMap.findSystemCommand("AddText")
         addText.setinfo(self.newText, self.newTextStyle)
         addText.execute()
         self.history.append(addText)
         messages.queue('You cannot type in Locked text.')
         messages.display()
Beispiel #19
0
    def execute(self):
        self.commandList = []
    
        mT = archyState.mainText
        self.origSel = mT.getSelection('selection')

        text = mT.textArray.getSubString(*self.origSel)
        words, wordRanges = self._findWordsAndRanges(text, self.origSel[0])

        c = getSpellChecker()

        firstWordPos = None
        for word, wordRange in zip(words, wordRanges):
            if c.check(word.lower()) or c.check(word.title()):
                pass
            else:
                mT.setSelection('selection', *wordRange)

                if firstWordPos == None:
                    firstWordPos = wordRange[0]
                
                styleCommand = archyState.commandMap.findSystemCommand("Style")
                styleCommand.setinfo(backgroundColor = (255,100,100))
                styleCommand.execute()
                self.commandList.append( styleCommand )
                
                storage = SpellcheckStorage()
                storage.setWord(word)
                mT.behaviorArray.setStorage("SPELLCHECK", storage)
                actionCommand = behavior_editing.AddActionCommand("SPELLCHECK")
                actionCommand.execute()
                self.commandList.append( actionCommand )
                
                
        
        if firstWordPos <> None:
            mT.setSelection('selection', firstWordPos, firstWordPos)
            mT.setCursor(firstWordPos)
        else:
            messages.queue('No spelling errors found.')
        
        self.commandList.reverse()
Beispiel #20
0
    def execute(self):
        mT = archyState.mainText

        self.origSel = mT.getSelection('selection')
        if mT.textArray.getSubString(*self.origSel).lower() <> FindNextCommand.searchTerm.lower():
            raise commands.AbortCommandException("Current selection is not \"%s\". Use command-tab to find the next instantance." % (FindNextCommand.searchTerm))

        self.origSearchEnd = FindNextCommand.searchEnd
        FindNextCommand.searchEnd += len(self.replacement) - len(FindNextCommand.searchTerm)

        self.delText = DeleteTextCommand()
        self.addText = AddTextCommand(self.replacement)
        self.findNext = FindNextCommand()

        self.delText.execute()
        self.addText.execute()
        try:
            self.findNext.execute()
        except commands.AbortCommandException, e:
            self.findNext = None
            messages.queue(e.getExplanation())
Beispiel #21
0
    def execute(self):
        self.commandList = []

        mT = archyState.mainText
        self.origSel = mT.getSelection('selection')

        text = mT.textArray.getSubString(*self.origSel)
        words, wordRanges = self._findWordsAndRanges(text, self.origSel[0])

        c = getSpellChecker()

        firstWordPos = None
        for word, wordRange in zip(words, wordRanges):
            if c.check(word.lower()) or c.check(word.title()):
                pass
            else:
                mT.setSelection('selection', *wordRange)

                if firstWordPos == None:
                    firstWordPos = wordRange[0]

                styleCommand = archyState.commandMap.findSystemCommand("Style")
                styleCommand.setinfo(backgroundColor=(255, 100, 100))
                styleCommand.execute()
                self.commandList.append(styleCommand)

                storage = SpellcheckStorage()
                storage.setWord(word)
                mT.behaviorArray.setStorage("SPELLCHECK", storage)
                actionCommand = behavior_editing.AddActionCommand("SPELLCHECK")
                actionCommand.execute()
                self.commandList.append(actionCommand)

        if firstWordPos <> None:
            mT.setSelection('selection', firstWordPos, firstWordPos)
            mT.setCursor(firstWordPos)
        else:
            messages.queue('No spelling errors found.')

        self.commandList.reverse()
Beispiel #22
0
    def execute(self):
        import email.Message

        selRange = archyState.mainText.getSelection("selection")
        text, style = archyState.mainText.getStyledText(*selRange)
        text = filter(lambda x: x <> "~", text)

        serverForm = getEmailServerInformation()
        emailForm = EmailForm()
        emailForm.parse(text)

        bodyTag = "Body:"
        bodyStart = text.find(bodyTag)
        text[bodyStart + len(bodyTag) :]
        msg = email.Message.Message()
        msg.set_payload(text[bodyStart + len(bodyTag) :])
        msg["To"] = emailForm["To"]
        msg["CC"] = emailForm["CC"]
        msg["Subject"] = emailForm["Subject"]

        newServerInfo = {
            "server": serverForm["Outgoing Server"],
            "authentication": serverForm["Outgoing Authentication"],
            "From": serverForm["Email Address"],
            "password": serverForm["Outgoing Password"],
            "user": serverForm["Outgoing User"],
            "TLS": serverForm["TLS"],
        }
        email_thread.outgoing_servers_lock.acquire()
        email_thread.outgoing_servers = [newServerInfo]
        email_thread.outgoing_servers_lock.release()

        email_thread.outgoing_email_lock.acquire()
        email_thread.outgoing_email.append(msg)
        email_thread.is_outgoing_mail.set()
        email_thread.outgoing_email_lock.release()

        messages.queue("Email sent successfully", "normal")
Beispiel #23
0
def show_message(msg):
    import messages
    messages.queue(msg)
Beispiel #24
0
        except SystemExit:
            raise
        except commands.AbortCommandException, e:
            messages.hide()
            messages.queue("%s: %s" % (command.name(), e.getExplanation()))
            messages.display()
        except:
            import debug

            error_name = "Command %s did not run properly." % command.name()
            print error_name
            tb_info = debug.get_traceback()
            debug.report_bug(error_name, tb_info)

            messages.hide()
            messages.queue(error_name)
            messages.display()

    def runCommand(self, command):
        commands.save_and_load.saveChanges()
        self._executeCommand(command, clearDisplay=1)
        archyState.commandHistory.setLastCommand(command)

    def runLastCommand(self):
        lastCommand = archyState.commandHistory.getLastCommand()
        if lastCommand == None:
            return
        if lastCommand.name()[:4] == "LEAP":
            if lastCommand.name()[5:13] == 'backward':
                command = archyState.commandMap.findSystemCommand( "Repeat LEAP backward" )
                command.setinfo( lastCommand._target )
Beispiel #25
0
    def undo(self):
        archyState.commandMap.registerCommand(EndReplaceCommand())
        archyState.commandMap.registerCommand(AcceptReplaceCommand())
        archyState.commandMap.registerCommand(FindNextCommand())

        messages.queue("command-space: change\ncommand-tab: find next\nEND - Exit REPLACE", "persistant")
Beispiel #26
0
def show_message(msg):
    import messages
    messages.queue(msg)