当前位置: 首页>>代码示例>>Python>>正文


Python FlexTable.clear方法代码示例

本文整理汇总了Python中pyjamas.ui.FlexTable.FlexTable.clear方法的典型用法代码示例。如果您正苦于以下问题:Python FlexTable.clear方法的具体用法?Python FlexTable.clear怎么用?Python FlexTable.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyjamas.ui.FlexTable.FlexTable的用法示例。


在下文中一共展示了FlexTable.clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: RadioEditor

# 需要导入模块: from pyjamas.ui.FlexTable import FlexTable [as 别名]
# 或者: from pyjamas.ui.FlexTable.FlexTable import clear [as 别名]
class RadioEditor ( BaseEditor ):
    """ Enumeration editor, used for the "custom" style, that displays radio
        buttons.
    """

    # Is the button layout row-major or column-major?
    row_major = Bool( False )

    #---------------------------------------------------------------------------
    #  Finishes initializing the editor by creating the underlying toolkit
    #  widget:
    #---------------------------------------------------------------------------

    def init ( self, parent ):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        super( RadioEditor, self ).init( parent )

        self.control = FlexTable( BorderWidth=0, Width="100%" )
        self.control.addTableListener( self.update_object )

        self.rebuild_editor()

    #---------------------------------------------------------------------------
    #  Handles the user clicking one of the 'custom' radio buttons:
    #---------------------------------------------------------------------------

    def update_object ( self, index ):
        """ Handles the user clicking one of the custom radio buttons.
        """
        try:
            self.value = self.mapping[ self.names[ index ] ]
        except:
            pass

    #---------------------------------------------------------------------------
    #  Updates the editor when the object trait changes external to the editor:
    #---------------------------------------------------------------------------

    def update_editor ( self ):
        """ Updates the editor when the object trait changes externally to the
            editor.
        """
        table = self.control
        value = self.value

        for row in range( table.getRowCount() ):
            for cell in range( table.getCellCount( row ) ):
                rb = table.getWidget( row, cell )
                rb.setChecked( rb.getText == value )

    #---------------------------------------------------------------------------
    #  Rebuilds the contents of the editor whenever the original factory
    #  object's 'values' trait changes:
    #---------------------------------------------------------------------------

    def rebuild_editor ( self ):
        """ Rebuilds the contents of the editor whenever the original factory
            object's **values** trait changes.
        """
        # Clear any existing content:
        self.control.clear()

        # Get the current trait value:
        cur_name = self.str_value

        # Create a sizer to manage the radio buttons:
        names   = self.names
        mapping = self.mapping
        n       = len( names )
        cols    = self.factory.cols
        rows    = (n + cols - 1) / cols
        if self.row_major:
            incr = [ 1 ] * cols
        else:
            incr = [ n / cols ] * cols
            rem  = n % cols
            for i in range( cols ):
                incr[i] += (rem > i)
            incr[-1] = -(reduce( lambda x, y: x + y, incr[:-1], 0 ) - 1)

        # Add the set of all possible choices:
        table = self.control
        index = 0
        for i in range( rows ):
            for j in range( cols ):
                if n > 0:
                    name = names[index]
                    rb = self.create_button(name)
                    rb.setText = mapping[name]

                    rb.setChecked(name == cur_name)

                    rb.addClickListener( getattr(self, "update_object") )

                    self.set_tooltip(rb)
                    table.setWidget(i, j, rb)

                    index += incr[j]
#.........这里部分代码省略.........
开发者ID:rwl,项目名称:traitsbackendpyjamas,代码行数:103,代码来源:enum_editor.py


注:本文中的pyjamas.ui.FlexTable.FlexTable.clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。