Skip to content

Commit 604b765

Browse files
hugtalbotbakpaul
andauthored
[examples] Simplify use of ImGui (#525)
* [examples] Simplify use of ImGui * Fix liver-scriptcontroller --------- Co-authored-by: Paul Baksic <[email protected]>
1 parent d02c833 commit 604b765

File tree

9 files changed

+16
-25
lines changed

9 files changed

+16
-25
lines changed

examples/basic-addGUI.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
def main():
55
# Required import for python
66
import Sofa
7-
import SofaRuntime
7+
import SofaImGui
88

99
#Create the root node
1010
root = Sofa.Core.Node("root")
@@ -16,8 +16,8 @@ def main():
1616
for iteration in range(10):
1717
Sofa.Simulation.animate(root, root.dt.value)
1818
else:
19+
# Required import to manage the GUI
1920
import Sofa.Gui
20-
SofaRuntime.importPlugin("SofaImGui")
2121

2222
# Find out the supported GUIs
2323
print ("Supported GUIs are: " + Sofa.Gui.GUIManager.ListSupportedGUI(","))

examples/basic-useQtGUI.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
def main():
55
# Required import for python
66
import Sofa
7-
import SofaRuntime
87

98
# Make sure to load all SOFA libraries
109

@@ -19,7 +18,7 @@ def main():
1918
Sofa.Simulation.animate(root, root.dt.value)
2019
else:
2120
import Sofa.Gui
22-
import SofaQt
21+
import SofaQt # specific import for Qt-based GUI
2322

2423
# Find out the supported GUIs
2524
print ("Supported GUIs are: " + Sofa.Gui.GUIManager.ListSupportedGUI(","))

examples/emptyController.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,8 @@ def createScene(root):
102102

103103

104104
def main():
105-
import SofaRuntime
105+
import SofaImGui
106106
import Sofa.Gui
107-
SofaRuntime.importPlugin("SofaImGui")
108107

109108
root=Sofa.Core.Node("root")
110109
createScene(root)

examples/emptyDataEngine.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ def createScene(root):
3131

3232

3333
def main():
34+
import SofaImGui
3435
import Sofa.Gui
35-
import SofaRuntime
36-
SofaRuntime.importPlugin("SofaImGui")
3736

3837
root=Sofa.Core.Node("root")
3938
createScene(root)

examples/emptyForceField.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ def createScene(root):
5656

5757

5858
def main():
59-
import SofaRuntime
59+
import SofaImGui
6060
import Sofa.Gui
61-
SofaRuntime.importPlugin("SofaImGui")
6261

6362
root=Sofa.Core.Node("root")
6463
createScene(root)

examples/example-forcefield.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ def createScene(root):
5858

5959

6060
def main():
61-
import SofaRuntime
61+
import SofaImGui
6262
import Sofa.Gui
63-
SofaRuntime.importPlugin("SofaImGui")
6463

6564
root=Sofa.Core.Node("root")
6665
createScene(root)

examples/liver-scriptcontroller.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Required import for python
21
import Sofa
32

43

@@ -7,8 +6,11 @@
76

87

98
def main():
10-
import SofaRuntime
9+
# Required import for python
10+
import Sofa
1111
import Sofa.Gui
12+
import SofaImGui
13+
1214

1315
root = Sofa.Core.Node("root")
1416
createScene(root)
@@ -18,7 +20,6 @@ def main():
1820
for iteration in range(10):
1921
Sofa.Simulation.animate(root, root.dt.value)
2022
else:
21-
SofaRuntime.importPlugin("SofaImGui")
2223
Sofa.Gui.GUIManager.Init("myscene", "imgui")
2324
Sofa.Gui.GUIManager.createGUI(root, __file__)
2425
Sofa.Gui.GUIManager.SetDimension(1080, 1080)

examples/liver.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
# Required import for python
2-
import Sofa
3-
4-
51
# Choose in your script to activate or not the GUI
62
USE_GUI = True
73

8-
94
def main():
10-
import SofaRuntime
11-
import Sofa.Gui
5+
# Required import for python
6+
import Sofa
7+
import SofaImGui
128

139
root = Sofa.Core.Node("root")
1410
createScene(root)
@@ -18,7 +14,7 @@ def main():
1814
for iteration in range(10):
1915
Sofa.Simulation.animate(root, root.dt.value)
2016
else:
21-
SofaRuntime.importPlugin("SofaImGui")
17+
import Sofa.Gui
2218
Sofa.Gui.GUIManager.Init("myscene", "imgui")
2319
Sofa.Gui.GUIManager.createGUI(root, __file__)
2420
Sofa.Gui.GUIManager.SetDimension(1080, 1080)

examples/loadXMLfromPython.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def createScene(root):
2929

3030

3131
def main():
32-
import SofaRuntime
32+
import SofaImGui
3333
import Sofa.Gui
3434

3535
root = Sofa.Core.Node("root")
@@ -39,7 +39,6 @@ def main():
3939
# Find out the supported GUIs
4040
print ("Supported GUIs are: " + Sofa.Gui.GUIManager.ListSupportedGUI(","))
4141
# Launch the GUI (imgui is now by default, to use Qt please refer to the example "basic-useQtGui.py")
42-
SofaRuntime.importPlugin("SofaImGui")
4342
Sofa.Gui.GUIManager.Init("myscene", "imgui")
4443
Sofa.Gui.GUIManager.createGUI(root, __file__)
4544
Sofa.Gui.GUIManager.SetDimension(1080, 1080)

0 commit comments

Comments
 (0)