Wednesday, 15 May 2013

traits - How to update ListStrEditor in TraitsUI? Or another way of displaying a list in a Python GUI? -



traits - How to update ListStrEditor in TraitsUI? Or another way of displaying a list in a Python GUI? -

i'm trying larn utilize traits building simple uis python scripts. want create programme list, user can add together words 1 button, or clear list another.

so far, i've used traits:

mylist = list(str) mylist = ['item1','item2'] #initial items in list

to display list in traits ui, used liststreditor traits ui package: item('mylist', show_label = false, label = 'data files', editor = liststreditor(auto_add = false)

i have coded 2 buttons: 1 adding item list (mylist.append('item3')) , clear button empty list (mylist = []). basic ui good, buttons work , list variable changed expected.

however, problem is, list in gui doesn't update. if click on it, new values displayed however. also, want potentially add together many items , wonder if there way add together scrollbar side?

i've looked liststreditor manual , usage, although i'm getting bit bogged downwards terminology. apparently refresh function exists, i'm not sure how apply liststreditor , also, i'm not sure if need utilize things called "adapters" , "handlers".

any tips / pointers in right direction much appreciated!

without seeing more finish code, hard know why code not working. perhaps missing utilize of self? e.g. self.mylist.append('item3') instead of mylist.append('item3')?

the next works me. display of list updates buttons pressed.

import random traits.api import hastraits, list, str, button traitsui.api import liststreditor, view, uitem class demo(hastraits): my_list = list(str) add together = button("add") clear = button("clear") traits_view = \ view( uitem('my_list', editor=liststreditor(auto_add=false)), uitem('add'), uitem('clear'), ) def _my_list_default(self): homecoming ['item1', 'item2'] def _add_fired(self): new_item = "item%d" % random.randint(3, 999) self.my_list.append(new_item) def _clear_fired(self): self.my_list = [] if __name__ == "__main__": demo = demo() demo.configure_traits()

it works both wx , qt4+pyside backends. i'm using enthought python distribution, epd 7.3, has version 4.2.0 of traits , traitsui.

if code different, add together question?

python traits enthought traitsui

No comments:

Post a Comment