Gui: Move Python functions from Application to ApplicationPy

This reduces build time when adding new Python functions because only one file must be compiled.
Handles also many linter warnings.
This commit is contained in:
wmayer
2024-12-17 17:08:28 +01:00
committed by Chris Hennes
parent f6e33eb5f4
commit 5302033c76
4 changed files with 512 additions and 369 deletions

View File

@@ -60,6 +60,7 @@
#include <Quarter/Quarter.h>
#include "Application.h"
#include "ApplicationPy.h"
#include "AxisOriginPy.h"
#include "BitmapFactory.h"
#include "Command.h"
@@ -436,7 +437,7 @@ Application::Application(bool GUIenabled)
"FreeCADGui",
FreeCADGui_doc,
-1,
Application::Methods,
ApplicationPy::Methods,
nullptr,
nullptr,
nullptr,
@@ -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"),

View File

@@ -39,6 +39,7 @@ class SoNode;
class NavlibInterface;
namespace Gui{
class ApplicationPy;
class BaseView;
class CommandManager;
class Document;
@@ -293,89 +294,13 @@ public:
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

File diff suppressed because it is too large Load Diff

120
src/Gui/ApplicationPy.h Normal file
View File

@@ -0,0 +1,120 @@
/***************************************************************************
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef GUI_APPLICATIONPY_H
#define GUI_APPLICATIONPY_H
#include <Base/PyObjectBase.h>
namespace Gui{
/** The ApplicationPy class
* This is the Python wrapper class of Application.
* @author Jürgen Riegel, Werner Mayer
*/
class GuiExport ApplicationPy
{
public:
// clang-format off
//---------------------------------------------------------------------
// 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[];
// clang-format on
};
} //namespace Gui
#endif