Skip to content

Commit 07abb34

Browse files
committedApr 16, 2013
[pyqgis-console] cleaning up code and minor fixes
1 parent b67d360 commit 07abb34

File tree

4 files changed

+38
-84
lines changed

4 files changed

+38
-84
lines changed
 

‎python/console/console.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def __init__(self, parent=None):
352352
self.toolBarEditor.addAction(self.uncommentEditorButton)
353353
self.toolBarEditor.addSeparator()
354354
self.toolBarEditor.addAction(self.runScriptEditorButton)
355-
355+
356356
## Menu Import Class
357357
self.classMenu = QMenu(self)
358358
self.classMenu.addAction(self.loadSextanteButton)
@@ -523,7 +523,7 @@ def openScriptFile(self):
523523
else:
524524
tabName = filename.split('/')[-1]
525525
self.tabEditorWidget.newTabEditor(tabName, filename)
526-
526+
527527
lastDirPath = QFileInfo(filename).path()
528528
settings.setValue("pythonConsole/lastDirPath", QVariant(filename))
529529
self.tabListScript.append(filename)

‎python/console/console_editor.py

Lines changed: 34 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,14 @@ def __init__(self, parent=None):
168168

169169
def autoComplete(self):
170170
self.autoCompleteFromAll()
171-
172-
#self.modificationChanged.connect(self.textEdited)
173171

174172
def on_margin_clicked(self, nmargin, nline, modifiers):
175173
# Toggle marker for the line the margin was clicked on
176174
if self.markersAtLine(nline) != 0:
177175
self.markerDelete(nline, self.ARROW_MARKER_NUM)
178176
else:
179177
self.markerAdd(nline, self.ARROW_MARKER_NUM)
180-
178+
181179
def refreshLexerProperties(self):
182180
self.setLexers()
183181

@@ -217,19 +215,19 @@ def setLexers(self):
217215
self.lexer.setAPIs(self.api)
218216

