Skip to content

Commit

Permalink
Merge pull request #311 from slarosa/master
Browse files Browse the repository at this point in the history
python console: add splitter and scrollbars, fix for DEL and Backspace key
  • Loading branch information
brushtyler committed Nov 1, 2012
2 parents 98e8ba4 + 66368f9 commit 29ed401
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
27 changes: 15 additions & 12 deletions python/console.py
Expand Up @@ -88,6 +88,11 @@ def __init__(self, parent=None):

self.options = optionsDialog(self)

self.splitter = QSplitter(self)
self.splitter.setOrientation(Qt.Vertical)
self.splitter.setHandleWidth(3)
self.splitter.setChildrenCollapsible(False)

self.toolBar = QToolBar()
self.toolBar.setEnabled(True)
self.toolBar.setFocusPolicy(Qt.NoFocus)
Expand Down Expand Up @@ -262,25 +267,23 @@ def __init__(self, parent=None):
sizePolicy.setHeightForWidth(self.widgetButton.sizePolicy().hasHeightForWidth())
self.widgetButton.setSizePolicy(sizePolicy)

self.consoleFrame = QFrame(self)
self.consoleFrame.setObjectName("consoleFrame")
self.consoleLayout = QVBoxLayout(self.consoleFrame)
self.consoleLayout.setSpacing(0)
self.consoleLayout.setMargin(0)
self.splitter.addWidget(self.textEditOut)
self.splitter.addWidget(self.edit)

sizes = self.splitter.sizes()
self.splitter.setSizes(sizes)

self.f.addWidget(self.widgetButton, 0, 0)
self.f.addWidget(self.splitter, 0, 1)

sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.textEditOut.sizePolicy().hasHeightForWidth())
self.textEditOut.setSizePolicy(sizePolicy)
self.consoleLayout.addWidget(self.textEditOut)

self.edit.setMinimumSize(QSize(0, 32))
self.edit.setMaximumSize(QSize(16777215, 32))
self.consoleLayout.addWidget(self.edit)

self.f.addWidget(self.widgetButton, 0, 0)
self.f.addWidget(self.consoleFrame, 0, 1)
self.textEditOut.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
self.edit.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)

self.clearButton.triggered.connect(self.textEditOut.clearConsole)
self.optionsButton.triggered.connect(self.openSettings)
Expand Down
3 changes: 2 additions & 1 deletion python/console_output.py
Expand Up @@ -94,6 +94,7 @@ def __init__(self, parent=None):
self.setCaretLineVisible(True)
self.setCaretLineBackgroundColor(QColor("#fcf3ed"))

self.setMinimumHeight(80)

# Folding
#self.setFolding(QsciScintilla.BoxedTreeFoldStyle)
Expand All @@ -105,7 +106,7 @@ def __init__(self, parent=None):
#self.setEdgeColumn(80)
#self.setEdgeColor(QColor("#FF0000"))

self.SendScintilla(QsciScintilla.SCI_SETWRAPMODE, 2)
self.setWrapMode(QsciScintilla.WrapCharacter)
self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0)

self.runShortcut = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_E), self)
Expand Down
13 changes: 6 additions & 7 deletions python/console_sci.py
Expand Up @@ -50,7 +50,7 @@ def __init__(self, parent=None):

self.buffer = []

#self.insertInitText()
self.insertInitText()
self.displayPrompt(False)

for line in _init_commands:
Expand Down Expand Up @@ -92,14 +92,12 @@ def __init__(self, parent=None):
# Use raw message to Scintilla here (all messages are documented
# here: http://www.scintilla.org/ScintillaDoc.html)
self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0)
self.SendScintilla(QsciScintilla.SCI_SETVSCROLLBAR, 0)


# not too small
#self.setMinimumSize(500, 300)
self.setMinimumHeight(32)
self.SendScintilla(QsciScintilla.SCI_SETWRAPMODE, 2)
self.setMinimumHeight(50)

self.setWrapMode(QsciScintilla.WrapCharacter)
self.SendScintilla(QsciScintilla.SCI_EMPTYUNDOBUFFER)

## Disable command key
Expand Down Expand Up @@ -394,6 +392,7 @@ def keyPressEvent(self, e):
# fix the cursor position
self.insert( cmd[:3-newindex] + " " )
self.setCursorPosition(line, 4)
self.recolor()

elif e.modifiers() & (Qt.ControlModifier | Qt.MetaModifier) and \
e.key() == Qt.Key_V:
Expand Down Expand Up @@ -553,6 +552,6 @@ def write(self, txt):

def write_stdout(self, txt):
if len(txt) > 0:
getCmdString = self.text()
getCmdString = self.text(2)
prompt = getCmdString[0:4]
sys.stdout.write(prompt+txt+'\n')

0 comments on commit 29ed401

Please sign in to comment.