[education/labplot] src: [scripting] allow to open python files directly - a new script oject is created with the content of the selected python file.
Alexander Semke <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit a81290df6632a421d5bf3605daffe8d81ae6601f by Alexander Semke.
Committed on 06/08/2026 at 18:23.
Pushed by asemke into branch 'master'.
[scripting] allow to open python files directly - a new script oject is created with the content of the selected python file.
M +5 -0 src/backend/core/Project.cpp
M +20 -0 src/frontend/MainWin.cpp
https://invent.kde.org/education/labplot/-/commit/a81290df6632a421d5bf3605daffe8d81ae6601f
diff --git a/src/backend/core/Project.cpp b/src/backend/core/Project.cpp
index feef57ae18..5208d19818 100644
--- a/src/backend/core/Project.cpp
+++ b/src/backend/core/Project.cpp
@@ -444,6 +444,11 @@ bool Project::isSupportedProject(const QString& fileName) {
}
#endif
+#ifdef HAVE_SCRIPTING
+ if (!open)
+ open = fileName.endsWith(QLatin1String(".py"), Qt::CaseInsensitive);
+#endif
+
return open;
}
diff --git a/src/frontend/MainWin.cpp b/src/frontend/MainWin.cpp
index 12b85ea396..8cf4d3a500 100644
--- a/src/frontend/MainWin.cpp
+++ b/src/frontend/MainWin.cpp
@@ -739,6 +739,12 @@ void MainWin::openProject() {
supportOthers = true;
#endif
+#ifdef HAVE_SCRIPTING
+ extensions += QLatin1String(";;") + i18n("Python Scripts (*.py)");
+ allExtensions += QLatin1String(" *.py");
+ supportOthers = true;
+#endif
+
// add an entry for "All supported files" if we support more than labplot
if (supportOthers)
extensions = i18n("All supported files (%1)", allExtensions) + QLatin1String(";;") + extensions;
@@ -829,6 +835,20 @@ bool MainWin::openProject(const QString& fileName) {
}
#endif
+#ifdef HAVE_SCRIPTING
+ else if (fileName.endsWith(QLatin1String(".py"), Qt::CaseInsensitive)) {
+ WAIT_CURSOR_AUTO_RESET;
+ auto* script = new Script(QFileInfo(fileName).fileName(), QStringLiteral("Python"));
+ if (script->isInitialized() && script->kTextEditorDocument()->openUrl(QUrl::fromLocalFile(fileName))) {
+ addAspectToProject(script);
+ rc = true;
+ } else {
+ delete script;
+ rc = false;
+ }
+ }
+#endif
+
m_project->setChanged(false);
if (!rc) {