FreeCAD

Форк
0
/
WorkbenchPyImp.cpp 
170 строк · 5.5 Кб
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 "PreCompiled.h"
25

26
#include "Workbench.h"
27
#include "WorkbenchManager.h"
28

29
// inclusion of the generated files (generated out of WorkbenchPy.xml)
30
#include "WorkbenchPy.h"
31
#include "WorkbenchPy.cpp"
32

33
using namespace Gui;
34

35
/** @class WorkbenchPy
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.
39
 * @see Workbench
40
 * @see PythonWorkbench
41
 * @see PythonWorkbenchPy
42
 * @author Werner Mayer
43
 */
44

45
// returns a string which represent the object e.g. when printed in python
46
std::string WorkbenchPy::representation() const
47
{
48
    return {"<Workbench object>"};
49
}
50

51
/** Retrieves the workbench name */
52
PyObject*  WorkbenchPy::name(PyObject *args)
53
{
54
    if (!PyArg_ParseTuple(args, ""))
55
        return nullptr;
56

57
    PY_TRY {
58
        Py::String name(getWorkbenchPtr()->name());
59
        return Py::new_reference_to(name);
60
    }PY_CATCH;
61
}
62

63
/** Activates the workbench object */
64
PyObject*  WorkbenchPy::activate(PyObject *args)
65
{
66
    if (!PyArg_ParseTuple(args, ""))
67
        return nullptr;
68

69
    PY_TRY {
70
        std::string name = getWorkbenchPtr()->name();
71
        WorkbenchManager::instance()->activate( name, getWorkbenchPtr()->getTypeId().getName() );
72
        Py_Return;
73
    }PY_CATCH;
74
}
75

76
/** Shows a list of all menus */
77
PyObject* WorkbenchPy::listMenus(PyObject *args)
78
{
79
    PY_TRY {
80
        if (!PyArg_ParseTuple(args, ""))
81
            return nullptr;
82

83
        std::list<std::string> menus = getWorkbenchPtr()->listMenus();
84

85
        Py::List list;
86
        for (const auto & menu : menus) {
87
            list.append(Py::String(menu));
88
        }
89
        return Py::new_reference_to(list);
90
    } PY_CATCH;
91
}
92

93
/** Shows a list of all toolbars */
94
PyObject* WorkbenchPy::listToolbars(PyObject *args)
95
{
96
    PY_TRY {
97
        if (!PyArg_ParseTuple(args, ""))
98
            return nullptr;
99

100
        std::list<std::string> bars = getWorkbenchPtr()->listToolbars();
101

102
        Py::List list;
103
        for (const auto & bar : bars) {
104
            list.append(Py::String(bar));
105
        }
106
        return Py::new_reference_to(list);
107
    } PY_CATCH;
108
}
109

110
/** Shows a dict of all toolbars and their commands*/
111
PyObject* WorkbenchPy::getToolbarItems(PyObject *args)
112
{
113
    PY_TRY {
114
        if (!PyArg_ParseTuple(args, ""))
115
            return nullptr;
116

117
        std::list<std::pair<std::string, std::list<std::string>>> bars = getWorkbenchPtr()->getToolbarItems();
118

119
        Py::Dict dict;
120
        for (const auto& it : bars) {
121
            Py::List list;
122
            for (const auto& jt : it.second) {
123
                list.append(Py::String(jt));
124
            }
125
            dict.setItem(it.first, list);
126
        }
127
        return Py::new_reference_to(dict);
128
    } PY_CATCH;
129
}
130

131
/** Shows a list of all command bars */
132
PyObject* WorkbenchPy::listCommandbars(PyObject *args)
133
{
134
    PY_TRY {
135
        if (!PyArg_ParseTuple(args, ""))
136
            return nullptr;
137

138
        std::list<std::string> bars = getWorkbenchPtr()->listCommandbars();
139

140
        Py::List list;
141
        for (const auto & bar : bars) {
142
            list.append(Py::String(bar));
143
        }
144
        return Py::new_reference_to(list);
145
    } PY_CATCH;
146
}
147

148
/** Reload the workbench */
149
PyObject*  WorkbenchPy::reloadActive(PyObject *args)
150
{
151
    PY_TRY {
152
        if (!PyArg_ParseTuple(args, ""))
153
            return nullptr;
154

155
        Workbench* active = Gui::WorkbenchManager::instance()->active();
156
        if (active)
157
            active->activate();
158
        Py_Return;
159
    } PY_CATCH;
160
}
161

162
PyObject* WorkbenchPy::getCustomAttributes(const char*) const
163
{
164
    return nullptr;
165
}
166

167
int WorkbenchPy::setCustomAttributes(const char*, PyObject *)
168
{
169
    return 0;
170
}
171

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.