Launcherスクリプト仕様書:実例編

1. 本書の位置付け

本書は Launcher スクリプトの代表的な実例パターンを示す。
新しい PDF 資料に沿って、なるべく現行実装に近い書き方を示す。 fileciteturn7file0 fileciteturn7file1


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
  • ファイル選択結果は $o

  • get_directory, get_filebody で派生情報を作る fileciteturn7file0


5. 例4:Cancel しても続行するファイル選択

[Sample]
get_open_file_name_continue "*.xlsx" "$(last_dir)" "Choose Excel file"
set input_path=$o
End

*_continue 系は、Cancel 時にもスクリプトを継続させたいときに使う。 fileciteturn7file0


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

定番の作業ディレクトリ保持パターン。 fileciteturn7file0


7. 例6:join_path で安全にパスを作る

[Sample]
join_path parameter_path "$(dir_name)" "$(filebody).prm"
echo $(parameter_path)
End

OS 依存セパレータを意識せずパスを作れる。 fileciteturn7file0


8. 例7:コメント付き候補値

[Sample]
set_if_blank method_llsq method_llsq=nelder-mead # Downhill simplex
remove_comment method_llsq
echo $(method_llsq)
End

GUI では説明付き、実行時は値だけ、という使い方。 fileciteturn7file0turn7file1


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 の流れ。 fileciteturn7file1


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 にある主要オプションをまとめて使っている。 fileciteturn7file1


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 で除去可能 fileciteturn7file1


12. 例11:listbox / radiobutton / spinbox / checkbox

add_dialog listbox\
  method\
  width=50\
  height=5\
  relief=groove\
  def_val=$(method)\
  values=a##b\
  "linear #線形回帰"\
  "ridge #Ridge回帰"

add_dialog radiobutton\
  method1\
  def_val=$(method1)\
  "linear #線形回帰"\
  "lasso #LASSO回帰"

add_dialog spinbox\
  nmaxiter\
  var_type=int\
  "label_head=# of max iter:"\
  entry_width=5\
  from=1\
  to=10000\
  increment=50\
  "label_tail=最大繰り返し回数"

add_dialog checkbox\
  plot_boxplot\
  def_val=0\
  "text=箱ひげ図を描く"

PDF の widget 資料に沿った代表例。 fileciteturn7file1


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 の最小例。 fileciteturn7file1


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 仕様書で正式に確認できる。 fileciteturn7file1


15. 例14:ツールチップ

[TButton].onload
add_tooltip TButton1 "Edit ini file" #FFFF00 #0000ff
End

ボタンに説明文を付与する。
色指定も可能。 fileciteturn7file1


16. 例15:設定変数と config 変数の相互コピー

copy_config2scars
...
copy_svars2config

PDF widget 仕様書では、config 変数とスクリプト変数のコピー機構が明示されている。 fileciteturn7file1


17. 例16:実行前確認と待機

confirm on
$(start_cmd_C) "$(python3_path)" "$(script)" --mode=fit
wait_process
confirm off
  • confirm on でコマンドライン確認

  • wait_process で終了待ち fileciteturn7file0


18. 実務上の定番パターンまとめ

Launcher スクリプトでは、次の流れがよく使われる。

  1. read_ini で前回値を復元

  2. get_open_file_name で入力取得

  3. get_directory で作業ディレクトリ抽出

  4. write_ini で作業ディレクトリ保存

  5. new_dialog + add_dialog で設定画面作成

  6. call [xxx_execute] で実行部へ移動

  7. 外部 Python やアプリを起動

  8. 必要なら wait_process で同期


19. ひとことで言うと

Launcher スクリプトの実例は、

「設定を保持し、GUI で条件を編集し、外部ツールを安全に起動する」

というワークフローの積み重ねである。