Skip to content

Commit

Permalink
[pyqgis-console] allow to disable the object inspector from settings …
Browse files Browse the repository at this point in the history
…(default it is disabled)

- fixes some translation string
  • Loading branch information
slarosa committed May 15, 2013
1 parent aa0c754 commit 2566841
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 73 deletions.
5 changes: 3 additions & 2 deletions python/console/console.py
Expand Up @@ -122,7 +122,8 @@ def __init__(self, parent=None):

self.listClassMethod = QTreeWidget(self.splitterObj)
self.listClassMethod.setColumnCount(2)
self.listClassMethod.setHeaderLabels(['Object', 'Line'])
objInspLabel = QCoreApplication.translate("PythonConsole", "Object Inspector")
self.listClassMethod.setHeaderLabels([objInspLabel, ''])
self.listClassMethod.setColumnHidden(1, True)
self.listClassMethod.setAlternatingRowColors(True)

Expand Down Expand Up @@ -237,7 +238,7 @@ def __init__(self, parent=None):
self.uncommentEditorButton.setToolTip(uncommentEditorBt)
self.uncommentEditorButton.setText(uncommentEditorBt)
## Action for Object browser
objList = QCoreApplication.translate("PythonConsole", "Object browser")
objList = QCoreApplication.translate("PythonConsole", "Object Inspector")
self.objectListButton = QAction(self)
self.objectListButton.setCheckable(True)
self.objectListButton.setEnabled(True)
Expand Down
33 changes: 25 additions & 8 deletions python/console/console_editor.py
Expand Up @@ -186,6 +186,7 @@ def settingsEditor(self):
threshold = self.settings.value("pythonConsole/autoCompThresholdEditor", 2).toInt()[0]
radioButtonSource = self.settings.value("pythonConsole/autoCompleteSourceEditor", 'fromAPI').toString()
autoCompEnabled = self.settings.value("pythonConsole/autoCompleteEnabledEditor", True).toBool()

self.setAutoCompletionThreshold(threshold)
if autoCompEnabled:
if radioButtonSource == 'fromDoc':
Expand Down Expand Up @@ -693,6 +694,7 @@ def __init__(self, parent, parentConsole, filename, readOnly):
self.setEventFilter(self.keyFilter)

def loadFile(self, filename, modified):
self.newEditor.lastModified = QFileInfo(filename).lastModified()
fn = open(unicode(filename), "rb")
txt = fn.read()
fn.close()
Expand All @@ -702,7 +704,6 @@ def loadFile(self, filename, modified):
self.newEditor.setReadOnly(self.readOnly)
QApplication.restoreOverrideCursor()
self.newEditor.setModified(modified)
self.newEditor.lastModified = QFileInfo(filename).lastModified()
self.newEditor.recolor()

def save(self, fileName=None):
Expand Down Expand Up @@ -869,7 +870,9 @@ def __init__(self, parent):
self.connect(self.newTabButton, SIGNAL('clicked()'), self.newTabEditor)

def _currentWidgetChanged(self, tab):
self.listObject(tab)
if self.settings.value("pythonConsole/enableObjectInsp",
False).toBool():
self.listObject(tab)
self.changeLastDirPath(tab)
self.enableSaveIfModified(tab)

Expand Down Expand Up @@ -1021,6 +1024,7 @@ def closeCurrentWidget(self):
self.parent.updateTabListScript(currWidget.path, action='remove')

def restoreTabs(self):
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
for script in self.restoreTabList:
pathFile = unicode(script.toString())
if os.path.exists(pathFile):
Expand All @@ -1034,6 +1038,7 @@ def restoreTabs(self):
s = errOnRestore
sys.stderr.write(s)
self.parent.updateTabListScript(pathFile, action='remove')
QApplication.restoreOverrideCursor()
if self.count() < 1:
self.newTabEditor(filename=None)
self.topFrame.close()
Expand Down Expand Up @@ -1074,11 +1079,11 @@ def listObject(self, tab):
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)):
superClassName = []
for superClass in class_data.super:
if superClass == 'object':
continue
Expand All @@ -1088,7 +1093,7 @@ def listObject(self, tab):
superClassName.append(superClass.name)
classItem = QTreeWidgetItem()
if superClassName:
for i in superClassName: super = i
super = ', '.join([i for i in superClassName])
classItem.setText(0, name + ' [' + super + ']')
classItem.setToolTip(0, name + ' [' + super + ']')
else:
Expand Down Expand Up @@ -1128,16 +1133,28 @@ def listObject(self, tab):
iconWarning = QgsApplication.getThemeIcon("console/iconSyntaxErrorConsole.png")
msgItem.setIcon(0, iconWarning)
self.parent.listClassMethod.addTopLevelItem(msgItem)
#s = traceback.format_exc()
#print '## Error: '
#sys.stderr.write(s)
#pass
# s = traceback.format_exc()
# print '## Error: '
# sys.stderr.write(s)
# pass

def refreshSettingsEditor(self):
countTab = self.count()
for i in range(countTab):
self.widget(i).newEditor.settingsEditor()

objInspectorEnabled = self.settings.value("pythonConsole/enableObjectInsp",
False).toBool()
listObj = self.parent.objectListButton
listObj.setChecked(objInspectorEnabled)
listObj.setEnabled(objInspectorEnabled)
if objInspectorEnabled:
cW = self.currentWidget()
if cW:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
self.listObject(cW)
QApplication.restoreOverrideCursor()

def changeLastDirPath(self, tab):
tabWidget = self.widget(tab)
if tabWidget:
Expand Down
2 changes: 2 additions & 0 deletions python/console/console_settings.py
Expand Up @@ -175,6 +175,7 @@ def saveSettings(self):

settings.setValue("pythonConsole/autoCompleteEnabledEditor", QVariant(self.autoCompleteEnabledEditor.isChecked()))
settings.setValue("pythonConsole/autoCompleteEnabled", QVariant(self.autoCompleteEnabled.isChecked()))
settings.setValue("pythonConsole/enableObjectInsp", QVariant(self.enableObjectInspector.isChecked()))

def restoreSettings(self):
settings = QSettings()
Expand All @@ -196,6 +197,7 @@ def restoreSettings(self):

self.autoCompleteEnabledEditor.setChecked(settings.value("pythonConsole/autoCompleteEnabledEditor", True).toBool())
self.autoCompleteEnabled.setChecked(settings.value("pythonConsole/autoCompleteEnabled", True).toBool())
self.enableObjectInspector.setChecked(settings.value("pythonConsole/enableObjectInsp", False).toBool())

if settings.value("pythonConsole/autoCompleteSource") == 'fromDoc':
self.autoCompFromDoc.setChecked(True)
Expand Down

0 comments on commit 2566841

Please sign in to comment.