class PopupTextField(popup_view.IContent): def __init__(self): self._root = VerticalLayout() self._tf = TextField('Edit me') self._root.setSizeUndefined() self._root.setSpacing(True) self._root.setMargin(True) self._root.addComponent(Label(('The changes made to any components ' 'inside the popup are reflected automatically when the popup ' 'is closed, but you might want to provide explicit action ' 'buttons for the user, like \"Save\" or \"Close\".'))) self._root.addComponent(self._tf) self._tf.setValue('Initial dynamic content') self._tf.setWidth('300px') def getMinimizedValueAsHTML(self): return str(self._tf.getValue()) def getPopupComponent(self): return self._root
def showComponent(self, c, name): layout = VerticalLayout() layout.setSizeUndefined() layout.setMargin(True) w = Window(name, layout) w.setSizeUndefined() c.setSizeUndefined() w.addComponent(c) self._component.getWindow().addWindow(w)
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 CompoundEditor ( Editor ): """ Editor for compound traits, which displays editors for each of the combined traits, in the appropriate style. """ #--------------------------------------------------------------------------- # Trait definitions: #--------------------------------------------------------------------------- # The kind of editor to create for each list item kind = Str #--------------------------------------------------------------------------- # 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 = VerticalLayout() self.control.setSizeUndefined() # Add all of the component trait editors: self._editors = editors = [] for factory in self.factory.editors: editor = getattr( factory, self.kind )( self.ui, self.object, self.name, self.description, None ) editor.prepare(self.control) self.control.addComponent(editor.control) editors.append(editor) #--------------------------------------------------------------------------- # 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. """ pass #--------------------------------------------------------------------------- # Disposes of the contents of an editor: #--------------------------------------------------------------------------- def dispose ( self ): """ Disposes of the contents of an editor. """ for editor in self._editors: editor.dispose() super( CompoundEditor, self ).dispose()
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(ProminentPrimaryActionExample, self).__init__() self.setSpacing(True) # Cancel / Save horiz = HorizontalLayout() horiz.setCaption('Save/cancel example:') horiz.setSpacing(True) horiz.setMargin(True) self.addComponent(horiz) secondary = Button('Cancel', self) secondary.setStyleName(BaseTheme.BUTTON_LINK) horiz.addComponent(secondary) primary = Button('Save', self) horiz.addComponent(primary) # Sign up / Sign in horiz = HorizontalLayout() horiz.setCaption('Sign up example:') horiz.setSpacing(True) horiz.setMargin(True) self.addComponent(horiz) primary = Button('Sign up', self) primary.addStyleName('primary') horiz.addComponent(primary) secondary = Button('or Sign in', self) secondary.setStyleName(BaseTheme.BUTTON_LINK) horiz.addComponent(secondary) horiz.setComponentAlignment(secondary, Alignment.MIDDLE_LEFT) # Login / Forgot password? vert = VerticalLayout() vert.setCaption('Login example:') vert.setSizeUndefined() vert.setSpacing(True) vert.setMargin(True) self.addComponent(vert) primary = Button('Login', self) vert.addComponent(primary) vert.setComponentAlignment(primary, Alignment.BOTTOM_RIGHT) secondary = Button('Forgot your password?', self) secondary.setStyleName(BaseTheme.BUTTON_LINK) vert.addComponent(secondary) vert.setComponentAlignment(secondary, Alignment.BOTTOM_RIGHT)
class PopupTextField(popup_view.IContent): def __init__(self): self._root = VerticalLayout() self._tf = TextField('Edit me') self._root.setSizeUndefined() self._root.setSpacing(True) self._root.setMargin(True) self._root.addComponent( Label( ('The changes made to any components ' 'inside the popup are reflected automatically when the popup ' 'is closed, but you might want to provide explicit action ' 'buttons for the user, like \"Save\" or \"Close\".'))) self._root.addComponent(self._tf) self._tf.setValue('Initial dynamic content') self._tf.setWidth('300px') def getMinimizedValueAsHTML(self): return str(self._tf.getValue()) def getPopupComponent(self): return self._root
def init ( self, parent ): """ Finishes initializing the editor by creating the underlying toolkit widget. """ factory = self.factory if factory.name != '': self._object, self._name, self._value = \ self.parse_extended_name( factory.name ) # Create a panel to hold the object trait's view: if factory.editable: self.control = self._panel = parent = Panel() # Build the instance selector if needed: selectable = factory.selectable droppable = factory.droppable items = self.items for item in items: droppable |= item.is_droppable() selectable |= item.is_selectable() if selectable: self._object_cache = {} item = self.item_for( self.value ) if item is not None: self._object_cache[ id( item ) ] = self.value self._choice = ComboBox() self._choice.addCallback(self.update_object, ValueChangeEvent) self.set_tooltip( self._choice ) if factory.name != '': self._object.on_trait_change( self.rebuild_items, self._name, dispatch = 'ui' ) self._object.on_trait_change( self.rebuild_items, self._name + '_items', dispatch = 'ui' ) factory.on_trait_change( self.rebuild_items, 'values', dispatch = 'ui' ) factory.on_trait_change( self.rebuild_items, 'values_items', dispatch = 'ui' ) self.rebuild_items() elif droppable: self._choice = TextField() self._choice.setReadOnly(True) self.set_tooltip( self._choice ) if droppable: raise NotImplementedError # self._choice.SetDropTarget( PythonDropTarget( self ) ) orientation = factory.orientation if orientation == 'default': orientation = self.orientation if (selectable or droppable) and factory.editable: if orientation == 'vertical': layout = VerticalLayout() else: layout = HorizontalLayout() layout.setSizeUndefined() parent.addComponent(layout) # layout.setParent(parent) layout.setMargin(False) layout.addComponent(self._choice) if orientation == 'vertical': hline = Label('<hr />', Label.CONTENT_XHTML) layout.addComponent(hline) # FIXME: explicit parent size self.create_editor(parent, layout) elif self.control is None: if self._choice is None: self._choice = ComboBox() self._choice.addCallback(self.update_object, ValueChangeEvent) self.control = self._choice else: if orientation == 'vertical': layout = VerticalLayout() else: layout = HorizontalLayout() parent.addComponent(layout) layout.setMargin(False) layout.setSizeUndefined() self.create_editor(parent, layout) # Synchronize the 'view' to use: # fixme: A normal assignment can cause a crash (for unknown reasons) in # some cases, so we make sure that no notifications are generated: self.trait_setq( view = factory.view ) self.sync_value( factory.view_name, 'view', 'from' )