File: ControlAccessor.py

package info (click to toggle)
python2.1 2.1.3dfsg-1sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 38,028 kB
  • ctags: 64,228
  • sloc: python: 186,023; ansic: 184,754; xml: 43,435; sh: 12,381; makefile: 3,523; perl: 3,108; lisp: 2,460; cpp: 106; sed: 2
file content (57 lines) | stat: -rw-r--r-- 1,743 bytes parent folder | download | duplicates (4)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Accessor functions for control properties

from Controls import *
import struct

# These needn't go through this module, but are here for completeness
def SetControlData_Handle(control, part, selector, data):
	control.SetControlData_Handle(part, selector, data)
	
def GetControlData_Handle(control, part, selector):
	return control.GetControlData_Handle(part, selector)
	
_accessdict = {
	kControlPopupButtonMenuHandleTag: (SetControlData_Handle, GetControlData_Handle),
}

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

def SetControlData(control, part, selector, data):
	if _accessdict.has_key(selector):
		setfunc, getfunc = _accessdict[selector]
		setfunc(control, part, selector, data)
		return
	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 _accessdict.has_key(selector):
		setfunc, getfunc = _accessdict[selector]
		return getfunc(control, part, selector, data)
	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)
	if type(data) == type(()) and len(data) == 1:
		data = data[0]
	return data