Skip to content

Commit

Permalink
[pyqgis-console] allows to handle non-ascii chars in script file name
Browse files Browse the repository at this point in the history
  • Loading branch information
slarosa committed Apr 22, 2013
1 parent 12a8390 commit 4e4b0a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
5 changes: 3 additions & 2 deletions python/console/console.py
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
22 changes: 11 additions & 11 deletions python/console/console_editor.py
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,7 +723,7 @@ def closeCurrentWidget(self):

def restoreTabs(self):
for script in self.restoreTabList:
pathFile = str(script.toString())
pathFile = unicode(script.toString())
if os.path.exists(pathFile):
tabName = pathFile.split('/')[-1]
self.newTabEditor(tabName, pathFile)
Expand Down Expand Up @@ -755,9 +756,8 @@ 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:
Expand Down

0 comments on commit 4e4b0a9

Please sign in to comment.