DlgFromDict ============================= .. code-block:: python class psychopy.gui.DlgFromDict(dictionary, title='', fixed=(), order=(), tip=None, screen=-1) 辞書オブジェクトからダイアログボックスを作成する。ユーザーがダイアログの値を変更した結果は辞書オブジェクトに反映される。 以下に例を示す。 .. code-block:: python info = {'Observer':'jwp', 'GratingOri':45, 'ExpVersion': 1.1, 'Group': ['Test', 'Control']} dictDlg = gui.DlgFromDict(dictionary=info, title='TestExperiment', fixed=['ExpVersion']) if dictDlg.OK: print(info) else: print('User Cancelled') このコードにおいて、変数infoの内容はダイアログによって更新される。 ユーザーがダイアログのOKボタンを押さずにキャンセルした場合は、辞書オブジェクトの内容は変更されない。 OKボタンが押されたか否かはデータ属性OKがTrueかFalseかで確認することが出来る。 oderやtipの例についてはデモのGUI.py参照のこと。 (訳注:ダイアログの項目は自動的に並び替えられる。順序を固定したい場合は引数orderにキーをダイアログに並べたい順番に列挙する。orderにはすべてのキーを書く必要はなく、書かれなかったキーはorderに挙げられたキーの後に自動的に並び替えられる。表示はしたいがユーザーに値を変更させたくない項目はfixedに列挙する。引数screenはマルチモニター時に表示したいモニターを指定するために使用する。引数screenはQtをバックエンドとして用いている場合のみ利用できる。) .. Creates a dialogue box that represents a dictionary of values. Any values changed by the user are change (in-place) by this dialogue box. e.g.: .. info = {'Observer':'jwp', 'GratingOri':45, 'ExpVersion': 1.1, .. 'Group': ['Test', 'Control']} .. dictDlg = gui.DlgFromDict(dictionary=info, .. title='TestExperiment', fixed=['ExpVersion']) .. if dictDlg.OK: .. print(info) .. else: .. print('User Cancelled') .. In the code above, the contents of info will be updated to the values returned by the dialogue box. .. If the user cancels (rather than pressing OK), then the dictionary remains unchanged. If you want to check whether the user hit OK, then check whether DlgFromDict.OK equals True or False .. See GUI.py for a usage demo, including order and tip (tooltip).