Debian Codegraph @

src/Gui/WorkbenchPyImp.cpp

raw
1 /***************************************************************************
2 * Copyright (c) 2007 Werner Mayer <wmayer[at]users.sourceforge.net> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
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. *
10 * *
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. *
15 * *
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 *
20 * *
21 ***************************************************************************/
22
23
24 #include "Workbench.h"
25 #include "WorkbenchManager.h"
26
27 // inclusion of the generated files (generated out of WorkbenchPy.xml)
28 #include "WorkbenchPy.h"
29 #include "WorkbenchPy.cpp"
30
31 using namespace Gui;
32
33 /** @class WorkbenchPy
34 * The workbench Python base class doesn't allow you to manipulate the C++ workbench class behind.
35 * You're only allowed either to activate the workbench class or get its name.
36 * The WorkbenchPy class is associated to all C++ workbench classes except of PythonWorkbench.
37 * @see Workbench
38 * @see PythonWorkbench
39 * @see PythonWorkbenchPy
40 * @author Werner Mayer
41 */
42
43 // returns a string which represent the object e.g. when printed in python
44 std::string WorkbenchPy::representation() const
45 {
46 return {"<Workbench object>"};
47 }
48
49 /** Retrieves the workbench name */
50 PyObject* WorkbenchPy::name(PyObject* args)
51 {
52 if (!PyArg_ParseTuple(args, "")) {
53 return nullptr;
54 }
55
56 PY_TRY
57 {
58 Py::String name(getWorkbenchPtr()->name());
59 return Py::new_reference_to(name);
60 }
61 PY_CATCH;
62 }
63
64 /** Activates the workbench object */
65 PyObject* WorkbenchPy::activate(PyObject* args)
66 {
67 if (!PyArg_ParseTuple(args, "")) {
68 return nullptr;
69 }
70
71 PY_TRY
72 {
73 std::string name = getWorkbenchPtr()->name();
74 WorkbenchManager::instance()->activate(name, getWorkbenchPtr()->getTypeId().getName());
75 Py_Return;
76 }
77 PY_CATCH;
78 }
79
80 /** Shows a list of all menus */
81 PyObject* WorkbenchPy::listMenus(PyObject* args)
82 {
83 PY_TRY
84 {
85 if (!PyArg_ParseTuple(args, "")) {
86 return nullptr;
87 }
88
89 std::list<std::string> menus = getWorkbenchPtr()->listMenus();
90
91 Py::List list;
92 for (const auto& menu : menus) {
93 list.append(Py::String(menu));
94 }
95 return Py::new_reference_to(list);
96 }
97 PY_CATCH;
98 }
99
100 /** Shows a list of all toolbars */
101 PyObject* WorkbenchPy::listToolbars(PyObject* args)
102 {
103 PY_TRY
104 {
105 if (!PyArg_ParseTuple(args, "")) {
106 return nullptr;
107 }
108
109 std::list<std::string> bars = getWorkbenchPtr()->listToolbars();
110
111 Py::List list;
112 for (const auto& bar : bars) {
113 list.append(Py::String(bar));
114 }
115 return Py::new_reference_to(list);
116 }
117 PY_CATCH;
118 }
119
120 /** Shows a dict of all toolbars and their commands*/
121 PyObject* WorkbenchPy::getToolbarItems(PyObject* args)
122 {
123 PY_TRY
124 {
125 if (!PyArg_ParseTuple(args, "")) {
126 return nullptr;
127 }
128
129 std::list<std::pair<std::string, std::list<std::string>>> bars
130 = getWorkbenchPtr()->getToolbarItems();
131
132 Py::Dict dict;
133 for (const auto& it : bars) {
134 Py::List list;
135 for (const auto& jt : it.second) {
136 list.append(Py::String(jt));
137 }
138 dict.setItem(it.first, list);
139 }
140 return Py::new_reference_to(dict);
141 }
142 PY_CATCH;
143 }
144
145 /** Shows a list of all command bars */
146 PyObject* WorkbenchPy::listCommandbars(PyObject* args)
147 {
148 PY_TRY
149 {
150 if (!PyArg_ParseTuple(args, "")) {
151 return nullptr;
152 }
153
154 std::list<std::string> bars = getWorkbenchPtr()->listCommandbars();
155
156 Py::List list;
157 for (const auto& bar : bars) {
158 list.append(Py::String(bar));
159 }
160 return Py::new_reference_to(list);
161 }
162 PY_CATCH;
163 }
164
165 /** Reload the workbench */
166 PyObject* WorkbenchPy::reloadActive(PyObject* args)
167 {
168 PY_TRY
169 {
170 if (!PyArg_ParseTuple(args, "")) {
171 return nullptr;
172 }
173
174 Workbench* active = Gui::WorkbenchManager::instance()->active();
175 if (active) {
176 active->activate();
177 }
178 Py_Return;
179 }
180 PY_CATCH;
181 }
182
183 PyObject* WorkbenchPy::getCustomAttributes(const char*) const
184 {
185 return nullptr;
186 }
187
188 int WorkbenchPy::setCustomAttributes(const char*, PyObject*)
189 {
190 return 0;
191 }