Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
gepetto-viewer-corba
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gepetto
gepetto-viewer-corba
Commits
3dcf1cae
Commit
3dcf1cae
authored
7 years ago
by
Joseph Mirabel
Committed by
Joseph Mirabel
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Clean PythonWidget
parent
7080be35
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/gepetto/gui/pythonwidget.hh
+11
-5
11 additions, 5 deletions
include/gepetto/gui/pythonwidget.hh
src/gui/pythonwidget.cc
+120
-95
120 additions, 95 deletions
src/gui/pythonwidget.cc
with
131 additions
and
100 deletions
include/gepetto/gui/pythonwidget.hh
+
11
−
5
View file @
3dcf1cae
...
...
@@ -8,12 +8,13 @@
# error "hpp-gui was not compile with PythonQt dependency."
#endif
#include
<QVariant>
#include
<QDockWidget>
#include
<QLayout>
#include
<QPushButton>
#include
<PythonQt/PythonQt.h>
#include
<PythonQt/PythonQt_QtAll.h>
#include
<PythonQt/
PythonQtScriptingConsole
.h>
class
PythonQtObjectPtr
;
class
PythonQtScriptingConsole
;
namespace
gepetto
{
namespace
gui
{
...
...
@@ -51,7 +52,7 @@ namespace gepetto {
///
/// ### Signals and slots:
///
/// The most important signals and slots you should now about are listed here.
/// The most important signals and slots you should
k
now about are listed here.
/// A more up-to-date list of the \ref available_in_python
///
/// The following method will be automatically connected to Qt signals:
...
...
@@ -76,6 +77,12 @@ namespace gepetto {
void
addToContext
(
QString
const
&
name
,
QObject
*
obj
);
virtual
~
PythonWidget
();
/// Calls a method on each plugin that has it.
/// \return a list of QVariant returned by each call.
QVariantList
callPluginMethod
(
const
QString
&
method
,
const
QVariantList
&
args
=
QVariantList
(),
const
QVariantMap
&
kwargs
=
QVariantMap
())
const
;
public
slots
:
/// Load a plugin by importing a module
///
...
...
@@ -98,7 +105,6 @@ namespace gepetto {
void
addSignalHandlersToPlugin
(
PythonQtObjectPtr
plugin
);
PythonQtObjectPtr
mainContext_
;
PythonQtScriptingConsole
*
console_
;
QPushButton
*
button_
;
QMap
<
QString
,
PythonQtObjectPtr
>
modules_
;
...
...
This diff is collapsed.
Click to expand it.
src/gui/pythonwidget.cc
+
120
−
95
View file @
3dcf1cae
#include
"gepetto/gui/pythonwidget.hh"
#include
<QFileDialog>
#include
<PythonQt/PythonQt.h>
#include
<PythonQt/PythonQt_QtAll.h>
#include
<PythonQt/PythonQtScriptingConsole.h>
#include
<PythonQt/PythonQtClassInfo.h>
#include
<PythonQt/PythonQt_QtBindings.h>
#include
"gepetto/gui/osgwidget.hh"
#include
"gepetto/gui/mainwindow.hh"
#include
"gepetto/gui/plugin-interface.hh"
namespace
gepetto
{
namespace
gui
{
...
...
@@ -29,43 +33,43 @@ namespace gepetto {
}
}
PythonWidget
::
PythonWidget
(
QWidget
*
parent
)
:
QDockWidget
(
"&PythonQt console"
,
parent
)
{
PythonQt
::
init
(
PythonQt
::
RedirectStdOut
);
PythonQt_init_QtBindings
();
mainContext
_
=
PythonQt
::
self
()
->
getMainModule
();
PythonQtObjectPtr
sys
=
PythonQt
::
self
()
->
importModule
(
"sys"
);
sys
.
evalScript
(
"argv = ['gepetto-gui']"
);
console_
=
new
PythonQtScriptingConsole
(
NULL
,
mainContext
_
);
PythonQt
::
self
()
->
registerQObjectClassNames
(
QStringList
()
<<
"BodyTreeWidget"
<<
"BodyTreeItem"
<<
"SelectionEvent"
<<
"WindowsManager"
);
mainContext
_
.
addObject
(
"mainWindow"
,
MainWindow
::
instance
());
mainContext
_
.
addObject
(
"windowsManager"
,
MainWindow
::
instance
()
->
osg
().
get
());
console_
->
QTextEdit
::
clear
();
console_
->
consoleMessage
(
"PythonQt command prompt
\n
"
"Use Shift+Enter for multiline code.
\n
"
"Variable mainWindow and osg are available.
\n
"
);
console_
->
appendCommandPrompt
();
QWidget
*
widget
=
new
QWidget
;
QVBoxLayout
*
layout
=
new
QVBoxLayout
;
button_
=
new
QPushButton
;
button_
->
setText
(
"Choose file"
);
layout
->
addWidget
(
console_
);
layout
->
addWidget
(
button_
);
widget
->
setLayout
(
layout
);
this
->
setWidget
(
widget
);
toggleViewAction
()
->
setShortcut
(
gepetto
::
gui
::
DockKeyShortcutBase
+
Qt
::
Key_A
);
connect
(
button_
,
SIGNAL
(
clicked
()),
SLOT
(
browseFile
()));
}
PythonWidget
::
PythonWidget
(
QWidget
*
parent
)
:
QDockWidget
(
"&PythonQt console"
,
parent
)
{
PythonQt
::
init
(
PythonQt
::
RedirectStdOut
);
PythonQt_init_QtBindings
();
PythonQtObjectPtr
mainContext
=
PythonQt
::
self
()
->
getMainModule
();
PythonQtObjectPtr
sys
=
PythonQt
::
self
()
->
importModule
(
"sys"
);
sys
.
evalScript
(
"argv = ['gepetto-gui']"
);
console_
=
new
PythonQtScriptingConsole
(
NULL
,
mainContext
);
PythonQt
::
self
()
->
registerQObjectClassNames
(
QStringList
()
<<
"BodyTreeWidget"
<<
"BodyTreeItem"
<<
"SelectionEvent"
<<
"WindowsManager"
);
mainContext
.
addObject
(
"mainWindow"
,
MainWindow
::
instance
());
mainContext
.
addObject
(
"windowsManager"
,
MainWindow
::
instance
()
->
osg
().
get
());
console_
->
QTextEdit
::
clear
();
console_
->
consoleMessage
(
"PythonQt command prompt
\n
"
"Use Shift+Enter for multiline code.
\n
"
"Variable mainWindow and osg are available.
\n
"
);
console_
->
appendCommandPrompt
();
QWidget
*
widget
=
new
QWidget
;
QVBoxLayout
*
layout
=
new
QVBoxLayout
;
button_
=
new
QPushButton
;
button_
->
setText
(
"Choose file"
);
layout
->
addWidget
(
console_
);
layout
->
addWidget
(
button_
);
widget
->
setLayout
(
layout
);
this
->
setWidget
(
widget
);
toggleViewAction
()
->
setShortcut
(
gepetto
::
gui
::
DockKeyShortcutBase
+
Qt
::
Key_A
);
connect
(
button_
,
SIGNAL
(
clicked
()),
SLOT
(
browseFile
()));
}
PythonWidget
::~
PythonWidget
()
{
...
...
@@ -74,71 +78,74 @@ namespace gepetto {
PythonQt
::
cleanup
();
}
void
PythonWidget
::
browseFile
()
{
QFileDialog
*
fd
=
new
QFileDialog
;
void
PythonWidget
::
browseFile
()
{
QFileDialog
*
fd
=
new
QFileDialog
;
fd
->
setFileMode
(
QFileDialog
::
ExistingFile
);
fd
->
setNameFilter
(
"All python file (*.py)"
);
if
(
fd
->
exec
()
==
QDialog
::
Accepted
)
{
QStringList
file
=
fd
->
selectedFiles
();
fd
->
setFileMode
(
QFileDialog
::
ExistingFile
);
fd
->
setNameFilter
(
"All python file (*.py)"
);
if
(
fd
->
exec
()
==
QDialog
::
Accepted
)
{
QStringList
file
=
fd
->
selectedFiles
();
mainContext_
.
evalFile
(
file
.
at
(
0
));
}
fd
->
close
();
fd
->
deleteLater
();
PythonQtObjectPtr
mainContext
=
PythonQt
::
self
()
->
getMainModule
();
mainContext
.
evalFile
(
file
.
at
(
0
));
}
fd
->
close
();
fd
->
deleteLater
();
}
void
PythonWidget
::
loadModulePlugin
(
QString
moduleName
)
{
MainWindow
*
main
=
MainWindow
::
instance
();
PythonQt
*
pqt
=
PythonQt
::
self
();
PythonQtObjectPtr
module
=
pqt
->
importModule
(
moduleName
);
if
(
pqt
->
handleError
())
{
return
;
}
if
(
module
.
isNull
())
{
pqt
->
handleError
();
qDebug
()
<<
"Enable to load module"
<<
moduleName
;
return
;
}
module
.
addObject
(
"windowsManager"
,
main
->
osg
().
get
());
QString
var
=
"pluginInstance"
;
QVariantList
args
;
args
<<
QVariant
::
fromValue
((
QObject
*
)
main
);
QVariant
instance
=
module
.
call
(
"Plugin"
,
args
);
module
.
addVariable
(
var
,
instance
);
QDockWidget
*
dw
=
qobject_cast
<
QDockWidget
*>
(
instance
.
value
<
QObject
*>
());
if
(
dw
)
main
->
insertDockWidget
(
dw
,
Qt
::
RightDockWidgetArea
);
// PythonQtObjectPtr dockPyObj (instance);
PythonQtObjectPtr
dockPyObj
=
pqt
->
lookupObject
(
module
,
var
);
addSignalHandlersToPlugin
(
dockPyObj
);
modules_
[
moduleName
]
=
module
;
void
PythonWidget
::
loadModulePlugin
(
QString
moduleName
)
{
MainWindow
*
main
=
MainWindow
::
instance
();
PythonQt
*
pqt
=
PythonQt
::
self
();
PythonQtObjectPtr
module
=
pqt
->
importModule
(
moduleName
);
if
(
pqt
->
handleError
())
{
return
;
}
void
PythonWidget
::
unloadModulePlugin
(
QString
moduleName
)
{
if
(
modules_
.
contains
(
moduleName
))
{
PythonQtObjectPtr
module
=
modules_
.
value
(
moduleName
);
unloadModulePlugin
(
module
);
modules_
.
remove
(
moduleName
);
}
if
(
module
.
isNull
())
{
pqt
->
handleError
();
qDebug
()
<<
"Enable to load module"
<<
moduleName
;
return
;
}
module
.
addObject
(
"windowsManager"
,
main
->
osg
().
get
());
QString
var
=
"pluginInstance"
;
QVariantList
args
;
args
<<
QVariant
::
fromValue
((
QObject
*
)
main
);
QVariant
instance
=
module
.
call
(
"Plugin"
,
args
);
module
.
addVariable
(
var
,
instance
);
QDockWidget
*
dw
=
qobject_cast
<
QDockWidget
*>
(
instance
.
value
<
QObject
*>
());
if
(
dw
)
main
->
insertDockWidget
(
dw
,
Qt
::
RightDockWidgetArea
);
// PythonQtObjectPtr dockPyObj (instance);
PythonQtObjectPtr
dockPyObj
=
pqt
->
lookupObject
(
module
,
var
);
addSignalHandlersToPlugin
(
dockPyObj
);
modules_
[
moduleName
]
=
module
;
}
void
PythonWidget
::
unloadModulePlugin
(
PythonQtObjectPtr
module
)
{
PythonQt
*
pqt
=
PythonQt
::
self
();
QString
var
=
"pluginInstance"
;
QVariant
instance
=
pqt
->
getVariable
(
module
,
var
);
QDockWidget
*
dw
=
qobject_cast
<
QDockWidget
*>
(
instance
.
value
<
QObject
*>
());
if
(
dw
)
MainWindow
::
instance
()
->
removeDockWidget
(
dw
);
module
.
removeVariable
(
var
);
void
PythonWidget
::
unloadModulePlugin
(
QString
moduleName
)
{
if
(
modules_
.
contains
(
moduleName
))
{
PythonQtObjectPtr
module
=
modules_
.
value
(
moduleName
);
unloadModulePlugin
(
module
);
modules_
.
remove
(
moduleName
);
}
}
void
PythonWidget
::
addToContext
(
QString
const
&
name
,
QObject
*
obj
)
{
mainContext_
.
addObject
(
name
,
obj
);
}
void
PythonWidget
::
unloadModulePlugin
(
PythonQtObjectPtr
module
)
{
PythonQt
*
pqt
=
PythonQt
::
self
();
QString
var
=
"pluginInstance"
;
QVariant
instance
=
pqt
->
getVariable
(
module
,
var
);
QDockWidget
*
dw
=
qobject_cast
<
QDockWidget
*>
(
instance
.
value
<
QObject
*>
());
if
(
dw
)
MainWindow
::
instance
()
->
removeDockWidget
(
dw
);
module
.
removeVariable
(
var
);
}
void
PythonWidget
::
addToContext
(
QString
const
&
name
,
QObject
*
obj
)
{
PythonQtObjectPtr
mainContext
=
PythonQt
::
self
()
->
getMainModule
();
mainContext
.
addObject
(
name
,
obj
);
}
void
PythonWidget
::
addSignalHandlersToPlugin
(
PythonQtObjectPtr
plugin
)
{
...
...
@@ -148,17 +155,35 @@ namespace gepetto {
QAction
*
reconnect
=
main
->
findChild
<
QAction
*>
(
"actionReconnect"
);
if
(
reconnect
)
addSignalHandler
(
plugin
,
"resetConnection"
,
reconnect
,
SIGNAL
(
triggered
()));
reconnect
,
SIGNAL
(
triggered
()));
else
qDebug
()
<<
"Could not find actionReconnect button. The plugin will"
<<
"not be able to reset CORBA connections"
;
QAction
*
refresh
=
main
->
findChild
<
QAction
*>
(
"actionRefresh"
);
if
(
refresh
)
addSignalHandler
(
plugin
,
"refreshInterface"
,
refresh
,
SIGNAL
(
triggered
()));
refresh
,
SIGNAL
(
triggered
()));
else
qDebug
()
<<
"Could not find actionRefresh button. The plugin will"
<<
"not be able to refresh interface."
;
}
QVariantList
PythonWidget
::
callPluginMethod
(
const
QString
&
method
,
const
QVariantList
&
args
,
const
QVariantMap
&
kwargs
)
const
{
PythonQt
*
pqt
=
PythonQt
::
self
();
QString
var
=
"pluginInstance"
;
QVariantList
ret
;
foreach
(
const
PythonQtObjectPtr
&
m
,
modules_
)
{
PythonQtObjectPtr
dockPyObj
=
pqt
->
lookupObject
(
m
,
var
);
PythonQtObjectPtr
call
=
pqt
->
lookupCallable
(
dockPyObj
,
method
);
if
(
!
call
.
isNull
())
{
ret
<<
call
.
call
(
args
,
kwargs
);
}
}
return
ret
;
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment