CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkWidgetsPythonQtDecorators.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Library: CTK
4 
5  Copyright (c) Kitware Inc.
6 
7  Licensed under the Apache License, Version 2.0 (the "License");
8  you may not use this file except in compliance with the License.
9  You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0.txt
12 
13  Unless required by applicable law or agreed to in writing, software
14  distributed under the License is distributed on an "AS IS" BASIS,
15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  See the License for the specific language governing permissions and
17  limitations under the License.
18 
19 =========================================================================*/
20 
21 #ifndef __ctkWidgetsPythonQtDecorators_h
22 #define __ctkWidgetsPythonQtDecorators_h
23 
24 // PythonQt includes
25 #include <PythonQt.h>
26 
27 // CTK includes
28 #include <ctkErrorLogModel.h>
32 #include <ctkWidgetsUtils.h>
33 #include <ctkWorkflowWidgetStep.h>
34 
35 // NOTE:
36 //
37 // For decorators it is assumed that the methods will never be called
38 // with the self argument as NULL. The self argument is the first argument
39 // for non-static methods.
40 //
41 
43 class ctkWidgetsPythonQtDecorators : public QObject
44 {
45  Q_OBJECT
46 public:
47 
49  {
50  PythonQt::self()->addParentClass("ctkWorkflowWidgetStep", "ctkWorkflowStep",
51  PythonQtUpcastingOffset<ctkWorkflowWidgetStep,ctkWorkflowStep>());
52  }
53 
54 public Q_SLOTS:
55 
56  // ctkWorkflowWidgetStep
57 
59  {
60  return step->hasCreateUserInterfaceCommand();
61  }
62 
64  ctkWorkflowWidgetStep* step, bool newHasCreateUserInterfaceCommand)
65  {
66  step->setHasCreateUserInterfaceCommand(newHasCreateUserInterfaceCommand);
67  }
68 
70  {
71  return step->hasShowUserInterfaceCommand();
72  }
73 
75  ctkWorkflowWidgetStep* step, bool newHasShowUserInterfaceCommand)
76  {
77  step->setHasShowUserInterfaceCommand(newHasShowUserInterfaceCommand);
78  }
79 
80  // ctkErrorLogLevel
81 
83  {
84  return ctkErrorLogLevel::logLevelAsString(logLevel);
85  }
86 
87  // ctkTransferFunctionBarsItem
88 
90  {
91  return new ctkTransferFunctionBarsItem(parent);
92  }
93 
95  ctkTransferFunction* transferFunc,
96  QGraphicsItem* parent = 0)
97  {
98  return new ctkTransferFunctionBarsItem(transferFunc, parent);
99  }
100 
102  {
103  delete obj;
104  }
105 
106  // ctkTransferFunctionControlPointsItem
107 
109  QGraphicsItem* parent = 0)
110  {
111  return new ctkTransferFunctionControlPointsItem(parent);
112  }
113 
115  ctkTransferFunction* transferFunc,
116  QGraphicsItem* parent = 0)
117  {
118  return new ctkTransferFunctionControlPointsItem(transferFunc, parent);
119  }
120 
122  {
123  delete obj;
124  }
125 
126  // ctkTransferFunctionGradientItem
127 
129  QGraphicsItem* parent = 0)
130  {
131  return new ctkTransferFunctionGradientItem(parent);
132  }
133 
135  ctkTransferFunction* transferFunc,
136  QGraphicsItem* parent = 0)
137  {
138  return new ctkTransferFunctionGradientItem(transferFunc, parent);
139  }
140 
142  {
143  delete obj;
144  }
145 
146 };
147 
148 //-----------------------------------------------------------------------------
149 class PythonQtWrapper_CTKWidgets : public QObject
150 {
151  Q_OBJECT
152 
153 public Q_SLOTS:
154  QImage static_ctkWidgetsUtils_grabWidget(QWidget* widget, QRect rectangle = QRect())
155  {
156  return ctk::grabWidget(widget, rectangle);
157  }
158 };
159 
160 //-----------------------------------------------------------------------------
163 {
164  // HACK: Since the CMake based light wrapping only consider class name matching the
165  // filename where the class is defined, let's explicitly register ctkErrorLogLevel
166  // so that the log level QFlags are exposed to python.
167  PythonQt::self()->registerClass(&ctkErrorLogLevel::staticMetaObject, "CTKCore");
168 
169  PythonQt::self()->registerClass(&ctkTransferFunctionBarsItem::staticMetaObject, "CTKWidgets");
170  PythonQt::self()->registerClass(&ctkTransferFunctionControlPointsItem::staticMetaObject, "CTKWidgets");
171  PythonQt::self()->registerClass(&ctkTransferFunctionGradientItem::staticMetaObject, "CTKWidgets");
172 
173  PythonQt::self()->addDecorators(new ctkWidgetsPythonQtDecorators);
174 
175  // NOTE: This exposes ctk.ctkWidgetsUtils.grabWidget(), for example. PythonQt
176  // doesn't support wrapping a static function and adding it to the top-level
177  // ctk module. Note that PythonQtWrapper_CTKDICOMCore installs itself as ctk.ctk,
178  // but using that same module here would replace PythonQtWrapper_CTKDICOMCore.
179  PythonQt::self()->registerCPPClass("ctkWidgetsUtils", "", "CTKWidgets", PythonQtCreateObject<PythonQtWrapper_CTKWidgets>);
180 }
181 
182 #endif
ctkWidgetsPythonQtDecorators::setHasCreateUserInterfaceCommand
void setHasCreateUserInterfaceCommand(ctkWorkflowWidgetStep *step, bool newHasCreateUserInterfaceCommand)
Definition: ctkWidgetsPythonQtDecorators.h:63
ctkWidgetsPythonQtDecorators::setHasShowUserInterfaceCommand
void setHasShowUserInterfaceCommand(ctkWorkflowWidgetStep *step, bool newHasShowUserInterfaceCommand)
Definition: ctkWidgetsPythonQtDecorators.h:74
ctkWidgetsPythonQtDecorators::new_ctkTransferFunctionBarsItem
ctkTransferFunctionBarsItem * new_ctkTransferFunctionBarsItem(ctkTransferFunction *transferFunc, QGraphicsItem *parent=0)
Definition: ctkWidgetsPythonQtDecorators.h:94
ctkWidgetsPythonQtDecorators::delete_ctkTransferFunctionControlPointsItem
void delete_ctkTransferFunctionControlPointsItem(ctkTransferFunctionControlPointsItem *obj)
Definition: ctkWidgetsPythonQtDecorators.h:121
ctkWidgetsUtils.h
ctkErrorLogLevel::LogLevel
LogLevel
Definition: ctkErrorLogLevel.h:40
ctkTransferFunctionBarsItem
Definition: ctkTransferFunctionBarsItem.h:38
ctkErrorLogModel.h
ctkWidgetsPythonQtDecorators::new_ctkTransferFunctionGradientItem
ctkTransferFunctionGradientItem * new_ctkTransferFunctionGradientItem(ctkTransferFunction *transferFunc, QGraphicsItem *parent=0)
Definition: ctkWidgetsPythonQtDecorators.h:134
ctkTransferFunctionBarsItem.h
ctkTransferFunctionGradientItem.h
ctkWidgetsPythonQtDecorators::new_ctkTransferFunctionGradientItem
ctkTransferFunctionGradientItem * new_ctkTransferFunctionGradientItem(QGraphicsItem *parent=0)
Definition: ctkWidgetsPythonQtDecorators.h:128
ctkTransferFunction
Definition: ctkTransferFunction.h:86
ctkWorkflowWidgetStep::hasCreateUserInterfaceCommand
virtual bool hasCreateUserInterfaceCommand() const
ctkWidgetsPythonQtDecorators::hasShowUserInterfaceCommand
bool hasShowUserInterfaceCommand(ctkWorkflowWidgetStep *step) const
Definition: ctkWidgetsPythonQtDecorators.h:69
PythonQtWrapper_CTKWidgets::static_ctkWidgetsUtils_grabWidget
QImage static_ctkWidgetsUtils_grabWidget(QWidget *widget, QRect rectangle=QRect())
Definition: ctkWidgetsPythonQtDecorators.h:154
initCTKWidgetsPythonQtDecorators
void initCTKWidgetsPythonQtDecorators()
Definition: ctkWidgetsPythonQtDecorators.h:162
ctkWidgetsPythonQtDecorators::new_ctkTransferFunctionBarsItem
ctkTransferFunctionBarsItem * new_ctkTransferFunctionBarsItem(QGraphicsItem *parent=0)
Definition: ctkWidgetsPythonQtDecorators.h:89
ctkWidgetsPythonQtDecorators::ctkWidgetsPythonQtDecorators
ctkWidgetsPythonQtDecorators()
Definition: ctkWidgetsPythonQtDecorators.h:48
ctkWidgetsPythonQtDecorators::new_ctkTransferFunctionControlPointsItem
ctkTransferFunctionControlPointsItem * new_ctkTransferFunctionControlPointsItem(QGraphicsItem *parent=0)
Definition: ctkWidgetsPythonQtDecorators.h:108
ctkWorkflowWidgetStep::hasShowUserInterfaceCommand
virtual bool hasShowUserInterfaceCommand() const
ctkTransferFunctionGradientItem
Definition: ctkTransferFunctionGradientItem.h:38
ctkTransferFunctionControlPointsItem.h
ctkTransferFunctionControlPointsItem
Definition: ctkTransferFunctionControlPointsItem.h:37
PythonQtWrapper_CTKWidgets
Definition: ctkWidgetsPythonQtDecorators.h:150
ctkWidgetsPythonQtDecorators::static_ctkErrorLogLevel_logLevelAsString
QString static_ctkErrorLogLevel_logLevelAsString(ctkErrorLogLevel::LogLevel logLevel)
Definition: ctkWidgetsPythonQtDecorators.h:82
ctkWorkflowWidgetStep::setHasCreateUserInterfaceCommand
virtual void setHasCreateUserInterfaceCommand(bool flag)
ctkWorkflowWidgetStep.h
ctkErrorLogLevel::logLevelAsString
static QString logLevelAsString(ctkErrorLogLevel::LogLevel logLevel)
ctkWorkflowWidgetStep
ctkWorkflowWidgetStep is a convienience class to quickly construct a ctkWorkflowStep with a user inte...
Definition: ctkWorkflowWidgetStep.h:60
ctkWidgetsPythonQtDecorators
Definition: ctkWidgetsPythonQtDecorators.h:44
ctkWidgetsPythonQtDecorators::delete_ctkTransferFunctionGradientItem
void delete_ctkTransferFunctionGradientItem(ctkTransferFunctionGradientItem *obj)
Definition: ctkWidgetsPythonQtDecorators.h:141
ctkWidgetsPythonQtDecorators::delete_ctkTransferFunctionBarsItem
void delete_ctkTransferFunctionBarsItem(ctkTransferFunctionBarsItem *obj)
Definition: ctkWidgetsPythonQtDecorators.h:101
ctkWorkflowWidgetStep::setHasShowUserInterfaceCommand
virtual void setHasShowUserInterfaceCommand(bool flag)
ctk::grabWidget
QImage CTK_WIDGETS_EXPORT grabWidget(QWidget *widget, QRect rectangle=QRect())
ctkWidgetsPythonQtDecorators::new_ctkTransferFunctionControlPointsItem
ctkTransferFunctionControlPointsItem * new_ctkTransferFunctionControlPointsItem(ctkTransferFunction *transferFunc, QGraphicsItem *parent=0)
Definition: ctkWidgetsPythonQtDecorators.h:114
ctkWidgetsPythonQtDecorators::hasCreateUserInterfaceCommand
bool hasCreateUserInterfaceCommand(ctkWorkflowWidgetStep *step) const
Definition: ctkWidgetsPythonQtDecorators.h:58