def __init__(self): super(SplitPanelBasicExample, self).__init__() # First a vertical SplitPanel vert = VerticalSplitPanel() vert.setHeight('450px') vert.setWidth('100%') vert.setSplitPosition(150, ISizeable.UNITS_PIXELS) self.addComponent(vert) # add a label to the upper area vert.addComponent(Label(self.brownFox)) # Add a horizontal SplitPanel to the lower area horiz = HorizontalSplitPanel() horiz.setSplitPosition(50) # percent vert.addComponent(horiz) # left component: horiz.addComponent(Label(self.brownFox)) # right component: horiz.addComponent(Label(self.brownFox)) # Lock toggle button toggleLocked = CheckBox('Splits locked', LockListener(vert, horiz)) toggleLocked.setImmediate(True) self.addComponent(toggleLocked)
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 MuntjacCheckBox(MuntjacToggleControl, AbstractTkCheckBox): """ A Muntjac implementation of CheckBox. """ #-------------------------------------------------------------------------- # Setup methods #-------------------------------------------------------------------------- def create(self, parent): """ Creates the underlying CheckBox widget. """ self.widget = CheckBox() self.widget.setImmediate(True) parent.addComponent(self.widget) def bind(self): """ Binds the event handlers for the check box. """ super(MuntjacCheckBox, self).bind() widget = self.widget widget.toggled.connect(self.on_toggled) widget.pressed.connect(self.on_pressed) widget.released.connect(self.on_released)
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
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(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)
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)