Skip to content
Permalink
Browse files

[pyqgis-console] add scroll area for settigs dialog

- does also the last tab closable
- fixes some translate string and warns the user
  if the file has been deleted
- minor fixes
  • Loading branch information
slarosa committed May 7, 2013
1 parent 469fb25 commit 9e5b889ac3aa0e77db0ff3feb0b18287ef8ffddd
Showing with 577 additions and 521 deletions.
  1. +1 −1 python/console/console.py
  2. +81 −76 python/console/console_editor.py
  3. +0 −8 python/console/console_settings.py
  4. +495 −436 python/console/console_settings.ui
@@ -652,7 +652,7 @@ def saveScriptFile(self):
except (IOError, OSError), e:
errTr = QCoreApplication.translate("PythonConsole", "Save Error")
msgErrTr = QCoreApplication.translate("PythonConsole",
"Failed to save %1: %2").arg(tabWidget.path, e)
"Failed to save %1: %2").arg(tabWidget.path).arg(e)
QMessageBox.warning(self, errTr, msgErrTr)

def saveAsScriptFile(self):
@@ -494,7 +494,7 @@ def _runSubProcess(self, filename, tmp=False):
except IOError, error:
IOErrorTr = QCoreApplication.translate('PythonConsole',
'Cannot execute file %1. Error: %2') \
.arg(filename, error.strerror)
.arg(filename).arg(error.strerror)
print IOErrorTr
except:
s = traceback.format_exc()
@@ -555,7 +555,12 @@ def goToLine(self, objName, linenr):
def focusInEvent(self, e):
pathfile = self.parent.path
if pathfile:
if not os.path.exists(pathfile): return
if not os.path.exists(pathfile):
msgText = QCoreApplication.translate('PythonConsole',
'The file <b>"%1"</b> has been deleted or is not accessible') \
.arg(pathfile)
self.parent.pc.callWidgetMessageBarEditor(msgText, 2, False)
return
if pathfile and self.mtime != os.stat(pathfile).st_mtime:
self.beginUndoAction()
self.selectAll()
@@ -567,7 +572,7 @@ def focusInEvent(self, e):
except IOError, error:
IOErrorTr = QCoreApplication.translate('PythonConsole',
'The file %1 could not be opened. Error: %2') \
.arg(pathfile, error.strerro)
.arg(pathfile).arg(error.strerror)
print IOErrorTr
for line in reversed(file):
self.insert(line)
@@ -581,7 +586,6 @@ def focusInEvent(self, e):
'The file <b>"%1"</b> has been changed and reloaded') \
.arg(pathfile)
self.parent.pc.callWidgetMessageBarEditor(msgText, 1, False)

QsciScintilla.focusInEvent(self, e)

class EditorTab(QWidget):
@@ -624,7 +628,7 @@ def loadFile(self, filename, modified):
except IOError, error:
IOErrorTr = QCoreApplication.translate('PythonConsole',
'The file <b>%1</b> could not be opened. Error: %2') \
.arg(filename, error.strerror)
.arg(filename).arg(error.strerror)
print IOErrorTr
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
txt = fn.read()
@@ -753,7 +757,7 @@ def __init__(self, parent):
self.setDocumentMode(True)

self.setMovable(True)
#self.setTabsClosable(True)
self.setTabsClosable(True)
self.setTabPosition(QTabWidget.North)

