diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 1999-12-13 16:04:48 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 1999-12-13 16:04:48 (GMT) |
commit | 30f208047530436d191178314f32ba63dc065df4 (patch) | |
tree | a4e1e5536ee2e29aa1bbb770b4adaac19256823f /Mac/Lib | |
parent | 871a8897f2e49d34c6cbcbdca9d54e77e6cb8047 (diff) | |
download | cpython-30f208047530436d191178314f32ba63dc065df4.zip cpython-30f208047530436d191178314f32ba63dc065df4.tar.gz cpython-30f208047530436d191178314f32ba63dc065df4.tar.bz2 |
Methods {Get,Set}ControlData that know about data types passed for the various
4-char codes. The table which maps codes to datatypes is still pretty empty,
I'll fill it as I need entries (or maybe someone wants to spend a nice day filling it?).
Diffstat (limited to 'Mac/Lib')
-rw-r--r-- | Mac/Lib/lib-toolbox/ControlAccessor.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Mac/Lib/lib-toolbox/ControlAccessor.py b/Mac/Lib/lib-toolbox/ControlAccessor.py new file mode 100644 index 0000000..d3952f7 --- /dev/null +++ b/Mac/Lib/lib-toolbox/ControlAccessor.py @@ -0,0 +1,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 + |