Пример #1
0
class CheckListEditorDemo(HasTraits):
    """ Define the main CheckListEditor demo class. """

    # Define a trait for each of three formations:
    checklist_4col = List(
        editor=CheckListEditor(values=['one', 'two', 'three', 'four'], cols=4))

    checklist_2col = List(
        editor=CheckListEditor(values=['one', 'two', 'three', 'four'], cols=2))

    checklist_1col = List(
        editor=CheckListEditor(values=['one', 'two', 'three', 'four'], cols=1))

    # CheckListEditor display with four columns:
    cl_4_group = Group(Item('checklist_4col', style='simple', label='Simple'),
                       Item('_'),
                       Item('checklist_4col', style='custom', label='Custom'),
                       Item('_'),
                       Item('checklist_4col', style='text', label='Text'),
                       Item('_'),
                       Item('checklist_4col',
                            style='readonly',
                            label='ReadOnly'),
                       label='4-column')

    # CheckListEditor display with two columns:
    cl_2_group = Group(Item('checklist_2col', style='simple', label='Simple'),
                       Item('_'),
                       Item('checklist_2col', style='custom', label='Custom'),
                       Item('_'),
                       Item('checklist_2col', style='text', label='Text'),
                       Item('_'),
                       Item('checklist_2col',
                            style='readonly',
                            label='ReadOnly'),
                       label='2-column')

    # CheckListEditor display with one column:
    cl_1_group = Group(Item('checklist_1col', style='simple', label='Simple'),
                       Item('_'),
                       Item('checklist_1col', style='custom', label='Custom'),
                       Item('_'),
                       Item('checklist_1col', style='text', label='Text'),
                       Item('_'),
                       Item('checklist_1col',
                            style='readonly',
                            label='ReadOnly'),
                       label='1-column')

    # The view includes one group per column formation.  These will be displayed
    # on separate tabbed panels.
    view1 = View(cl_4_group,
                 cl_2_group,
                 cl_1_group,
                 title='CheckListEditor',
                 buttons=['OK'],
                 resizable=True)
Пример #2
0
class CheckListTest ( Handler ):
    
    #---------------------------------------------------------------------------
    #  Trait definitions:  
    #---------------------------------------------------------------------------
    
    value       = List( editor = CheckListEditor( name = 'values', cols = 5 ) )
    values      = List( Str )
    values_text = Str( 'red orange yellow green blue indigo violet' )
    
    #---------------------------------------------------------------------------
    #  Traits view definitions:  
    #---------------------------------------------------------------------------
        
    simple_view = View( 'value',  'values_text@' )
    custom_view = View( 'value@', 'values_text@' )
                        
    #---------------------------------------------------------------------------
    #  'Initializes the object:  
    #---------------------------------------------------------------------------
                               
    def __init__ ( self, **traits ):
        super( CheckListTest, self ).__init__( **traits )
        self._values_text_changed()
    
    #---------------------------------------------------------------------------
    #  Event handlers:  
    #---------------------------------------------------------------------------
        
    def _values_text_changed ( self ):
        self.values = self.values_text.split()
class ListDemo2(HasTraits):
    filter_types = List(Str, value=[u"低通", u"高通", u"带通", u"带阻"])
    items = List(Str)
    view = View(HGroup(Item("filter_types", label=u"候选"),
                       Item("items",
                            style="custom",
                            editor=CheckListEditor(name="filter_types")),
                       show_labels=False),
                resizable=True,
                width=300,
                height=180,
                title=u"动态修改候选值")
class ListDemo(HasTraits):

    items = List(Str)
    view = View(HSplit(Item("items", style="custom", show_label=False),
                       Item("items",
                            style="custom",
                            editor=CheckListEditor(values=filter_types,
                                                   cols=4)),
                       Item("items", editor=SetEditor(values=filter_types)),
                       show_labels=False),
                resizable=True,
                width=600,
                title=u"简单列表编辑器演示")
Пример #5
0
 def default_traits_view(self):
     view = View(HGroup(
         VGroup('renormalized',
                Item('data_fig', style='custom', show_label=False),
                'cr_fig', 'corr_fig'),
         Item('usable_data',
              style='custom',
              show_label=False,
              editor=CheckListEditor(values=list(
                  map(str, self.possible_usable_data)),
                                     cols=1)),
     ),
                 height=800,
                 width=800,
                 handler=DLS_DataHandler)
     return view
