Skip to content

Commit 2c1f7e3

Browse files
committedApr 16, 2013
[pyqgis-console] some fix for run script and restore tabs
1 parent 708a99c commit 2c1f7e3

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed
 

‎python/console/console.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,6 @@ def saveScriptFile(self):
421421
QMessageBox.warning(self, "Save Error",
422422
"Failed to save %s: %s" % (tabWidget.path, e))
423423

424-
self.tabListScript.append(tabWidget.path)
425-
self.updateTabListScript(script=None)
426-
427424
def saveAsScriptFile(self):
428425
tabWidget = self.tabEditorWidget.currentWidget()
429426
if tabWidget is None:
@@ -432,6 +429,7 @@ def saveAsScriptFile(self):
432429
"Save File As",
433430
tabWidget.path, "Script file (*.py)")
434431
if not filename.isEmpty():
432+
self.tabListScript.remove(tabWidget.path)
435433
tabWidget.path = filename
436434
self.saveScriptFile()
437435

‎python/console/console_editor.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,14 +349,17 @@ def runScriptCode(self):
349349
else:
350350
try:
351351
p = subprocess.Popen(['python', filename], shell=False, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
352-
output = p.stderr.read()
353-
354-
if output:
352+
traceback = p.stderr.read()
353+
out = p.stdout.read()
354+
if traceback:
355355
print "## %s" % datetime.datetime.now()
356356
print "## Script error: %s" % name
357-
sys.stderr.write(output)
357+
sys.stderr.write(traceback)
358+
else:
359+
print "## %s" % datetime.datetime.now()
360+
print "## Script executed successfully: %s" % name
361+
sys.stdout.write(out)
358362
del p
359-
360363
#execfile(unicode(filename))
361364
except IOError, error:
362365
print 'Cannot execute file %s. Error: %s' % (filename, error.strerror)
@@ -434,7 +437,6 @@ def save(self):
434437
return
435438
msgText = QCoreApplication.translate('PythonConsole',
436439
'Script was correctly saved.')
437-
self.pc.updateTabListScript(self.path, action='append')
438440
self.pc.callWidgetMessageBarEditor(msgText)
439441
# Rename the original file, if it exists
440442
overwrite = os.path.exists(self.path)
@@ -451,7 +453,8 @@ def save(self):
451453
fN = self.path.split('/')[-1]
452454
self.mw.setTabTitle(self, fN)
453455
self.newEditor.setModified(False)
454-
456+
self.pc.updateTabListScript(self.path, action='append')
457+
455458
def changeFont(self):
456459
self.newEditor.refreshLexerProperties()
457460

0 commit comments

Comments
 (0)
Please sign in to comment.