From e22f0d162fdcced81b089611377ece8112ce6dd4 Mon Sep 17 00:00:00 2001 From: Salvatore Larosa Date: Mon, 22 Apr 2013 22:43:43 +0200 Subject: [PATCH] [pyqgis-console] fixes #7653 and #7646 - more minor fixes --- python/console/console.py | 11 ++++++++--- python/console/console_editor.py | 24 ++++++++++++++---------- python/console/console_sci.py | 9 ++++++--- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/python/console/console.py b/python/console/console.py index 20f18c5b3e4..adaf971e10d 100644 --- a/python/console/console.py +++ b/python/console/console.py @@ -130,7 +130,7 @@ class PythonConsoleWidget(QWidget): #self.splitterObj.addWidget(self.widgetEditor) # Hide side editor on start up - self.widgetEditor.hide() + self.splitterObj.hide() self.listClassMethod.hide() sizes = self.splitter.sizes() @@ -474,7 +474,12 @@ class PythonConsoleWidget(QWidget): def onClickGoToLine(self, item, column): linenr = int(item.text(1)) - objName = item.text(0) + itemName = str(item.text(0)) + charPos = itemName.find(' ') + if charPos != -1: + objName = itemName[0:charPos] + else: + objName = itemName self.tabEditorWidget.currentWidget().newEditor.goToLine(objName, linenr) def sextante(self): @@ -487,7 +492,7 @@ class PythonConsoleWidget(QWidget): self.shell.commandConsole('qtGui') def toggleEditor(self, checked): - self.widgetEditor.show() if checked else self.widgetEditor.hide() + self.splitterObj.show() if checked else self.splitterObj.hide() self.tabEditorWidget.enableToolBarEditor(checked) def toggleObjectListWidget(self, checked): diff --git a/python/console/console_editor.py b/python/console/console_editor.py index 773cbcb4b6d..2c5bc4adcf2 100644 --- a/python/console/console_editor.py +++ b/python/console/console_editor.py @@ -477,7 +477,7 @@ class EditorTab(QWidget): self.newEditor.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) self.newEditor.modificationChanged.connect(self.modified) if filename: - self.newEditor.setText(open(unicode(filename), "rt").read()) + self.newEditor.setText(open(unicode(filename), "r").read()) self.newEditor.setModified(False) self.path = filename @@ -605,8 +605,11 @@ class EditorTabWidget(QTabWidget): self.topFrame.show() else: self.newTabEditor(filename=None) + + ## Fixes #7653 + if sys.platform != 'darwin': + self.setDocumentMode(True) - self.setDocumentMode(True) self.setMovable(True) #self.setTabsClosable(True) self.setTabPosition(QTabWidget.South) @@ -723,12 +726,13 @@ class EditorTabWidget(QTabWidget): def restoreTabs(self): for script in self.restoreTabList: - pathFile = unicode(script.toString()) - if os.path.exists(pathFile): - tabName = pathFile.split('/')[-1] - self.newTabEditor(tabName, pathFile) - else: - self.newTabEditor(filename=None) + if script != '': + pathFile = unicode(script.toString()) + if os.path.exists(pathFile): + tabName = pathFile.split('/')[-1] + self.newTabEditor(tabName, pathFile) + else: + self.newTabEditor(filename=None) self.topFrame.close() self.enableToolBarEditor(True) @@ -788,7 +792,7 @@ class EditorTabWidget(QTabWidget): dictObject[name] = class_data.lineno for meth, lineno in sorted(class_data.methods.items(), key=itemgetter(1)): methodItem = QTreeWidgetItem() - methodItem.setText(0, meth) + methodItem.setText(0, meth + ' ') methodItem.setText(1, str(lineno)) methodItem.setToolTip(0, meth) methodItem.setIcon(0, QgsApplication.getThemeIcon("console/iconMethodTreeWidgetConsole.png")) @@ -798,7 +802,7 @@ class EditorTabWidget(QTabWidget): for func_name, data in sorted(readModuleFunction.items(), key=lambda x:x[1].lineno): if isinstance(data, pyclbr.Function) and data.file == tabWidget.path: funcItem = QTreeWidgetItem() - funcItem.setText(0, func_name) + funcItem.setText(0, func_name + ' ') funcItem.setText(1, str(data.lineno)) funcItem.setToolTip(0, func_name) funcItem.setIcon(0, QgsApplication.getThemeIcon("console/iconFunctionTreeWidgetConsole.png")) diff --git a/python/console/console_sci.py b/python/console/console_sci.py index 0bb0d9cb102..fa12bdc9e09 100644 --- a/python/console/console_sci.py +++ b/python/console/console_sci.py @@ -416,16 +416,16 @@ class ShellScintilla(QsciScintilla, code.InteractiveInterpreter): stringDrag = e.mimeData().text() self.insertFromDropPaste(stringDrag) self.setFocus() - e.setDropAction(Qt.MoveAction) + e.setDropAction(Qt.CopyAction) e.accept() else: QsciScintillaCompat.dropEvent(self, e) def insertFromDropPaste(self, textDP): - pasteList = textDP.split("\n") + pasteList = str(textDP).splitlines() for line in pasteList[:-1]: line.replace(">>> ", "").replace("... ", "") - self.insert(line) + self.insert(unicode(line)) self.move_cursor_to_end() self.runCommand(unicode(self.currentCommand())) if pasteList[-1] != "": @@ -493,6 +493,9 @@ class ShellScintilla(QsciScintilla, code.InteractiveInterpreter): more = self.runsource(src, "") if not more: self.buffer = [] + ## prevents to commands with more lines to break the console + ## in the case they have a eol different from '\n' + self.setText('') self.move_cursor_to_end() self.displayPrompt(more)