Skip to content

Commit e22f0d1

Browse files
committedApr 23, 2013
[pyqgis-console] fixes #7653 and #7646
- more minor fixes
1 parent 2e6178c commit e22f0d1

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed
 

‎python/console/console.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def __init__(self, parent=None):
130130
#self.splitterObj.addWidget(self.widgetEditor)
131131

132132
# Hide side editor on start up
133-
self.widgetEditor.hide()
133+
self.splitterObj.hide()
134134
self.listClassMethod.hide()
135135

136136
sizes = self.splitter.sizes()
@@ -474,7 +474,12 @@ def __init__(self, parent=None):
474474

475475
def onClickGoToLine(self, item, column):
476476
linenr = int(item.text(1))
477-
objName = item.text(0)
477+
itemName = str(item.text(0))
478+
charPos = itemName.find(' ')
479+
if charPos != -1:
480+
objName = itemName[0:charPos]
481+
else:
482+
objName = itemName
478483
self.tabEditorWidget.currentWidget().newEditor.goToLine(objName, linenr)
479484

480485
def sextante(self):
@@ -487,7 +492,7 @@ def qtGui(self):
487492
self.shell.commandConsole('qtGui')
488493

489494
def toggleEditor(self, checked):
490-
self.widgetEditor.show() if checked else self.widgetEditor.hide()
495+
self.splitterObj.show() if checked else self.splitterObj.hide()
491496
self.tabEditorWidget.enableToolBarEditor(checked)
492497

493498
def toggleObjectListWidget(self, checked):

‎python/console/console_editor.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ def __init__(self, parent, parentConsole, filename, *args):
477477
self.newEditor.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
478478
self.newEditor.modificationChanged.connect(self.modified)
479479
if filename:
480-
self.newEditor.setText(open(unicode(filename), "rt").read())
480+
self.newEditor.setText(open(unicode(filename), "r").read())
481481
self.newEditor.setModified(False)
482482
self.path = filename
483483

@@ -605,8 +605,11 @@ def __init__(self, parent):
605605
self.topFrame.show()
606606
else:
607607
self.newTabEditor(filename=None)
608+
609+
## Fixes #7653
610+
if sys.platform != 'darwin':
611+
self.setDocumentMode(True)
608612

609-
self.setDocumentMode(True)
610613
self.setMovable(True)
611614
#self.setTabsClosable(True)
612615
self.setTabPosition(QTabWidget.South)
@@ -723,12 +726,13 @@ def closeCurrentWidget(self):
723726

724727
def restoreTabs(self):
725728
for script in self.restoreTabList:
726-
pathFile = unicode(script.toString())
727-
if os.path.exists(pathFile):
728-
tabName = pathFile.split('/')[-1]
729-
self.newTabEditor(tabName, pathFile)
730-
else:
731-
self.newTabEditor(filename=None)
729+
if script != '':
730+
pathFile = unicode(script.toString())
731+
if os.path.exists(pathFile):
732+
tabName = pathFile.split('/')[-1]
733+
self.newTabEditor(tabName, pathFile)
734+
else:
735+
self.newTabEditor(filename=None)
732736
self.topFrame.close()
733737
self.enableToolBarEditor(True)
734738

@@ -788,7 +792,7 @@ def listObject(self, tab):
788792
dictObject[name] = class_data.lineno
789793
for meth, lineno in sorted(class_data.methods.items(), key=itemgetter(1)):
790794
methodItem = QTreeWidgetItem()
791-
methodItem.setText(0, meth)
795+
methodItem.setText(0, meth + ' ')
792796
methodItem.setText(1, str(lineno))
793797
methodItem.setToolTip(0, meth)
794798
methodItem.setIcon(0, QgsApplication.getThemeIcon("console/iconMethodTreeWidgetConsole.png"))
@@ -798,7 +802,7 @@ def listObject(self, tab):
798802
for func_name, data in sorted(readModuleFunction.items(), key=lambda x:x[1].lineno):
799803
if isinstance(data, pyclbr.Function) and data.file == tabWidget.path:
800804
funcItem = QTreeWidgetItem()
801-
funcItem.setText(0, func_name)
805+
funcItem.setText(0, func_name + ' ')
802806
funcItem.setText(1, str(data.lineno))
803807
funcItem.setToolTip(0, func_name)
804808
funcItem.setIcon(0, QgsApplication.getThemeIcon("console/iconFunctionTreeWidgetConsole.png"))

‎python/console/console_sci.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,16 +416,16 @@ def dropEvent(self, e):
416416
stringDrag = e.mimeData().text()
417417
self.insertFromDropPaste(stringDrag)
418418
self.setFocus()
419-
e.setDropAction(Qt.MoveAction)
419+
e.setDropAction(Qt.CopyAction)
420420
e.accept()
421421
else:
422422
QsciScintillaCompat.dropEvent(self, e)
423423

424424
def insertFromDropPaste(self, textDP):
425-
pasteList = textDP.split("\n")
425+
pasteList = str(textDP).splitlines()
426426
for line in pasteList[:-1]:
427427
line.replace(">>> ", "").replace("... ", "")
428-
self.insert(line)
428+
self.insert(unicode(line))
429429
self.move_cursor_to_end()
430430
self.runCommand(unicode(self.currentCommand()))
431431
if pasteList[-1] != "":
@@ -493,6 +493,9 @@ def runCommand(self, cmd):
493493
more = self.runsource(src, "<input>")
494494
if not more:
495495
self.buffer = []
496+
## prevents to commands with more lines to break the console
497+
## in the case they have a eol different from '\n'
498+
self.setText('')
496499
self.move_cursor_to_end()
497500
self.displayPrompt(more)
498501

0 commit comments

Comments
 (0)
Please sign in to comment.