[Tutor] If not global, how?

vicki@stanfield.net vicki@stanfield.net
Mon Mar 31 11:13:01 2003


In the app that I am developing, I have some callbacks
that need data from other methods. I am trying to
figure out how to make that data available without
making it global. Here is an example:

This class is instantiated.

class EntryClass(Pmw.EntryField):

	def __init__(self, parent=0):
		Pmw.EntryField.__init__(self, parent)

	def SendCommand(command):
		for command in ('\x09','\x06'):
			port = serial.Serial(0, 9600, 8, 'N', 2, timeout=2)
			port.write(command)
			old=outputbox.getvalue()
			new=string.join([old, hex(ord(command))])
			outputbox.setvalue(new)
			input=port.read()
			print input
			if input:
				returnedval=hex(ord(input))
				if returnedval:
					print returnedval
					old=outputbox.getvalue()
					new=string.join([old, returnedval])
					outputbox.setvalue(new)
			port.close()

	def Callback(self):
		value=self.getvalue()
		print value
		if value
			SendCommand(value)

------------------------------------
As you can see, I need to call SendCommand from the
callback. Since it is not an instance within the class,
I can't use EntryClass.SendCommand. If I move the call
to SendCommand into the main code, I don't think I can
be sure that it was just called and has a value that I
actually want to send out. I realize that I am probably
making this much harder than it is, but I am stuck. Can
someone help me fix this one?

--vicki