ctkWidgetsPythonQtDecorators.h 5.7 KB

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