Skip to content

Commit 7b9aa99

Browse files
committed
Merge pull request #316 from slarosa/master
Minor changes for layout in console
2 parents 08b05f3 + 38f82d3 commit 7b9aa99

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

python/console/console_output.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def __init__(self, parent=None):
7575
sys.stdout = writeOut(self, sys.stdout)
7676
sys.stderr = writeOut(self, sys.stderr, "traceback")
7777

78+
self.insertInitText()
7879
self.setLexers()
7980
self.setReadOnly(True)
8081

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

98-
self.setMinimumHeight(80)
99+
self.setMinimumHeight(120)
99100

100101
# Folding
101102
#self.setFolding(QsciScintilla.BoxedTreeFoldStyle)
@@ -117,7 +118,13 @@ def __init__(self, parent=None):
117118
self.copyShortcut.activated.connect(self.copy)
118119
self.selectAllShortcut = QShortcut(QKeySequence.SelectAll, self)
119120
self.selectAllShortcut.activated.connect(self.selectAll)
120-
121+
122+
def insertInitText(self):
123+
txtInit = QCoreApplication.translate("PythonConsole",
124+
"## To access Quantum GIS environment from this console\n"
125+
"## use qgis.utils.iface object (instance of QgisInterface class). Read help for more info.\n\n")
126+
initText = self.setText(txtInit)
127+
121128
def refreshLexerProperties(self):
122129
self.setLexers()
123130

@@ -150,6 +157,7 @@ def getTextFromEditor(self):
150157
def clearConsole(self):
151158
#self.SendScintilla(QsciScintilla.SCI_CLEARALL)
152159
self.setText('')
160+
self.insertInitText()
153161

154162
def contextMenuEvent(self, e):
155163
menu = QMenu(self)
@@ -175,6 +183,7 @@ def contextMenuEvent(self, e):
175183
self.selectAll,
176184
QKeySequence.SelectAll)
177185
runAction.setEnabled(False)
186+
clearAction.setEnabled(False)
178187
copyAction.setEnabled(False)
179188
pastebinAction.setEnabled(False)
180189
selectAllAction.setEnabled(False)
@@ -184,6 +193,7 @@ def contextMenuEvent(self, e):
184193
pastebinAction.setEnabled(True)
185194
if not self.text() == '':
186195
selectAllAction.setEnabled(True)
196+
clearAction.setEnabled(True)
187197
action = menu.exec_(self.mapToGlobal(e.pos()))
188198

189199
def copy(self):
@@ -214,14 +224,15 @@ def keyPressEvent(self, e):
214224

215225
def pastebin(self):
216226
import urllib2, urllib
217-
#listText = self.getTextFromEditor()
218227
listText = self.selectedText().split('\n')
219228
getCmd = []
220-
for s in listText:
221-
if s[0:3] in (">>>", "..."):
222-
if not s[4] == "_":
223-
s.replace(">>> ", "").replace("... ", "")
224-
getCmd.append(unicode(s))
229+
for strLine in listText:
230+
if strLine != "":
231+
#if s[0:3] in (">>>", "..."):
232+
# filter for special command (_save,_clear) and comment
233+
if strLine[4] != "_" and strLine[:2] != "##":
234+
strLine.replace(">>> ", "").replace("... ", "")
235+
getCmd.append(unicode(strLine))
225236
pasteText= u"\n".join(getCmd)
226237
url = 'http://codepad.org'
227238
values = {'lang' : 'Python',

python/console/console_sci.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ def __init__(self, parent=None):
5050

5151
self.buffer = []
5252

53-
self.insertInitText()
5453
self.displayPrompt(False)
5554

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

9695
# not too small
9796
#self.setMinimumSize(500, 300)
98-
self.setMinimumHeight(50)
97+
self.setMinimumHeight(20)
9998

10099
self.setWrapMode(QsciScintilla.WrapCharacter)
101100
self.SendScintilla(QsciScintilla.SCI_EMPTYUNDOBUFFER)
@@ -174,7 +173,7 @@ def setLexers(self):
174173
self.lexer.setFont(font, 4)
175174

176175
self.api = QsciAPIs(self.lexer)
177-
chekBoxAPI = settings.value( "pythonConsole/preloadAPI" ).toBool()
176+
chekBoxAPI = settings.value("pythonConsole/preloadAPI", True).toBool()
178177
if chekBoxAPI:
179178
self.api.loadPrepared( QgsApplication.pkgDataPath() + "/python/qsci_apis/pyqgis_master.pap" )
180179
else:
@@ -199,13 +198,6 @@ def completion_list_selected(self, id, txt):
199198
self.removeSelectedText()
200199
self.insert(txt)
201200

202-
def insertInitText(self):
203-
#self.setLexers(False)
204-
txtInit = QCoreApplication.translate("PythonConsole", "## Interactive Python Console for Quantum GIS\n\n")
205-
#"## To access Quantum GIS environment from this console\n"
206-
#"## use qgis.utils.iface object (instance of QgisInterface class). Read help for more info.\n\n")
207-
initText = self.setText(txtInit)
208-
209201
def getText(self):
210202
""" Get the text as a unicode string. """
211203
value = self.getBytes().decode('utf-8')
@@ -546,6 +538,6 @@ def write(self, txt):
546538

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

python/console/console_settings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def saveSettings(self):
138138
def restoreSettings(self):
139139
settings = QSettings()
140140
self.spinBox.setValue(settings.value("pythonConsole/fontsize").toInt()[0])
141-
self.preloadAPI.setChecked(settings.value( "pythonConsole/preloadAPI" ).toBool())
141+
self.preloadAPI.setChecked(settings.value("pythonConsole/preloadAPI", True).toBool())
142142
itemTable = settings.value("pythonConsole/userAPI").toStringList()
143143
for i in range(len(itemTable)):
144144
self.tableWidget.insertRow(i)

0 commit comments

Comments
 (0)