# Menu button list tabs
@@ -840,11 +844,11 @@ def newTabEditor(self, tabName=None, filename=None):
nr = self.count()
if not tabName:
tabName = QCoreApplication.translate('PythonConsole', 'Untitled-%1').arg(nr)
if self.count() < 1:
self.setTabsClosable(False)
else:
if not self.tabsClosable():
self.setTabsClosable(True)
# if self.count() < 1:
# self.setTabsClosable(False)
# else:
# if not self.tabsClosable():
# self.setTabsClosable(True)
self.tab = EditorTab(self, self.parent, filename)
self.iconTab = QgsApplication.getThemeIcon('console/iconTabEditorConsole.png')
self.addTab(self.tab, self.iconTab, tabName)
@@ -899,9 +903,10 @@ def _removeTab(self, tab, tab2index=False):
if self.widget(tab).path is not None or \
self.widget(tab).path in self.restoreTabList:
self.parent.updateTabListScript(self.widget(tab).path)
if self.count() <= 2:
self.setTabsClosable(False)
if self.count() <= 1:
# self.setTabsClosable(False)
self.removeTab(tab)
self.newTabEditor()
else:
self.removeTab(tab)
self.currentWidget().newEditor.setFocus(Qt.TabFocusReason)
@@ -963,69 +968,68 @@ def listObject(self, tab):
tabWidget = self.widget(self.indexOf(tab))
else:
tabWidget = self.widget(tab)
if tabWidget.path:
pathFile, file = os.path.split(unicode(tabWidget.path))
module, ext = os.path.splitext(file)
found = False
if pathFile not in sys.path:
sys.path.append(pathFile)
found = True
try:
reload(pyclbr)
dictObject = {}
superClassName = []
readModule = pyclbr.readmodule(module)
readModuleFunction = pyclbr.readmodule_ex(module)
for name, class_data in sorted(readModule.items(), key=lambda x:x[1].lineno):
if os.path.normpath(str(class_data.file)) == os.path.normpath(str(tabWidget.path)):
for superClass in class_data.super:
if superClass == 'object':
continue
if isinstance(superClass, basestring):
superClassName.append(superClass)
if tabWidget:
if tabWidget.path:
pathFile, file = os.path.split(unicode(tabWidget.path))
module, ext = os.path.splitext(file)
found = False
if pathFile not in sys.path:
sys.path.append(pathFile)
found = True
try:
reload(pyclbr)
dictObject = {}
superClassName = []
readModule = pyclbr.readmodule(module)
readModuleFunction = pyclbr.readmodule_ex(module)
for name, class_data in sorted(readModule.items(), key=lambda x:x[1].lineno):
if os.path.normpath(str(class_data.file)) == os.path.normpath(str(tabWidget.path)):
for superClass in class_data.super:
if superClass == 'object':
continue
if isinstance(superClass, basestring):
superClassName.append(superClass)
else:
superClassName.append(superClass.name)
classItem = QTreeWidgetItem()
if superClassName:
for i in superClassName: super = i
classItem.setText(0, name + ' [' + super + ']')
classItem.setToolTip(0, name + ' [' + super + ']')
else:
superClassName.append(superClass.name)
classItem = QTreeWidgetItem()
if superClassName:
for i in superClassName: super = i
classItem.setText(0, name + ' [' + super + ']')
classItem.setToolTip(0, name + ' [' + super + ']')
else:
classItem.setText(0, name)
classItem.setToolTip(0, name)
classItem.setText(1, str(class_data.lineno))
iconClass = QgsApplication.getThemeIcon("console/iconClassTreeWidgetConsole.png")
classItem.setIcon(0, iconClass)
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(1, str(lineno))
methodItem.setToolTip(0, meth)
iconMeth = QgsApplication.getThemeIcon("console/iconMethodTreeWidgetConsole.png")
methodItem.setIcon(0, iconMeth)
classItem.addChild(methodItem)
dictObject[meth] = lineno
# if found:
# sys.path.remove(os.path.split(unicode(str(class_data.file)))[0])
self.parent.listClassMethod.addTopLevelItem(classItem)
for func_name, data in sorted(readModuleFunction.items(), key=lambda x:x[1].lineno):
if isinstance(data, pyclbr.Function) and \
os.path.normpath(str(data.file)) == os.path.normpath(str(tabWidget.path)):
funcItem = QTreeWidgetItem()
funcItem.setText(0, func_name + ' ')
funcItem.setText(1, str(data.lineno))
funcItem.setToolTip(0, func_name)
iconFunc = QgsApplication.getThemeIcon("console/iconFunctionTreeWidgetConsole.png")
funcItem.setIcon(0, iconFunc)
dictObject[func_name] = data.lineno
self.parent.listClassMethod.addTopLevelItem(funcItem)
if found:
sys.path.remove(pathFile)
except:
s = traceback.format_exc()
print '## Error: '
sys.stderr.write(s)
classItem.setText(0, name)
classItem.setToolTip(0, name)
classItem.setText(1, str(class_data.lineno))
iconClass = QgsApplication.getThemeIcon("console/iconClassTreeWidgetConsole.png")
classItem.setIcon(0, iconClass)
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(1, str(lineno))
methodItem.setToolTip(0, meth)
iconMeth = QgsApplication.getThemeIcon("console/iconMethodTreeWidgetConsole.png")
methodItem.setIcon(0, iconMeth)
classItem.addChild(methodItem)
dictObject[meth] = lineno
self.parent.listClassMethod.addTopLevelItem(classItem)
for func_name, data in sorted(readModuleFunction.items(), key=lambda x:x[1].lineno):
if isinstance(data, pyclbr.Function) and \
os.path.normpath(str(data.file)) == os.path.normpath(str(tabWidget.path)):
funcItem = QTreeWidgetItem()
funcItem.setText(0, func_name + ' ')
funcItem.setText(1, str(data.lineno))
funcItem.setToolTip(0, func_name)
iconFunc = QgsApplication.getThemeIcon("console/iconFunctionTreeWidgetConsole.png")
funcItem.setIcon(0, iconFunc)
dictObject[func_name] = data.lineno
self.parent.listClassMethod.addTopLevelItem(funcItem)
if found:
sys.path.remove(pathFile)
except:
s = traceback.format_exc()
print '## Error: '
sys.stderr.write(s)

