Skip to content

Commit 275e859

Browse files
committed
Update code to use trame.state
1 parent 8594111 commit 275e859

6 files changed

Lines changed: 42 additions & 42 deletions

File tree

03_html/solution_final.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from trame import change, update_state
1+
from trame import state
22
from trame.layouts import SinglePage
33
from trame.html import vtk, vuetify
44

@@ -50,14 +50,14 @@
5050
# -----------------------------------------------------------------------------
5151

5252

53-
@change("resolution")
53+
@state.change("resolution")
5454
def update_resolution(resolution, **kwargs):
5555
cone_source.SetResolution(resolution)
5656
html_view.update()
5757

5858

5959
def reset_resolution():
60-
update_state("resolution", DEFAULT_RESOLUTION)
60+
state.resolution = DEFAULT_RESOLUTION
6161

6262

6363
# -----------------------------------------------------------------------------

04_application/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22

3-
from trame import change, update_state
3+
from trame import state
44
from trame.layouts import SinglePage
55
from trame.html import vtk, vuetify
66

04_application/solution-auto-view.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22

3-
from trame import change, state
3+
from trame import state
44
from trame.layouts import SinglePageWithDrawer
55
from trame.html import vtk, vuetify, widgets
66

@@ -170,7 +170,7 @@ class LookupTable:
170170
# -----------------------------------------------------------------------------
171171

172172

173-
@change("cube_axes_visibility")
173+
@state.change("cube_axes_visibility")
174174
def update_cube_axes_visibility(cube_axes_visibility, **kwargs):
175175
cube_axes.SetVisibility(cube_axes_visibility)
176176
html_view.update()
@@ -220,13 +220,13 @@ def update_representation(actor, mode):
220220
property.EdgeVisibilityOn()
221221

222222

223-
@change("mesh_representation")
223+
@state.change("mesh_representation")
224224
def update_mesh_representation(mesh_representation, **kwargs):
225225
update_representation(mesh_actor, mesh_representation)
226226
html_view.update()
227227

228228

229-
@change("contour_representation")
229+
@state.change("contour_representation")
230230
def update_contour_representation(contour_representation, **kwargs):
231231
update_representation(contour_actor, contour_representation)
232232
html_view.update()
@@ -246,14 +246,14 @@ def color_by_array(actor, array):
246246
mapper.SetUseLookupTableScalarRange(True)
247247

248248

249-
@change("mesh_color_array_idx")
249+
@state.change("mesh_color_array_idx")
250250
def update_mesh_color_by_name(mesh_color_array_idx, **kwargs):
251251
array = dataset_arrays[mesh_color_array_idx]
252252
color_by_array(mesh_actor, array)
253253
html_view.update()
254254

255255

256-
@change("contour_color_array_idx")
256+
@state.change("contour_color_array_idx")
257257
def update_contour_color_by_name(contour_color_array_idx, **kwargs):
258258
array = dataset_arrays[contour_color_array_idx]
259259
color_by_array(contour_actor, array)
@@ -282,33 +282,33 @@ def use_preset(actor, preset):
282282
lut.Build()
283283

284284

285-
@change("mesh_color_preset")
285+
@state.change("mesh_color_preset")
286286
def update_mesh_color_preset(mesh_color_preset, **kwargs):
287287
use_preset(mesh_actor, mesh_color_preset)
288288
html_view.update()
289289

290290

291-
@change("contour_color_preset")
291+
@state.change("contour_color_preset")
292292
def update_contour_color_preset(contour_color_preset, **kwargs):
293293
use_preset(contour_actor, contour_color_preset)
294294
html_view.update()
295295

296296

297297
# Opacity Callbacks
298-
@change("mesh_opacity")
298+
@state.change("mesh_opacity")
299299
def update_mesh_opacity(mesh_opacity, **kwargs):
300300
mesh_actor.GetProperty().SetOpacity(mesh_opacity)
301301
html_view.update()
302302

303303

304-
@change("contour_opacity")
304+
@state.change("contour_opacity")
305305
def update_contour_opacity(contour_opacity, **kwargs):
306306
contour_actor.GetProperty().SetOpacity(contour_opacity)
307307
html_view.update()
308308

309309

310310
# Contour Callbacks
311-
@change("contour_by_array_idx")
311+
@state.change("contour_by_array_idx")
312312
def update_contour_by(contour_by_array_idx, **kwargs):
313313
array = dataset_arrays[contour_by_array_idx]
314314
contour_min, contour_max = array.get("range")
@@ -327,7 +327,7 @@ def update_contour_by(contour_by_array_idx, **kwargs):
327327
html_view.update()
328328

329329

330-
@change("contour_value")
330+
@state.change("contour_value")
331331
def update_contour_value(contour_value, **kwargs):
332332
contour.SetValue(0, float(contour_value))
333333
html_view.update()

04_application/solution.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22

3-
from trame import change, update_state
3+
from trame import state
44
from trame.layouts import SinglePageWithDrawer
55
from trame.html import vtk, vuetify, widgets
66

@@ -170,13 +170,13 @@ class LookupTable:
170170
# -----------------------------------------------------------------------------
171171

172172

173-
@change("cube_axes_visibility")
173+
@state.change("cube_axes_visibility")
174174
def update_cube_axes_visibility(cube_axes_visibility, **kwargs):
175175
cube_axes.SetVisibility(cube_axes_visibility)
176176
html_view.update()
177177

178178

