pythonwidget.hh
Go to the documentation of this file.
1 // Copyright (c) 2015-2018, LAAS-CNRS
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 //
4 // This file is part of gepetto-viewer.
5 // gepetto-viewer is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // gepetto-viewer is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // gepetto-viewer. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef GEPETTO_GUI_PYTHONWIDGET_HH
18 #define GEPETTO_GUI_PYTHONWIDGET_HH
19 
20 #include <gepetto/gui/fwd.hh>
21 #include <gepetto/gui/config-dep.hh>
22 
23 #if ! GEPETTO_GUI_HAS_PYTHONQT
24 # error "gepetto-viewer was not compile with PythonQt dependency."
25 #endif
26 
27 #include <QVariant>
28 #include <QDockWidget>
29 #include <QLayout>
30 #include <QPushButton>
31 #include <QSettings>
32 
33 class PythonQtObjectPtr;
34 class PythonQtScriptingConsole;
35 
36 namespace gepetto {
37  namespace gui {
87  class PythonWidget : public QDockWidget
88  {
89  Q_OBJECT
90  public:
91  explicit PythonWidget(QWidget *parent = 0);
92  void addToContext(QString const& name, QObject *obj);
93  virtual ~PythonWidget();
94 
97  QVariantList callPluginMethod (const QString& method,
98  const QVariantList& args = QVariantList(),
99  const QVariantMap& kwargs = QVariantMap()) const;
100 
101  void saveHistory (QSettings& settings);
102  void restoreHistory (QSettings& settings);
103 
104  bool hasPlugin (const QString& name);
105 
106  public slots:
120  void loadModulePlugin(QString moduleName);
121  void unloadModulePlugin(QString moduleName);
122  void loadScriptPlugin(QString moduleName, QString fileName);
123  void runScript(QString fileName);
124 
125  private:
126  void loadPlugin(QString moduleName, PythonQtObjectPtr module);
127  void unloadModulePlugin(PythonQtObjectPtr module);
128 
129  void addSignalHandlersToPlugin(PythonQtObjectPtr plugin);
130 
131  PythonQtScriptingConsole* console_;
132  QPushButton* button_;
133  QMap<QString, PythonQtObjectPtr> modules_;
134 
135  signals:
136 
137  public slots:
138  void browseFile();
139  };
152  } // namespace gui
153 } // namespace gepetto
154 
155 #endif // GEPETTO_GUI_PYTHONWIDGET_HH
void unloadModulePlugin(QString moduleName)
void restoreHistory(QSettings &settings)
QVariantList callPluginMethod(const QString &method, const QVariantList &args=QVariantList(), const QVariantMap &kwargs=QVariantMap()) const
Definition: action-search-bar.hh:27
PythonWidget(QWidget *parent=0)
void loadScriptPlugin(QString moduleName, QString fileName)
Definition: pythonwidget.hh:87
bool hasPlugin(const QString &name)
void saveHistory(QSettings &settings)
void addToContext(QString const &name, QObject *obj)
void loadModulePlugin(QString moduleName)
void runScript(QString fileName)