Пример #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)
Пример #2
0
 def _handle_lines(self, lines):
     try:
         self._input_data = []
         for line in lines:
             self.handle_line(line)
         
         if self._input_data:
             self.handle_line('')
         self.Dispatcher.BeginInvoke(self.Focus)
     except Exception, e:
         _debug('Handle lines', e)
Пример #3
0
    def _handle_lines(self, lines):
        try:
            self._input_data = []
            for line in lines:
                self.handle_line(line)

            if self._input_data:
                self.handle_line('')
            self.Dispatcher.BeginInvoke(lambda: self.Focus())
        except Exception, e:
            _debug('Handle lines', e)
Пример #4
0
    def print_lines(self, data):
        code = data.replace('\r\n', '\n').replace('\r', '\n')
        _debug('code', repr(code))

        self.block = get_console_block()
        self.parent.Children.Add(self.block)
        ps1 = sys.ps1
        ps2 = sys.ps2
        if not isinstance(ps1, str):
            ps1 = str(ps1)
            ps2 = str(ps2)
        for run in colorize(code, ps1, ps2):
            self.block.Inlines.Add(run)
            color = run.Foreground.Color
            #_debug("Printing run", repr(run.Text), color.R, color.G, color.B)
        #_debug(repr(self.block.Text))
        self.block = None
Пример #5
0
    def print_lines(self, data):
        code = data.replace('\r\n', '\n').replace('\r', '\n')
        _debug('code', repr(code))

        self.block = get_console_block()
        self.parent.Children.Add(self.block)
        ps1 = sys.ps1
        ps2 = sys.ps2
        if not isinstance(ps1, str):
            ps1 = str(ps1)
            ps2 = str(ps2)
        for run in colorize(code, ps1, ps2):
            self.block.Inlines.Add(run)
            color = run.Foreground.Color
            #_debug("Printing run", repr(run.Text), color.R, color.G, color.B)
        #_debug(repr(self.block.Text))
        self.block = None
Пример #6
0
def colorize(code, ps1, ps2):
    results = [get_prompt(ps1)]
    position = 0
    count_newlines = 0
    previous_token = None
    for token in tokenize(code):
        _debug(token.Category)
        if extra_newline(token, previous_token, code):
            position = token.SourceSpan.Start.Index + token.SourceSpan.Length
            continue
                
        results.extend(create_leading_whitespace_run(code, position, token, ps2))
        if token.Category == TokenCategory.WhiteSpace:
            continue
        position = token.SourceSpan.Start.Index + token.SourceSpan.Length
        results.extend(create_text_run(code, token, ps2))
        previous_token = token
    return results
Пример #7
0
def colorize(code, ps1, ps2):
    results = [get_prompt(ps1)]
    position = 0
    count_newlines = 0
    previous_token = None
    for token in tokenize(code):
        _debug(token.Category)
        if extra_newline(token, previous_token, code):
            position = token.SourceSpan.Start.Index + token.SourceSpan.Length
            continue

        results.extend(
            create_leading_whitespace_run(code, position, token, ps2))
        if token.Category == TokenCategory.WhiteSpace:
            continue
        position = token.SourceSpan.Start.Index + token.SourceSpan.Length
        results.extend(create_text_run(code, token, ps2))
        previous_token = token
    return results
Пример #8
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)
 def on_mouse_wheel(self, sender, event):
     delta = 0
     e = event.EventObject
     if e.GetProperty("detail"):
         delta = e.GetProperty("detail")
     elif e.GetProperty("wheelDelta"):
         delta = -e.GetProperty("wheelDelta")
     delta = Math.Sign(delta) * 40
     
     try:
         for scroller in self.scrollers:
             if self.mouse_over(scroller):
                 e.SetProperty('cancel', True)
                 e.SetProperty('cancelBubble', True)
                 e.SetProperty('returnValue', False)
                 if e.GetProperty('preventDefault'):
                     e.Invoke('preventDefault')
                 elif e.GetProperty('stopPropagation'):
                     e.Invoke('stopPropagation')
                 scroller.ScrollToVerticalOffset(scroller.VerticalOffset + delta)
                 return
     except Exception, e:
         _debug('Error in mouse wheel handler', e)
Пример #10
0
    def on_mouse_wheel(self, sender, event):
        delta = 0
        e = event.EventObject
        if e.GetProperty("detail"):
            delta = e.GetProperty("detail")
        elif e.GetProperty("wheelDelta"):
            delta = -e.GetProperty("wheelDelta")
        delta = Math.Sign(delta) * 40

        try:
            for scroller in self.scrollers:
                if self.mouse_over(scroller):
                    e.SetProperty('cancel', True)
                    e.SetProperty('cancelBubble', True)
                    e.SetProperty('returnValue', False)
                    if e.GetProperty('preventDefault'):
                        e.Invoke('preventDefault')
                    elif e.GetProperty('stopPropagation'):
                        e.Invoke('stopPropagation')
                    scroller.ScrollToVerticalOffset(scroller.VerticalOffset +
                                                    delta)
                    return
        except Exception, e:
            _debug('Error in mouse wheel handler', e)
Пример #11
0
 def goto_page(s, e, page=i + 1):
     _debug('goto', page)
     if topComboBoxPart.SelectedIndex == 0:
         topComboBoxPart.SelectedIndex = page
     else:
         topComboBoxPage.SelectedIndex = page
Пример #12
0
 def goto_page(s, e, page=i + 1):
     _debug("goto", page)
     if topComboBoxPart.SelectedIndex == 0:
         topComboBoxPart.SelectedIndex = page
     else:
         topComboBoxPage.SelectedIndex = page