From b4783a2011682c559a99d0068c459406d400d6d4 Mon Sep 17 00:00:00 2001
From: Joseph Mirabel <jmirabel@laas.fr>
Date: Fri, 20 May 2016 19:53:20 +0200
Subject: [PATCH] Expose resetConnection signal to Python and update the doc.

---
 include/gepetto/gui/pythonwidget.hh   | 38 ++++++++++++++++++++++-----
 pyplugins/gepetto/gui/pythonwidget.py |  1 +
 src/gui/pythonwidget.cc               | 10 ++++++-
 3 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/include/gepetto/gui/pythonwidget.hh b/include/gepetto/gui/pythonwidget.hh
index 0691f58..42a619d 100644
--- a/include/gepetto/gui/pythonwidget.hh
+++ b/include/gepetto/gui/pythonwidget.hh
@@ -23,29 +23,46 @@ namespace gepetto {
     /// \ingroup plugin
     /// Python plugin interface
     ///
+    /// ## Overview
+    ///
     /// A Python plugin is a Python module containing a class Plugin, with a
     /// constructor taking a pointer to the MainWindow as input.
     ///
-    /// For instance, if you have \code gepetto.gui=true \endcode in your
-    /// configuration file, then the Plugin class will be accessed via:
+    /// For instance, if you have
+    /// \code
+    /// [pyplugins]
+    /// module.submodule=true
+    /// \endcode
+    /// in your configuration file (Settings::readSettingFile), then the Plugin
+    /// class will be accessed by the GUI in a way similar to:
     ///
     /// \code{py}
-    /// from gepetto.gui import Plugin
+    /// from module.submodule import Plugin
     /// pluginInstance = Plugin(mainWindow)
     /// \endcode
     ///
-    /// It may interact with the interface in two following ways.
+    /// It may interact with the interface in following ways.
     ///
-    /// pyplugin_dockwidget Add a dock widget:
+    /// ### Add a dock widget:
     ///
     /// Your plugin may inherits from class PythonQt.QtGui.QDockWidget.
     /// In this case, an instance of the Plugin  will be added to the MainWindow
     /// as a QDockWidget.
     ///
-    /// pyplugin_signals Signals and slots:
+    /// ### Signals and slots:
     ///
     /// The following method will be automatically connected to Qt signals:
-    /// \li MainWindow::viewCreated(OSGWidget*) -> Plugin.osgWidget
+    /// \li \c Plugin.osgWidget when a new OSGWidget is created (MainWindow::viewCreated(OSGWidget*))
+    /// \li \c Plugin.resetConnection triggered when CORBA connection should be reset.
+    ///
+    /// ### Logging
+    ///
+    /// Logging can be done from Python through:
+    /// \li MainWindow::log(const QString&)
+    /// \li MainWindow::logError(const QString&)
+    /// \li MainWindow::logJobStarted, MainWindow::logJobDone and
+    ///     MainWindow::logJobFailed to inform users when
+    ///     something may take some time.
     ///
     /// \sa See example \ref pyplugins/gepetto/gui/pythonwidget.py
     class PythonWidget : public QDockWidget
@@ -93,6 +110,13 @@ namespace gepetto {
     /// This is an example Python Plugin for \link hpp::gui::PythonWidget \endlink. Two classes are defined:
     /// \b _NodeCreator and \b Plugin. Two signals are used: \a mainWindow.refresh()
     /// and \a osgWidget.
+    /// Add this to your configuration file to load this plugin
+    /// \code
+    /// [pyplugins]
+    /// gepetto.gui=true
+    /// \endcode
+    /// Then right-click on a tool bar, menu bar or title bar of dock widgets
+    /// to open your window.
   } // namespace gui
 } // namespace gepetto
 
diff --git a/pyplugins/gepetto/gui/pythonwidget.py b/pyplugins/gepetto/gui/pythonwidget.py
index e7d1264..5a6039b 100644
--- a/pyplugins/gepetto/gui/pythonwidget.py
+++ b/pyplugins/gepetto/gui/pythonwidget.py
@@ -53,6 +53,7 @@ class _NodeCreator (QtGui.QWidget):
 
     def createGroup (self):
         self.client.gui.createGroup(str(self.nodeName.text))
+        self.groupNodes.addItem(self.nodeName.text)
 
     def addToGroup (self):
         self.client.gui.addToGroup(str(self.nodeName.text), str(self.groupNodes.currentText))
diff --git a/src/gui/pythonwidget.cc b/src/gui/pythonwidget.cc
index bfb49ee..d22067d 100644
--- a/src/gui/pythonwidget.cc
+++ b/src/gui/pythonwidget.cc
@@ -128,8 +128,16 @@ namespace gepetto {
 
       void PythonWidget::addSignalHandlersToPlugin(PythonQtObjectPtr plugin)
       {
+        MainWindow* main = MainWindow::instance();
         addSignalHandler(plugin, "osgWidget",
-            MainWindow::instance(), SIGNAL(viewCreated(OSGWidget*)));
+            main, SIGNAL(viewCreated(OSGWidget*)));
+        QAction* reconnect = main->findChild<QAction*>("actionReconnect");
+        if (reconnect)
+          addSignalHandler(plugin, "resetConnection",
+            reconnect, SIGNAL(triggered()));
+        else
+          qDebug() << "Could not find actionReconnect button. The plugin will"
+            << "not be able to reset CORBA connections";
       }
     }
 }
-- 
GitLab