219217
self.setLexer(self.lexer)
220-
218+
221219
def move_cursor_to_end(self):
222220
"""Move cursor to end of text"""
223221
line, index = self.get_end_pos()
224222
self.setCursorPosition(line, index)
225223
self.ensureCursorVisible()
226224
self.ensureLineVisible(line)
227-
225+
228226
def get_end_pos(self):
229227
"""Return (line, index) position of the last character"""
230228
line = self.lines() - 1
231229
return (line, self.text(line).length())
232-
230+
233231
def contextMenuEvent(self, e):
234232
menu = QMenu(self)
235233
iconRun = QgsApplication.getThemeIcon("console/iconRunConsole.png")
@@ -302,7 +300,7 @@ def contextMenuEvent(self, e):
302300
if QApplication.clipboard().text() != "":
303301
pasteAction.setEnabled(True)
304302
action = menu.exec_(self.mapToGlobal(e.pos()))
305-
303+
306304
def codepad(self):
307305
import urllib2, urllib
308306
listText = self.selectedText().split('\n')
@@ -336,11 +334,12 @@ def codepad(self):
336334
except urllib2.URLError, e:
337335
msgText = QCoreApplication.translate('PythonConsole', 'Connection error: ')
338336
self.parent.pc.callWidgetMessageBarEditor(msgText + str(e.args))
339-
337+
340338
def hideEditor(self):
341339
Ed = self.parent.pc.widgetEditor
342340
Ed.hide()
343-
341+
self.parent.pc.showEditorButton.setChecked(False)
342+
344343
def commentEditorCode(self, commentCheck):
345344
if self.hasSelectedText():
346345
startLine, _, endLine, _ = self.getSelection()
@@ -357,7 +356,6 @@ def commentEditorCode(self, commentCheck):
357356
else:
358357
self.insert(selCmd)
359358
self.setCursorPosition(endLine, selCmd.length() - 2)
360-
361359
else:
362360
line, pos = self.getCursorPosition()
363361
selCmd = self.text(line)
@@ -423,36 +421,36 @@ def runScriptCode(self):
423421
#execfile(unicode(filename))
424422
except IOError, error:
425423
print 'Cannot execute file %s. Error: %s' % (filename, error.strerror)
426-
424+
427425
def runSelectedCode(self):
428426
cmd = self.selectedText()
429427
self.parent.pc.shell.insertFromDropPaste(cmd)
430428
self.parent.pc.shell.entered()
431429
self.setFocus()
432-
430+
433431
def getTextFromEditor(self):
434432
text = self.text()
435433
textList = text.split("\n")
436434
return textList
437-
435+
438436
class EditorTab(QWidget):
439437
def __init__(self, parent, parentConsole, filename, *args):
440438
QWidget.__init__(self, parent=None, *args)
441439
self.mw = parent
442440
self.pc = parentConsole
443441
self.path = None
444-
442+
445443
self.fileExcuteList = {}
446444
self.fileExcuteList = dict()
447-
445+
448446
self.newEditor = Editor(self)
449447
self.newEditor.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
450448
self.newEditor.modificationChanged.connect(self.modified)
451449
if filename:
452450
self.newEditor.setText(open(filename, "r").read())
453451
self.newEditor.setModified(False)
454452
self.path = filename
455-
453+
456454
# Creates layout for message bar
457455
self.layout = QGridLayout(self.newEditor)
458456
self.layout.setContentsMargins(0, 0, 0, 0)
@@ -463,28 +461,14 @@ def __init__(self, parent, parentConsole, filename, *args):
463461
sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
464462
self.infoBar.setSizePolicy(sizePolicy)
465463
self.layout.addWidget(self.infoBar, 0, 0, 1, 1)
466-
464+
467465
self.tabLayout = QGridLayout(self)
468466
self.tabLayout.setContentsMargins(0, 0, 0, 0)
469467
self.tabLayout.addWidget(self.newEditor)
470-
468+
471469
self.keyFilter = KeyFilter(parent, self)
472470
self.setEventFilter(self.keyFilter)
473-
474-
# def openFile(self):
475-
# scriptFile = QFileDialog.getOpenFileName(
476-
# self, "Open File", "", "Script file (*.py)")
477-
# if os.path.exists(scriptFile):
478-
# self.newEditor.setText(open(scriptFile, "r").read())
479-
# self.newEditor.setModified(False)
480-
# fN = scriptFile.split('/')[-1]
481-
# if fN:
482-
# self.mw.setTabTitle(self, fN)
483-
# self.path = scriptFile
484-
# index = self.mw.currentIndex()
485-
# idx = unicode(index)
486-
# self.fileExcuteList[idx] = unicode(scriptFile)
487-
471+
488472
def save(self):
489473
if self.path is None:
490474
self.path = str(QFileDialog().getSaveFileName(self,
@@ -514,27 +498,27 @@ def save(self):
514498
self.mw.setTabTitle(self, fN)
515499
self.newEditor.setModified(False)
516500
self.pc.updateTabListScript(self.path, action='append')
517-
501+
518502
def changeFont(self):
519503
self.newEditor.refreshLexerProperties()
520-
504+
521505
def modified(self, modified):
522506
self.mw.tabModified(self, modified)
523-
507+
524508
def close(self):
525509
self.mw._removeTab(self, tab2index=True)
526-
510+
527511
def setEventFilter(self, filter):
528512
self.newEditor.installEventFilter(filter)
529-
513+
530514
def newTab(self):
531515
self.mw.newTabEditor()
532-
516+
533517
class EditorTabWidget(QTabWidget):
534518
def __init__(self, parent):
535519
QTabWidget.__init__(self, parent=None)
536520
self.parent = parent
537-
521+
538522
# Layout for top frame (restore tabs)
539523
self.layoutTopFrame = QGridLayout(self)
540524
self.layoutTopFrame.setContentsMargins(0, 0, 0, 0)
@@ -549,7 +533,7 @@ def __init__(self, parent):
549533
label = QCoreApplication.translate("PythonConsole",
550534
"Click on button to restore all tabs from last session.")
551535
self.label = QLabel(label)
552-
536+
553537
self.restoreTabsButton = QToolButton()
554538
toolTipRestore = QCoreApplication.translate("PythonConsole",
555539
"Restore tabs")
@@ -559,7 +543,7 @@ def __init__(self, parent):
559543
self.restoreTabsButton.setCursor(Qt.PointingHandCursor)
560544
self.restoreTabsButton.setStyleSheet('QToolButton:hover{border: none } \
561545
QToolButton:pressed{border: none}')
562-
546+
563547
self.clButton = QToolButton()
564548
toolTipClose = QCoreApplication.translate("PythonConsole",
565549
"Close")
@@ -570,14 +554,14 @@ def __init__(self, parent):
570554
self.clButton.setStyleSheet('QToolButton:hover{border: none } \
571555
QToolButton:pressed{border: none}')
572556
self.clButton.setAutoRaise(True)
573-
557+
574558
sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
575559
self.topFrame.setSizePolicy(sizePolicy)
576560
self.layoutTopFrame.addWidget(self.topFrame, 0, 0, 1, 1)
577561
self.layoutTopFrame2.addWidget(self.label, 0, 1, 1, 1)
578562
self.layoutTopFrame2.addWidget(self.restoreTabsButton, 0, 0, 1, 1)
579563
self.layoutTopFrame2.addWidget(self.clButton, 0, 2, 1, 1)
580-
564+
581565
self.topFrame.hide()
582566
self.connect(self.restoreTabsButton, SIGNAL('clicked()'), self.restoreTabs)
583567
self.connect(self.clButton, SIGNAL('clicked()'), self.closeRestore)
@@ -589,12 +573,12 @@ def __init__(self, parent):
589573
self.newTabEditor(filename=None)
590574
if self.restoreTabList:
591575
self.topFrame.show()
592-
576+
593577
self.setDocumentMode(True)
594578
self.setMovable(True)
595579
#self.setTabsClosable(True)
596580
self.setTabPosition(QTabWidget.South)
597-
581+
598582
# Menu button list tabs
599583
self.fileTabMenu = QMenu(self)
600584
self.connect(self.fileTabMenu, SIGNAL("aboutToShow()"),
@@ -608,18 +592,16 @@ def __init__(self, parent):
608592
self.fileTabButton.setPopupMode(QToolButton.InstantPopup)
609593
self.fileTabButton.setMenu(self.fileTabMenu)
610594
self.setCornerWidget(self.fileTabButton, Qt.TopRightCorner)
611-
#self.connect(self.closeTabButton, SIGNAL('clicked()'), self.buttonClosePressed)
612-
613595
self.connect(self, SIGNAL("tabCloseRequested(int)"), self._removeTab)
614-
596+
615597
# Open button
616598
self.newTabButton = QToolButton(self)
617599
self.newTabButton.setToolTip('New Tab')
618600
self.newTabButton.setAutoRaise(True)
619601
self.newTabButton.setIcon(QgsApplication.getThemeIcon("console/iconNewTabEditorConsole.png"))
620602
self.setCornerWidget(self.newTabButton, Qt.TopLeftCorner)
621603
self.connect(self.newTabButton, SIGNAL('clicked()'), self.newTabEditor)
622-
604+
623605
def newTabEditor(self, tabName=None, filename=None):
624606
nr = self.count()
625607
if not tabName:
@@ -633,12 +615,12 @@ def newTabEditor(self, tabName=None, filename=None):
633615
self.iconTab = QgsApplication.getThemeIcon('console/iconTabEditorConsole.png')
634616
self.addTab(self.tab, self.iconTab, tabName)
635617
self.setCurrentWidget(self.tab)
636-
618+
637619
def tabModified(self, tab, modified):
638620
index = self.indexOf(tab)
639621
color = Qt.darkGray if modified else Qt.black
640622
self.tabBar().setTabTextColor(index, color)
641-
623+
642624
def closeTab(self, tab):
643625
# Check if file has been saved
644626
#if isModified:

‎python/console/console_output.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,13 @@ def __init__(self, parent=None):
119119
self.setWrapMode(QsciScintilla.WrapCharacter)
120120
self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0)
121121

122-
#self.runShortcut = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_E), self)
123-
#self.runShortcut.activated.connect(self.enteredSelected)
124122
# Reimplemeted copy action to prevent paste prompt (>>>,...) in command view
125123
self.copyShortcut = QShortcut(QKeySequence.Copy, self)
126124
self.copyShortcut.activated.connect(self.copy)
127125
self.selectAllShortcut = QShortcut(QKeySequence.SelectAll, self)
128126
self.selectAllShortcut.activated.connect(self.selectAll)
129127

130128
def insertInitText(self):
131-
# txtInit = QCoreApplication.translate("PythonConsole",
132-
# "## To access Quantum GIS environment from this console\n"
133-
# "## use iface object (instance of QgisInterface class).\n"
134-
# "## Type help(iface) for more info and list of methods.\n\n")
135-
# initText = self.setText(txtInit)
136129
txtInit = QCoreApplication.translate("PythonConsole",
137130
"Python %1 on %2\n"
138131
"## Type help(iface) for more info and list of methods.\n").arg(sys.version, socket.gethostname())
@@ -162,13 +155,7 @@ def setLexers(self):
162155

163156
self.setLexer(self.lexer)
164157

165-
# def getTextFromEditor(self):
166-
# text = self.text()
167-
# textList = text.split("\n")
168-
# return textList
169-
170158
def clearConsole(self):
171-
#self.SendScintilla(QsciScintilla.SCI_CLEARALL)
172159
self.setText('')
173160
self.insertInitText()
174161
self.shell.setFocus()
@@ -219,11 +206,12 @@ def hideToolBar(self):
219206
tB = self.parent.toolBar
220207
tB.hide() if tB.isVisible() else tB.show()
221208
self.shell.setFocus()
222-
209+
223210
def showEditor(self):
224211
Ed = self.parent.widgetEditor
225212
if not Ed.isVisible():
226213
Ed.show()
214+
self.parent.showEditorButton.setChecked(True)
227215
self.shell.setFocus()
228216

229217
def copy(self):
@@ -255,4 +243,3 @@ def keyPressEvent(self, e):
255243
def widgetMessageBar(self, iface, text):
256244
timeout = iface.messageTimeout()
257245
self.infoBar.pushMessage('Console', text, QgsMessageBar.INFO, timeout)
258-

‎python/console/console_sci.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -245,20 +245,6 @@ def new_prompt(self, prompt):
245245
def refreshLexerProperties(self):
246246
self.setLexers()
247247

248-
#def check_selection(self):
249-
#"""
250-
#Check if selected text is r/w,
251-
#otherwise remove read-only parts of selection
252-
#"""
253-
##if self.current_prompt_pos is None:
254-
##self.move_cursor_to_end()
255-
##return
256-
#line_from, index_from, line_to, index_to = self.getSelection()
257-
#pline, pindex = self.getCursorPosition()
258-
#if line_from < pline or \
259-
#(line_from == pline and index_from < pindex):
260-
#self.setSelection(pline, pindex, line_to, index_to)
261-
262248
def displayPrompt(self, more=False):
263249
self.append("... ") if more else self.append(">>> ")
264250
self.move_cursor_to_end()
@@ -338,7 +324,6 @@ def keyPressEvent(self, e):
338324
if e.key() in (Qt.Key_Left, Qt.Key_Right, Qt.Key_Home, Qt.Key_End):
339325
QsciScintilla.keyPressEvent(self, e)
340326
return
341-
342327
# all other keystrokes get sent to the input line
343328
self.move_cursor_to_end()
344329

0 commit comments

Comments
 (0)
Please sign in to comment.