IgorでGUI part2(ユーザー定義関数でボタン)
前回からの続きです。
IgorでGUI part1(panelの作成とボタン) - Igorの解説とか
今回はユーザー定義関数を用いてボタンを作成します。
パネルを作成してボタンを作るまでは
Newpanel
Button button0
Button button0
の二行で出来ます。
そこからボタンを押したときに作動する内容を、別のユーザー定義関数で書く必要があります。
ボタン作成
function make_button()
newpanel //panelの作成
Button example, proc=example_proc //ボタンをexampleという名前で定義、押したらexample_procというユーザー定義関数を実行
end
function example_proc(ctrlName) : buttoncontrol //ボタンを押した際の実行内容
string ctrlName
print "yes"
end
newpanel //panelの作成
Button example, proc=example_proc //ボタンをexampleという名前で定義、押したらexample_procというユーザー定義関数を実行
end
function example_proc(ctrlName) : buttoncontrol //ボタンを押した際の実行内容
string ctrlName
print "yes"
end
これで前回と同じ内容のパネルを作成することが出来ます。
さて上の例ですが、特にfunction example_procでは通常使わないものがあります。
それが ctrlName と : buttoncontrol です。
ctrlNameはボタンを押した時に自動的に返される文字列で、ボタンの名前を返します。
この例では make_button 内でButton exampleとしているため、ctrlNameにはexampleが代入されています。
: buttoncontrol についてはigorのマニュアルで
ボタン2
function make_button2()
newpanel
Button example,pos={10,10},size={80,25}
Button example,title="yes",fsize=16
Button example fColor=(0,65535,65535),valueColor=(65535,65535,65535)
Button example,proc=example_proc2
end
function example_proc2(ctrlName):buttoncontrol
string ctrlName
print "yes"
Button example,title="no"
end
newpanel
Button example,pos={10,10},size={80,25}
Button example,title="yes",fsize=16
Button example fColor=(0,65535,65535),valueColor=(65535,65535,65535)
Button example,proc=example_proc2
end
function example_proc2(ctrlName):buttoncontrol
string ctrlName
print "yes"
Button example,title="no"
end
上の例でのポイントを挙げておきます。
・Button ctrlName pos={左辺の座標、上辺の座標}
(パネルの左上が原点、座標の向きは右と下)
・Button ctrlName size={長さ、高さ}
・Button ctrlName title="パネル状に表示されるテキスト"
・Button ctrlName fsize=フォントサイズ
・Button ctrlName fcolor=フォントカラー
・Button ctrlName valuecolor=ボタンの色
(色はRGB値を{R,G,B}の順に書く)
・Button ctrlName proc=ボタンを押した際に実行する関数名
(パネルの左上が原点、座標の向きは右と下)
・Button ctrlName size={長さ、高さ}
・Button ctrlName title="パネル状に表示されるテキスト"
・Button ctrlName fsize=フォントサイズ
・Button ctrlName fcolor=フォントカラー
・Button ctrlName valuecolor=ボタンの色
(色はRGB値を{R,G,B}の順に書く)
・Button ctrlName proc=ボタンを押した際に実行する関数名
さらに重要なこととしては、二番目の例、example_proc2では
print "yes"
Button example,title="no"
Button example,title="no"
としているように、ボタン上のテキストを"no"にするようにしています。
実際にボタンを押すと、ボタン上のテキストが変化すると思います。
(コマンドウィンドウに出力されるテキストはyesのままですが・・・)
このように、ボタンの定義は別のユーザー定義関数でも行うことが出来ます。
これはかなり便利な機能ですので覚えておくとプログラムの幅が広がります。