From 111c73ab80549913cc405d86d09ca69ef648e583 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 20 Sep 2010 13:46:11 -0600 Subject: [PATCH] ... --- .../utils/pyconsole/{editor.py => console.py} | 31 ++++++++++++------- src/calibre/utils/pyconsole/main.py | 4 +-- 2 files changed, 21 insertions(+), 14 deletions(-) rename src/calibre/utils/pyconsole/{editor.py => console.py} (96%) diff --git a/src/calibre/utils/pyconsole/editor.py b/src/calibre/utils/pyconsole/console.py similarity index 96% rename from src/calibre/utils/pyconsole/editor.py rename to src/calibre/utils/pyconsole/console.py index 431a10eda5..d95e86c7ef 100644 --- a/src/calibre/utils/pyconsole/editor.py +++ b/src/calibre/utils/pyconsole/console.py @@ -29,7 +29,7 @@ class EditBlock(object): # {{{ self.cursor.endEditBlock() # }}} -class Editor(QTextEdit): +class Console(QTextEdit): @property def doc(self): @@ -86,6 +86,8 @@ class Editor(QTextEdit): print list(self.prompt()) + # Prompt management {{{ + def prompt(self, strip_prompt_strings=True): if not self.prompt_frame: yield u'' if strip_prompt_strings else self.formatter.prompt @@ -99,15 +101,8 @@ class Editor(QTextEdit): yield t it += 1 - - # Rendering {{{ - - def render_block(self, text, restore_prompt=True): - self.formatter.render(self.lexer.get_tokens(text), self.cursor) - self.cursor.insertBlock() - self.cursor.movePosition(self.cursor.End) - if restore_prompt: - self.render_current_prompt() + def set_prompt(self, lines): + self.render_current_prompt(lines) def clear_current_prompt(self): if self.prompt_frame is None: @@ -121,8 +116,8 @@ class Editor(QTextEdit): c.removeSelectedText() c.setPosition(self.prompt_frame.firstPosition()) - def render_current_prompt(self): - cp = list(self.prompt()) + def render_current_prompt(self, lines=None): + cp = list(self.prompt()) if lines is None else lines self.clear_current_prompt() for i, line in enumerate(cp): @@ -133,6 +128,18 @@ class Editor(QTextEdit): if not end: self.cursor.insertBlock() + # }}} + + + # Non-prompt Rendering {{{ + + def render_block(self, text, restore_prompt=True): + self.formatter.render(self.lexer.get_tokens(text), self.cursor) + self.cursor.insertBlock() + self.cursor.movePosition(self.cursor.End) + if restore_prompt: + self.render_current_prompt() + def show_error(self, is_syntax_err, tb): if self.prompt_frame is not None: # At a prompt, so redirect output diff --git a/src/calibre/utils/pyconsole/main.py b/src/calibre/utils/pyconsole/main.py index c2694aae5f..af99ec66bb 100644 --- a/src/calibre/utils/pyconsole/main.py +++ b/src/calibre/utils/pyconsole/main.py @@ -10,7 +10,7 @@ from PyQt4.Qt import QMainWindow, QToolBar, QStatusBar, QLabel, QFont, Qt, \ QApplication from calibre.constants import __appname__, __version__ -from calibre.utils.pyconsole.editor import Editor +from calibre.utils.pyconsole.console import Console class MainWindow(QMainWindow): @@ -37,7 +37,7 @@ class MainWindow(QMainWindow): self.tool_bar.setToolButtonStyle(Qt.ToolButtonTextOnly) # }}} - self.editor = Editor(parent=self) + self.editor = Console(parent=self) self.setCentralWidget(self.editor)