fix(gui): add interactive methods to FileOriginPython and fix Console API calls
Some checks failed
Build and Test / build (push) Failing after 2m13s

- Add openDocumentInteractive() and saveDocumentAsInteractive() to FileOriginPython
- Fix Console API: Warning -> warning, Error -> error in OriginManager.cpp
- These methods bridge Python origins to the new interactive document operations
This commit is contained in:
2026-02-05 14:25:21 -06:00
parent 38358e431d
commit 79c85ed2e5
3 changed files with 71 additions and 23 deletions

View File

@@ -24,6 +24,7 @@
#include <App/Application.h>
#include <App/Document.h>
#include <App/DocumentPy.h>
#include <Base/Console.h>
#include <Base/Interpreter.h>
#include <Base/PyObjectBase.h>
@@ -41,7 +42,7 @@ void FileOriginPython::addOrigin(const Py::Object& obj)
{
// Check if already registered
if (findOrigin(obj)) {
Base::Console().Warning("FileOriginPython: Origin already registered\n");
Base::Console().warning("FileOriginPython: Origin already registered\n");
return;
}
@@ -50,7 +51,7 @@ void FileOriginPython::addOrigin(const Py::Object& obj)
// Cache the ID immediately for registration
origin->_cachedId = origin->callStringMethod("id");
if (origin->_cachedId.empty()) {
Base::Console().Error("FileOriginPython: Origin must have non-empty id()\n");
Base::Console().error("FileOriginPython: Origin must have non-empty id()\n");
delete origin;
return;
}
@@ -117,7 +118,7 @@ Py::Object FileOriginPython::callMethod(const char* method, const Py::Tuple& arg
}
catch (Py::Exception&) {
Base::PyException e;
e.ReportException();
e.reportException();
}
return Py::None();
}
@@ -139,7 +140,7 @@ bool FileOriginPython::callBoolMethod(const char* method, bool defaultValue) con
}
catch (Py::Exception&) {
Base::PyException e;
e.ReportException();
e.reportException();
}
return defaultValue;
}
@@ -158,7 +159,7 @@ std::string FileOriginPython::callStringMethod(const char* method, const std::st
}
catch (Py::Exception&) {
Base::PyException e;
e.ReportException();
e.reportException();
}
return defaultValue;
}
@@ -210,7 +211,7 @@ OriginType FileOriginPython::type() const
}
catch (Py::Exception&) {
Base::PyException e;
e.ReportException();
e.reportException();
}
return OriginType::Custom;
}
@@ -265,7 +266,7 @@ ConnectionState FileOriginPython::connectionState() const
}
catch (Py::Exception&) {
Base::PyException e;
e.ReportException();
e.reportException();
}
return ConnectionState::Connected;
}
@@ -297,7 +298,7 @@ std::string FileOriginPython::documentIdentity(App::Document* doc) const
}
catch (Py::Exception&) {
Base::PyException e;
e.ReportException();
e.reportException();
}
return {};
}
@@ -318,7 +319,7 @@ std::string FileOriginPython::documentDisplayId(App::Document* doc) const
}
catch (Py::Exception&) {
Base::PyException e;
e.ReportException();
e.reportException();
}
return documentIdentity(doc);
}
@@ -342,7 +343,7 @@ bool FileOriginPython::ownsDocument(App::Document* doc) const
}
catch (Py::Exception&) {
Base::PyException e;
e.ReportException();
e.reportException();
}
return false;
}
@@ -366,7 +367,7 @@ bool FileOriginPython::syncProperties(App::Document* doc)
}
catch (Py::Exception&) {
Base::PyException e;
e.ReportException();
e.reportException();
}
return true;
}
@@ -391,7 +392,7 @@ App::Document* FileOriginPython::newDocument(const std::string& name)
}
catch (Py::Exception&) {
Base::PyException e;
e.ReportException();
e.reportException();
}
return nullptr;
}
@@ -414,7 +415,7 @@ App::Document* FileOriginPython::openDocument(const std::string& identity)
}
catch (Py::Exception&) {
Base::PyException e;
e.ReportException();
e.reportException();
}
return nullptr;
}
@@ -438,7 +439,7 @@ bool FileOriginPython::saveDocument(App::Document* doc)
}
catch (Py::Exception&) {
Base::PyException e;
e.ReportException();
e.reportException();
}
return false;
}
@@ -463,7 +464,7 @@ bool FileOriginPython::saveDocumentAs(App::Document* doc, const std::string& new
}
catch (Py::Exception&) {
Base::PyException e;
e.ReportException();
e.reportException();
}
return false;
}
@@ -488,7 +489,7 @@ bool FileOriginPython::commitDocument(App::Document* doc)
}
catch (Py::Exception&) {
Base::PyException e;
e.ReportException();
e.reportException();
}
return false;
}
@@ -512,7 +513,7 @@ bool FileOriginPython::pullDocument(App::Document* doc)
}
catch (Py::Exception&) {
Base::PyException e;
e.ReportException();
e.reportException();
}
return false;
}
@@ -536,7 +537,7 @@ bool FileOriginPython::pushDocument(App::Document* doc)
}
catch (Py::Exception&) {
Base::PyException e;
e.ReportException();
e.reportException();
}
return false;
}
@@ -554,7 +555,7 @@ void FileOriginPython::showInfo(App::Document* doc)
}
catch (Py::Exception&) {
Base::PyException e;
e.ReportException();
e.reportException();
}
}
@@ -571,8 +572,53 @@ void FileOriginPython::showBOM(App::Document* doc)
}
catch (Py::Exception&) {
Base::PyException e;
e.ReportException();
e.reportException();
}
}
App::Document* FileOriginPython::openDocumentInteractive()
{
Base::PyGILStateLocker lock;
try {
if (_inst.hasAttr("openDocumentInteractive")) {
Py::Callable func(_inst.getAttr("openDocumentInteractive"));
Py::Object result = func.apply(Py::Tuple());
if (!result.isNone()) {
if (PyObject_TypeCheck(result.ptr(), &(App::DocumentPy::Type))) {
return static_cast<App::DocumentPy*>(result.ptr())->getDocumentPtr();
}
}
}
}
catch (Py::Exception&) {
Base::PyException e;
e.reportException();
}
return nullptr;
}
bool FileOriginPython::saveDocumentAsInteractive(App::Document* doc)
{
Base::PyGILStateLocker lock;
try {
if (_inst.hasAttr("saveDocumentAsInteractive")) {
Py::Callable func(_inst.getAttr("saveDocumentAsInteractive"));
Py::Tuple args(1);
args.setItem(0, getDocPyObject(doc));
Py::Object result = func.apply(args);
if (result.isBoolean()) {
return Py::Boolean(result);
}
if (result.isNumeric()) {
return Py::Long(result) != 0;
}
}
}
catch (Py::Exception&) {
Base::PyException e;
e.reportException();
}
return false;
}
} // namespace Gui

