• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Accessor functions for control properties
2
3from Controls import *
4import struct
5
6# These needn't go through this module, but are here for completeness
7def SetControlData_Handle(control, part, selector, data):
8    control.SetControlData_Handle(part, selector, data)
9
10def GetControlData_Handle(control, part, selector):
11    return control.GetControlData_Handle(part, selector)
12
13_accessdict = {
14    kControlPopupButtonMenuHandleTag: (SetControlData_Handle, GetControlData_Handle),
15}
16
17_codingdict = {
18    kControlPushButtonDefaultTag : ("b", None, None),
19
20    kControlEditTextTextTag: (None, None, None),
21    kControlEditTextPasswordTag: (None, None, None),
22
23    kControlPopupButtonMenuIDTag: ("h", None, None),
24
25    kControlListBoxDoubleClickTag: ("b", None, None),
26}
27
28def SetControlData(control, part, selector, data):
29    if _accessdict.has_key(selector):
30        setfunc, getfunc = _accessdict[selector]
31        setfunc(control, part, selector, data)
32        return
33    if not _codingdict.has_key(selector):
34        raise KeyError, ('Unknown control selector', selector)
35    structfmt, coder, decoder = _codingdict[selector]
36    if coder:
37        data = coder(data)
38    if structfmt:
39        data = struct.pack(structfmt, data)
40    control.SetControlData(part, selector, data)
41
42def GetControlData(control, part, selector):
43    if _accessdict.has_key(selector):
44        setfunc, getfunc = _accessdict[selector]
45        return getfunc(control, part, selector, data)
46    if not _codingdict.has_key(selector):
47        raise KeyError, ('Unknown control selector', selector)
48    structfmt, coder, decoder = _codingdict[selector]
49    data = control.GetControlData(part, selector)
50    if structfmt:
51        data = struct.unpack(structfmt, data)
52    if decoder:
53        data = decoder(data)
54    if type(data) == type(()) and len(data) == 1:
55        data = data[0]
56    return data
57