def refreshSettingsEditor(self):
countTab = self.count()
@@ -1034,7 +1038,8 @@ def refreshSettingsEditor(self):

def changeLastDirPath(self, tab):
tabWidget = self.widget(tab)
self.settings.setValue("pythonConsole/lastDirPath", QVariant(tabWidget.path))
if tabWidget:
self.settings.setValue("pythonConsole/lastDirPath", QVariant(tabWidget.path))

def widgetMessageBar(self, iface, text, level, timed=True):
messageLevel = [QgsMessageBar.INFO, QgsMessageBar.WARNING, QgsMessageBar.CRITICAL]
@@ -118,10 +118,6 @@ def addAPI(self, pathAPI):
apiNameItem = QTableWidgetItem(apiName)
self.tableWidget.setItem(count, 0, apiNameItem)
self.tableWidget.setItem(count, 1, pathItem)
self.tableWidget.setHorizontalHeaderLabels([self.tr("API"), self.tr("PATH")])
self.tableWidget.horizontalHeader().setResizeMode(0, QHeaderView.ResizeToContents)
self.tableWidget.horizontalHeader().show()
self.tableWidget.horizontalHeader().setResizeMode(1, QHeaderView.Stretch)

def removeAPI(self):
listItemSel = self.tableWidget.selectionModel().selectedRows()
@@ -193,10 +189,6 @@ def restoreSettings(self):
apiName = pathSplit[-1][0:-4]
self.tableWidget.setItem(i, 0, QTableWidgetItem(apiName))
self.tableWidget.setItem(i, 1, QTableWidgetItem(itemTable[i]))
self.tableWidget.setHorizontalHeaderLabels([self.tr("API"), self.tr("PATH")])
self.tableWidget.horizontalHeader().setResizeMode(0, QHeaderView.ResizeToContents)
self.tableWidget.horizontalHeader().show()
self.tableWidget.horizontalHeader().setResizeMode(1, QHeaderView.Stretch)
self.autoSaveScript.setChecked(settings.value("pythonConsole/autoSaveScript", False).toBool())

self.autoCompThreshold.setValue(settings.value("pythonConsole/autoCompThreshold", 2).toInt()[0])

0 comments on commit 9e5b889

Please sign in to comment.
You can’t perform that action at this time.