Пример #6
0
class XSetting(HasTraits):   #设定Y轴所用的数据列表,暂时不用
    candidate_items = List(Str) #可选的Y轴数据 
    selected_items = List(Str) # 
    must_have_items = List(Str)
    must_not_items = List(Str)
    name2item = DictStrAny

    speed1 = Int(3,label=u'前进速度')
    speed2 = Int(30,label=u'翻页速度')
    index_from = Int(0,label=u'起始坐标')
    index_width = Int(30,label=u'显示宽度')
    index_cur = Int(0,label=u'当前坐标')
    


    view = View(
            Heading(u'基本状态'),
            Group(
                Item('index_cur'),                
                Item('index_from'),
                Item('index_width'),
                Item('speed1'),
                Item('speed2'),
            ),
            Heading(u'设定显示指标'),
            Group(
                Item("selected_items", style="custom",editor=CheckListEditor(name="object.candidate_items",cols=2, format_str=u"%s")),
                show_labels = False,
            ),
            buttons = [OKButton,]
    )
    
    def generate_candidate(self,infos):
        candidate_items = []
        must_have_items = []
        must_not_items = []
        name2item = {}
        for info in infos:
            for du in info.data_units:
                name2item[du.name] = du
                if du.display == MUST_HAVE:
                    self.must_have_items.append(du.name)
                elif du.display == MUST_NOT:
                    self.must_not_items.append(du.name)
                elif du.display == OPTIONAL:
                    self.candidate_items.append(du.name)
Пример #7
0
class TraitsTest(HasTraits):

    #---------------------------------------------------------------------------
    #  Trait definitions:
    #---------------------------------------------------------------------------

    integer_text = Int(1)
    enumeration = Enum('one', 'two', 'three', 'four', 'five', 'six', cols=3)
    float_range = Range(0.0, 10.0, 10.0)
    int_range = Range(1, 6)
    int_range2 = Range(1, 50)
    compound = Trait(1, Range(1, 6), 'one', 'two', 'three', 'four', 'five',
                     'six')
    boolean = Bool(True)
    instance = Trait(Instance())
    color = Color
    font = Font
    check_list = List(
        editor=CheckListEditor(values=['one', 'two', 'three', 'four'], cols=4))
    list = List(Str,
                ['East of Eden', 'The Grapes of Wrath', 'Of Mice and Men'])
    button = Event(0, editor=ButtonEditor(label='Click'))
    file = File
    directory = Directory
    image_enum = Trait(editor=ImageEnumEditor(values=origin_values,
                                              suffix='_origin',
                                              cols=4,
                                              klass=Instance),
                       *origin_values)

    #---------------------------------------------------------------------------
    #  View definitions:
    #---------------------------------------------------------------------------

    view = View(
        ('|{Enum}', ('|<[Enumeration]', 'enumeration[Simple]', '_',
                     'enumeration[Custom]@', '_', 'enumeration[Text]*', '_',
                     'enumeration[Readonly]~'),
         ('|<[Check List]', 'check_list[Simple]', '_', 'check_list[Custom]@',
          '_', 'check_list[Text]*', '_', 'check_list[Readonly]~')),
        ('|{Range}', ('|<[Float Range]', 'float_range[Simple]', '_',
                      'float_range[Custom]@', '_', 'float_range[Text]*', '_',
                      'float_range[Readonly]~'),
         ('|<[Int Range]', 'int_range[Simple]', '_', 'int_range[Custom]@', '_',
          'int_range[Text]*', '_', 'int_range[Readonly]~'),
         ('|<[Int Range 2]', 'int_range2[Simple]', '_', 'int_range2[Custom]@',
          '_', 'int_range2[Text]*', '_', 'int_range2[Readonly]~')),
        ('|{Misc}', ('|<[Integer Text]', 'integer_text[Simple]', '_',
                     'integer_text[Custom]@', '_', 'integer_text[Text]*', '_',
                     'integer_text[Readonly]~'),
         ('|<[Compound]', 'compound[Simple]', '_', 'compound[Custom]@', '_',
          'compound[Text]*', '_', 'compound[Readonly]~'),
         ('|<[Boolean]', 'boolean[Simple]', '_', 'boolean[Custom]@', '_',
          'boolean[Text]*', '_', 'boolean[Readonly]~')),
        ('|{Color/Font}', ('|<[Color]', 'color[Simple]', '_', 'color[Custom]@',
                           '_', 'color[Text]*', '_', 'color[Readonly]~'),
         ('|<[Font]', 'font[Simple]', '_', 'font[Custom]@', '_', 'font[Text]*',
          '_', 'font[Readonly]~')),
        ('|{List}', ('|<[List]', 'list[Simple]', '_', 'list[Custom]@', '_',
                     'list[Text]*', '_', 'list[Readonly]~')),
        (
            '|{Button}',
            ('|<[Button]', 'button[Simple]', '_', 'button[Custom]@'),
            #                                        'button[Text]*',
            #                                        'button[Readonly]~' ),
            ('|<[Image Enum]', 'image_enum[Simple]', '_',
             'image_enum[Custom]@', '_', 'image_enum[Text]*', '_',
             'image_enum[Readonly]~'),
            ('|<[Instance]', 'instance[Simple]', '_', 'instance[Custom]@', '_',
             'instance[Text]*', '_', 'instance[Readonly]~'),
        ),
        ('|{File}', (
            '|<[File]',
            'file[Simple]',
            '_',
            'file[Custom]@',
            '_',
            'file[Text]*',
            '_',
            'file[Readonly]~',
        ), ('|<[Directory]', 'directory[Simple]', '_', 'directory[Custom]@',
            '_', 'directory[Text]*', '_', 'directory[Readonly]~')),
        buttons=['Apply', 'Revert', 'Undo', 'OK'])
