Skip to content

Commit

Permalink
[pyqgis-console] add scroll area for settigs dialog
Browse files Browse the repository at this point in the history
- 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 9e5b889
Show file tree
Hide file tree
Showing 4 changed files with 577 additions and 521 deletions.
2 changes: 1 addition & 1 deletion python/console/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
157 changes: 81 additions & 76 deletions python/console/console_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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]
Expand Down
8 changes: 0 additions & 8 deletions python/console/console_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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])
Expand Down
Loading

0 comments on commit 9e5b889

Please sign in to comment.