diff options
Diffstat (limited to 'src/ipython_view.py')
-rw-r--r-- | src/ipython_view.py | 94 |
1 files changed, 47 insertions, 47 deletions
diff --git a/src/ipython_view.py b/src/ipython_view.py index a4ef8ca70..ef1cae5d2 100644 --- a/src/ipython_view.py +++ b/src/ipython_view.py @@ -37,8 +37,8 @@ Provides IPython console widget. @copyright: Copyright (c) 2007 IBM Corporation @license: BSD -All rights reserved. This program and the accompanying materials are made -available under the terms of the BSD which accompanies this distribution, and +All rights reserved. This program and the accompanying materials are made +available under the terms of the BSD which accompanies this distribution, and is available at U{http://www.opensource.org/licenses/bsd-license.php} ''' @@ -57,7 +57,7 @@ except ImportError: class IterableIPShell: ''' Create an IPython instance. Does not start a blocking event loop, - instead allow single iterations. This allows embedding in GTK+ + instead allow single iterations. This allows embedding in GTK+ without blockage. @ivar IP: IPython instance. @@ -65,17 +65,17 @@ class IterableIPShell: @ivar iter_more: Indicates if the line executed was a complete command, or we should wait for more. @type iter_more: integer - @ivar history_level: The place in history where we currently are + @ivar history_level: The place in history where we currently are when pressing up/down. @type history_level: integer @ivar complete_sep: Seperation delimeters for completion function. @type complete_sep: _sre.SRE_Pattern ''' - def __init__(self,argv=[],user_ns=None,user_global_ns=None, + def __init__(self,argv=[],user_ns=None,user_global_ns=None, cin=None, cout=None,cerr=None, input_func=None): ''' - - + + @param argv: Command line options for IPython @type argv: list @param user_ns: User namespace. @@ -85,7 +85,7 @@ class IterableIPShell: @param cin: Console standard input. @type cin: IO stream @param cout: Console standard output. - @type cout: IO stream + @type cout: IO stream @param cerr: Console standard error. @type cerr: IO stream @param input_func: Replacement for builtin raw_input() @@ -100,13 +100,13 @@ class IterableIPShell: if cerr: IPython.Shell.Term.cerr = cerr - # This is to get rid of the blockage that accurs during + # This is to get rid of the blockage that accurs during # IPython.Shell.InteractiveShell.user_setup() IPython.iplib.raw_input = lambda x: None self.term = IPython.genutils.IOTerm(cin=cin, cout=cout, cerr=cerr) os.environ['TERM'] = 'dumb' - excepthook = sys.excepthook + excepthook = sys.excepthook self.IP = IPython.Shell.make_IPython( argv,user_ns=user_ns, user_global_ns=user_global_ns, @@ -136,7 +136,7 @@ class IterableIPShell: self.IP.resetbuffer() # keep cache in sync with the prompt counter: self.IP.outputcache.prompt_count -= 1 - + if self.IP.autoindent: self.IP.indent_current_nsp = 0 self.iter_more = 0 @@ -158,27 +158,27 @@ class IterableIPShell: def historyBack(self): ''' Provides one history command back. - + @return: The command string. @rtype: string ''' self.history_level -= 1 return self._getHistory() - + def historyForward(self): ''' Provides one history command forward. - + @return: The command string. @rtype: string ''' self.history_level += 1 return self._getHistory() - + def _getHistory(self): ''' Get's the command string of the current history level. - + @return: Historic command string. @rtype: string ''' @@ -192,7 +192,7 @@ class IterableIPShell: def updateNamespace(self, ns_dict): ''' Add the current dictionary to the shell namespace. - + @param ns_dict: A dictionary of symbol-values. @type ns_dict: dictionary ''' @@ -201,11 +201,11 @@ class IterableIPShell: def complete(self, line): ''' Returns an auto completed line and/or posibilities for completion. - + @param line: Given line so far. @type line: string - - @return: Line completed as for as possible, + + @return: Line completed as for as possible, and possible further completions. @rtype: tuple ''' @@ -230,12 +230,12 @@ class IterableIPShell: else: completed = line return completed, possibilities - + def shell(self, cmd,verbose=0,debug=0,header=''): ''' Replacement method to allow shell commands without them blocking. - + @param cmd: Shell command to execute. @type cmd: string @param verbose: Verbosity @@ -286,28 +286,28 @@ class ConsoleView(gtk.TextView): self.modify_font(pango.FontDescription('Mono')) self.set_cursor_visible(True) self.text_buffer = self.get_buffer() - self.mark = self.text_buffer.create_mark('scroll_mark', + self.mark = self.text_buffer.create_mark('scroll_mark', self.text_buffer.get_end_iter(), False) for code in self.ANSI_COLORS: - self.text_buffer.create_tag(code, - foreground=self.ANSI_COLORS[code], + self.text_buffer.create_tag(code, + foreground=self.ANSI_COLORS[code], weight=700) self.text_buffer.create_tag('0') self.text_buffer.create_tag('notouch', editable=False) self.color_pat = re.compile('\x01?\x1b\[(.*?)m\x02?') self.line_start = \ - self.text_buffer.create_mark('line_start', + self.text_buffer.create_mark('line_start', self.text_buffer.get_end_iter(), True) self.connect('key-press-event', self.onKeyPress) - + def write(self, text, editable=False): gobject.idle_add(self._write, text, editable) def _write(self, text, editable=False): ''' Write given text to buffer. - + @param text: Text to append. @type text: string @param editable: If true, added text is editable. @@ -315,8 +315,8 @@ class ConsoleView(gtk.TextView): ''' segments = self.color_pat.split(text) segment = segments.pop(0) - start_mark = self.text_buffer.create_mark(None, - self.text_buffer.get_end_iter(), + start_mark = self.text_buffer.create_mark(None, + self.text_buffer.get_end_iter(), True) self.text_buffer.insert(self.text_buffer.get_end_iter(), segment) @@ -341,7 +341,7 @@ class ConsoleView(gtk.TextView): def _showPrompt(self, prompt): ''' Prints prompt at start of line. - + @param prompt: Prompt to print. @type prompt: string ''' @@ -355,7 +355,7 @@ class ConsoleView(gtk.TextView): def _changeLine(self, text): ''' Replace currently entered command line with given text. - + @param text: Text to use as replacement. @type text: string ''' @@ -367,7 +367,7 @@ class ConsoleView(gtk.TextView): def getCurrentLine(self): ''' Get text in current command line. - + @return: Text of current command line. @rtype: string ''' @@ -382,14 +382,14 @@ class ConsoleView(gtk.TextView): def _showReturned(self, text): ''' Show returned text from last command and print new prompt. - + @param text: Text to show. @type text: string ''' iter_ = self.text_buffer.get_iter_at_mark(self.line_start) iter_.forward_to_line_end() self.text_buffer.apply_tag_by_name( - 'notouch', + 'notouch', self.text_buffer.get_iter_at_mark(self.line_start), iter_) self._write('\n'+text) @@ -401,15 +401,15 @@ class ConsoleView(gtk.TextView): def onKeyPress(self, widget, event): ''' - Key press callback used for correcting behavior for console-like + Key press callback used for correcting behavior for console-like interfaces. For example 'home' should go to prompt, not to begining of line. - + @param widget: Widget that key press accored in. @type widget: gtk.Widget @param event: Event object @type event: gtk.gdk.Event - + @return: Return True if event should not trickle. @rtype: boolean ''' @@ -419,7 +419,7 @@ class ConsoleView(gtk.TextView): selection_iter = self.text_buffer.get_iter_at_mark(selection_mark) start_iter = self.text_buffer.get_iter_at_mark(self.line_start) if event.keyval == gtk.keysyms.Home: - if event.state == 0: + if event.state == 0: self.text_buffer.place_cursor(start_iter) return True elif event.state == gtk.gdk.SHIFT_MASK: @@ -440,7 +440,7 @@ class ConsoleView(gtk.TextView): elif insert_iter.compare(selection_iter) < 0: self.text_buffer.move_mark(insert_mark, start_iter) elif insert_iter.compare(selection_iter) > 0: - self.text_buffer.move_mark(selection_mark, start_iter) + self.text_buffer.move_mark(selection_mark, start_iter) return self.onKeyPressExtend(event) @@ -461,7 +461,7 @@ class IPythonView(ConsoleView, IterableIPShell): ''' ConsoleView.__init__(self) self.cout = StringIO() - IterableIPShell.__init__(self, cout=self.cout,cerr=self.cout, + IterableIPShell.__init__(self, cout=self.cout,cerr=self.cout, input_func=self.raw_input) # self.connect('key_press_event', self.keyPress) self.execute() @@ -472,10 +472,10 @@ class IPythonView(ConsoleView, IterableIPShell): def raw_input(self, prompt=''): ''' Custom raw_input() replacement. Get's current line from console buffer. - + @param prompt: Prompt to print. Here for compatability as replacement. @type prompt: string - + @return: The current command line text. @rtype: string ''' @@ -486,14 +486,14 @@ class IPythonView(ConsoleView, IterableIPShell): def onKeyPressExtend(self, event): ''' - Key press callback with plenty of shell goodness, like history, + Key press callback with plenty of shell goodness, like history, autocompletions, etc. - + @param widget: Widget that key press occured in. @type widget: gtk.Widget @param event: Event object. @type event: gtk.gdk.Event - + @return: True if event should not trickle. @rtype: boolean ''' @@ -533,6 +533,6 @@ class IPythonView(ConsoleView, IterableIPShell): if rv: rv = rv.strip('\n') self.showReturned(rv) self.cout.truncate(0) - + # vim: se ts=3: |