Пример #8
0
    'ten'
]

#-------------------------------------------------------------------------------
#  'CheckListTest' class:
#-------------------------------------------------------------------------------


class CheckListTest(Handler):

    #---------------------------------------------------------------------------
    #  Trait definitions:
    #---------------------------------------------------------------------------

    case = Enum('Colors', 'Numbers')
    value = List(editor=CheckListEditor(values=colors, cols=5))

    #---------------------------------------------------------------------------
    #  Event handlers:
    #---------------------------------------------------------------------------

    def object_case_changed(self, info):
        if self.case == 'Colors':
            info.value.factory.values = colors
        else:
            info.value.factory.values = numbers


#-------------------------------------------------------------------------------
#  Run the tests:
#-------------------------------------------------------------------------------
Пример #9
0
class Graph(HasTraits):
    """
    绘图组件,包括左边的数据选择控件和右边的绘图控件
    """
    name = Str # 绘图名,显示在标签页标题和绘图标题中
    data_source = Instance(DataSource) # 保存数据的数据源
    figure = Instance(Figure) # 控制绘图控件的Figure对象
    selected_xaxis = Str # X轴所用的数据名
    selected_items = List # Y轴所用的数据列表

    clear_button = Button(u"清除") # 快速清除Y轴的所有选择的数据

    view = View(
        HSplit( # HSplit分为左右两个区域,中间有可调节宽度比例的调节手柄
            # 左边为一个组
            VGroup(
                Item("name"),   # 绘图名编辑框
                Item("clear_button"), # 清除按钮
                Heading(u"X轴数据"),  # 静态文本
                # X轴选择器,用EnumEditor编辑器,即ComboBox控件,控件中的候选数据从
                # data_source的names属性得到
                Item("selected_xaxis", editor=
                    EnumEditor(name="object.data_source.names", format_str=u"%s")),
                Heading(u"Y轴数据"), # 静态文本
                # Y轴选择器,由于Y轴可以多选,因此用CheckBox列表编辑,按两列显示
                Item("selected_items", style="custom", 
                     editor=CheckListEditor(name="object.data_source.names", 
                            cols=2, format_str=u"%s")),
                show_border = True, # 显示组的边框
                scrollable = True,  # 组中的控件过多时,采用滚动条
                show_labels = False # 组中的所有控件都不显示标签
            ),
            # 右边绘图控件
            Item("figure", editor=MPLFigureEditor(), show_label=False, width=600)
        )        
    )

    def _name_changed(self):
        """
        当绘图名发生变化时,更新绘图的标题
        """
        axe = self.figure.axes[0]
        axe.set_title(self.name)
        self.figure.canvas.draw()

    def _clear_button_fired(self):
        """
        清除按钮的事件处理
        """
        self.selected_items = []
        self.update()

    def _figure_default(self):
        """
        figure属性的缺省值,直接创建一个Figure对象
        """
        figure = Figure()
        figure.add_axes([0.1, 0.1, 0.85, 0.80]) #添加绘图区域,四周留有边距
        return figure

    def _selected_items_changed(self):
        """
        Y轴数据选择更新
        """
        self.update()

    def _selected_xaxis_changed(self):
        """
        X轴数据选择更新
        """    
        self.update()

    def update(self):
        """
        重新绘制所有的曲线
        """    
        axe = self.figure.axes[0]
        axe.clear()
        try:
            xdata = self.data_source.data[self.selected_xaxis]
        except:
            return 
        for field in self.selected_items:
            axe.plot(xdata, self.data_source.data[field], label=field)
        axe.set_xlabel(self.selected_xaxis)
        axe.set_title(self.name)
        axe.legend()
        self.figure.canvas.draw()
