Skip to content

Commit

Permalink
Merge pull request #316 from slarosa/master
Browse files Browse the repository at this point in the history
Minor changes for layout in console
  • Loading branch information
brushtyler committed Nov 4, 2012
2 parents 08b05f3 + 38f82d3 commit 7b9aa99
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
27 changes: 19 additions & 8 deletions python/console/console_output.py
Expand Up @@ -75,6 +75,7 @@ def __init__(self, parent=None):
sys.stdout = writeOut(self, sys.stdout)
sys.stderr = writeOut(self, sys.stderr, "traceback")

self.insertInitText()
self.setLexers()
self.setReadOnly(True)

Expand All @@ -95,7 +96,7 @@ def __init__(self, parent=None):
self.setCaretLineVisible(True)
self.setCaretLineBackgroundColor(QColor("#fcf3ed"))

self.setMinimumHeight(80)
self.setMinimumHeight(120)

# Folding
#self.setFolding(QsciScintilla.BoxedTreeFoldStyle)
Expand All @@ -117,7 +118,13 @@ def __init__(self, parent=None):
self.copyShortcut.activated.connect(self.copy)
self.selectAllShortcut = QShortcut(QKeySequence.SelectAll, self)
self.selectAllShortcut.activated.connect(self.selectAll)


def insertInitText(self):
txtInit = QCoreApplication.translate("PythonConsole",
"## To access Quantum GIS environment from this console\n"
"## use qgis.utils.iface object (instance of QgisInterface class). Read help for more info.\n\n")
initText = self.setText(txtInit)

def refreshLexerProperties(self):
self.setLexers()

Expand Down Expand Up @@ -150,6 +157,7 @@ def getTextFromEditor(self):
def clearConsole(self):
#self.SendScintilla(QsciScintilla.SCI_CLEARALL)
self.setText('')
self.insertInitText()

def contextMenuEvent(self, e):
menu = QMenu(self)
Expand All @@ -175,6 +183,7 @@ def contextMenuEvent(self, e):
self.selectAll,
QKeySequence.SelectAll)
runAction.setEnabled(False)
clearAction.setEnabled(False)
copyAction.setEnabled(False)
pastebinAction.setEnabled(False)
selectAllAction.setEnabled(False)
Expand All @@ -184,6 +193,7 @@ def contextMenuEvent(self, e):
pastebinAction.setEnabled(True)
if not self.text() == '':
selectAllAction.setEnabled(True)
clearAction.setEnabled(True)
action = menu.exec_(self.mapToGlobal(e.pos()))

def copy(self):
Expand Down Expand Up @@ -214,14 +224,15 @@ def keyPressEvent(self, e):

def pastebin(self):
import urllib2, urllib
#listText = self.getTextFromEditor()
listText = self.selectedText().split('\n')
getCmd = []
for s in listText:
if s[0:3] in (">>>", "..."):
if not s[4] == "_":
s.replace(">>> ", "").replace("... ", "")
getCmd.append(unicode(s))
for strLine in listText:
if strLine != "":
#if s[0:3] in (">>>", "..."):
# filter for special command (_save,_clear) and comment
if strLine[4] != "_" and strLine[:2] != "##":
strLine.replace(">>> ", "").replace("... ", "")
getCmd.append(unicode(strLine))
pasteText= u"\n".join(getCmd)
url = 'http://codepad.org'
values = {'lang' : 'Python',
Expand Down
14 changes: 3 additions & 11 deletions python/console/console_sci.py
Expand Up @@ -50,7 +50,6 @@ def __init__(self, parent=None):

self.buffer = []

self.insertInitText()
self.displayPrompt(False)

for line in _init_commands:
Expand Down Expand Up @@ -95,7 +94,7 @@ def __init__(self, parent=None):

# not too small
#self.setMinimumSize(500, 300)
self.setMinimumHeight(50)
self.setMinimumHeight(20)

self.setWrapMode(QsciScintilla.WrapCharacter)
self.SendScintilla(QsciScintilla.SCI_EMPTYUNDOBUFFER)
Expand Down Expand Up @@ -174,7 +173,7 @@ def setLexers(self):
self.lexer.setFont(font, 4)

self.api = QsciAPIs(self.lexer)
chekBoxAPI = settings.value( "pythonConsole/preloadAPI" ).toBool()
chekBoxAPI = settings.value("pythonConsole/preloadAPI", True).toBool()
if chekBoxAPI:
self.api.loadPrepared( QgsApplication.pkgDataPath() + "/python/qsci_apis/pyqgis_master.pap" )
else:
Expand All @@ -199,13 +198,6 @@ def completion_list_selected(self, id, txt):
self.removeSelectedText()
self.insert(txt)

def insertInitText(self):
#self.setLexers(False)
txtInit = QCoreApplication.translate("PythonConsole", "## Interactive Python Console for Quantum GIS\n\n")
#"## To access Quantum GIS environment from this console\n"
#"## use qgis.utils.iface object (instance of QgisInterface class). Read help for more info.\n\n")
initText = self.setText(txtInit)

def getText(self):
""" Get the text as a unicode string. """
value = self.getBytes().decode('utf-8')
Expand Down Expand Up @@ -546,6 +538,6 @@ def write(self, txt):

def write_stdout(self, txt):
if len(txt) > 0:
getCmdString = self.text(2)
getCmdString = self.text()
prompt = getCmdString[0:4]
sys.stdout.write(prompt+txt+'\n')
2 changes: 1 addition & 1 deletion python/console/console_settings.py
Expand Up @@ -138,7 +138,7 @@ def saveSettings(self):
def restoreSettings(self):
settings = QSettings()
self.spinBox.setValue(settings.value("pythonConsole/fontsize").toInt()[0])
self.preloadAPI.setChecked(settings.value( "pythonConsole/preloadAPI" ).toBool())
self.preloadAPI.setChecked(settings.value("pythonConsole/preloadAPI", True).toBool())
itemTable = settings.value("pythonConsole/userAPI").toStringList()
for i in range(len(itemTable)):
self.tableWidget.insertRow(i)
Expand Down

0 comments on commit 7b9aa99

Please sign in to comment.