Browse Source

Add ctkPythonConsole designer plugin

Jean-Christophe Fillion-Robin 14 years ago
parent
commit
027821e765

+ 1 - 1
Libs/Scripting/Python/Widgets/CMakeLists.txt

@@ -49,7 +49,7 @@ ctkMacroBuildLib(
   )
 
 # Plugins
-#ADD_SUBDIRECTORY(Plugins)
+ADD_SUBDIRECTORY(Plugins)
 
 # Testing
 IF(BUILD_TESTING)

+ 44 - 0
Libs/Scripting/Python/Widgets/Plugins/CMakeLists.txt

@@ -0,0 +1,44 @@
+PROJECT(${PROJECT_NAME}Plugins)
+
+#
+# See CTK/CMake/ctkMacroBuildQtDesignerPlugin.cmake for details
+#
+
+SET(PLUGIN_export_directive "CTK_SCRIPTING_PYTHON_WIDGETS_PLUGINS_EXPORT")
+
+# Source files
+SET(PLUGIN_SRCS
+  ctkScriptingPythonWidgetsPlugins.cpp
+  ctkScriptingPythonWidgetsPlugins.h
+  ctkScriptingPythonWidgetsAbstractPlugin.cpp
+  ctkScriptingPythonWidgetsAbstractPlugin.h
+
+  ctkPythonConsolePlugin.cpp
+  ctkPythonConsolePlugin.h
+  )
+
+# Headers that should run through moc
+SET(PLUGIN_MOC_SRCS
+  ctkScriptingPythonWidgetsPlugins.h
+
+  ctkPythonConsolePlugin.h
+  )
+
+# Resources
+SET(PLUGIN_resources
+  Resources/CTKScriptingPythonWidgetsPlugins.qrc
+)
+
+# Target libraries
+SET(PLUGIN_target_libraries
+  CTKScriptingPythonWidgets
+  )
+
+ctkMacroBuildQtDesignerPlugin(
+  NAME ${PROJECT_NAME}
+  EXPORT_DIRECTIVE ${PLUGIN_export_directive}
+  SRCS ${PLUGIN_SRCS}
+  MOC_SRCS ${PLUGIN_MOC_SRCS}
+  RESOURCES ${PLUGIN_resources}
+  TARGET_LIBRARIES ${PLUGIN_target_libraries}
+)

+ 5 - 0
Libs/Scripting/Python/Widgets/Plugins/Resources/CTKScriptingPythonWidgetsPlugins.qrc

@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+  <qresource>
+    <file>Icons/console.png</file>
+  </qresource>
+</RCC>

BIN
Libs/Scripting/Python/Widgets/Plugins/Resources/Icons/console.png


+ 71 - 0
Libs/Scripting/Python/Widgets/Plugins/ctkPythonConsolePlugin.cpp

@@ -0,0 +1,71 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+// CTK includes
+#include "ctkPythonConsolePlugin.h"
+#include "ctkPythonConsole.h"
+#include "ctkAbstractPythonManager.h"
+
+//-----------------------------------------------------------------------------
+ctkPythonConsolePlugin::ctkPythonConsolePlugin(QObject* pluginParent)
+  : QObject(pluginParent)
+{
+
+}
+
+//-----------------------------------------------------------------------------
+QWidget *ctkPythonConsolePlugin::createWidget(QWidget* widgetParent)
+{
+  ctkPythonConsole* console = new ctkPythonConsole(widgetParent);
+  console->initialize(new ctkAbstractPythonManager(this));
+  return console;
+}
+
+//-----------------------------------------------------------------------------
+QString ctkPythonConsolePlugin::domXml() const
+{
+  return "<widget class=\"ctkPythonConsole\" \
+          name=\"PythonConsole\">\n"
+          "</widget>\n";
+}
+
+// --------------------------------------------------------------------------
+QIcon ctkPythonConsolePlugin::icon() const
+{
+  return QIcon(":/Icons/console.png");
+}
+
+//-----------------------------------------------------------------------------
+QString ctkPythonConsolePlugin::includeFile() const
+{
+  return "ctkPythonConsole.h";
+}
+
+//-----------------------------------------------------------------------------
+bool ctkPythonConsolePlugin::isContainer() const
+{
+  return false;
+}
+
+//-----------------------------------------------------------------------------
+QString ctkPythonConsolePlugin::name() const
+{
+  return "ctkPythonConsole";
+}

+ 45 - 0
Libs/Scripting/Python/Widgets/Plugins/ctkPythonConsolePlugin.h

