mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
57a8705ec1
commit
111c73ab80
@ -29,7 +29,7 @@ class EditBlock(object): # {{{
|
|||||||
self.cursor.endEditBlock()
|
self.cursor.endEditBlock()
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
class Editor(QTextEdit):
|
class Console(QTextEdit):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def doc(self):
|
def doc(self):
|
||||||
@ -86,6 +86,8 @@ class Editor(QTextEdit):
|
|||||||
print list(self.prompt())
|
print list(self.prompt())
|
||||||
|
|
||||||
|
|
||||||
|
# Prompt management {{{
|
||||||
|
|
||||||
def prompt(self, strip_prompt_strings=True):
|
def prompt(self, strip_prompt_strings=True):
|
||||||
if not self.prompt_frame:
|
if not self.prompt_frame:
|
||||||
yield u'' if strip_prompt_strings else self.formatter.prompt
|
yield u'' if strip_prompt_strings else self.formatter.prompt
|
||||||
@ -99,15 +101,8 @@ class Editor(QTextEdit):
|
|||||||
yield t
|
yield t
|
||||||
it += 1
|
it += 1
|
||||||
|
|
||||||
|
def set_prompt(self, lines):
|
||||||
# Rendering {{{
|
self.render_current_prompt(lines)
|
||||||
|
|
||||||
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 clear_current_prompt(self):
|
def clear_current_prompt(self):
|
||||||
if self.prompt_frame is None:
|
if self.prompt_frame is None:
|
||||||
@ -121,8 +116,8 @@ class Editor(QTextEdit):
|
|||||||
c.removeSelectedText()
|
c.removeSelectedText()
|
||||||
c.setPosition(self.prompt_frame.firstPosition())
|
c.setPosition(self.prompt_frame.firstPosition())
|
||||||
|
|
||||||
def render_current_prompt(self):
|
def render_current_prompt(self, lines=None):
|
||||||
cp = list(self.prompt())
|
cp = list(self.prompt()) if lines is None else lines
|
||||||
self.clear_current_prompt()
|
self.clear_current_prompt()
|
||||||
|
|
||||||
for i, line in enumerate(cp):
|
for i, line in enumerate(cp):
|
||||||
@ -133,6 +128,18 @@ class Editor(QTextEdit):
|
|||||||
if not end:
|
if not end:
|
||||||
self.cursor.insertBlock()
|
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):
|
def show_error(self, is_syntax_err, tb):
|
||||||
if self.prompt_frame is not None:
|
if self.prompt_frame is not None:
|
||||||
# At a prompt, so redirect output
|
# At a prompt, so redirect output
|
@ -10,7 +10,7 @@ from PyQt4.Qt import QMainWindow, QToolBar, QStatusBar, QLabel, QFont, Qt, \
|
|||||||
QApplication
|
QApplication
|
||||||
|
|
||||||
from calibre.constants import __appname__, __version__
|
from calibre.constants import __appname__, __version__
|
||||||
from calibre.utils.pyconsole.editor import Editor
|
from calibre.utils.pyconsole.console import Console
|
||||||
|
|
||||||
class MainWindow(QMainWindow):
|
class MainWindow(QMainWindow):
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ class MainWindow(QMainWindow):
|
|||||||
self.tool_bar.setToolButtonStyle(Qt.ToolButtonTextOnly)
|
self.tool_bar.setToolButtonStyle(Qt.ToolButtonTextOnly)
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
self.editor = Editor(parent=self)
|
self.editor = Console(parent=self)
|
||||||
self.setCentralWidget(self.editor)
|
self.setCentralWidget(self.editor)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user