#----------------------------------------------------------
#Function for the event procedure
#----------------------------------------------------------
import mpfc
from newwin000 import newvlab_001

def opbtnep(object):
	#do something...
	val2 = newvlab_001.getProperty("labelString").getDouble()
	op = newvlab_001.getVariantData("op-input").getInt()
	value1 = newvlab_001.getVariantData("value1").getDouble()
	# run before operation
	if op == 1:
		value1 = value1 + val2
	elif op == 2:
		value1 = value1 - val2
	elif op == 3:
		value1 = value1 * val2
	elif op == 4:
		value1 = value1 / val2
	else:
		value1 = val2

	# Check the operator button.
	val = object.getProperty("labelString").getCharPtr()
	if not val.find("+") == -1:
		newvlab_001.setVariantData("op-input",1)
	elif not val.find("-") == -1:
		newvlab_001.setVariantData("op-input",2)
	elif not val.find("*") == -1:
		newvlab_001.setVariantData("op-input",3)
	elif not val.find("/") == -1:
		newvlab_001.setVariantData("op-input",4)
	else:
		newvlab_001.setVariantData("op-input",0)

	buffer = "%g" % value1
	if len(buffer) > 12:
		buffer = buffer[:-1]
	newvlab_001.setProperty("labelString",buffer)
	newvlab_001.setVariantData("num-input",False)
	newvlab_001.setVariantData("dot-input",False)
	newvlab_001.setVariantData("value1",value1)
	return
mpfc.WSGFfunctionRegister("opbtnep",opbtnep)