179-
@change("local_vs_remote")
179+
@state.change("local_vs_remote")
180180
def update_local_vs_remote(local_vs_remote, **kwargs):
181181
# Switch html_view
182182
global html_view
@@ -197,11 +197,11 @@ def update_local_vs_remote(local_vs_remote, **kwargs):
197197
def actives_change(ids):
198198
_id = ids[0]
199199
if _id == "1": # Mesh
200-
update_state("active_ui", "mesh")
200+
state.active_ui = "mesh"
201201
elif _id == "2": # Contour
202-
update_state("active_ui", "contour")
202+
state.active_ui = "contour"
203203
else:
204-
update_state("active_ui", "nothing")
204+
state.active_ui= "nothing"
205205

206206

207207
# Visibility Change
@@ -237,13 +237,13 @@ def update_representation(actor, mode):
237237
property.EdgeVisibilityOn()
238238

239239

240-
@change("mesh_representation")
240+
@state.change("mesh_representation")
241241
def update_mesh_representation(mesh_representation, **kwargs):
242242
update_representation(mesh_actor, mesh_representation)
243243
html_view.update()
244244

245245

246-
@change("contour_representation")
246+
@state.change("contour_representation")
247247
def update_contour_representation(contour_representation, **kwargs):
248248
update_representation(contour_actor, contour_representation)
249249
html_view.update()
@@ -263,14 +263,14 @@ def color_by_array(actor, array):
263263
mapper.SetUseLookupTableScalarRange(True)
264264

265265

266-
@change("mesh_color_array_idx")
266+
@state.change("mesh_color_array_idx")
267267
def update_mesh_color_by_name(mesh_color_array_idx, **kwargs):
268268
array = dataset_arrays[mesh_color_array_idx]
269269
color_by_array(mesh_actor, array)
270270
html_view.update()
271271

272272

273-
@change("contour_color_array_idx")
273+
@state.change("contour_color_array_idx")
274274
def update_contour_color_by_name(contour_color_array_idx, **kwargs):
275275
array = dataset_arrays[contour_color_array_idx]
276276
color_by_array(contour_actor, array)
@@ -299,33 +299,33 @@ def use_preset(actor, preset):
299299
lut.Build()
300300

301301

302-
@change("mesh_color_preset")
302+
@state.change("mesh_color_preset")
303303
def update_mesh_color_preset(mesh_color_preset, **kwargs):
304304
use_preset(mesh_actor, mesh_color_preset)
305305
html_view.update()
306306

307307

308-
@change("contour_color_preset")
308+
@state.change("contour_color_preset")
309309
def update_contour_color_preset(contour_color_preset, **kwargs):
310310
use_preset(contour_actor, contour_color_preset)
311311
html_view.update()
312312

313313

314314
# Opacity Callbacks
315-
@change("mesh_opacity")
315+
@state.change("mesh_opacity")
316316
def update_mesh_opacity(mesh_opacity, **kwargs):
317317
mesh_actor.GetProperty().SetOpacity(mesh_opacity)
318318
html_view.update()
319319

320320

321-
@change("contour_opacity")
321+
@state.change("contour_opacity")
322322
def update_contour_opacity(contour_opacity, **kwargs):
323323
contour_actor.GetProperty().SetOpacity(contour_opacity)
324324
html_view.update()
325325

326326

327327
# Contour Callbacks
328-
@change("contour_by_array_idx")
328+
@state.change("contour_by_array_idx")
329329
def update_contour_by(contour_by_array_idx, **kwargs):
330330
array = dataset_arrays[contour_by_array_idx]
331331
contour_min, contour_max = array.get("range")
@@ -335,16 +335,16 @@ def update_contour_by(contour_by_array_idx, **kwargs):
335335
contour.SetValue(0, contour_value)
336336

337337
# Update UI
338-
update_state("contour_min", contour_min)
339-
update_state("contour_max", contour_max)
340-
update_state("contour_value", contour_value)
341-
update_state("contour_step", contour_step)
338+
state.contour_min = contour_min
339+
state.contour_max = contour_max
340+
state.contour_value = contour_value
341+
state.contour_step = contour_step
342342

343343
# Update View
344344
html_view.update()
345345

346346

347-
@change("contour_value")
347+
@state.change("contour_value")
348348
def update_contour_value(contour_value, **kwargs):
349349
contour.SetValue(0, float(contour_value))
350350
html_view.update()

05_paraview/SimpleCone.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import venv
22

3-
from trame import update_state, change
3+
from trame import state
44
from trame.html import vuetify, paraview
55
from trame.layouts import SinglePage
66

@@ -17,14 +17,14 @@
1717
view = simple.Render()
1818

1919

20-
@change("resolution")
20+
@state.change("resolution")
2121
def update_cone(resolution, **kwargs):
2222
cone.Resolution = resolution
2323
html_view.update()
2424

2525

2626
def update_reset_resolution():
27-
update_state("resolution", DEFAULT_RESOLUTION)
27+
state.resolution = DEFAULT_RESOLUTION
2828

2929

3030
# -----------------------------------------------------------------------------
@@ -35,7 +35,7 @@ def update_reset_resolution():
3535
# html_view = paraview.VtkLocalView(view) # Local rendering
3636

3737
layout = SinglePage("ParaView cone", on_ready=update_cone)
38-
layout.logo.click = "$refs.view.resetCamera()"
38+
layout.logo.click = html_view.reset_camera
3939
layout.title.set_text("Cone Application")
4040

4141
with layout.toolbar:

05_paraview/StateLoader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import venv
22
import os
33

4-
import trame
4+
from trame import get_cli_parser
55
from trame.html import vuetify, paraview
66
from trame.layouts import SinglePage
77

@@ -16,7 +16,7 @@
1616

1717
def load_data():
1818
# CLI
19-
parser = trame.get_cli_parser()
19+
parser = get_cli_parser()
2020
parser.add_argument("--data", help="Path to state file", dest="data")
2121
args, _ = parser.parse_known_args()
2222

0 commit comments

Comments
 (0)