##// END OF EJS Templates
fixed example for 2.0 API, factory example still not working...
florianlink -
r152:d0d61419dda4
parent child
Show More
@@ -1,5 +1,5
1 <!DOCTYPE RCC><RCC version="1.0">
1 <!DOCTYPE RCC><RCC version="1.0">
2 <qresource>
2 <qresource>
3 <file>example.py</file>
3 <file>example.py</file>
4 </qresource>
4 </qresource>
5 </RCC>
5 </RCC>
@@ -1,38 +1,38
1 from PythonQt import *
1 from PythonQt.example import *
2
2
3 print "alternative 1 : CustomObject wrapped by decorators"
3 print "alternative 1 : CustomObject wrapped by decorators"
4
4
5 # create a new object
5 # create a new object
6 custom = CustomObject("John","Doe")
6 custom = CustomObject("John","Doe")
7
7
8 # print the object (to see how it is wrapped)
8 # print the object (to see how it is wrapped)
9 print custom
9 print custom
10
10
11 # print the methods available
11 # print the methods available
12 print dir(custom)
12 print dir(custom)
13
13
14 # set a name
14 # set a name
15 custom.setFirstName("Mike")
15 custom.setFirstName("Mike")
16 custom.setLastName("Michels")
16 custom.setLastName("Michels")
17
17
18 # get the name
18 # get the name
19 print custom.firstName() + " " + custom.lastName();
19 print custom.firstName() + " " + custom.lastName();
20
20
21 print
21 print
22 print "alternative 2 : CustomObject2 wrapped by factory"
22 print "alternative 2 : CustomObject2 wrapped by factory"
23
23
24 # create a new object
24 # create a new object
25 custom2 = CustomObject2("John","Doe")
25 custom2 = CustomObject2("John","Doe")
26
26
27 # print the object (to see how it is wrapped)
27 # print the object (to see how it is wrapped)
28 print custom2
28 print custom2
29
29
30 # print the methods available
30 # print the methods available
31 print dir(custom2)
31 print dir(custom2)
32
32
33 # set a name
33 # set a name
34 custom2.setFirstName("Mike")
34 custom2.setFirstName("Mike")
35 custom2.setLastName("Michels")
35 custom2.setLastName("Michels")
36
36
37 # get the name
37 # get the name
38 print custom2.firstName() + " " + custom2.lastName();
38 print custom2.firstName() + " " + custom2.lastName();
@@ -1,84 +1,84
1 /*
1 /*
2 *
2 *
3 * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved.
3 * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved.
4 *
4 *
5 * This library is free software; you can redistribute it and/or
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
8 * version 2.1 of the License, or (at your option) any later version.
9 *
9 *
10 * This library is distributed in the hope that it will be useful,
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
13 * Lesser General Public License for more details.
14 *
14 *
15 * Further, this software is distributed without any warranty that it is
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
20 * other software, or any other product whatsoever.
21 *
21 *
22 * You should have received a copy of the GNU Lesser General Public
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
25 *
26 * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29,
26 * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29,
27 * 28359 Bremen, Germany or:
27 * 28359 Bremen, Germany or:
28 *
28 *
29 * http://www.mevis.de
29 * http://www.mevis.de
30 *
30 *
31 */
31 */
32
32
33 //----------------------------------------------------------------------------------
33 //----------------------------------------------------------------------------------
34 /*!
34 /*!
35 // \file PyGuiExample.cpp
35 // \file PyGuiExample.cpp
36 // \author Florian Link
36 // \author Florian Link
37 // \author Last changed by $Author: florian $
37 // \author Last changed by $Author: florian $
38 // \date 2007-04
38 // \date 2007-04
39 */
39 */
40 //----------------------------------------------------------------------------------
40 //----------------------------------------------------------------------------------
41
41
42 #include "PythonQt.h"
42 #include "PythonQt.h"
43 #include "gui/PythonQtScriptingConsole.h"
43 #include "gui/PythonQtScriptingConsole.h"
44 #include "CustomObjects.h"
44 #include "CustomObjects.h"
45
45
46 #include <QApplication>
46 #include <QApplication>
47
47
48 int main( int argc, char **argv )
48 int main( int argc, char **argv )
49 {
49 {
50 QApplication qapp(argc, argv);
50 QApplication qapp(argc, argv);
51
51
52 PythonQt::init(PythonQt::IgnoreSiteModule | PythonQt::RedirectStdOut);
52 PythonQt::init(PythonQt::IgnoreSiteModule | PythonQt::RedirectStdOut);
53
53
54 PythonQtObjectPtr mainContext = PythonQt::self()->getMainModule();
54 PythonQtObjectPtr mainContext = PythonQt::self()->getMainModule();
55 PythonQtScriptingConsole console(NULL, mainContext);
55 PythonQtScriptingConsole console(NULL, mainContext);
56
56
57 // -----------------------------------------------------------------
57 // -----------------------------------------------------------------
58 // Alternative 1: make CustomObject known and use decorators for wrapping:
58 // Alternative 1: make CustomObject known and use decorators for wrapping:
59 // -----------------------------------------------------------------
59 // -----------------------------------------------------------------
60
60
61 // register the new object as a known classname and add it's wrapper object
61 // register the new object as a known classname and add it's wrapper object
62 PythonQt::self()->registerCPPClass("CustomObject", "","", PythonQtCreateObject<CustomObjectWrapper>);
62 PythonQt::self()->registerCPPClass("CustomObject", "","example", PythonQtCreateObject<CustomObjectWrapper>);
63
63
64 // -----------------------------------------------------------------
64 // -----------------------------------------------------------------
65 // Alternative 2: make CustomObject2 known and use a wrapper factory for wrapping:
65 // Alternative 2: make CustomObject2 known and use a wrapper factory for wrapping:
66 // -----------------------------------------------------------------
66 // -----------------------------------------------------------------
67
67
68 // add a factory that can handle pointers to CustomObject2
68 // add a factory that can handle pointers to CustomObject2
69 PythonQt::self()->addWrapperFactory(new CustomFactory());
69 PythonQt::self()->addWrapperFactory(new CustomFactory());
70
70
71 // the following is optional and only needed if you want a constructor:
71 // the following is optional and only needed if you want a constructor:
72 // register the new object as a known classname
72 // register the new object as a known classname
73 PythonQt::self()->registerCPPClass("CustomObject2");
73 PythonQt::self()->registerCPPClass("CustomObject2", "", "example");
74 // add a constructor for CustomObject2
74 // add a constructor for CustomObject2
75 PythonQt::self()->addClassDecorators(new CustomObject2Constructor());
75 PythonQt::self()->addClassDecorators(new CustomObject2Constructor());
76
76
77 mainContext.evalFile(":example.py");
77 mainContext.evalFile(":example.py");
78
78
79 console.appendCommandPrompt();
79 console.appendCommandPrompt();
80 console.show();
80 console.show();
81
81
82 return qapp.exec();
82 return qapp.exec();
83 }
83 }
84
84
General Comments 0
You need to be logged in to leave comments. Login now