Пример #10
0
class TraitsTest(HasTraits):

    #---------------------------------------------------------------------------
    #  Trait definitions:
    #---------------------------------------------------------------------------

    enabled = true
    integer_text = Int(1)
    enumeration = Trait('one', 'two', 'three', 'four', 'five', 'six', cols=3)
    float_range = Range(0.0, 10.0, 10.0)
    int_range = Range(1, 6)
    int_range2 = Range(1, 50)
    compound = Trait(1, Range(1, 6), 'one', 'two', 'three', 'four', 'five',
                     'six')
    boolean = true
    instance = Trait(Instance())
    color = Color('cyan')
    font = Font()
    check_list = List(
        editor=CheckListEditor(values=['one', 'two', 'three', 'four'], cols=4))
    list = List(Str,
                ['East of Eden', 'The Grapes of Wrath', 'Of Mice and Men'])
    button = Event(0, editor=ButtonEditor(label='Click'))
    file = File()
    directory = Directory()
    image_enum = Trait(editor=ImageEnumEditor(values=origin_values,
                                              suffix='_origin',
                                              cols=4,
                                              klass=Instance),
                       *origin_values)

    #---------------------------------------------------------------------------
    #  View definitions:
    #---------------------------------------------------------------------------

    view = View(
        ('|{Enum}', ('enabled', ),
         ('|<[Enumeration]', 'f1:enumeration[Simple]', '_',
          'f2:enumeration[Custom]@', '_', 'f3:enumeration[Text]*', '_',
          'f4:enumeration[Readonly]~'),
         ('|<[Check List]', 'f5:check_list[Simple]', '_',
          'f6:check_list[Custom]@', '_', 'f7:check_list[Text]*', '_',
          'f8:check_list[Readonly]~')),
        ('|{Range}',
         ('|<[Float Range]', 'f9:float_range[Simple]', '_',
          'f10:float_range[Custom]@', '_', 'f11:float_range[Text]*', '_',
          'f12:float_range[Readonly]~'),
         ('|<[Int Range]', 'f13:int_range[Simple]', '_',
          'f14:int_range[Custom]@', '_', 'f15:int_range[Text]*', '_',
          'f16:int_range[Readonly]~'),
         ('|<[Int Range 2]', 'f17:int_range2[Simple]', '_',
          'f18:int_range2[Custom]@', '_', 'f19:int_range2[Text]*', '_',
          'f20:int_range2[Readonly]~')),
        ('|{Misc}',
         ('|<[Integer Text]', 'f21:integer_text[Simple]', '_',
          'f22:integer_text[Custom]@', '_', 'f23:integer_text[Text]*', '_',
          'f24:integer_text[Readonly]~'),
         ('|<[Compound]', 'f25:compound[Simple]', '_', 'f26:compound[Custom]@',
          '_', 'f27:compound[Text]*', '_', 'f28:compound[Readonly]~'),
         ('|<[Boolean]', 'f29:boolean[Simple]', '_', 'f30:boolean[Custom]@',
          '_', 'f31:boolean[Text]*', '_', 'f32:boolean[Readonly]~')),
        ('|{Color/Font}',
         ('|<[Color]', 'f33:color[Simple]', '_', 'f34:color[Custom]@', '_',
          'f35:color[Text]*', '_', 'f36:color[Readonly]~'),
         ('|<[Font]', 'f37:font[Simple]', '_', 'f38:font[Custom]@', '_',
          'f39:font[Text]*', '_', 'f40:font[Readonly]~')),
        ('|{List}', ('|<[List]', 'f41:list[Simple]', '_', 'f42:list[Custom]@',
                     '_', 'f43:list[Text]*', '_', 'f44:list[Readonly]~')),
        (
            '|{Button}',
            ('|<[Button]', 'f45:button[Simple]', '_', 'f46:button[Custom]@'),
            #                                        'button[Text]*',
            #                                        'button[Readonly]~' ),
            ('|<[Image Enum]', 'f47:image_enum[Simple]', '_',
             'f48:image_enum[Custom]@', '_', 'f49:image_enum[Text]*', '_',
             'f50:image_enum[Readonly]~'),
            ('|<[Instance]', 'f51:instance[Simple]', '_',
             'f52:instance[Custom]@', '_', 'f53:instance[Text]*', '_',
             'f54:instance[Readonly]~'),
        ),
        ('|{File}', (
            '|<[File]',
            'f55:file[Simple]',
            '_',
            'f56:file[Custom]@',
            '_',
            'f57:file[Text]*',
            '_',
            'f58:file[Readonly]~',
        ), ('|<[Directory]', 'f59:directory[Simple]', '_',
            'f60:directory[Custom]@', '_', 'f61:directory[Text]*', '_',
            'f62:directory[Readonly]~')),
        apply=True,
        revert=True,
        undo=True,
        ok=True,
        handler=TraitsTestHandler())
