Showing with 34 additions and 20 deletions.
  1. +3 −2 python/console/console.py
  2. +31 −18 python/console/console_editor.py
5 changes: 3 additions & 2 deletions python/console/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,10 @@ def saveAsScriptFile(self):
return
filename = QFileDialog.getSaveFileName(self,
"Save File As",
"*.py", "Script file (*.py)")
tabWidget.path, "Script file (*.py)")
if not filename.isEmpty():
self.tabListScript.remove(tabWidget.path)
#print tabWidget.path
self.tabListScript.remove(unicode(tabWidget.path))
tabWidget.path = filename
self.saveScriptFile()

Expand Down
49 changes: 31 additions & 18 deletions python/console/console_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ def __init__(self, parent, parentConsole, filename, *args):
self.newEditor.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
self.newEditor.modificationChanged.connect(self.modified)
if filename:
self.newEditor.setText(open(filename, "rt").read())
self.newEditor.setText(open(unicode(filename), "rt").read())
self.newEditor.setModified(False)
self.path = filename

Expand Down Expand Up @@ -513,22 +513,23 @@ def save(self):
'Script was correctly saved.')
self.pc.callWidgetMessageBarEditor(msgText)
# Rename the original file, if it exists
overwrite = os.path.exists(self.path)
path = unicode(self.path)
overwrite = os.path.exists(path)
if overwrite:
temp_path = self.path + "~"
temp_path = path + "~"
if os.path.exists(temp_path):
os.remove(temp_path)
os.rename(self.path, temp_path)
os.rename(path, temp_path)
# Save the new contents
with open(self.path, "w") as f:
with open(path, "w") as f:
f.write(self.newEditor.text())
if overwrite:
os.remove(temp_path)
fN = self.path.split('/')[-1]
fN = path.split('/')[-1]
self.mw.setTabTitle(self, fN)
self.mw.setTabToolTip(self.mw.currentIndex(), self.path)
self.mw.setTabToolTip(self.mw.currentIndex(), path)
self.newEditor.setModified(False)
self.pc.updateTabListScript(self.path, action='append')
self.pc.updateTabListScript(path, action='append')
self.mw.listObject(self)

def modified(self, modified):
Expand Down Expand Up @@ -722,12 +723,12 @@ def closeCurrentWidget(self):

def restoreTabs(self):
for script in self.restoreTabList:
pathFile = str(script.toString())
if os.path.exists(pathFile):
tabName = pathFile.split('/')[-1]
self.newTabEditor(tabName, pathFile)
else:
self.newTabEditor(filename=None)
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)

Expand Down Expand Up @@ -755,22 +756,34 @@ def listObject(self, tab):
else:
tabWidget = self.widget(tab)
if tabWidget.path:
pathFile, file = os.path.split(str(tabWidget.path))
pathFile, file = os.path.split(unicode(tabWidget.path))
module, ext = os.path.splitext(file)
#print sys.modules[module]
if pathFile not in sys.path:
sys.path.append(pathFile)
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 class_data.file == 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()
classItem.setText(0, name)
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))
classItem.setToolTip(0, name)
classItem.setIcon(0, QgsApplication.getThemeIcon("console/iconClassTreeWidgetConsole.png"))
dictObject[name] = class_data.lineno
for meth, lineno in sorted(class_data.methods.items(), key=itemgetter(1)):
Expand Down