热心的崔.在GUI中动态更新列表



好。所以我遇到了这个障碍,我无法根据我正在做的事情更新GUI。我找了很多书,也试着读,但我几乎无计可施。我得到的最接近的方法是从"myclass.uncx_thing"中删除该项,然后运行"edit_traits",但这只是在旧的GUI上创建了一个新的GUI。。。

摘要:我从.csv中得到了一个文件名列表,其中有很多项目每天都在更改。我只想能够从GUI上的列表中选择文件名,按下对文件执行某些操作的按钮并从.csv列表中检查该文件名,然后用更新的.csv 更新GUI上的下拉列表

这是我到目前为止的代码

class My_List(HasTraits):
tracker = RecordKeeping()
uncorrex_items = tracker.get_uncorrected_list() #this creates a list of filenames based on a .csv file
uncorrex_items.insert(0,'Select file')

class DataFrameEditorDemo(HasTraits): 
err_correct = PostProcessAutoErrorCorrection() #a separate module for correcting the files
myclass = Instance(My_List)
highlighted_thing = Str    
Calc = Button('Run Corrections')

traits_view = View( 
Item('Calc', label='correct file'),                       
Item("highlighted_thing", editor= EnumEditor(name = 'object.myclass.uncorrex_items')),                      
title="MyEditor"                                               
)
def _Calc_fired(self):
if len(self.highlighted_thing) == 8:
self.err_correct.correct_form(self.highlighted_thing) #this corrects the file selected from the dropdown list 
#AND it updates the .csv file so the file should be checked as complete and will not show up when "tracker.get_uncorrected_list()" is run again

好吧,对于任何看到这个并想知道的人来说,我终于解决了我的问题。基本上必须创建一个依赖于事件的属性类(按钮按下(。按下按钮后,highlighted_thing将更新,并且更正表单和更新.csv的功能将运行

class DataFrameEditorDemo(HasTraits): 
err_correct = PostProcessAutoErrorCorrection() #a separate module for correcting the files
tracker = RecordKeeping() #a separate module for managing the .csv

highlighted_thing = Property(List, depends_on = 'Calc')
test = Str
Calc = Button('Run Corrections')

traits_view = View( 
Item('Calc', label='correct file'),                       
Item("test", editor= EnumEditor(name = 'highlighted_thing')),                         
title="MyEditor"                                               
)
def _get_highlighted_thing(self):
return tracker.get_uncorrected_list()

def _Calc_fired(self):
if len(self.test) == 8:
self.err_correct.correct_form(self.test)

最新更新