def get_trait_names(): global TRAIT_NAMES from enthought.traits.api import HasTraits if TRAIT_NAMES is None: TRAIT_NAMES = set( dir2(HasTraits()) ) - set( dir2(object()) ) else: return TRAIT_NAMES
def test_extended(self): """ Tests a dynamic trait change handler using extended names. """ class Child(HasTraits): i = Int class Parent(HasTraits): child = Instance(Child) # Create objects parent = Parent(child=Child()) target = HasTraits() # Set up to count changes in i self.count = 0 def count_notifies(): self.count += 1 parent.on_trait_change(count_notifies, "child:i", target=target) # Change the trait parent.child.i = 10 # Delete the target and change it again del target parent.child.i = 0 # The count should be 1 self.assertEqual(self.count, 1)
def _showerror_fired(self,evt): if self.tmodel.lastfitfailure: ex = self.tmodel.lastfitfailure dialog = HasTraits(s=ex.__class__.__name__+': '+str(ex)) view = View(Item('s',style='custom',show_label=False), resizable=True,buttons=['OK'],title='Fitting error message') dialog.edit_traits(view=view)
def test_simple(self): """ Tests a simple dynamic trait change handler. """ class Test(HasTraits): i = Int # Create objects obj = Test() target = HasTraits() # Set up to count changes in i self.count = 0 def count_notifies(): self.count += 1 obj.on_trait_change(count_notifies, "i", target=target) # Change the trait obj.i = 10 # Delete the target and change it again del target obj.i = 0 # The count should be 1 self.assertEqual(self.count, 1)
Item('p2.name', label=u"姓名"), Item('p2.salary', label=u"工资"), Item('p2.bonus', label=u"奖金"), show_border=True), orientation='horizontal'), title=u"员工对比") employee1 = Employee(department=u"开发", name=u"张三", salary=3000, bonus=300) employee2 = Employee(department=u"销售", name=u"李四", salary=4000, bonus=400) if __name__ == "__main__": # 方法一:调用configure_traits,通过context关键字指定模型对象 HasTraits().configure_traits(view=comp_view, context={ "p1": employee1, "p2": employee2 }) # 方法二:调用视图对象的ui方法显示模型,它的参数是一个字典,将作为 # UI对象的context属性。此方法需要后续的代码启动界面库的消息循环 #comp_view.ui({"p1":employee1, "p2":employee2}) ##### 通过GUI启动消息循环 #from enthought.pyface.api import GUI #GUI().start_event_loop() # 开始后台界面库的消息循环 ##### 直接启动wx库的消息循环 #import wx #wx.PySimpleApp().MainLoop() # 开始wx的消息循环