summaryrefslogtreecommitdiffstats
path: root/Mac/Lib/lib-toolbox/ControlAccessor.py
blob: d3952f7b1f91eaa8348ae4c776e618bc411f504b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Accessor functions for control properties

from Controls import *
import struct

_codingdict = {
	kControlPushButtonDefaultTag : ("b", None, None),
	kControlEditTextTextTag: (None, None, None),
	kControlEditTextPasswordTag: (None, None, None),
}

def SetControlData(control, part, selector, data):
	if not _codingdict.has_key(selector):
		raise KeyError, ('Unknown control selector', selector)
	structfmt, coder, decoder = _codingdict[selector]
	if coder:
		data = coder(data)
	if structfmt:
		data = struct.pack(structfmt, data)
	control.SetControlData(part, selector, data)
	
def GetControlData(control, part, selector):
	if not _codingdict.has_key(selector):
		raise KeyError, ('Unknown control selector', selector)
	structfmt, coder, decoder = _codingdict[selector]
	data = control.GetControlData(part, selector)
	if structfmt:
		data = struct.unpack(structfmt, data)
	if decoder:
		data = decoder(data)
	return data