TraitsUIを使用して任意のコレクションの内容をリストするためにListEditorを調整するにはどうすればよいですか?私はコメントアウトコードを使用することによりSortedListWithKeyと標準リストを交換する場合はここでのサンプルコードTraitsUI ListEditorファクトリを任意のコレクションに使用する
from traits.api import HasStrictTraits, Instance, Int, List, Str
from traitsui.api import View, Item, ListEditor, InstanceEditor
from sortedcontainers import SortedListWithKey
class Person(HasStrictTraits):
name = Str
age = Int
class Office(HasStrictTraits):
# employees = Instance(SortedListWithKey,
kw={'key': lambda employee: employee.age})
employees = List
employee_view = View(
Item(name='name', show_label=False, style='readonly')
)
office_view = View(
Item(name='adults',
show_label=False,
style='readonly',
editor=ListEditor(
style='custom',
editor=InstanceEditor(view=employee_view),
),
),
resizable=True
)
employee_list = [Person(name='John', age=31), Person(name='Mike', age=31),
Person(name='Jill', age=37), Person(name='Eric', age=28)]
#office = Office()
#office.employees.update(employee_list)
office = Office(employees=employee_list)
office.configure_traits(view=office_view)
ですが、私は「はAttributeError: 『を得るオフィス値『』エラー』オブジェクトが属性を持っていません」。どうすれば解決できますか?
私の場合、並べ替えはビューだけでなく、ビジネスロジックの一部です。そしてあなたが正しいです、 'SortedListWithKey'は「ソートされたコンテナ」パッケージからのものです。 – MindV0rtex