简体   繁体   English

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

[英]Enthought traitsui. Dynamically update a list in the GUI

OK. 好。 So I have been running into this roadblock where I cant get the GUI to update based on what I am doing. 因此,我一直遇到这个障碍,无法根据自己的工作来更新GUI。 I've searched extensively and tried to read but I am at my wits end almost. 我进行了广泛的搜索并试图阅读,但我几乎无能为力了。 The closest Ive gotten is to remove the item from the "myclass.uncorrex_thing" and then run "edit_traits", but that just creates a new GUI over the old one... 我得到的最接近的方法是从“ myclass.uncorrex_thing”中删除该项目,然后运行“ edit_traits”,但这只是在旧的GUI上创建了一个新的GUI。

Summary: I am getting a list of filenames from a .csv that has alot of items that change daily. 摘要:我从.csv中获取文件名列表,该文件中包含很多每天更改的项目。 I just want to be able to select the filename from a list on the GUI, press a button that does something to the file and checks that filename off the .csv list, then have the dropdown list on the GUI updated with the updated .csv 我只希望能够从GUI上的列表中选择文件名,按一个对文件起作用的按钮,并检查.csv列表中的文件名,然后用更新的.csv更新GUI上的下拉列表。

Here is my code so far 到目前为止,这是我的代码

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

OK, for anyone looking at this and wondering, I finally solved my issue. 好的,对于任何想知道这一点并想知道的人,我终于解决了我的问题。 Basically had to create a property class which depends on an event (button press). 基本上必须创建一个依赖于事件(按下按钮)的属性类。 When the button is pressed the highlighted_thing updates and the function which corrects the form and updates the .csv is run 当按下按钮时, 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM