2009-12-08 92 views
3

我與使用性狀UI顯示一個對話框,用戶可以一些代碼的工作,選擇兩個文件:Python的性狀UI(Enthought)

class Files(HasTraits): 
    filename_1 = File(exists=True) 
    filename_2 = File(exists=True) 

    traits_ui = View(
     'filename_1', 'filename_2', 
     title = 'Select Geometry Files', 
     buttons = ['OK', 'Cancel'] 
    ) 

files = Files() 
ui = files.edit_traits(kind='modal') 

當編輯filename_1或filename_2值,一文件選擇器對話框顯示爲「另存爲」標題。我被要求將標題更改爲「打開」或者「選擇文件」。不幸的是,我似乎無法瞭解如何改變這一點。誰能幫忙?

+0

現在運行這個,我看到標題爲「Select a File」的文件瀏覽器對話框。你能證實這個問題仍然存在嗎? – 2010-01-08 15:25:23

+0

是的,自發布此消息以來,我注意到只有當上面的代碼作爲更大代碼集的一部分運行時,纔會顯示「另存爲..」標題。就其本身而言,你是正確的,它說「選擇一個文件」。我從來沒有深究爲什麼會出現這種情況,但由於我通常不使用TraitsUI,我只寫了一些簡單的Qt代碼。謝謝。 – 2010-01-09 17:25:05

+0

答案可以接受嗎?那麼請接受它。謝謝。 – 2012-03-26 16:06:35

回答

2

在特徵3.2之後的某個時間點,FileEditor ToolkitEditorFactory中增加了一個新特徵,使您可以設置編輯特徵是「打開」還是「保存」對話框。試試這個:

from enthought.traits.ui.api import FileEditor  

save_file_editor = FileEditor(dialog_style='save') 

class Files(HasTraits): 
    filename_1 = File(exists=True) 
    filename_2 = File(exists=True) 

    traits_ui = View(
     Item('filename_1', editor=save_file_editor), 
     Item('filename_2', editor=save_file_editor), 
     title = 'Select Geometry Files', 
     buttons = ['OK', 'Cancel'] 
    ) 

files = Files() 
ui = files.edit_traits(kind='modal')