Пример #11
0
class ControlTab(HasTraits):
    """ This object is the core of the traitsUI interface. Its view is
        the right panel of the application, and it hosts the method for
        interaction between the objects and the GUI.
    """
    move_step = Enum(1,0.2,0.5,1,2,5,10)
    scale_step = Enum(10,1,5,10,20,50,100)
    channels = List()
    ch_editor = CheckListEditor(values=[],cols=2)
    num_channels = Int(0)
    patient_name = Str()
    select_all = Button("all")
    select_none = Button("none")
    select_good = Button("good (db)")
    mlcount = Int(0)
    mrcount = Int(0)
    mucount = Int(0)
    mdcount = Int(0)
    #_sls = [0,1100,5] #StartLengthStride
    #acquisition_thread = Instance(AcquisitionThread)
    
    move_left = Action(name = "Left",
                        action = "_trigger_move_left",
                        toolip = "Move to the left",
                        image = ImageResource("images/left_32.png")
                        )
    move_right = Action(name = "Right",
                        action = "_trigger_move_right",
                        toolip = "Move to the right",
                        image = ImageResource("images/right_32.png")
                        )
    scale_up = Action(name = "Scale up",
                        action = "_trigger_scale_up",
                        toolip = "Move to the right",
                        image = ImageResource("images/up_32.png")
                        )
    scale_down = Action(name = "Scale down",
                        action = "_trigger_scale_down",
                        toolip = "Move to the right",
                        image = ImageResource("images/down_32.png")
                        )
                        
    toolbar = ToolBar(move_left, move_right,scale_up,scale_down)
    
    
    traits_view = View(VGroup(
                  #Item('do_plot', show_label=False ),
                    VGroup(
                      Item('move_step',label="Move by:"),
                      Item('scale_step',label="Scale by"),
                    ),
                    VGroup(
                      Group(
                          Item('channels',
                               show_label=False,
                               style='custom',
                               editor=ch_editor,
                               #springy=True,
                               #height=-500,
                          ),
                          scrollable=True,
                          springy=True,
                      ),
                      HGroup(
                        spring,
                        Item('select_all',show_label=False),
                        Item('select_none',show_label=False),
                        Item('select_good',show_label=False),
                        spring,
                      ),
                      label = "Choose channels",
                      #height=300,
                    ),
                  #Item('results_string',show_label=False, 
                  #                      springy=True, style='custom' ),
                  #springy=True,
                  #scrollable=True,
                  #height=-500,
                  dock='tab',
                  springy=True
                  #scrollable=True
                  ),
               toolbar=toolbar,
               scrollable=True
               #height=-500,
               )
               #key_bindings=key_bindings,
               #handler=ControlHandler,
               
    def _trigger_move_left(self):
        #print "Trigger Left"
        self.mlcount+=1
    def _trigger_move_right(self):
        self.mrcount+=1
        #print "Trigger Right"
    def _trigger_scale_up(self):
        self.mucount+=1
    def _trigger_scale_down(self):
        self.mdcount+=1

    def _select_none_fired(self):
        self.channels = []
 
    def _select_all_fired(self):
        self.channels = range(self.num_channels)

    def _select_good_fired(self):
        try:
            gc = schlaf_ged.get_good_channels(self.patient_name)
            print "Got", gc, "from database"
            self.channels = gc
        except ValueError, ve:
            #Zeige Fehlermeldung
            print ve
            print self.patient_name
            try:
                short_patient_name = self.patient_name.split("_")[0]
                gc = schlaf_ged.get_good_channels(short_patient_name)
                print "Got", gc, "from database"
                self.channels = gc
            except ValueError,ve:
                print ve
                print short_patient_name
                message = Message(message="Cannot find good channels for subject %s" % self.patient_name)
                message.edit_traits()
