有思想的特质。在GUI中动态更新列表

时间:2018-10-30 18:50:42

标签: python user-interface enthought traitsui

好。因此,我一直遇到这个障碍,无法根据自己的工作来更新GUI。我进行了广泛的搜索并试图阅读,但我几乎无能为力了。我得到的最接近的方法是从“ myclass.uncorrex_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

1 个答案:

答案 0 :(得分:0)

好的,对于任何想知道这个问题并想知道的人,我终于解决了我的问题。基本上必须创建一个依赖于事件(按下按钮)的属性类。按下按钮后,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)