Esempio n. 1
0
    def handle_line(self, line):
        self._input_data.append(line)

        code = '\n'.join(self._input_data)

        if len(self._input_data) == 1 and empty_or_comment_only(code):
            _debug('empty or comment')
            # needed or we get a SyntaxError
            self._input_data = []

            def enter_comment():
                self.Text = ''
                self.printer.print_lines(code)
                self.printer.scroll()

            return self.do_synchronously(enter_comment)

        if not self.is_complete(code, len(code)):
            return
        else:
            self._input_data = []

            def execute():
                self.execute(code)

            return self.do_synchronously(execute, wait_sync=True)
Esempio n. 2
0
 def handle_line(self, line):
     self._input_data.append(line)
     
     code = '\n'.join(self._input_data)
 
     if len(self._input_data) == 1 and empty_or_comment_only(code):
         _debug('empty or comment')
         # needed or we get a SyntaxError
         self._input_data = []
         def enter_comment():
             self.Text = ''
             self.printer.print_lines(code)
             self.printer.scroll()
         return self.do_synchronously(enter_comment)
     
     if not self.is_complete(code, len(code)):
         return
     else:
         self._input_data = []
         def execute():
             self.execute(code)
             
         return self.do_synchronously(execute, wait_sync=True)
Esempio n. 3
0
    def handle_key(self, sender, event):
        # Mac Safari uses '\r' for newlines in Silverlight TextBox??
        contents = self.Text.replace('\r\n', '\n').replace('\r', '\n')
        key = event.Key
        start = self.SelectionStart
        end = start + self.SelectionLength
        
        modifiers = Keyboard.Modifiers
        control = (modifiers & ModifierKeys.Control) or (modifiers & ModifierKeys.Apple)
        if key == Key.C and control:
            event.Handled = True
            self.keyboard_interrupt()
            return
        
        if self._thread is not None:
            # ignore key events (we have already checked for Ctrl-C)
            event.Handled = True
            return

        if key != Key.Enter:
            if key == Key.Up:
                if self.on_first_line(contents):
                    event.Handled = True
                    previous = self.history.back(contents)
                    if previous is not None:
                        self.Text = previous
                        self.SelectionStart = len(previous)
                    return
                
            elif key == Key.Down:
                if self.on_last_line(contents):
                    event.Handled = True
                    next = self.history.forward(contents)
                    if next is not None:
                        self.Text = next
                        self.SelectionStart = len(next)
                    return
            
            elif key == Key.Tab:
                event.Handled = True
                self.Text = self.Text[:start] + '    ' + self.Text[end:]
                self.SelectionStart = start + 4
                return
            
            if key == key.Add and self.ff3:
                if not (modifiers & ModifierKeys.Shift):
                    event.Handled = True
                    self.Text = self.Text[:start] + '=' + self.Text[end:]
                    self.SelectionStart = start + 1
                    return 
            
            TextBox.OnKeyDown(self, event)
            return
        
        event.Handled = True
        if empty_or_comment_only(contents):
            # needed or we get a SyntaxError
            self.Text = ''
            self.printer.print_lines(contents)
            self.printer.scroll()
            return
        
        # manual handling unfortunately
        # means things like trailing comments break
        # these functions; so not ideal
        stripped = contents.rstrip()
        if stripped == 'gohome':
            gohome()
        elif stripped == 'reset':
            contents = 'reset()'
        elif stripped == 'import this':
            # import hook so that importing *worked*
            # would be a better solution...
            self.printer.print_lines(stripped)
            self.Text = ''
            self.history.append(contents)
            import this
            self.context['this'] = this
            self.printer.set_prompt()
            self.printer.scroll()
            return
        
        if not self.is_complete(contents, start):
            self.do_indent(start)
        else:
            self.execute(contents)
Esempio n. 4
0
    def handle_key(self, sender, event):
        # Mac Safari uses '\r' for newlines in Silverlight TextBox??
        contents = self.Text.replace('\r\n', '\n').replace('\r', '\n')
        key = event.Key
        start = self.SelectionStart
        end = start + self.SelectionLength

        modifiers = Keyboard.Modifiers
        control = (modifiers & ModifierKeys.Control) or (modifiers
                                                         & ModifierKeys.Apple)
        if key == Key.C and control:
            event.Handled = True
            self.keyboard_interrupt()
            return

        if self._thread is not None:
            # ignore key events (we have already checked for Ctrl-C)
            event.Handled = True
            return

        if key != Key.Enter:
            if key == Key.Up:
                if self.on_first_line(contents):
                    event.Handled = True
                    previous = self.history.back(contents)
                    if previous is not None:
                        self.Text = previous
                        self.SelectionStart = len(previous)
                    return

            elif key == Key.Down:
                if self.on_last_line(contents):
                    event.Handled = True
                    next = self.history.forward(contents)
                    if next is not None:
                        self.Text = next
                        self.SelectionStart = len(next)
                    return

            elif key == Key.Tab:
                event.Handled = True
                self.Text = self.Text[:start] + '    ' + self.Text[end:]
                self.SelectionStart = start + 4
                return

            if key == key.Add and self.ff3:
                if not (modifiers & ModifierKeys.Shift):
                    event.Handled = True
                    self.Text = self.Text[:start] + '=' + self.Text[end:]
                    self.SelectionStart = start + 1
                    return

            TextBox.OnKeyDown(self, event)
            return

        event.Handled = True
        if empty_or_comment_only(contents):
            # needed or we get a SyntaxError
            self.Text = ''
            self.printer.print_lines(contents)
            self.printer.scroll()
            return

        # manual handling unfortunately
        # means things like trailing comments break
        # these functions; so not ideal
        stripped = contents.rstrip()
        if stripped == 'gohome':
            gohome()
        elif stripped == 'reset':
            contents = 'reset()'
        elif stripped == 'import this':
            # import hook so that importing *worked*
            # would be a better solution...
            self.printer.print_lines(stripped)
            self.Text = ''
            self.history.append(contents)
            import this
            self.context['this'] = this
            self.printer.set_prompt()
            self.printer.scroll()
            return

        if not self.is_complete(contents, start):
            self.do_indent(start)
        else:
            self.execute(contents)