Skip to content
Permalink
Browse files
Ensure python script files saved in the Python console editor use
.py file extension
  • Loading branch information
nyalldawson committed Jul 1, 2021
1 parent cb1b8d0 commit 174d5ee9e040282ef022fa63d2abf279b1e01896
Showing with 17 additions and 2 deletions.
  1. +8 −1 python/console/console.py
  2. +9 −1 python/console/console_editor.py
@@ -32,7 +32,12 @@
from .console_output import ShellOutputScintilla
from .console_editor import EditorTabWidget
from .console_settings import ConsoleOptionsFactory
from qgis.core import Qgis, QgsApplication, QgsSettings
from qgis.core import (
Qgis,
QgsApplication,
QgsSettings,
QgsFileUtils
)
from qgis.gui import (
QgsFilterLineEdit,
QgsHelp,
@@ -714,6 +719,8 @@ def saveAsScriptFile(self, index=None):
saveAsFileTr,
pathFileName, "Script file (*.py)")
if filename:
filename = QgsFileUtils.ensureFileNameHasExtension(filename, ['py'])

try:
tabWidget.save(filename)
except (IOError, OSError) as error:
@@ -23,7 +23,13 @@
from qgis.PyQt.QtNetwork import QNetworkRequest
from qgis.PyQt.QtWidgets import QShortcut, QMenu, QApplication, QWidget, QGridLayout, QSpacerItem, QSizePolicy, QFileDialog, QTabWidget, QTreeWidgetItem, QFrame, QLabel, QToolButton, QMessageBox
from qgis.PyQt.Qsci import QsciScintilla, QsciStyle
from qgis.core import Qgis, QgsApplication, QgsSettings, QgsBlockingNetworkRequest
from qgis.core import (
Qgis,
QgsApplication,
QgsSettings,
QgsBlockingNetworkRequest,
QgsFileUtils
)
from qgis.gui import QgsMessageBar, QgsCodeEditorPython
from qgis.utils import OverrideCursor
import sys
@@ -652,6 +658,8 @@ def save(self, fileName=None):
if len(self.path) == 0:
self.path = None
return

self.path = QgsFileUtils.ensureFileNameHasExtension(self.path, ['py'])
self.tw.setCurrentWidget(self)
msgText = QCoreApplication.translate('PythonConsole',
'Script was correctly saved.')

0 comments on commit 174d5ee

Please sign in to comment.