@@ -0,0 +1,45 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+#ifndef __ctkPythonConsolePlugin_h
+#define __ctkPythonConsolePlugin_h
+
+// CTK includes
+#include "ctkScriptingPythonWidgetsAbstractPlugin.h"
+
+class CTK_SCRIPTING_PYTHON_WIDGETS_PLUGINS_EXPORT ctkPythonConsolePlugin
+  : public QObject
+  , public ctkScriptingPythonWidgetsAbstractPlugin
+{
+  Q_OBJECT
+
+public:
+  ctkPythonConsolePlugin(QObject *_parent = 0);
+  
+  QWidget *createWidget(QWidget *_parent);
+  QString  domXml() const;
+  QIcon    icon() const;
+  QString  includeFile() const;
+  bool     isContainer() const;
+  QString  name() const;
+
+};
+
+#endif

+ 63 - 0
Libs/Scripting/Python/Widgets/Plugins/ctkScriptingPythonWidgetsAbstractPlugin.cpp

@@ -0,0 +1,63 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+// CTK includes
+#include "ctkScriptingPythonWidgetsAbstractPlugin.h"
+
+//-----------------------------------------------------------------------------
+ctkScriptingPythonWidgetsAbstractPlugin::ctkScriptingPythonWidgetsAbstractPlugin()
+{
+  this->Initialized = false;
+}
+
+//-----------------------------------------------------------------------------
+QString ctkScriptingPythonWidgetsAbstractPlugin::group() const
+{ 
+  return "CTK [ScriptingPythonWidgets]";
+}
+
+//-----------------------------------------------------------------------------
+QIcon ctkScriptingPythonWidgetsAbstractPlugin::icon() const
+{
+  return QIcon(); 
+}
+
+//-----------------------------------------------------------------------------
+QString ctkScriptingPythonWidgetsAbstractPlugin::toolTip() const
+{ 
+  return QString(); 
+}
+
+//-----------------------------------------------------------------------------
+QString ctkScriptingPythonWidgetsAbstractPlugin::whatsThis() const
+{
+  return QString(); 
+}
+
+//-----------------------------------------------------------------------------
+void ctkScriptingPythonWidgetsAbstractPlugin::initialize(QDesignerFormEditorInterface *formEditor)
+{
+  Q_UNUSED(formEditor);
+  if (this->Initialized)
+    {
+    return;
+    }
+  this->Initialized = true;
+}

+ 51 - 0
Libs/Scripting/Python/Widgets/Plugins/ctkScriptingPythonWidgetsAbstractPlugin.h

@@ -0,0 +1,51 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+#ifndef __ctkScriptingPythonWidgetsAbstractPlugin_h
+#define __ctkScriptingPythonWidgetsAbstractPlugin_h
+
+// Qt includes
+#include <QDesignerCustomWidgetInterface>
+
+// CTK includes
+#include "ctkScriptingPythonWidgetsPluginsExport.h"
+
+class CTK_SCRIPTING_PYTHON_WIDGETS_PLUGINS_EXPORT ctkScriptingPythonWidgetsAbstractPlugin :
+  public QDesignerCustomWidgetInterface
+{
+  Q_INTERFACES(QDesignerCustomWidgetInterface);
+public:
+
+  ctkScriptingPythonWidgetsAbstractPlugin();
+  
+  // Do *NOT* reimplement this method.
+  QString group() const;
+  
+  // You can reimplement these methods
+  virtual QIcon icon() const;
+  virtual QString toolTip() const;
+  virtual QString whatsThis() const;
+  virtual void initialize(QDesignerFormEditorInterface *formEditor);
+  
+protected:
+  bool Initialized;
+};
+
+#endif

+ 27 - 0
Libs/Scripting/Python/Widgets/Plugins/ctkScriptingPythonWidgetsPlugins.cpp

@@ -0,0 +1,27 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+// Qt includes
+#include <QtPlugin>
+
+// CTK includes
+#include "ctkScriptingPythonWidgetsPlugins.h"
+
+Q_EXPORT_PLUGIN2(customwidgetplugin, ctkScriptingPythonWidgetsPlugins);

+ 47 - 0
Libs/Scripting/Python/Widgets/Plugins/ctkScriptingPythonWidgetsPlugins.h

@@ -0,0 +1,47 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+#ifndef __ctkScriptingPythonWidgetsPlugins_h
+#define __ctkScriptingPythonWidgetsPlugins_h
+
+// Qt includes
+#include <QDesignerCustomWidgetCollectionInterface>
+
+// CTK includes
+#include "ctkScriptingPythonWidgetsPluginsExport.h"
+#include "ctkPythonConsolePlugin.h"
+
+/// \class Group the plugins in one library
+class CTK_SCRIPTING_PYTHON_WIDGETS_PLUGINS_EXPORT ctkScriptingPythonWidgetsPlugins : 
+  public QObject, public QDesignerCustomWidgetCollectionInterface
+{
+  Q_OBJECT
+  Q_INTERFACES(QDesignerCustomWidgetCollectionInterface);
+
+public:
+  QList<QDesignerCustomWidgetInterface*> customWidgets() const
+    {
+    QList<QDesignerCustomWidgetInterface *> plugins;
+    plugins << new ctkPythonConsolePlugin;
+    return plugins;
+    }
+};
+
+#endif