#!/usr/bin/env python
from coral import kernel as coral
import traceback

def observer(dir):
	global tm
	global d
	aom = tm.getCurrentTransaction()
	assert aom
	print aom
	if dir == coral.TRANSACTION_UNDO:
		assert d.width == 0
		assert d.height == 0
	else:
		assert d.width == 200
		assert d.height == 150
        print "OBSERVER!"

xmidi=coral.lang.XMIDI20

tm = coral.getTransactionManager()
tm.addObserver(observer)

s=coral.Project()

d = xmidi.Dimension()

d.__setProject__(s)

assert not tm.canUndo()
assert not tm.canRedo()

tm.beginModifyCmd()
try:
	d.width = 200
	d.height = 150
	print
	print
	print "Doing..."
finally:
	tm.endModifyCmd()

assert d.width == 200
assert d.height == 150

print "X",tm.getAmountOfTransactions()
for i in range(tm.getAmountOfTransactions()):
	print "TRANSACTION", i
	t = tm.getTransaction(i)
	print id(t)
	print t

print "---"
print "Current", id(tm.getCurrentTransaction())
assert tm.canUndo()
assert not tm.canRedo()

print
print
print "Undoing..."

tm.undo()

assert d.width == 0
assert d.height == 0

assert not tm.canUndo()
assert tm.canRedo()

