Example #1
0
class SimpleEditor ( Editor, IClickListener ):
    """ Simple style of editor for Boolean values, which displays a check box.
    """
    #---------------------------------------------------------------------------
    #  Finishes initializing the editor by creating the underlying toolkit
    #  widget:
    #---------------------------------------------------------------------------

    def init ( self, parent ):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        self.control = CheckBox()
        self.control.setImmediate(True)
        self.control.addListener(self, IClickListener)
        self.set_tooltip()

    #---------------------------------------------------------------------------
    #  Handles the user clicking on the checkbox:
    #---------------------------------------------------------------------------

    def buttonClick ( self, event ):
        """ Handles the user clicking the checkbox.
        """
        self.value = event.getButton().booleanValue()

    #---------------------------------------------------------------------------
    #  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.
        """
        self.control.setValue(self.value)
Example #2
0
    def rebuild_editor ( self ):
        """ Rebuilds the editor after its definition is modified.
        """
        # Clear any existing content:
        self.control.removeAllComponents()

        cur_value = parse_value( self.value )

        # Create a sizer to manage the radio buttons:
        labels = self.names
        values = self.values
        n      = len( labels )
        cols   = self.factory.cols
        rows   = (n + cols - 1) / cols
        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)

        self.control.setRows(rows)
        self.control.setColumns(cols)

        # Add the set of all possible choices:
        layout = self.control
        index = 0
        for i in range( rows ):
            for j in range( cols ):
                if n > 0:
                    cb = CheckBox( str(labels[index]) )
                    cb.setImmediate(True)
                    cb.value = values[index]

                    if cb.value in cur_value:
                        cb.setValue(True)
                    else:
                        cb.setValue(False)

                    cb.addListener(self, IClickListener)

                    layout.addComponent(cb, j, i)

                    index += incr[j]
                    n -= 1
Example #3
0
class LayoutMarginExample(GridLayout, IClickListener):

    def __init__(self):
        super(LayoutMarginExample, self).__init__(3, 3)

        self.setWidth('100%')
        self.setSpacing(True)

        self.addComponent(Label('Toggle layout margins with the checkboxes. '
                'The right side margin has a theme-specified value, while '
                'the other margins are the defaults.'), 0, 0, 2, 0)

        self.space()
        self._topMargin = CheckBox('Top', self)
        self._topMargin.setValue(True)
        self._topMargin.setImmediate(True)
        self.addComponent(self._topMargin)
        self.setComponentAlignment(self._topMargin, Alignment.TOP_CENTER)

        self.space()
        self._leftMargin = CheckBox('Left', self)
        self._leftMargin.setValue(True)
        self._leftMargin.setImmediate(True)
        self.addComponent(self._leftMargin)
        self.setComponentAlignment(self._leftMargin, Alignment.MIDDLE_LEFT)

        self._marginLayout = VerticalLayout()
        self._marginLayout.setStyleName('marginexample')
        self._marginLayout.setSizeUndefined()
        self._marginLayout.setMargin(True)
        self.addComponent(self._marginLayout)
        self._marginLayout.addComponent(Label('Margins all around?'))

        self._rightMargin = CheckBox('Right (100px)', self)
        self._rightMargin.setValue(True)
        self._rightMargin.setImmediate(True)
        self.addComponent(self._rightMargin)
        self.setComponentAlignment(self._rightMargin, Alignment.MIDDLE_LEFT)

        self.space()
        self._bottomMargin = CheckBox('Bottom', self)
        self._bottomMargin.setValue(True)
        self._bottomMargin.setImmediate(True)
        self.addComponent(self._bottomMargin)
        self.setComponentAlignment(self._bottomMargin, Alignment.TOP_CENTER)


    def buttonClick(self, event):
        self._marginLayout.setMargin(  # FIXME:
            self._topMargin.booleanValue(),
            self._rightMargin.booleanValue(),
            self._bottomMargin.booleanValue(),
            self._leftMargin.booleanValue()
        )
class LayoutMarginExample(GridLayout, IClickListener):
    def __init__(self):
        super(LayoutMarginExample, self).__init__(3, 3)

        self.setWidth('100%')
        self.setSpacing(True)

        self.addComponent(
            Label('Toggle layout margins with the checkboxes. '
                  'The right side margin has a theme-specified value, while '
                  'the other margins are the defaults.'), 0, 0, 2, 0)

        self.space()
        self._topMargin = CheckBox('Top', self)
        self._topMargin.setValue(True)
        self._topMargin.setImmediate(True)
        self.addComponent(self._topMargin)
        self.setComponentAlignment(self._topMargin, Alignment.TOP_CENTER)

        self.space()
        self._leftMargin = CheckBox('Left', self)
        self._leftMargin.setValue(True)
        self._leftMargin.setImmediate(True)
        self.addComponent(self._leftMargin)
        self.setComponentAlignment(self._leftMargin, Alignment.MIDDLE_LEFT)

        self._marginLayout = VerticalLayout()
        self._marginLayout.setStyleName('marginexample')
        self._marginLayout.setSizeUndefined()
        self._marginLayout.setMargin(True)
        self.addComponent(self._marginLayout)
        self._marginLayout.addComponent(Label('Margins all around?'))

        self._rightMargin = CheckBox('Right (100px)', self)
        self._rightMargin.setValue(True)
        self._rightMargin.setImmediate(True)
        self.addComponent(self._rightMargin)
        self.setComponentAlignment(self._rightMargin, Alignment.MIDDLE_LEFT)

        self.space()
        self._bottomMargin = CheckBox('Bottom', self)
        self._bottomMargin.setValue(True)
        self._bottomMargin.setImmediate(True)
        self.addComponent(self._bottomMargin)
        self.setComponentAlignment(self._bottomMargin, Alignment.TOP_CENTER)

    def buttonClick(self, event):
        self._marginLayout.setMargin(  # FIXME:
            self._topMargin.booleanValue(), self._rightMargin.booleanValue(),
            self._bottomMargin.booleanValue(), self._leftMargin.booleanValue())
    def __init__(self):
        super(UploadWithProgressMonitoringExample, self).__init__()

        self.setSpacing(True)

        self._state = Label()
        self._result = Label()
        self._fileName = Label()
        self._textualProgress = Label()
        self._pi = ProgressIndicator()
        self._counter = LineBreakCounter()
        self._upload = Upload(None, self._counter)

        self.addComponent(Label('Upload a file and we\'ll count the number '
                'of line break characters (\\n) found in it.'))

        # make analyzing start immediatedly when file is selected
        self._upload.setImmediate(True)
        self._upload.setButtonCaption('Upload File')
        self.addComponent(self._upload)

        handBrake = CheckBox('Simulate slow server')
        handBrake.setValue(True)
        self._counter.setSlow(True)
        handBrake.setDescription('Sleep for 100ms after each kilobyte to '
                'simulate slower processing/bandwidth. This is to show '
                'progress indicator even with rather small files.')
        handBrake.addListener(HandBrakeListener(self), button.IClickListener)

        cancelProcessing = Button('Cancel')
        cancelProcessing.addListener(CancelListener(self),
                button.IClickListener)
        cancelProcessing.setVisible(False)
        cancelProcessing.setStyleName('small')

        handBrake.setImmediate(True)
        self.addComponent(handBrake)

        p = Panel('Status')
        p.setSizeUndefined()

        l = FormLayout()
        l.setMargin(True)
        p.setContent(l)

        stateLayout = HorizontalLayout()
        stateLayout.setSpacing(True)
        stateLayout.addComponent(self._state)
        stateLayout.addComponent(cancelProcessing)
        stateLayout.setCaption('Current state')
        self._state.setValue('Idle')
        l.addComponent(stateLayout)

        self._fileName.setCaption('File name')
        l.addComponent(self._fileName)

        self._result.setCaption('Line breaks counted')
        l.addComponent(self._result)

        self._pi.setCaption('Progress')
        self._pi.setVisible(False)
        l.addComponent(self._pi)
        self._textualProgress.setVisible(False)
        l.addComponent(self._textualProgress)

        self.addComponent(p)

        self._upload.addListener(StartedListener(self),
                upload.IStartedListener)

        self._upload.addListener(ProgressListener(self),
                upload.IProgressListener)

        self._upload.addListener(SucceededListener(self),
                upload.ISucceededListener)

        self._upload.addListener(FailedListener(self),
                upload.IFailedListener)

        self._upload.addListener(FinishedListener(self),
                upload.IFinishedListener)
    def __init__(self):
        super(UploadWithProgressMonitoringExample, self).__init__()

        self.setSpacing(True)

        self._state = Label()
        self._result = Label()
        self._fileName = Label()
        self._textualProgress = Label()
        self._pi = ProgressIndicator()
        self._counter = LineBreakCounter()
        self._upload = Upload(None, self._counter)

        self.addComponent(
            Label('Upload a file and we\'ll count the number '
                  'of line break characters (\\n) found in it.'))

        # make analyzing start immediatedly when file is selected
        self._upload.setImmediate(True)
        self._upload.setButtonCaption('Upload File')
        self.addComponent(self._upload)

        handBrake = CheckBox('Simulate slow server')
        handBrake.setValue(True)
        self._counter.setSlow(True)
        handBrake.setDescription(
            'Sleep for 100ms after each kilobyte to '
            'simulate slower processing/bandwidth. This is to show '
            'progress indicator even with rather small files.')
        handBrake.addListener(HandBrakeListener(self), button.IClickListener)

        cancelProcessing = Button('Cancel')
        cancelProcessing.addListener(CancelListener(self),
                                     button.IClickListener)
        cancelProcessing.setVisible(False)
        cancelProcessing.setStyleName('small')

        handBrake.setImmediate(True)
        self.addComponent(handBrake)

        p = Panel('Status')
        p.setSizeUndefined()

        l = FormLayout()
        l.setMargin(True)
        p.setContent(l)

        stateLayout = HorizontalLayout()
        stateLayout.setSpacing(True)
        stateLayout.addComponent(self._state)
        stateLayout.addComponent(cancelProcessing)
        stateLayout.setCaption('Current state')
        self._state.setValue('Idle')
        l.addComponent(stateLayout)

        self._fileName.setCaption('File name')
        l.addComponent(self._fileName)

        self._result.setCaption('Line breaks counted')
        l.addComponent(self._result)

        self._pi.setCaption('Progress')
        self._pi.setVisible(False)
        l.addComponent(self._pi)
        self._textualProgress.setVisible(False)
        l.addComponent(self._textualProgress)

        self.addComponent(p)

        self._upload.addListener(StartedListener(self),
                                 upload.IStartedListener)

        self._upload.addListener(ProgressListener(self),
                                 upload.IProgressListener)

        self._upload.addListener(SucceededListener(self),
                                 upload.ISucceededListener)

        self._upload.addListener(FailedListener(self), upload.IFailedListener)

        self._upload.addListener(FinishedListener(self),
                                 upload.IFinishedListener)