Python.use(better, src=”PyPy”) #164: MultiCall.py

中級篇

Python.use(better, src=”PyPy”) # ソースコードの歩き方《復刻版》
ソースコードの歩き方《PyPy1.2》

《著》小粒ちゃん@湘南組、小粒ちゃん@博多組《監修》小泉ひよ子とタマゴ倶楽部
第1版♪2008/11/25 ● 第2版♪2010/04/29

PyPy1.2 のリリースを機に、PyPy1.1 版を再構成しました。
※ compiler の傘下にあるモジュールは、PyPy1.1.0 からの変更はありません。


《余録》ClassBrowser.py

■ 大域変数 _modifier_names

大域変数 _modifiers は、

# define the list of modifiers, to be used in complex event types.
if sys.platform == "darwin" and sys.executable.count(".app"):
    _modifiers = (("Shift",), ("Control",), ("Option",), ("Command",))
    _modifier_masks = (MC_SHIFT, MC_CONTROL, MC_OPTION, MC_COMMAND)
else:
    _modifiers = (("Control",), ("Alt",), ("Shift",), ("Meta", "M"))
    _modifier_masks = (MC_CONTROL, MC_ALT, MC_SHIFT, MC_META)

Macintosh で扱える特殊(修飾)キーを表わす「文字列を列挙したタプル」を列挙したタプルという、二重構造になっています。

# a dictionary to map a modifier name into its number
_modifier_names = dict([(name, number)
                         for number in range(len(_modifiers))
                         for name in _modifiers[number]])

外側の for に呼応する制御変数 number は、外側のタプルを構成する各要素(タプル)のオフセット値に対応します。内側の for に呼応する制御変数 name は、内側のタプルを構成する各要素(文字列)を順に参照します。すると、大域変数 _modifier_names には、次のような

>>> _modifier_names
{'Control': 1, 'Shift': 0, 'Command': 3, 'Option': 2}

特殊キーを表わす文字列と数値との要素対を列挙した辞書が得られます。

■ 大域変数 _type_names

大域変数 _types は、

# define the list of event types to be handled by MultiEvent. the order is
# compatible with the definition of event type constants.
_types = (
    ("KeyPress", "Key"), ("KeyRelease",), ("ButtonPress", "Button"),
    ("ButtonRelease",), ("Activate",), ("Circulate",), ("Colormap",),
    ("Configure",), ("Deactivate",), ("Destroy",), ("Enter",), ("Expose",),
    ("FocusIn",), ("FocusOut",), ("Gravity",), ("Leave",), ("Map",),
    ("Motion",), ("MouseWheel",), ("Property",), ("Reparent",), ("Unmap",),
    ("Visibility",),
)

Tk で扱えるイベント型を表わす「文字列を列挙したタプル」を列挙したタプルという、二重構造になっています。

# A dictionary to map a type name into its number
_type_names = dict([(name, number)
                     for number in range(len(_types))
                     for name in _types[number]])

外側の for に呼応する制御変数 number は、外側のタプルを構成する各要素(タプル)のオフセット値に対応します。内側の for に呼応する制御変数 name は、内側のタプルを構成する各要素(文字列)を順に参照します。すると、大域変数 _type_names には、次のような

>>> _type_names
{'KeyRelease': 1, 'Deactivate': 8, 'FocusOut': 13, 'Gravity': 14, 'Destroy': 9, 'Circulate': 5, 'Map': 16, 'Colormap': 6, 'Expose': 11, 'Visibility': 22, 'Key': 0, 'ButtonPress': 2, 'MouseWheel': 18, 'Button': 2, 'Reparent': 20, 'Leave': 15, 'Enter': 10, 'Property': 19, 'ButtonRelease': 3, 'Configure': 7, 'Motion': 17, 'Activate': 4, 'KeyPress': 0, 'Unmap': 21, 'FocusIn': 12}
>>> 

イベント型を表わす文字列と数値との要素対を列挙した辞書が得られます。ここで注目して欲しいのは、異なるキー 'Key' および 'KeyPress' に対して、同じ値 0 が対応しているのが分かります。
■■

TOP
》作業中です《


関連記事

Last updated♪2010/05/26