1
/***************************************************************************
2
* Copyright (c) 2007 Werner Mayer <wmayer[at]users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
24
#include "PreCompiled.h"
27
#include "WorkbenchManager.h"
29
// inclusion of the generated files (generated out of WorkbenchPy.xml)
30
#include "WorkbenchPy.h"
31
#include "WorkbenchPy.cpp"
36
* The workbench Python base class doesn't allow you to manipulate the C++ workbench class behind.
37
* You're only allowed either to activate the workbench class or get its name.
38
* The WorkbenchPy class is associated to all C++ workbench classes except of PythonWorkbench.
40
* @see PythonWorkbench
41
* @see PythonWorkbenchPy
42
* @author Werner Mayer
45
// returns a string which represent the object e.g. when printed in python
46
std::string WorkbenchPy::representation() const
48
return {"<Workbench object>"};
51
/** Retrieves the workbench name */
52
PyObject* WorkbenchPy::name(PyObject *args)
54
if (!PyArg_ParseTuple(args, ""))
58
Py::String name(getWorkbenchPtr()->name());
59
return Py::new_reference_to(name);
63
/** Activates the workbench object */
64
PyObject* WorkbenchPy::activate(PyObject *args)
66
if (!PyArg_ParseTuple(args, ""))
70
std::string name = getWorkbenchPtr()->name();
71
WorkbenchManager::instance()->activate( name, getWorkbenchPtr()->getTypeId().getName() );
76
/** Shows a list of all menus */
77
PyObject* WorkbenchPy::listMenus(PyObject *args)
80
if (!PyArg_ParseTuple(args, ""))
83
std::list<std::string> menus = getWorkbenchPtr()->listMenus();
86
for (const auto & menu : menus) {
87
list.append(Py::String(menu));
89
return Py::new_reference_to(list);
93
/** Shows a list of all toolbars */
94
PyObject* WorkbenchPy::listToolbars(PyObject *args)
97
if (!PyArg_ParseTuple(args, ""))
100
std::list<std::string> bars = getWorkbenchPtr()->listToolbars();
103
for (const auto & bar : bars) {
104
list.append(Py::String(bar));
106
return Py::new_reference_to(list);
110
/** Shows a dict of all toolbars and their commands*/
111
PyObject* WorkbenchPy::getToolbarItems(PyObject *args)
114
if (!PyArg_ParseTuple(args, ""))
117
std::list<std::pair<std::string, std::list<std::string>>> bars = getWorkbenchPtr()->getToolbarItems();
120
for (const auto& it : bars) {
122
for (const auto& jt : it.second) {
123
list.append(Py::String(jt));
125
dict.setItem(it.first, list);
127
return Py::new_reference_to(dict);
131
/** Shows a list of all command bars */
132
PyObject* WorkbenchPy::listCommandbars(PyObject *args)
135
if (!PyArg_ParseTuple(args, ""))
138
std::list<std::string> bars = getWorkbenchPtr()->listCommandbars();
141
for (const auto & bar : bars) {
142
list.append(Py::String(bar));
144
return Py::new_reference_to(list);
148
/** Reload the workbench */
149
PyObject* WorkbenchPy::reloadActive(PyObject *args)
152
if (!PyArg_ParseTuple(args, ""))
155
Workbench* active = Gui::WorkbenchManager::instance()->active();
162
PyObject* WorkbenchPy::getCustomAttributes(const char*) const
167
int WorkbenchPy::setCustomAttributes(const char*, PyObject *)