Skip to content

Commit

Permalink
Gui: Move Python functions from Application to ApplicationPy
Browse files Browse the repository at this point in the history
This reduces build time when adding new Python functions because only one file must be compiled.
Handles also many linter warnings.
  • Loading branch information
wwmayer committed Dec 17, 2024
1 parent 1289997 commit 486e622
Show file tree
Hide file tree
Showing 4 changed files with 512 additions and 369 deletions.
5 changes: 3 additions & 2 deletions src/Gui/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include <Quarter/Quarter.h>

#include "Application.h"
#include "ApplicationPy.h"
#include "AxisOriginPy.h"
#include "BitmapFactory.h"
#include "Command.h"
Expand Down Expand Up @@ -436,7 +437,7 @@ Application::Application(bool GUIenabled)
"FreeCADGui",
FreeCADGui_doc,
-1,
Application::Methods,
ApplicationPy::Methods,
nullptr,
nullptr,
nullptr,
Expand All @@ -447,7 +448,7 @@ Application::Application(bool GUIenabled)
}
else {
// extend the method list
PyModule_AddFunctions(module, Application::Methods);
PyModule_AddFunctions(module, ApplicationPy::Methods);
}
Py::Module(module).setAttr(std::string("ActiveDocument"), Py::None());
Py::Module(module).setAttr(std::string("HasQtBug_129596"),
Expand Down
83 changes: 4 additions & 79 deletions src/Gui/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class SoNode;
class NavlibInterface;

namespace Gui{
class ApplicationPy;
class BaseView;
class CommandManager;
class Document;
Expand Down Expand Up @@ -293,89 +294,13 @@ class GuiExport Application
bool setUserEditMode(const std::string &mode);
//@}

public:
//---------------------------------------------------------------------
// python exports goes here +++++++++++++++++++++++++++++++++++++++++++
//---------------------------------------------------------------------
// static python wrapper of the exported functions
static PyObject* sActivateWorkbenchHandler (PyObject *self,PyObject *args); // activates a workbench object
static PyObject* sAddWorkbenchHandler (PyObject *self,PyObject *args); // adds a new workbench handler to a list
static PyObject* sRemoveWorkbenchHandler (PyObject *self,PyObject *args); // removes a workbench handler from the list
static PyObject* sGetWorkbenchHandler (PyObject *self,PyObject *args); // retrieves the workbench handler
static PyObject* sListWorkbenchHandlers (PyObject *self,PyObject *args); // retrieves a list of all workbench handlers
static PyObject* sActiveWorkbenchHandler (PyObject *self,PyObject *args); // retrieves the active workbench object
static PyObject* sAddResPath (PyObject *self,PyObject *args); // adds a path where to find resources
static PyObject* sAddLangPath (PyObject *self,PyObject *args); // adds a path to a qm file
static PyObject* sAddIconPath (PyObject *self,PyObject *args); // adds a path to an icon file
static PyObject* sAddIcon (PyObject *self,PyObject *args); // adds an icon to the cache
static PyObject* sGetIcon (PyObject *self,PyObject *args); // get an icon from the cache
static PyObject* sIsIconCached (PyObject *self,PyObject *args); // check if an icon is cached

static PyObject* sSendActiveView (PyObject *self,PyObject *args);
static PyObject* sSendFocusView (PyObject *self,PyObject *args);

static PyObject* sGetMainWindow (PyObject *self,PyObject *args);
static PyObject* sUpdateGui (PyObject *self,PyObject *args);
static PyObject* sUpdateLocale (PyObject *self,PyObject *args);
static PyObject* sGetLocale (PyObject *self,PyObject *args);
static PyObject* sSetLocale (PyObject *self,PyObject *args);
static PyObject* sSupportedLocales (PyObject *self,PyObject *args);
static PyObject* sCreateDialog (PyObject *self,PyObject *args);
static PyObject* sAddPreferencePage (PyObject *self,PyObject *args);

static PyObject* sRunCommand (PyObject *self,PyObject *args);
static PyObject* sAddCommand (PyObject *self,PyObject *args);

static PyObject* sHide (PyObject *self,PyObject *args); // deprecated
static PyObject* sShow (PyObject *self,PyObject *args); // deprecated
static PyObject* sHideObject (PyObject *self,PyObject *args); // hide view provider object
static PyObject* sShowObject (PyObject *self,PyObject *args); // show view provider object

static PyObject* sOpen (PyObject *self,PyObject *args); // open Python scripts
static PyObject* sInsert (PyObject *self,PyObject *args); // open Python scripts
static PyObject* sExport (PyObject *self,PyObject *args);
static PyObject* sReload (PyObject *self,PyObject *args); // reload FCStd file
static PyObject* sLoadFile (PyObject *self,PyObject *args); // open all types of files

static PyObject* sCoinRemoveAllChildren (PyObject *self,PyObject *args);

static PyObject* sActiveDocument (PyObject *self,PyObject *args);
static PyObject* sSetActiveDocument (PyObject *self,PyObject *args);
static PyObject* sActiveView (PyObject *self,PyObject *args);
static PyObject* sActivateView (PyObject *self,PyObject *args);
static PyObject* sGetDocument (PyObject *self,PyObject *args);
static PyObject* sEditDocument (PyObject *self,PyObject *args);

static PyObject* sDoCommand (PyObject *self,PyObject *args);
static PyObject* sDoCommandGui (PyObject *self,PyObject *args);
static PyObject* sDoCommandEval (PyObject *self,PyObject *args);
static PyObject* sDoCommandSkip (PyObject *self,PyObject *args);
static PyObject* sAddModule (PyObject *self,PyObject *args);

static PyObject* sShowDownloads (PyObject *self,PyObject *args);
static PyObject* sShowPreferences (PyObject *self,PyObject *args);
static PyObject* sShowPreferencesByName (PyObject *self,PyObject *args);

static PyObject* sCreateViewer (PyObject *self,PyObject *args);
static PyObject* sGetMarkerIndex (PyObject *self,PyObject *args);

static PyObject* sAddDocObserver (PyObject *self,PyObject *args);
static PyObject* sRemoveDocObserver (PyObject *self,PyObject *args);

static PyObject* sAddWbManipulator (PyObject *self,PyObject *args);
static PyObject* sRemoveWbManipulator (PyObject *self,PyObject *args);

static PyObject* sListUserEditModes (PyObject *self,PyObject *args);
static PyObject* sGetUserEditMode (PyObject *self,PyObject *args);
static PyObject* sSetUserEditMode (PyObject *self,PyObject *args);

static PyMethodDef Methods[];

private:
struct ApplicationP* d;
/// workbench python dictionary
PyObject* _pcWorkbenchDictionary;
PyObject* _pcWorkbenchDictionary;
NavlibInterface* pNavlibInterface;

friend class ApplicationPy;
};

} //namespace Gui
Expand Down
Loading

0 comments on commit 486e622

Please sign in to comment.