def add_button ( self, action, bbox, method=None, enabled=True, name=None, default=False ): """ Creates a button. """ ui = self.ui if ((action.defined_when != '') and (not ui.eval_when( action.defined_when ))): return None if name is None: name = action.name id = action.id button = Button( str(name) ) bbox.addComponent(button) bbox.setComponentAlignment(button, Alignment.MIDDLE_RIGHT) if default: button.focus() button.setEnabled(enabled) if (method is None) or (action.enabled_when != '') or (id != ''): editor = ButtonEditor( ui = ui, action = action, control = button ) if id != '': ui.info.bind( id, editor ) if action.visible_when != '': ui.add_visible( action.visible_when, editor ) if action.enabled_when != '': ui.add_enabled( action.enabled_when, editor ) if method is None: method = editor.perform if method is not None: button.addCallback(method, ClickEvent) if action.tooltip != '': button.setDescription(action.tooltip) return button
def __init__(self): super(ButtonLinkExample, self).__init__() self.setSpacing(True) # Button w/ text and tooltip b = Button(self._CAPTION) b.setStyleName(BaseTheme.BUTTON_LINK) b.setDescription(self._TOOLTIP) b.addListener(self, button.IClickListener) # react to clicks self.addComponent(b) # Button w/ text, icon and tooltip b = Button(self._CAPTION) b.setStyleName(BaseTheme.BUTTON_LINK) b.setDescription(self._TOOLTIP) b.setIcon(self._ICON) b.addListener(self, button.IClickListener) # react to clicks self.addComponent(b) # Button w/ icon and tooltip b = Button() b.setStyleName(BaseTheme.BUTTON_LINK) b.setDescription(self._TOOLTIP) b.setIcon(self._ICON) b.addListener(self, button.IClickListener) # react to clicks self.addComponent(b)
def __init__(self): super(TooltipsExample, self).__init__() self.setSpacing(True) # Plain tooltip (description) plain = Button("Mouse over for plain tooltip") plain.setStyleName(BaseTheme.BUTTON_LINK) # add the tooltip: plain.setDescription("A simple plaintext tooltip") self.addComponent(plain) # Richtext tooltip (description) rich = Button("Mouse over for richtext tooltip") rich.setStyleName(BaseTheme.BUTTON_LINK) # add the tooltip: rich.setDescription( ( '<h2><img src="../VAADIN/themes/sampler/' 'icons/comment_yellow.gif"/>A richtext tooltip</h2>' "<ul>" "<li>HTML formatting</li><li>Images<br/>" "</li><li>etc...</li></ul>" ) ) self.addComponent(rich) # Edit rte = RichTextArea() rte.setValue(("Click <b>" + self._editTxt + "</b> to edit this tooltip, then <b>" + self._applyTxt + "</b>")) rte.setVisible(False) # hide editor initially rte.setWidth("100%") self.addComponent(rte) aply = Button(self._editTxt, EditListener(self, rte)) aply.setDescription(rte.getValue()) self.addComponent(aply)
def __init__(self): super(TooltipsExample, self).__init__() self.setSpacing(True) # Plain tooltip (description) plain = Button('Mouse over for plain tooltip') plain.setStyleName(BaseTheme.BUTTON_LINK) # add the tooltip: plain.setDescription('A simple plaintext tooltip') self.addComponent(plain) # Richtext tooltip (description) rich = Button('Mouse over for richtext tooltip') rich.setStyleName(BaseTheme.BUTTON_LINK) # add the tooltip: rich.setDescription( ('<h2><img src=\"../VAADIN/themes/sampler/' 'icons/comment_yellow.gif\"/>A richtext tooltip</h2>' '<ul>' '<li>HTML formatting</li><li>Images<br/>' '</li><li>etc...</li></ul>')) self.addComponent(rich) # Edit rte = RichTextArea() rte.setValue( ('Click <b>' + self._editTxt + '</b> to edit this tooltip, then <b>' + self._applyTxt + '</b>')) rte.setVisible(False) # hide editor initially rte.setWidth('100%') self.addComponent(rte) aply = Button(self._editTxt, EditListener(self, rte)) aply.setDescription(rte.getValue()) self.addComponent(aply)
def __init__(self): super(ExpandingComponentExample, self).__init__() self.setSpacing(True) # Basic scenario: single expanded component layout = HorizontalLayout() layout.setWidth('100%') # make the layout grow with the window size self.addComponent(layout) naturalButton = Button('Natural') naturalButton.setDescription('This button does not have an explicit ' 'size - instead, its size depends on it\'s content - a.k.a ' '<i>natural size.</i>') layout.addComponent(naturalButton) expandedButton = Button('Expanded') expandedButton.setWidth('100%') expandedButton.setDescription('The width of this button is set to ' '100% and expanded, and will thus occupy the space left over ' 'by the other components.') layout.addComponent(expandedButton) layout.setExpandRatio(expandedButton, 1.0) sizedButton = Button('Explicit') sizedButton.setWidth('150px') sizedButton.setDescription('This button is explicitly set to be ' '150 pixels wide.') layout.addComponent(sizedButton) # Ratio example layout = HorizontalLayout() layout.setWidth('100%') # make the layout grow with the window size self.addComponent(layout) naturalButton = Button('Natural') naturalButton.setDescription('This button does not have an explicit ' 'size - instead, its size depends on it\'s content - a.k.a ' '<i>natural size.</i>') layout.addComponent(naturalButton) expandedButton1 = Button('Ratio 1.0') expandedButton1.setWidth('100%') expandedButton1.setDescription('The width of this button is set to ' '100% and expanded with a ratio of 1.0, and will in this ' 'example occupy 1:3 of the leftover space.') layout.addComponent(expandedButton1) layout.setExpandRatio(expandedButton1, 1.0) expandedButton2 = Button('Ratio 2.0') expandedButton2.setWidth('100%') expandedButton2.setDescription('The width of this button is set to ' '100% and expanded with a ratio of 2.0, and will in this ' 'example occupy 2:3 of the leftover space.') layout.addComponent(expandedButton2) layout.setExpandRatio(expandedButton2, 2.0)
def __init__(self): super(ButtonPushExample, self).__init__() # Normal buttons (more themable) buttons = VerticalLayout() buttons.setSpacing(True) buttons.setMargin(False, True, False, False) self.addComponent(buttons) buttons.addComponent(Label("<h3>Normal buttons</h3>", Label.CONTENT_XHTML)) # Button w/ text and tooltip b = Button(self._CAPTION) b.setDescription(self._TOOLTIP) b.addListener(self, IClickListener) # react to clicks buttons.addComponent(b) # Button w/ text, icon and tooltip b = Button(self._CAPTION) b.setDescription(self._TOOLTIP) b.setIcon(self._ICON) b.addListener(self, IClickListener) # react to clicks buttons.addComponent(b) # Button w/ icon and tooltip b = Button() b.setDescription(self._TOOLTIP) b.setIcon(self._ICON) b.addListener(self, IClickListener) # react to clicks buttons.addComponent(b) # NativeButtons buttons = VerticalLayout() buttons.setSpacing(True) buttons.setMargin(False, False, False, True) self.addComponent(buttons) buttons.addComponent(Label("<h3>Native buttons</h3>", Label.CONTENT_XHTML)); # NativeButton w/ text and tooltip b = NativeButton(self._CAPTION) b.setDescription(self._TOOLTIP) b.addListener(self, IClickListener) # react to clicks buttons.addComponent(b) # NativeButton w/ text, icon and tooltip b = NativeButton(self._CAPTION) b.setDescription(self._TOOLTIP) b.setIcon(self._ICON) b.addListener(self, IClickListener) # react to clicks buttons.addComponent(b) # NativeButton w/ icon and tooltip b = NativeButton() b.setDescription(self._TOOLTIP) b.setIcon(self._ICON) b.addListener(self, IClickListener) # react to clicks buttons.addComponent(b)