summaryrefslogtreecommitdiffstats
path: root/Lib/plat-mac/Carbon/ControlAccessor.py
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2002-12-30 22:04:23 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>2002-12-30 22:04:23 (GMT)
commit60087fb45092d9c199cea162e58d9193c7c1558c (patch)
tree05f3343e7707c4a4179e409506b39601279f04c1 /Lib/plat-mac/Carbon/ControlAccessor.py
parentc262a1f51ce89dbea4aeb072cf631686c47ed97f (diff)
downloadcpython-60087fb45092d9c199cea162e58d9193c7c1558c.zip
cpython-60087fb45092d9c199cea162e58d9193c7c1558c.tar.gz
cpython-60087fb45092d9c199cea162e58d9193c7c1558c.tar.bz2
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
in MacPython-OS9 and MacPython-OSX (or the equivalent unix Python on Mac OS X). The only items remaining in Mac/Lib are modules that are meaningful only for MacPython-OS9 (CFM stuff, MacPython preferences in resources, etc).
Diffstat (limited to 'Lib/plat-mac/Carbon/ControlAccessor.py')
-rw-r--r--Lib/plat-mac/Carbon/ControlAccessor.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/Lib/plat-mac/Carbon/ControlAccessor.py b/Lib/plat-mac/Carbon/ControlAccessor.py
new file mode 100644
index 0000000..20cf414
--- /dev/null
+++ b/Lib/plat-mac/Carbon/ControlAccessor.py
@@ -0,0 +1,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
+