GUIKit`
GUIKit`
"FileDialog"
GUIKitで提供されていた機能は,組込みのWolfram言語にネイティブのインターフェース構造およびコントロール関数で利用できるようになった.
Widget["FileDialog"]
ダイアログを「開く」あるいはダイアログを「保存」を表す.
詳細
- Widget["FileDialog"]を使用する際は,まずNeeds["GUIKit`"]を使って GUIKit をロードする必要がある.
- 使用可能なプロパティ:
-
"multiSelectionEnabled" False 複数ファイルの選択が可能かどうか "fileSelectionMode" 0 ファイル,ディレクトリ、あるいはファイルとディレクトリが選択できるかどうか "selectedFile" Null 選択されたファイル - 使用可能なメソッド:
-
"showOpenDialog" ダイアログが"open a file"モードで開かれるようにリクエストする "showSaveDialog" ダイアログが"save a file"モードで開かれるようにリクエストする - モーダルファイルダイアログの位置とプロパティが親ウィンドウと相対的になるようにするために,"showOpenDialog"と"showSaveDialog"の引数呼び出しから(Nullではなく)ウィンドウあるいはフレームのウィジェットのリファレンスを渡したいこともあるだろう.
例題
すべて開く すべて閉じる例 (1)
Needs["GUIKit`"]ref = GUIRun[Widget["FileDialog"]]GUIScreenShot[ref]インタラクティブな例題 (1)
Needs["GUIKit`"]単一のファイルを選択しパスの文字列を返すOpenダイアログを作成する:
ref = GUIRun[
Widget["Panel", {
Widget["Button", {"text" -> "Open File...", BindEvent["action", Script[
Widget["FileDialog", Name -> "openFileDialog"];
SetPropertyValue[{"openFileDialog", "multiSelectionEnabled"}, False];
SetPropertyValue[{"openFileDialog", "fileSelectionMode"},
PropertyValue[{"openFileDialog", "FILES_ONLY"}]];
returnValue = InvokeMethod[{"openFileDialog", "showOpenDialog"}, Null];
If[returnValue === PropertyValue[{"openFileDialog", "APPROVE_OPTION"}], PropertyValue[{PropertyValue[{"openFileDialog", "selectedFile"}], "path"}],
Null
]
]]}],
Widget["Button", {"text" -> "Cancel"}]
}]
]ref = GUIRun[
Widget["Panel", {
Widget["Button", {"text" -> "Open File...", BindEvent["action",
Script[
Widget["FileDialog", Name -> "openFileDialog"];
SetPropertyValue[{"openFileDialog", "multiSelectionEnabled"}, True];
SetPropertyValue[{"openFileDialog", "fileSelectionMode"},
PropertyValue[{"openFileDialog", "FILES_ONLY"}]];
returnValue = InvokeMethod[{"openFileDialog", "showOpenDialog"}, Null];
If[returnValue === PropertyValue[{"openFileDialog", "APPROVE_OPTION"}], PropertyValue[{#, "path"}]& /@ PropertyValue[{"openFileDialog", "selectedFiles"}],
Null
]
]]}],
Widget["Button", {"text" -> "Cancel"}]
}]
]ref = GUIRun[
Widget["Panel", {
Widget["Button", {"text" -> "Open File...", BindEvent["action",
Script[
Widget["FileDialog", Name -> "openFileDialog"];
SetPropertyValue[{"openFileDialog", "multiSelectionEnabled"}, False];
SetPropertyValue[{"openFileDialog", "fileSelectionMode"},
PropertyValue[{"openFileDialog", "DIRECTORIES_ONLY"}]];
returnValue = InvokeMethod[{"openFileDialog", "showOpenDialog"}, Null];
If[returnValue === PropertyValue[{"openFileDialog", "APPROVE_OPTION"}], PropertyValue[{PropertyValue[{"openFileDialog", "selectedFile"}], "path"}],
Null
]
]]}],
Widget["Button", {"text" -> "Cancel"}]
}]
]ref = GUIRun[
Widget["Panel", {
Widget["Button", {"text" -> "Open File...", BindEvent["action",
Script[
Widget["FileDialog", Name -> "openFileDialog"];
SetPropertyValue[{"openFileDialog", "multiSelectionEnabled"}, True];
SetPropertyValue[{"openFileDialog", "fileSelectionMode"},
PropertyValue[{"openFileDialog", "FILES_AND_DIRECTORIES"}]];
returnValue = InvokeMethod[{"openFileDialog", "showOpenDialog"}, Null];
If[returnValue === PropertyValue[{"openFileDialog", "APPROVE_OPTION"}], PropertyValue[{#, "path"}]& /@ PropertyValue[{"openFileDialog", "selectedFiles"}],
Null
]
]]}],
Widget["Button", {"text" -> "Cancel"}]
}]
]ファイル名の選択または作成を促し結果としてパスの文字列を返すSaveダイアログを作成する:
ref = GUIRun[
Widget["Panel", {
Widget["Button", {"text" -> "Save File...", BindEvent["action",
Script[
Widget["FileDialog", Name -> "saveFileDialog"];
returnValue = InvokeMethod[{"saveFileDialog", "showSaveDialog"}, Null];
If[returnValue === PropertyValue[{"saveFileDialog", "APPROVE_OPTION"}], PropertyValue[{PropertyValue[{"saveFileDialog", "selectedFile"}], "path"}],
Null
]
]]}],
Widget["Button", {"text" -> "Cancel"}]
}]
]