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をまとめたもの。

rowColumnLayout

GUIの部品を横に並べるためにはrowColumnLayoutを使用する。
rowColumnLayoutを使用する時には-numberOfRowsによって横の列が何列かを指定する。
また、rowColumnLayoutとcolumnLayoutをいっしょに使用することで、部品を縦・横に並べることができる。
その際、setParent ..;というコマンドによって、どのような構造でレイアウトを組み合わせるかを決めてゆく。
例えば、以下の様にレイアウトとsetParentを組み合わせると、横1列目にA、横2列目にB、Cが並び、横3列目にD、横3列目E、F、Gが並ぶ。

columnLayout;
A;
rowColumnLayout -numberOfRows 1;
	B;
	C;
setParent ..;
D;
rowColumnLayout -numberOfRows 1;
	E;
	F;
	G;
setParent ..;
[sample of rowColumnLayout]

radioButtonの使用例

ラジオボタンによってプリミティブ(球、キューブ、コーンのうちのどれか)を作るGUIを作ってみよう。

$windowName = `window -title "radioButton1"`;
columnLayout;
text -label "make Primitive";
$radioName = `radioCollection`;
	radioButton -label "Sphere" -select sphereButton;
	radioButton -label "Cube" cubeButton;
	radioButton -label "Cone" coneButton;
rowColumnLayout -numberOfRows 1;
	button -label "OK"
		-command "$selected = `radioCollection -q -select $radioName`;\
		if($selected == \"sphereButton\") sphere;\
		else if($selected == \"cubeButton\") nurbsCube;\
		else if($selected == \"coneButton\") cone;";
	button -label "Close" -command "deleteUI $windowName";
showWindow;
[image of radio1]

練習

まとめ

参考


prev | next
Home | Contents
abe@injapan.net