View File

@@ -115,8 +115,10 @@ public:
App::Document* newDocument(const std::string& name = "") override;
App::Document* openDocument(const std::string& identity) override;
App::Document* openDocumentInteractive() override;
bool saveDocument(App::Document* doc) override;
bool saveDocumentAs(App::Document* doc, const std::string& newIdentity) override;
bool saveDocumentAsInteractive(App::Document* doc) override;
bool commitDocument(App::Document* doc) override;
bool pullDocument(App::Document* doc) override;

View File

@@ -111,14 +111,14 @@ bool OriginManager::registerOrigin(FileOrigin* origin)
std::string originId = origin->id();
if (originId.empty()) {
Base::Console().Warning("OriginManager: Cannot register origin with empty ID\n");
Base::Console().warning("OriginManager: Cannot register origin with empty ID\n");
delete origin;
return false;
}
// Check if ID already in use
if (_origins.find(originId) != _origins.end()) {
Base::Console().Warning("OriginManager: Origin '%s' already registered\n", originId.c_str());
Base::Console().warning("OriginManager: Origin '%s' already registered\n", originId.c_str());
delete origin;
return false;
}
@@ -134,7 +134,7 @@ bool OriginManager::unregisterOrigin(const std::string& id)
{
// Cannot unregister the built-in local origin
if (id == LOCAL_ORIGIN_ID) {
Base::Console().Warning("OriginManager: Cannot unregister built-in local origin\n");
Base::Console().warning("OriginManager: Cannot unregister built-in local origin\n");
return false;
}