gepetto-viewer  4.13.0
An user-friendly Graphical Interface
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 
21 #include <gepetto/gui/fwd.hh>
22 
23 #if !GEPETTO_GUI_HAS_PYTHONQT
24 #error "gepetto-viewer was not compile with PythonQt dependency."
25 #endif
26 
27 #include <QDockWidget>
28 #include <QLayout>
29 #include <QPushButton>
30 #include <QSettings>
31 #include <QVariant>
32 
33 class PythonQtObjectPtr;
34 class PythonQtScriptingConsole;
35 
36 namespace gepetto {
37 namespace gui {
89 class PythonWidget : public QDockWidget {
90  Q_OBJECT
91  public:
92  explicit PythonWidget(QWidget* parent = 0);
93  void addToContext(QString const& name, QObject* obj);
94  virtual ~PythonWidget();
95 
98  QVariantList callPluginMethod(
99  const QString& method, const QVariantList& args = QVariantList(),
100  const QVariantMap& kwargs = QVariantMap()) const;
101 
102  void saveHistory(QSettings& settings);
103  void restoreHistory(QSettings& settings);
104 
105  bool hasPlugin(const QString& name);
106 
107  public slots:
121  void loadModulePlugin(QString moduleName);
122  void unloadModulePlugin(QString moduleName);
123  void loadScriptPlugin(QString moduleName, QString fileName);
124  void runScript(QString fileName);
125 
126  private:
127  void loadPlugin(QString moduleName, PythonQtObjectPtr module);
128  void unloadModulePlugin(PythonQtObjectPtr module);
129 
130  void addSignalHandlersToPlugin(PythonQtObjectPtr plugin);
131 
132  PythonQtScriptingConsole* console_;
133  QPushButton* button_;
134  QMap<QString, PythonQtObjectPtr> modules_;
135 
136  signals:
137 
138  public slots:
139  void browseFile();
140 };
151 } // namespace gui
152 } // namespace gepetto
153 
154 #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:26
PythonWidget(QWidget *parent=0)
void loadScriptPlugin(QString moduleName, QString fileName)
Definition: pythonwidget.hh:89
bool hasPlugin(const QString &name)
void saveHistory(QSettings &settings)
void addToContext(QString const &name, QObject *obj)
void loadModulePlugin(QString moduleName)
void runScript(QString fileName)