Launcherスクリプト仕様書:実例編
1. 本書の位置付け
本書は Launcher スクリプトの代表的な実例パターンを示す。
新しい PDF 資料に沿って、なるべく現行実装に近い書き方を示す。 fileciteturn7file0 fileciteturn7file1
2. 例1:最小セクション
[Sample]
echo Hello
End
基本的なセクション構造。
3. 例2:変数設定と利用
[Sample]
set outprefix=result
echo $(outprefix)
End
setで値を入れる$(varname)で展開する
4. 例3:ファイル選択
[Sample]
get_open_file_name "*.csv" "$(last_dir)" "Choose input CSV"
set input_path=$o
get_directory "$(input_path)" dir_name
get_filebody "$(input_path)" filebody
End
ファイル選択結果は
$oget_directory,get_filebodyで派生情報を作る fileciteturn7file0
5. 例4:Cancel しても続行するファイル選択
[Sample]
get_open_file_name_continue "*.xlsx" "$(last_dir)" "Choose Excel file"
set input_path=$o
End
*_continue 系は、Cancel 時にもスクリプトを継続させたいときに使う。 fileciteturn7file0
6. 例5:前回フォルダの保存・復元
[Button5.Sample]
Caption=Persistent work dir
read_ini $i "sample" "work_dir" last_dir "."
chdir "$(last_dir)"
get_open_file_name "*.txt" "$(last_dir)" "Choose text file"
set input_path=$o
get_directory "$(input_path)" dir_name
write_ini $i "sample" "work_dir" "$(dir_name)"
End
定番の作業ディレクトリ保持パターン。 fileciteturn7file0
7. 例6:join_path で安全にパスを作る
[Sample]
join_path parameter_path "$(dir_name)" "$(filebody).prm"
echo $(parameter_path)
End
OS 依存セパレータを意識せずパスを作れる。 fileciteturn7file0
8. 例7:コメント付き候補値
[Sample]
set_if_blank method_llsq method_llsq=nelder-mead # Downhill simplex
remove_comment method_llsq
echo $(method_llsq)
End
GUI では説明付き、実行時は値だけ、という使い方。 fileciteturn7file0turn7file1
9. 例8:最小ダイアログ
[Button1.Sample]
Caption=Simple dialog
set_if_blank name name=world
set_title Sample dialog
new_dialog
add_dialog entry\
name\
"label_head=Name:"\
width=20\
"def_val=$(name)"\
"label_tail="
add_dialog frame dummy "bg=#ececec" "relief=groove"
add_dialog button dummy "text=Run" "command=call [Sample_execute]"
add_dialog pack_frame dummy
custom_dialog "Simple dialog" close
End
[Sample_execute]
echo Hello $(name)
End
基本的な new_dialog -> add_dialog -> custom_dialog の流れ。 fileciteturn7file1
10. 例9:choose_file の詳細オプション
add_dialog choose_file\
python3_path\
"label_head=python3:"\
entry_width=40\
"def_val=$(python3_path)"\
initialdir=.\ \
"file_type=Exec:*.exe"\
state=readonly\
check_exist=1\
show_path_button=1\
label_tail=\
button1_text=check\
"button1_command=call [Check_python]"
この例では、PDF にある主要オプションをまとめて使っている。 fileciteturn7file1
11. 例10:combobox
add_dialog combobox\
method_llsq\
"label_head=method:"\
state=readonly\
width=80\
height=15\
init_val=$(method_llsq)\
def_val=$(method_llsq)\
"nelder-mead # Downhill simplex"\
"powell # Modified Powell"\
label_tail=
init_valは初期値def_valは default ボタン用リセット値#以降はremove_commentで除去可能 fileciteturn7file1
13. 例12:タブ付きダイアログ
new_dialog
add_dialog tab dummy "text=main"
add_dialog entry\
input_path\
"label_head=Input:"\
width=40\
"def_val=$(input_path)"\
"label_tail="
add_dialog reset_tab dummy
custom_dialog "Tabbed dialog" close
タブ付き UI の最小例。 fileciteturn7file1
14. 例13:メニューとコンテキストメニュー
[VASP].select
create_menu hmenu "title=examples"\
"label=show dialog" "command=call [Button10.VASP]"\
"label=show example dir" "command=call [VASP_Show]"
add_context_menu hmenu 10
End
create_menuでメニュー作成add_context_menuでボタンへ関連付け
これは PDF widget 仕様書で正式に確認できる。 fileciteturn7file1
15. 例14:ツールチップ
[TButton].onload
add_tooltip TButton1 "Edit ini file" #FFFF00 #0000ff
End
ボタンに説明文を付与する。
色指定も可能。 fileciteturn7file1
16. 例15:設定変数と config 変数の相互コピー
copy_config2scars
...
copy_svars2config
PDF widget 仕様書では、config 変数とスクリプト変数のコピー機構が明示されている。 fileciteturn7file1
17. 例16:実行前確認と待機
confirm on
$(start_cmd_C) "$(python3_path)" "$(script)" --mode=fit
wait_process
confirm off
confirm onでコマンドライン確認wait_processで終了待ち fileciteturn7file0
18. 実務上の定番パターンまとめ
Launcher スクリプトでは、次の流れがよく使われる。
read_iniで前回値を復元get_open_file_nameで入力取得get_directoryで作業ディレクトリ抽出write_iniで作業ディレクトリ保存new_dialog+add_dialogで設定画面作成call [xxx_execute]で実行部へ移動外部 Python やアプリを起動
必要なら
wait_processで同期
19. ひとことで言うと
Launcher スクリプトの実例は、
「設定を保持し、GUI で条件を編集し、外部ツールを安全に起動する」
というワークフローの積み重ねである。