AppTestGui.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2006 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 #ifndef _PreComp_
00026 # include <Python.h>
00027 #endif
00028 
00029 #include "UnitTestPy.h"
00030 #include "UnitTestImp.h"
00031 #include "qrc_Test.cpp"
00032 
00033 #include <Gui/Language/Translator.h>
00034 #include <Base/Console.h>
00035 
00036 class UnitTestModule : public Py::ExtensionModule<UnitTestModule>
00037 {
00038 
00039 public:
00040     UnitTestModule() : Py::ExtensionModule<UnitTestModule>("QtUnitGui")
00041     {
00042         TestGui::UnitTestDialogPy::init_type();
00043         add_varargs_method("UnitTest",&UnitTestModule::new_UnitTest,"UnitTest");
00044         add_varargs_method("setTest",&UnitTestModule::setTest,"setTest");
00045         add_varargs_method("addTest",&UnitTestModule::addTest,"addTest");
00046         initialize("This module is the QtUnitGui module"); // register with Python
00047     }
00048     
00049     virtual ~UnitTestModule() {}
00050 
00051 private:
00052     Py::Object new_UnitTest(const Py::Tuple& args)
00053     {
00054         return Py::asObject(new TestGui::UnitTestDialogPy());
00055     }
00056     Py::Object setTest(const Py::Tuple& args)
00057     {
00058         char *pstr=0;
00059         if (!PyArg_ParseTuple(args.ptr(), "|s", &pstr))
00060             throw Py::Exception();
00061 
00062         TestGui::UnitTestDialog* dlg = TestGui::UnitTestDialog::instance();
00063         if (pstr)
00064             dlg->setUnitTest(QString::fromLatin1(pstr));
00065         dlg->show();
00066         dlg->raise();
00067         return Py::None();
00068     }
00069     Py::Object addTest(const Py::Tuple& args)
00070     {
00071         char *pstr=0;
00072         if (!PyArg_ParseTuple(args.ptr(), "|s", &pstr))
00073             throw Py::Exception();
00074 
00075         TestGui::UnitTestDialog* dlg = TestGui::UnitTestDialog::instance();
00076         if (pstr)
00077             dlg->addUnitTest(QString::fromLatin1(pstr));
00078         dlg->show();
00079         dlg->raise();
00080         return Py::None();
00081     }
00082 };
00083 /*
00084 static PyObject* addTest(PyObject *self, PyObject *args)          
00085 {
00086     char *pstr=0;
00087     if (!PyArg_ParseTuple(args, "|s", &pstr))     // convert args: Python->C 
00088         return NULL;                             // NULL triggers exception
00089 
00090     TestGui::UnitTestDialog* dlg = TestGui::UnitTestDialog::instance();
00091     if (pstr)
00092         dlg->addUnitTest(QString::fromLatin1(pstr));
00093     dlg->show();
00094     dlg->raise();
00095     Py_Return;       
00096 }
00097 
00098 static PyObject* setTest(PyObject *self, PyObject *args)          
00099 {
00100     char *pstr=0;
00101     if (!PyArg_ParseTuple(args, "|s", &pstr))     // convert args: Python->C 
00102         return NULL;                             // NULL triggers exception
00103 
00104     TestGui::UnitTestDialog* dlg = TestGui::UnitTestDialog::instance();
00105     if (pstr)
00106         dlg->setUnitTest(QString::fromLatin1(pstr));
00107     dlg->show();
00108     dlg->raise();
00109     Py_Return;       
00110 }
00111 */
00112 /* registration table  */
00113 //static struct PyMethodDef TestGui_methods[] = {
00114 //    {"addTest", addTest, 1},       
00115 //    {"setTest", setTest, 1},       
00116 //    {NULL, NULL}                   /* end of table marker */
00117 //};
00118 
00119 void loadTestResource()
00120 {
00121     // add resources and reloads the translators
00122     Q_INIT_RESOURCE(Test);
00123     Gui::Translator::instance()->refresh();
00124 }
00125 
00126 /* Python entry */
00127 extern "C" {
00128 void AppTestGuiExport initQtUnitGui()
00129 {
00130     // the following constructor call registers our extension module
00131     // with the Python runtime system
00132     (void)new UnitTestModule;
00133 
00134     //if(PyType_Ready(&TestGui::UnitTestPy::Type) < 0) return;
00135     //PyObject* pyModule = Py_InitModule("QtUnitGui", TestGui_methods);   /* mod name, table ptr */
00136     //union PyType_Object pyDlgType = {&TestGui::UnitTestPy::Type};
00137     //PyModule_AddObject(pyModule, "UnitTest", pyDlgType.o);
00138     Base::Console().Log("Loading GUI of Test module... done\n");
00139 
00140     // add resources and reloads the translators
00141     loadTestResource();
00142     return;
00143 }
00144 
00145 } // extern "C"

Generated on Wed Nov 23 18:59:57 2011 for FreeCAD by  doxygen 1.6.1