mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-08 17:24:20 +02:00
...
This commit is contained in:
parent
57a8705ec1
commit
111c73ab80
2 changed files with 21 additions and 14 deletions
|
|
@ -29,7 +29,7 @@ def __exit__(self, *args):
|
|||
self.cursor.endEditBlock()
|
||||
# }}}
|
||||
|
||||
class Editor(QTextEdit):
|
||||
class Console(QTextEdit):
|
||||
|
||||
@property
|
||||
def doc(self):
|
||||
|
|
@ -86,6 +86,8 @@ def __init__(self,
|
|||
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 @@ def prompt(self, strip_prompt_strings=True):
|
|||
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 @@ def clear_current_prompt(self):
|
|||
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 @@ def render_current_prompt(self):
|
|||
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
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
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 @@ def __init__(self, default_status_msg):
|
|||
self.tool_bar.setToolButtonStyle(Qt.ToolButtonTextOnly)
|
||||
# }}}
|
||||
|
||||
self.editor = Editor(parent=self)
|
||||
self.editor = Console(parent=self)
|
||||
self.setCentralWidget(self.editor)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue