File: undo_redo_errors.py

package info (click to toggle)
k3d 0.8.0.2-6
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 40,692 kB
  • ctags: 39,695
  • sloc: cpp: 171,303; ansic: 24,129; xml: 6,995; python: 5,796; makefile: 726; sh: 22
file content (20 lines) | stat: -rw-r--r-- 632 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#python

import k3d

# While recording state changes for undo/redo purposes, you must ensure that errors are handled properly!

context.document.start_change_set()
try:
	if k3d.ui().query_message("Choose one ...", ["Succeed", "Fail"]) == 2:
		raise RuntimeError("Simulated error condition.")

	null_node = k3d.plugin.create("Null", context.document)
	null_node.name = "Test Node"

	context.document.finish_change_set("Test Change Set")
	k3d.ui().message("State recording completed successfully ... check the Edit menu.")

except:
	context.document.cancel_change_set()
	k3d.ui().message("State recording cancelled due to an error!")