class LayoutSpacingExample(VerticalLayout, IClickListener): def __init__(self): super(LayoutSpacingExample, self).__init__() # Create a grid layout. self.grid = GridLayout(3, 3) # Enable sp for the example layout (this is the one we'll toggle # with the checkbox) self.grid.setSpacing(False) # CheckBox for toggling sp on and off self.sp = CheckBox("Spacing enabled") # self.sp.setValue(True) # FIXME: self.sp.setImmediate(True) self.sp.addListener(self, IClickListener) self.addComponent(self.sp) # Add the layout to the containing layout. self.addComponent(self.grid) # Populate the layout with components. for i in range(9): self.grid.addComponent(Button('Component %d' % (i + 1))) self.setSpacing(True) # enable sp for the example itself def buttonClick(self, event): enabled = self.sp.booleanValue() self.grid.setSpacing(enabled)
class SubwindowCloseExample(VerticalLayout): _openWindowText = 'Open a window' _closeWindowText = 'Close the window' def __init__(self): super(SubwindowCloseExample, self).__init__() self._closableWindow = CheckBox('Allow user to close the window', True) self._closableWindow.setImmediate(True) self._closableWindow.addListener(ClosableChangeListener(self), IValueChangeListener) # Create the window self._subwindow = Window('A subwindow w/ close-listener') self._subwindow.addListener(CloseListener(self), ICloseListener) # Configure the windws layout; by default a VerticalLayout layout = self._subwindow.getContent() layout.setMargin(True) layout.setSpacing(True) # Add some content; a label and a close-button message = Label('This is a subwindow with a close-listener.') self._subwindow.addComponent(message) # Add a button for opening the subwindow self._openCloseButton = Button("Open window", ClickListener(self)) self.setSpacing(True) self.addComponent(self._closableWindow) self.addComponent(self._openCloseButton)
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)
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
def __init__(self): super(CheckBoxesExample, self).__init__() self.setSpacing(True) # Button w/ text and tooltip cb = CheckBox(self._CAPTION) cb.setDescription(self._TOOLTIP) cb.setImmediate(True) cb.addListener(self, IClickListener) # react to clicks self.addComponent(cb) # Button w/ text, icon and tooltip cb = CheckBox(self._CAPTION) cb.setDescription(self._TOOLTIP) cb.setIcon(self._ICON) cb.setImmediate(True) cb.addListener(self, IClickListener) # react to clicks self.addComponent(cb) # Button w/ icon and tooltip cb = CheckBox() cb.setDescription(self._TOOLTIP) cb.setIcon(self._ICON) cb.setImmediate(True) cb.addListener(self, IClickListener) # react to clicks self.addComponent(cb)
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)