私は TraitsUI 内で FileDialog クラスを使用しています。これは非常にうまく機能しますが、私の人生を除いて、ダイアログが使用するためにデフォルトのディレクトリ を渡す方法を理解できませんでした。
理想的には、ツリーの最上部以外のローカル ファイル システムのポイントでダイアログ ボックスが開きます...
初心者からの洞察や方向性は非常に感謝しています。
次のように、基本コードはかなり一般的/標準的です。
demo_id = 'traitsui.demo.standard_editors.file_dialog.file_info'
class FileDialog ( HasTraits ):
# The name of the selected file:
file_name = File
# The button used to display the file dialog:
open = Button( 'Open...' )
#-- Traits View Definitions ------------------------------------------------
view = View(
HGroup(
Item( 'open', show_label = False ),
'_',
Item( 'file_name', style = 'readonly', springy = True )
),
width = 0.5
)
#-- Traits Event Handlers --------------------------------------------------
def _open_changed ( self ):
""" Handles the user clicking the 'Open...' button.
"""
file_name = open_file( extensions = FileInfo(), id = demo_id )
if file_name != '':
self.file_name = file_name