Пример #12
0
class Person ( HasTraits ):

    #---------------------------------------------------------------------------
    #  Trait definitions:
    #---------------------------------------------------------------------------

    name      = Str( 'David Morrill' )
    age       = Int( 39 )
    sex       = Trait( 'Male', 'Female' )
    coolness  = Range( 0.0, 10.0, 10.0 )
    number    = Trait( 1, Range( 1, 6 ),
                       'one', 'two', 'three', 'four', 'five', 'six' )
    human     = Bool( True )
    employer  = Trait( Employer( company = 'Enthought, Inc.', boss = 'eric' ) )
    eye_color = RGBAColor
    set       = List( editor = CheckListEditor(
                                  values = [ 'one', 'two', 'three', 'four' ],
                                  cols   = 4 ) )
    font      = KivaFont
    street    = Str
    city      = Str
    state     = Str
    zip       = Int( 78663 )
    password  = Str
    books     = List( Str, [ 'East of Eden', 'The Grapes of Wrath',
                             'Of Mice and Men' ] )
    call      = Event( 0, editor = ButtonEditor( label = 'Click to call' ) )
    info      = Str( editor = FileEditor() )
    location  = Str( editor = DirectoryEditor() )
    origin    = Trait( editor = ImageEnumEditor( values = origin_values,
                                                 suffix = '_origin',
                                                 cols   = 4,
                                                 klass  = Employer ),
                       *origin_values )

    nm   = Item( 'name',     enabled_when = 'object.age >= 21' )
    pw   = Item( 'password', defined_when = 'object.zip == 78664' )
    view = View( ( ( nm, 'age', 'coolness',
                     '_', 'eye_color', 'eye_color@', 'eye_color*', 'eye_color~',
                     '_', 'font', 'font@', 'font*', 'font~',
                     '_', 'set', 'set@', 'set*', 'set~',
                     '_', 'sex', 'sex@', 'sex*', 'sex~',
                     '_', 'human', 'human@', 'human*', 'human~',
                     '_', 'number', 'number@', 'number*', 'number~',
                     '_', 'books', '_', 'books@', '_', 'books*', '_', 'books~',
                     '_', 'info', 'location', 'origin', 'origin@', 'call',
                     'employer', 'employer[]@', 'employer*', 'employer~',
                     pw,
                     '|<[Person:]' ),
                   ( ' ', 'street', 'city', 'state', 'zip', '|<[Address:]' ),
                   ( nm, nm, nm, nm, nm, nm, nm, nm, nm, nm, nm, nm, nm, nm,
                     '|<[Names:]' ),
                   '|' ),
                 title   = 'Traits 2 User Interface Test',
                 handler = PersonHandler(),
                 buttons = [ 'Apply', 'Revert', 'Undo', 'OK' ],
                 height  = 0.5 )

    wizard = View( ( '|p1:', 'name', 'age', 'sex' ),
                   ( '|p2:', 'street', 'city', 'state', 'zip' ),
                   ( '|p3:', 'eye_color', 'origin', 'human' ),
                   handler = WizardHandler() )