PythonWorkbenchPyImp.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2007 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 
00026 #include "Workbench.h"
00027 
00028 // inclusion of the generated files (generated out of PythonWorkbenchPy.xml)
00029 #include "PythonWorkbenchPy.h"
00030 #include "PythonWorkbenchPy.cpp"
00031 
00032 using namespace Gui;
00033 
00044 // returns a string which represent the object e.g. when printed in python
00045 std::string PythonWorkbenchPy::representation(void) const
00046 {
00047     return std::string("<Workbench object>");
00048 }
00049 
00051 PyObject*  PythonWorkbenchPy::appendMenu(PyObject *args)
00052 {
00053     PY_TRY {
00054         PyObject* pPath;
00055         PyObject* pItems;
00056         if ( !PyArg_ParseTuple(args, "OO", &pPath, &pItems) )
00057             return NULL;                             // NULL triggers exception 
00058 
00059         // menu path
00060         std::list<std::string> path;
00061         if (PyList_Check(pPath)) {
00062             int nDepth = PyList_Size(pPath);
00063             for (int j=0; j<nDepth;++j) {
00064                 PyObject* item = PyList_GetItem(pPath, j);
00065                 if (!PyString_Check(item))
00066                     continue;
00067                 char* pItem = PyString_AsString(item);
00068                 path.push_back(pItem);
00069             }
00070         } else if (PyString_Check(pPath)) {
00071             // one single item
00072             char* pItem = PyString_AsString(pPath);
00073             path.push_back(pItem);
00074         } else {
00075             PyErr_SetString(PyExc_AssertionError, "Expected either a string or a stringlist as first argument");
00076             return NULL;                             // NULL triggers exception 
00077         }
00078 
00079         // menu items
00080         std::list<std::string> items;
00081         if (PyList_Check(pItems)) {
00082             int nItems = PyList_Size(pItems);
00083             for (int i=0; i<nItems;++i) {
00084                 PyObject* item = PyList_GetItem(pItems, i);
00085                 if (!PyString_Check(item))
00086                     continue;
00087                 char* pItem = PyString_AsString(item);
00088                 items.push_back(pItem);
00089             }
00090         } else if (PyString_Check(pItems)) {
00091             // one single item
00092             char* pItem = PyString_AsString(pItems);
00093             items.push_back(pItem);
00094         } else {
00095             PyErr_SetString(PyExc_AssertionError, "Expected either a string or a stringlist as first argument");
00096             return NULL;                             // NULL triggers exception 
00097         }
00098 
00099         getPythonWorkbenchPtr()->appendMenu( path, items );
00100 
00101         Py_Return; 
00102     } PY_CATCH;
00103 }
00104 
00106 PyObject*  PythonWorkbenchPy::removeMenu(PyObject *args)
00107 {
00108     PY_TRY {
00109         char *psMenu;
00110         if (!PyArg_ParseTuple(args, "s", &psMenu))     // convert args: Python->C 
00111             return NULL;                             // NULL triggers exception 
00112     
00113         getPythonWorkbenchPtr()->removeMenu( psMenu );
00114         Py_Return; 
00115     } PY_CATCH;
00116 }
00117 
00119 PyObject*  PythonWorkbenchPy::listMenus(PyObject *args)
00120 {
00121     PY_TRY {
00122         std::list<std::string> menus = getPythonWorkbenchPtr()->listMenus();
00123 
00124         PyObject* pyList = PyList_New(menus.size());
00125         int i=0;
00126         for (std::list<std::string>::iterator it = menus.begin(); it != menus.end(); ++it, ++i ) {
00127             PyObject* str = PyString_FromString(it->c_str());
00128             PyList_SetItem(pyList, i, str);
00129         }
00130         return pyList; 
00131     } PY_CATCH;
00132 }
00133 
00135 PyObject*  PythonWorkbenchPy::appendContextMenu(PyObject *args)
00136 {
00137     PY_TRY {
00138         PyObject* pPath;
00139         PyObject* pItems;
00140         if ( !PyArg_ParseTuple(args, "OO", &pPath, &pItems) )
00141             return NULL;                             // NULL triggers exception 
00142 
00143         // menu path
00144         std::list<std::string> path;
00145         if (PyList_Check(pPath)) {
00146             int nDepth = PyList_Size(pPath);
00147             for (int j=0; j<nDepth;++j) {
00148                 PyObject* item = PyList_GetItem(pPath, j);
00149                 if (!PyString_Check(item))
00150                     continue;
00151                 char* pItem = PyString_AsString(item);
00152                 path.push_back(pItem);
00153             }
00154         } else if (PyString_Check(pPath)) {
00155             // one single item
00156             char* pItem = PyString_AsString(pPath);
00157             path.push_back(pItem);
00158         } else {
00159             PyErr_SetString(PyExc_AssertionError, "Expected either a string or a stringlist as first argument");
00160             return NULL;                             // NULL triggers exception 
00161         }
00162 
00163         // menu items
00164         std::list<std::string> items;
00165         if (PyList_Check(pItems)) {
00166             int nItems = PyList_Size(pItems);
00167             for (int i=0; i<nItems;++i) {
00168                 PyObject* item = PyList_GetItem(pItems, i);
00169                 if (!PyString_Check(item))
00170                     continue;
00171                 char* pItem = PyString_AsString(item);
00172                 items.push_back(pItem);
00173             }
00174         } else if (PyString_Check(pItems)) {
00175             // one single item
00176             char* pItem = PyString_AsString(pItems);
00177             items.push_back(pItem);
00178         } else {
00179             PyErr_SetString(PyExc_AssertionError, "Expected either a string or a stringlist as first argument");
00180             return NULL;                             // NULL triggers exception 
00181         }
00182 
00183         getPythonWorkbenchPtr()->appendContextMenu( path, items );
00184 
00185         Py_Return; 
00186     } PY_CATCH;
00187 }
00188 
00190 PyObject*  PythonWorkbenchPy::removeContextMenu(PyObject *args)
00191 {
00192     PY_TRY {
00193         char *psMenu;
00194         if (!PyArg_ParseTuple(args, "s", &psMenu))     // convert args: Python->C 
00195             return NULL;                             // NULL triggers exception 
00196     
00197         getPythonWorkbenchPtr()->removeContextMenu( psMenu );
00198         Py_Return; 
00199     } PY_CATCH;
00200 }
00201 
00203 PyObject*  PythonWorkbenchPy::appendToolbar(PyObject *args)
00204 {
00205     PY_TRY {
00206         PyObject* pObject;
00207         char* psToolBar;
00208         if ( !PyArg_ParseTuple(args, "sO", &psToolBar, &pObject) )
00209             return NULL;                             // NULL triggers exception 
00210         if (!PyList_Check(pObject)) {
00211             PyErr_SetString(PyExc_AssertionError, "Expected a list as second argument");
00212             return NULL;                             // NULL triggers exception 
00213         }
00214 
00215         std::list<std::string> items;
00216         int nSize = PyList_Size(pObject);
00217         for (int i=0; i<nSize;++i) {
00218             PyObject* item = PyList_GetItem(pObject, i);
00219             if (!PyString_Check(item))
00220                 continue;
00221             char* pItem = PyString_AsString(item);
00222             items.push_back(pItem);
00223         }
00224 
00225         getPythonWorkbenchPtr()->appendToolbar( psToolBar, items );
00226 
00227         Py_Return; 
00228     } PY_CATCH;
00229 }
00230 
00232 PyObject*  PythonWorkbenchPy::removeToolbar(PyObject *args)
00233 {
00234     PY_TRY {
00235         char *psToolBar;
00236         if (!PyArg_ParseTuple(args, "s", &psToolBar))     // convert args: Python->C 
00237             return NULL;                             // NULL triggers exception 
00238     
00239         getPythonWorkbenchPtr()->removeToolbar( psToolBar );
00240         Py_Return; 
00241     } PY_CATCH;
00242 }
00243 
00245 PyObject*  PythonWorkbenchPy::listToolbars(PyObject *args)
00246 {
00247     PY_TRY {
00248         std::list<std::string> bars = getPythonWorkbenchPtr()->listToolbars();
00249 
00250         PyObject* pyList = PyList_New(bars.size());
00251         int i=0;
00252         for (std::list<std::string>::iterator it = bars.begin(); it != bars.end(); ++it, ++i ) {
00253             PyObject* str = PyString_FromString(it->c_str());
00254             PyList_SetItem(pyList, i, str);
00255         }
00256         return pyList; 
00257     } PY_CATCH;
00258 }
00259 
00261 PyObject*  PythonWorkbenchPy::appendCommandbar(PyObject *args)
00262 {
00263     PY_TRY {
00264         PyObject* pObject;
00265         char* psToolBar;
00266         if ( !PyArg_ParseTuple(args, "sO", &psToolBar, &pObject) )
00267             return NULL;                             // NULL triggers exception 
00268         if (!PyList_Check(pObject)) {
00269             PyErr_SetString(PyExc_AssertionError, "Expected a list as second argument");
00270             return NULL;                             // NULL triggers exception 
00271         }
00272 
00273         std::list<std::string> items;
00274         int nSize = PyList_Size(pObject);
00275         for (int i=0; i<nSize;++i) {
00276             PyObject* item = PyList_GetItem(pObject, i);
00277             if (!PyString_Check(item))
00278                 continue;
00279             char* pItem = PyString_AsString(item);
00280             items.push_back(pItem);
00281         }
00282 
00283         getPythonWorkbenchPtr()->appendCommandbar( psToolBar, items );
00284 
00285         Py_Return; 
00286     } PY_CATCH;
00287 }
00288 
00290 PyObject*  PythonWorkbenchPy::removeCommandbar(PyObject *args)
00291 {
00292     PY_TRY {
00293         char *psToolBar;
00294         if (!PyArg_ParseTuple(args, "s", &psToolBar))     // convert args: Python->C 
00295             return NULL;                             // NULL triggers exception 
00296     
00297         getPythonWorkbenchPtr()->removeCommandbar( psToolBar );
00298         Py_Return; 
00299     } PY_CATCH;
00300 }
00301 
00303 PyObject*  PythonWorkbenchPy::listCommandbars(PyObject *args)
00304 {
00305     PY_TRY {
00306         std::list<std::string> bars = getPythonWorkbenchPtr()->listCommandbars();
00307 
00308         PyObject* pyList = PyList_New(bars.size());
00309         int i=0;
00310         for (std::list<std::string>::iterator it = bars.begin(); it != bars.end(); ++it, ++i) {
00311             PyObject* str = PyString_FromString(it->c_str());
00312             PyList_SetItem(pyList, i, str);
00313         }
00314         return pyList; 
00315     } PY_CATCH;
00316 }
00317 
00318 PyObject *PythonWorkbenchPy::getCustomAttributes(const char* attr) const
00319 {
00320     return 0;
00321 }
00322 
00323 int PythonWorkbenchPy::setCustomAttributes(const char* attr, PyObject *obj)
00324 {
00325     return 0; 
00326 }
00327 
00328 PyObject*  PythonWorkbenchPy::AppendMenu(PyObject *args)
00329 {
00330     return appendMenu(args);
00331 }
00332 
00333 PyObject*  PythonWorkbenchPy::RemoveMenu(PyObject *args)
00334 {
00335     return removeMenu(args);
00336 }
00337 
00338 PyObject*  PythonWorkbenchPy::ListMenus(PyObject *args)
00339 {
00340     return listMenus(args);
00341 }
00342 
00343 PyObject*  PythonWorkbenchPy::AppendContextMenu(PyObject *args)
00344 {
00345     return appendContextMenu(args);
00346 }
00347 
00348 PyObject*  PythonWorkbenchPy::RemoveContextMenu(PyObject *args)
00349 {
00350     return removeContextMenu(args);
00351 }
00352 
00353 PyObject*  PythonWorkbenchPy::AppendToolbar(PyObject *args)
00354 {
00355     return appendToolbar(args);
00356 }
00357 
00358 PyObject*  PythonWorkbenchPy::RemoveToolbar(PyObject *args)
00359 {
00360     return removeToolbar(args);
00361 }
00362 
00363 PyObject*  PythonWorkbenchPy::ListToolbars(PyObject *args)
00364 {
00365     return listToolbars(args);
00366 }
00367 
00368 PyObject*  PythonWorkbenchPy::AppendCommandbar(PyObject *args)
00369 {
00370     return appendCommandbar(args);
00371 }
00372 
00373 PyObject*  PythonWorkbenchPy::RemoveCommandbar(PyObject *args)
00374 {
00375     return removeCommandbar(args);
00376 }
00377 
00378 PyObject*  PythonWorkbenchPy::ListCommandbars(PyObject *args)
00379 {
00380     return listCommandbars(args);
00381 }
00382 
00383 

Generated on Wed Nov 23 19:00:32 2011 for FreeCAD by  doxygen 1.6.1