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
***************************************************************************/
23
#include "PreCompiled.h"
25
// inclusion of the generated files (generated out of PythonWorkbenchPy.xml)
26
#include "PythonWorkbenchPy.h"
27
#include "PythonWorkbenchPy.cpp"
32
/** @class PythonWorkbenchPy
33
* The workbench Python class provides additional methods for manipulation of python
35
* From the view of Python PythonWorkbenchPy is also derived from WorkbenchPy as in C++.
38
* @see PythonWorkbench
39
* @author Werner Mayer
42
// returns a string which represent the object e.g. when printed in python
43
std::string PythonWorkbenchPy::representation() const
45
return {"<Workbench object>"};
48
/** Appends a new menu */
49
PyObject* PythonWorkbenchPy::appendMenu(PyObject *args)
54
if ( !PyArg_ParseTuple(args, "OO", &pPath, &pItems) )
58
std::list<std::string> path;
59
if (PyList_Check(pPath)) {
60
int nDepth = PyList_Size(pPath);
61
for (int j=0; j<nDepth;++j) {
62
PyObject* item = PyList_GetItem(pPath, j);
63
if (PyUnicode_Check(item)) {
64
const char* pItem = PyUnicode_AsUTF8(item);
65
path.emplace_back(pItem);
70
} else if (PyUnicode_Check(pPath)) {
71
const char* pItem = PyUnicode_AsUTF8(pPath);
72
path.emplace_back(pItem);
74
PyErr_SetString(PyExc_AssertionError, "Expected either a string or a stringlist as first argument");
79
std::list<std::string> items;
80
if (PyList_Check(pItems)) {
81
int nItems = PyList_Size(pItems);
82
for (int i=0; i<nItems;++i) {
83
PyObject* item = PyList_GetItem(pItems, i);
84
if (PyUnicode_Check(item)) {
85
const char* pItem = PyUnicode_AsUTF8(item);
86
items.emplace_back(pItem);
91
} else if (PyUnicode_Check(pItems)) {
92
const char* pItem = PyUnicode_AsUTF8(pItems);
93
items.emplace_back(pItem);
95
PyErr_SetString(PyExc_AssertionError, "Expected either a string or a stringlist as first argument");
99
getPythonBaseWorkbenchPtr()->appendMenu( path, items );
106
PyObject* PythonWorkbenchPy::removeMenu(PyObject *args)
110
if (!PyArg_ParseTuple(args, "s", &psMenu))
113
getPythonBaseWorkbenchPtr()->removeMenu( psMenu );
118
/** Appends new context menu items */
119
PyObject* PythonWorkbenchPy::appendContextMenu(PyObject *args)
124
if ( !PyArg_ParseTuple(args, "OO", &pPath, &pItems) )
128
std::list<std::string> path;
129
if (PyList_Check(pPath)) {
130
int nDepth = PyList_Size(pPath);
131
for (int j=0; j<nDepth;++j) {
132
PyObject* item = PyList_GetItem(pPath, j);
133
if (PyUnicode_Check(item)) {
134
const char* pItem = PyUnicode_AsUTF8(item);
135
path.emplace_back(pItem);
140
} else if (PyUnicode_Check(pPath)) {
141
const char* pItem = PyUnicode_AsUTF8(pPath);
142
path.emplace_back(pItem);
144
PyErr_SetString(PyExc_AssertionError, "Expected either a string or a stringlist as first argument");
149
std::list<std::string> items;
150
if (PyList_Check(pItems)) {
151
int nItems = PyList_Size(pItems);
152
for (int i=0; i<nItems;++i) {
153
PyObject* item = PyList_GetItem(pItems, i);
154
if (PyUnicode_Check(item)) {
155
const char* pItem = PyUnicode_AsUTF8(item);
156
items.emplace_back(pItem);
161
} else if (PyUnicode_Check(pItems)) {
162
const char* pItem = PyUnicode_AsUTF8(pItems);
163
items.emplace_back(pItem);
165
PyErr_SetString(PyExc_AssertionError, "Expected either a string or a stringlist as first argument");
169
getPythonBaseWorkbenchPtr()->appendContextMenu( path, items );
175
/** Removes a context menu */
176
PyObject* PythonWorkbenchPy::removeContextMenu(PyObject *args)
180
if (!PyArg_ParseTuple(args, "s", &psMenu))
183
getPythonBaseWorkbenchPtr()->removeContextMenu( psMenu );
188
/** Appends a new toolbar */
189
PyObject* PythonWorkbenchPy::appendToolbar(PyObject *args)
194
if ( !PyArg_ParseTuple(args, "sO", &psToolBar, &pObject) )
196
if (!PyList_Check(pObject)) {
197
PyErr_SetString(PyExc_AssertionError, "Expected a list as second argument");
201
std::list<std::string> items;
202
int nSize = PyList_Size(pObject);
203
for (int i=0; i<nSize;++i) {
204
PyObject* item = PyList_GetItem(pObject, i);
205
if (PyUnicode_Check(item)) {
206
const char* pItem = PyUnicode_AsUTF8(item);
207
items.emplace_back(pItem);
212
getPythonBaseWorkbenchPtr()->appendToolbar( psToolBar, items );
218
/** Removes a toolbar */
219
PyObject* PythonWorkbenchPy::removeToolbar(PyObject *args)
223
if (!PyArg_ParseTuple(args, "s", &psToolBar))
226
getPythonBaseWorkbenchPtr()->removeToolbar( psToolBar );
231
/** Appends a new command bar */
232
PyObject* PythonWorkbenchPy::appendCommandbar(PyObject *args)
237
if ( !PyArg_ParseTuple(args, "sO", &psToolBar, &pObject) )
239
if (!PyList_Check(pObject)) {
240
PyErr_SetString(PyExc_AssertionError, "Expected a list as second argument");
244
std::list<std::string> items;
245
int nSize = PyList_Size(pObject);
246
for (int i=0; i<nSize;++i) {
247
PyObject* item = PyList_GetItem(pObject, i);
248
if (PyUnicode_Check(item)) {
249
const char* pItem = PyUnicode_AsUTF8(item);
250
items.emplace_back(pItem);
256
getPythonBaseWorkbenchPtr()->appendCommandbar( psToolBar, items );
262
/** Removes a command bar */
263
PyObject* PythonWorkbenchPy::removeCommandbar(PyObject *args)
267
if (!PyArg_ParseTuple(args, "s", &psToolBar))
270
getPythonBaseWorkbenchPtr()->removeCommandbar( psToolBar );
275
PyObject* PythonWorkbenchPy::getCustomAttributes(const char* ) const
280
int PythonWorkbenchPy::setCustomAttributes(const char* , PyObject *)
287
PyObject* PythonWorkbenchPy::AppendMenu(PyObject *args)
289
return appendMenu(args);
292
PyObject* PythonWorkbenchPy::RemoveMenu(PyObject *args)
294
return removeMenu(args);
297
PyObject* PythonWorkbenchPy::ListMenus(PyObject *args)
299
return listMenus(args);
302
PyObject* PythonWorkbenchPy::AppendContextMenu(PyObject *args)
304
return appendContextMenu(args);
307
PyObject* PythonWorkbenchPy::RemoveContextMenu(PyObject *args)
309
return removeContextMenu(args);
312
PyObject* PythonWorkbenchPy::AppendToolbar(PyObject *args)
314
return appendToolbar(args);
317
PyObject* PythonWorkbenchPy::RemoveToolbar(PyObject *args)
319
return removeToolbar(args);
322
PyObject* PythonWorkbenchPy::ListToolbars(PyObject *args)
324
return listToolbars(args);
327
PyObject* PythonWorkbenchPy::AppendCommandbar(PyObject *args)
329
return appendCommandbar(args);
332
PyObject* PythonWorkbenchPy::RemoveCommandbar(PyObject *args)
334
return removeCommandbar(args);
337
PyObject* PythonWorkbenchPy::ListCommandbars(PyObject *args)
339
return listCommandbars(args);