~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/Mod/Test/Gui/AppTestGui.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-07-16 18:37:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090716183741-oww9kcxqrk991i1n
Tags: upstream-0.8.2237
ImportĀ upstreamĀ versionĀ 0.8.2237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (c) 2006 Werner Mayer <werner.wm.mayer@gmx.de>              *
 
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
#ifndef _PreComp_
 
26
# include <Python.h>
 
27
#endif
 
28
 
 
29
#include "UnitTestPy.h"
 
30
#include "UnitTestImp.h"
 
31
#include "qrc_Test.cpp"
 
32
 
 
33
#include <Gui/Language/Translator.h>
 
34
#include <Base/Console.h>
 
35
 
 
36
class UnitTestModule : public Py::ExtensionModule<UnitTestModule>
 
37
{
 
38
 
 
39
public:
 
40
    UnitTestModule() : Py::ExtensionModule<UnitTestModule>("QtUnitGui")
 
41
    {
 
42
        TestGui::UnitTestDialogPy::init_type();
 
43
        add_varargs_method("UnitTest",&UnitTestModule::new_UnitTest,"UnitTest");
 
44
        add_varargs_method("setTest",&UnitTestModule::setTest,"setTest");
 
45
        add_varargs_method("addTest",&UnitTestModule::addTest,"addTest");
 
46
        initialize("This module is the QtUnitGui module"); // register with Python
 
47
    }
 
48
    
 
49
    virtual ~UnitTestModule() {}
 
50
 
 
51
private:
 
52
    Py::Object new_UnitTest(const Py::Tuple& args)
 
53
    {
 
54
        return Py::asObject(new TestGui::UnitTestDialogPy());
 
55
    }
 
56
    Py::Object setTest(const Py::Tuple& args)
 
57
    {
 
58
        char *pstr=0;
 
59
        if (!PyArg_ParseTuple(args.ptr(), "|s", &pstr))
 
60
            throw Py::Exception();
 
61
 
 
62
        TestGui::UnitTestDialog* dlg = TestGui::UnitTestDialog::instance();
 
63
        if (pstr)
 
64
            dlg->setUnitTest(QString::fromLatin1(pstr));
 
65
        dlg->show();
 
66
        dlg->raise();
 
67
        return Py::None();
 
68
    }
 
69
    Py::Object addTest(const Py::Tuple& args)
 
70
    {
 
71
        char *pstr=0;
 
72
        if (!PyArg_ParseTuple(args.ptr(), "|s", &pstr))
 
73
            throw Py::Exception();
 
74
 
 
75
        TestGui::UnitTestDialog* dlg = TestGui::UnitTestDialog::instance();
 
76
        if (pstr)
 
77
            dlg->addUnitTest(QString::fromLatin1(pstr));
 
78
        dlg->show();
 
79
        dlg->raise();
 
80
        return Py::None();
 
81
    }
 
82
};
 
83
 
 
84
static PyObject* addTest(PyObject *self, PyObject *args)          
 
85
{
 
86
    char *pstr=0;
 
87
    if (!PyArg_ParseTuple(args, "|s", &pstr))     // convert args: Python->C 
 
88
        return NULL;                             // NULL triggers exception
 
89
 
 
90
    TestGui::UnitTestDialog* dlg = TestGui::UnitTestDialog::instance();
 
91
    if (pstr)
 
92
        dlg->addUnitTest(QString::fromLatin1(pstr));
 
93
    dlg->show();
 
94
    dlg->raise();
 
95
    Py_Return;       
 
96
}
 
97
 
 
98
static PyObject* setTest(PyObject *self, PyObject *args)          
 
99
{
 
100
    char *pstr=0;
 
101
    if (!PyArg_ParseTuple(args, "|s", &pstr))     // convert args: Python->C 
 
102
        return NULL;                             // NULL triggers exception
 
103
 
 
104
    TestGui::UnitTestDialog* dlg = TestGui::UnitTestDialog::instance();
 
105
    if (pstr)
 
106
        dlg->setUnitTest(QString::fromLatin1(pstr));
 
107
    dlg->show();
 
108
    dlg->raise();
 
109
    Py_Return;       
 
110
}
 
111
 
 
112
/* registration table  */
 
113
static struct PyMethodDef TestGui_methods[] = {
 
114
    {"addTest", addTest, 1},       
 
115
    {"setTest", setTest, 1},       
 
116
    {NULL, NULL}                   /* end of table marker */
 
117
};
 
118
 
 
119
void loadTestResource()
 
120
{
 
121
    // add resources and reloads the translators
 
122
    Q_INIT_RESOURCE(Test);
 
123
    Gui::Translator::instance()->refresh();
 
124
}
 
125
 
 
126
/* Python entry */
 
127
extern "C" {
 
128
void AppTestGuiExport initQtUnitGui()
 
129
{
 
130
    // the following constructor call registers our extension module
 
131
    // with the Python runtime system
 
132
    (void)new UnitTestModule;
 
133
 
 
134
    //if(PyType_Ready(&TestGui::UnitTestPy::Type) < 0) return;
 
135
    //PyObject* pyModule = Py_InitModule("QtUnitGui", TestGui_methods);   /* mod name, table ptr */
 
136
    //union PyType_Object pyDlgType = {&TestGui::UnitTestPy::Type};
 
137
    //PyModule_AddObject(pyModule, "UnitTest", pyDlgType.o);
 
138
    Base::Console().Log("Loading GUI of Test module... done\n");
 
139
 
 
140
    // add resources and reloads the translators
 
141
    loadTestResource();
 
142
    return;
 
143
}
 
144
 
 
145
} // extern "C"