Friday, May 6, 2011

Dialogs with Octave or Python callback functions

#callback function
def myFunc(w,h,output):
print "width = " + str(w) + " height = " + str(h) + " output = " + output

#create the input window with 3 rows and 1 column
inputWindow = tc_createMatrix( 3, 1 )
tc_setMatrixValue(inputWindow, 0, 0, 0)
tc_setMatrixValue(inputWindow, 1, 0, 0.0)
tc_setMatrixValue(inputWindow, 2, 0, 0.0)

#given row names to display
tc_setRowName(inputWindow, 0, "Width")
tc_setRowName(inputWindow, 1, "Height")
tc_setRowName(inputWindow, 2, "Output")
tc_createInputWindowForScript(inputWindow, "Screenshot", "myFunc")

#make the last row a set of options
list = ["Wiki code","HTML code"]
tc_addInputWindowOptions("Screenshot", 2, 0, toTC(list))


Here is the screenshot. When the user clicks the ok button, the callback function is called with the arguments 55, 12, "Wiki code"


No comments: