GUIによる項目の選択

チェックボックスとラジオボタン

いくつかある項目の中から複数または、一つだけの項目を選びたい時にはcheckBoxとradioButtonを使用する。

checkBox
オンとオフができるコントロール。
例えば、以下のようにするとXというラベルのついたxCheckBoxという名前のcheckBoxが作られる。
checkBox -label "X" xCheckBox;
xCheckBoxという名前のcheckBoxの現在の値は以下のコマンドで得ることができる。
checkBox -q -value xCheckBox;
オンならtrue、オフならfalseが返される。
checkBoxGrp
複数のcheckBoxをまとめたもの。
radioButton
複数のボタンのうち一つだけがオンになるもの。
複数のradioButtonを一組のものとしてまとめるにはradioCollectionを使用する。
どのradioButtonが選ばれているかは以下のコマンドで得ることができる。
radioButton -q -select (radioButton名);
これによってオンになっているradioButtonの名前が返される。
radioButtonGrp
複数のradioButtonをまとめたもの。

radioButtonの使用例

ラジオボタンによってプリミティブ(球、キューブのうちのどれか)を作るGUIを作ってみよう。
以下のスクリプトをradio1.melという名前で作る。

global proc makePrimitive()
{
	$selected = `radioCollection -q -select radioCollection1`;
	if($selected == "sphereButton")
		sphere;
	else if($selected == "cubeButton")
		nurbsCube;
}

window -title "radioButton1" window1;
columnLayout;
text -label "make Primitive";
radioCollection radioCollection1;
	radioButton -label "Sphere" -select sphereButton;
	radioButton -label "Cube" cubeButton;
button -label "OK" -command "makePrimitive()";
button -label "Close" -command "deleteUI window1";
showWindow;
[image of example]

  1. global proc makePrimitive() このプロシージャがOKボタンによって実行される。
  2. $selected = `radioCollection -q -select radioCollection1`; radioCollection1という名前のラジオコレクションの中で選ばれているラジオボタンを調べて、その名前を$selectedという変数に代入する。
  3. if($selected == "sphereButton")
  4. sphere; sphereButtonが選ばれていれば、sphereコマンドを実行する。
  5. else if($selected == "cubeButton")
  6. nurbsCube; cubeButtonが選ばれていれば、nurbsCubeコマンドを実行する。
  7. window -title "radioButton1" window1; window1という名前でウインドウを作る。
  8. columnLayout; 部品を縦1列に並べる。
  9. text -label "make Primitive"; make Primitiveというテキストを表示。
  10. radioCollection radioCollection1; radioCollection1という名前でラジオコレクションを作る。
    これ以後に並べるラジオボタンが一つの組になる。 (この組から一つのボタンが選ばれる)
  11. radioButton -label "Sphere" -select sphereButton; sphereButtonという名前のラジオボタンを作る。
    -selectフラグがついていると最初にこのボタンが選ばれた状態で表示される。
  12. radioButton -label "Cube" cubeButton; cubeButtonという名前のラジオボタンを作る。
  13. button -label "OK" -command "makePrimitive()"; OKボタンを作る。
    ボタンを押すとmakePrimitive()が実行される。
  14. button -label "Close" -command "deleteUI window1"; Closeボタンを作る。
    ボタンを押すと、ウインドウが消される。
  15. showWindow; ウインドウを表示する。

練習

まとめ

参考


Prev | Next
Home | Contents
abe@injapan.net