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): 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)
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)
def __init__(self): super(FeatureView, self).__init__() self._right = None self._left = None self._controls = None self._title = Label("", Label.CONTENT_XHTML) self._showSrc = None self._exampleCache = dict() self._currentFeature = None self._srcWindow = None self.setWidth('100%') self.setMargin(True) self.setSpacing(True) self.setStyleName('sample-view') self._left = VerticalLayout() self._left.setWidth('100%') self._left.setSpacing(True) self._left.setMargin(False) self.addComponent(self._left) self.setExpandRatio(self._left, 1) rightLayout = VerticalLayout() self._right = Panel(rightLayout) rightLayout.setMargin(True, False, False, False) self._right.setStyleName(Reindeer.PANEL_LIGHT) self._right.addStyleName('feature-info') self._right.setWidth('319px') self.addComponent(self._right) self._controls = HorizontalLayout() self._controls.setWidth('100%') self._controls.setStyleName('feature-controls') self._title.setStyleName('title') self._controls.addComponent(self._title) self._controls.setExpandRatio(self._title, 1) resetExample = NativeButton('Reset', ResetListener(self)) resetExample.setStyleName(BaseTheme.BUTTON_LINK) resetExample.addStyleName('reset') resetExample.setDescription('Reset Sample') self._controls.addComponent(resetExample) self._showSrc = ActiveLink() self._showSrc.setDescription( 'Right / middle / ctrl / shift -click for browser window/tab') self._showSrc.addListener(ShowSrcListener(self), ILinkActivatedListener) self._showSrc.setCaption(self._MSG_SHOW_SRC) self._showSrc.addStyleName('showcode') self._showSrc.setTargetBorder(Link.TARGET_BORDER_NONE) self._controls.addComponent(self._showSrc)
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(FeatureView, self).__init__() self._right = None self._left = None self._controls = None self._title = Label("", Label.CONTENT_XHTML) self._showSrc = None self._exampleCache = dict() self._currentFeature = None self._srcWindow = None self.setWidth('100%') self.setMargin(True) self.setSpacing(True) self.setStyleName('sample-view') self._left = VerticalLayout() self._left.setWidth('100%') self._left.setSpacing(True) self._left.setMargin(False) self.addComponent(self._left) self.setExpandRatio(self._left, 1) rightLayout = VerticalLayout() self._right = Panel(rightLayout) rightLayout.setMargin(True, False, False, False) self._right.setStyleName(Reindeer.PANEL_LIGHT) self._right.addStyleName('feature-info') self._right.setWidth('319px') self.addComponent(self._right) self._controls = HorizontalLayout() self._controls.setWidth('100%') self._controls.setStyleName('feature-controls') self._title.setStyleName('title') self._controls.addComponent(self._title) self._controls.setExpandRatio(self._title, 1) resetExample = NativeButton('Reset', ResetListener(self)) resetExample.setStyleName(BaseTheme.BUTTON_LINK) resetExample.addStyleName('reset') resetExample.setDescription('Reset Sample') self._controls.addComponent(resetExample) self._showSrc = ActiveLink() self._showSrc.setDescription('Right / middle / ctrl / shift -click for browser window/tab') self._showSrc.addListener(ShowSrcListener(self), ILinkActivatedListener) self._showSrc.setCaption(self._MSG_SHOW_SRC) self._showSrc.addStyleName('showcode') self._showSrc.setTargetBorder(Link.TARGET_BORDER_NONE) self._controls.addComponent(self._showSrc)
def __init__(self): super(TabSheetClosingExample, self).__init__() # Tab 1 content l1 = VerticalLayout() l1.setMargin(True) l1.addComponent(Label('There are no previously saved actions.')) # Tab 2 content l2 = VerticalLayout() l2.setMargin(True) l2.addComponent(Label('There are no saved notes.')) # Tab 3 content l3 = VerticalLayout() l3.setMargin(True) l3.addComponent(Label('There are currently no issues.')) # Tab 4 content l4 = VerticalLayout() l4.setMargin(True) l4.addComponent(Label('There are no comments.')) # Tab 5 content l5 = VerticalLayout() l5.setMargin(True) l5.addComponent(Label('There is no new feedback.')) self._t = TabSheet() self._t.setHeight('200px') self._t.setWidth('400px') saved = self._t.addTab(l1, 'Saved actions', None) saved.setClosable(True) notes = self._t.addTab(l2, 'Notes', None) notes.setClosable(True) issues = self._t.addTab(l3, 'Issues', None) issues.setClosable(True) comments = self._t.addTab(l4, 'Comments', None) comments.setClosable(True) feedback = self._t.addTab(l5, 'Feedback', None) feedback.setClosable(True) self._t.addListener(self, tab_sheet.ISelectedTabChangeListener) self._t.setCloseHandler(self) self.addComponent(self._t)
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 resynch_editor ( self ): """ Resynchronizes the contents of the editor when the object trait changes externally to the editor. """ panel = self._panel if panel is not None: # Dispose of the previous contents of the panel: layout = panel.getParent() if layout is None: layout = VerticalLayout() panel.addComponent(layout) # layout.setParent(panel) layout.setMargin(False) elif self._ui is not None: self._ui.dispose() self._ui = None else: layout.removeAllComponents() # Create the new content for the panel: stretch = 0 value = self.value if not isinstance( value, HasTraits ): str_value = '' if value is not None: str_value = self.str_value control = Label() control.setValue(str_value) else: view = self.view_for( value, self.item_for( value ) ) context = value.trait_context() handler = None if isinstance( value, Handler ): handler = value context.setdefault( 'context', self.object ) context.setdefault( 'context_handler', self.ui.handler ) self._ui = ui = view.ui( context, panel, 'subpanel', value.trait_view_elements(), handler, self.factory.id ) control = ui.control self.scrollable = ui._scrollable ui.parent = self.ui if view.resizable or view.scrollable or ui._scrollable: stretch = 1 # FIXME: Handle stretch. layout.addComponent(control)
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)
def createKeyRegisterClickableLayout(self): # Create a vertical layout with click events layout = VerticalLayout() layout.setWidth('90%') layout.setSpacing(True) layout.addStyleName('border') layout.setMargin(True) # Add some components inside the layout layout.addComponent(Label('<b>Layout click events register if ' 'control keys are pressed during the click and double ' 'clicks. Try clicking anywhere inside this layout while ' 'holding CTRL, ALT, SHIFT or META key down.</b>', Label.CONTENT_RAW)) # Listen for layout click events layout.addListener(VerticalListener(self), ILayoutClickListener) return layout
def createVerticalClickableLayout(self): # Create a vertical layout with click events layout = VerticalLayout() layout.setWidth('90%') layout.setSpacing(True) layout.addStyleName('border') layout.setMargin(True) # Add some components inside the layout layout.addComponent( Label( '<b>This is a vertical layout with a ' 'click listener attached. Try clicking anywhere inside ' 'this layout.</b>', Label.CONTENT_RAW)) clickX = Label('X-coordinate: <i>Not available.</i>', Label.CONTENT_RAW) layout.addComponent(clickX) clickY = Label('Y-coordinate: <i>Not available.</i>', Label.CONTENT_RAW) layout.addComponent(clickY) clickRelativeX = Label( 'X-coordinate relative to the layout: ' '<i>Not available.</i>', Label.CONTENT_RAW) layout.addComponent(clickRelativeX) clickRelativeY = Label( 'Y-coordinate relative to the layout: ' '<i>Not available.</i>', Label.CONTENT_RAW) layout.addComponent(clickRelativeY) button = Label('Mouse button: <i>Not available.</i>', Label.CONTENT_RAW) layout.addComponent(button) # Listen for layout click events layout.addListener( LayoutListener(self, button, clickX, clickY, clickRelativeX, clickRelativeY), ILayoutClickListener) return layout
def createKeyRegisterClickableLayout(self): # Create a vertical layout with click events layout = VerticalLayout() layout.setWidth('90%') layout.setSpacing(True) layout.addStyleName('border') layout.setMargin(True) # Add some components inside the layout layout.addComponent( Label( '<b>Layout click events register if ' 'control keys are pressed during the click and double ' 'clicks. Try clicking anywhere inside this layout while ' 'holding CTRL, ALT, SHIFT or META key down.</b>', Label.CONTENT_RAW)) # Listen for layout click events layout.addListener(VerticalListener(self), ILayoutClickListener) return layout
def __init__(self): super(TabSheetIconsExample, self).__init__() # Tab 1 content l1 = VerticalLayout() l1.setMargin(True) l1.addComponent(Label('There are no previously saved actions.')) # Tab 2 content l2 = VerticalLayout() l2.setMargin(True) l2.addComponent(Label('There are no saved notes.')) # Tab 3 content l3 = VerticalLayout() l3.setMargin(True) l3.addComponent(Label('There are currently no issues.')) self._t = TabSheet() self._t.setHeight('200px') self._t.setWidth('400px') self._t.addTab(l1, 'Saved actions', self._icon1) self._t.addTab(l2, 'Notes', self._icon2) self._t.addTab(l3, 'Issues', self._icon3) self._t.addListener(self, ISelectedTabChangeListener) self.addComponent(self._t)
def createVerticalClickableLayout(self): # Create a vertical layout with click events layout = VerticalLayout() layout.setWidth('90%') layout.setSpacing(True) layout.addStyleName('border') layout.setMargin(True) # Add some components inside the layout layout.addComponent(Label('<b>This is a vertical layout with a ' 'click listener attached. Try clicking anywhere inside ' 'this layout.</b>', Label.CONTENT_RAW)) clickX = Label('X-coordinate: <i>Not available.</i>', Label.CONTENT_RAW) layout.addComponent(clickX) clickY = Label('Y-coordinate: <i>Not available.</i>', Label.CONTENT_RAW) layout.addComponent(clickY) clickRelativeX = Label('X-coordinate relative to the layout: ' '<i>Not available.</i>', Label.CONTENT_RAW) layout.addComponent(clickRelativeX) clickRelativeY = Label('Y-coordinate relative to the layout: ' '<i>Not available.</i>', Label.CONTENT_RAW) layout.addComponent(clickRelativeY) button = Label('Mouse button: <i>Not available.</i>', Label.CONTENT_RAW) layout.addComponent(button) # Listen for layout click events layout.addListener(LayoutListener(self, button, clickX, clickY, clickRelativeX, clickRelativeY), ILayoutClickListener) return layout
def __init__ ( self, parent, html, scale_dx, scale_dy ): """ Initializes the object. """ super(HTMLHelpWindow, self).__init__() self.setParent(parent) layout = VerticalLayout() layout.setMargin(False) # Create the html control html_control = Label(html) html_control.setContentMode(Label.CONTENT_XHTML) layout.addComponent(html_control) # Create the OK button ok = Button('OK') # FIXME: add event handler layout.addComponent(ok) layout.setComponentAlignment(ok, Alignment.BOTTOM_RIGHT) # Position and show the dialog position_window(self, parent=parent) self.show()
def _fill_panel(panel, content, ui, item_handler=None): """Fill a page based container panel with content. """ active = 0 for index, item in enumerate(content): page_name = item.get_label(ui) if page_name == "": page_name = "Page %d" % index if isinstance(item, Group): if item.selected: active = index gp = _GroupPanel(item, ui, suppress_label=True) page = gp.control sub_page = gp.sub_control # If the result is a TabSheet type with only one page, collapse it # down into just the page. if (isinstance(sub_page, TabSheet) and sub_page.getComponentCount() == 1): sub_page = sub_page.getTab(0).getComponent() else: new = page else: new = VerticalLayout() new.setMargin(False) item_handler(item, new) # Add the content. if isinstance(panel, TabSheet): panel.addTab(new, page_name) else: panel.addComponent(new, page_name) panel.setSelectedTab(panel.getTab(active))
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
class TabSheetDisabledExample(VerticalLayout, tab_sheet.ISelectedTabChangeListener, button.IClickListener): _icon1 = ThemeResource('../sampler/icons/action_save.gif') _icon2 = ThemeResource('../sampler/icons/comment_yellow.gif') _icon3 = ThemeResource('../sampler/icons/icon_info.gif') def __init__(self): super(TabSheetDisabledExample, self).__init__() self.setSpacing(True) # Tab 1 content self._l1 = VerticalLayout() self._l1.setMargin(True) self._l1.addComponent(Label('There are no previously saved actions.')) # Tab 2 content self._l2 = VerticalLayout() self._l2.setMargin(True) self._l2.addComponent(Label('There are no saved notes.')) # Tab 3 content self._l3 = VerticalLayout() self._l3.setMargin(True) self._l3.addComponent(Label('There are currently no issues.')) self._t = TabSheet() self._t.setHeight('200px') self._t.setWidth('400px') self._t1 = self._t.addTab(self._l1, 'Saved actions', self._icon1) self._t2 = self._t.addTab(self._l2, 'Notes', self._icon2) self._t3 = self._t.addTab(self._l3, 'Issues', self._icon3) self._t.addListener(self, tab_sheet.ISelectedTabChangeListener) self._toggleEnabled = Button('Disable \'Notes\' tab') self._toggleEnabled.addListener(self, button.IClickListener) self._toggleVisible = Button('Hide \'Issues\' tab') self._toggleVisible.addListener(self, button.IClickListener) hl = HorizontalLayout() hl.setSpacing(True) hl.addComponent(self._toggleEnabled) hl.addComponent(self._toggleVisible) self.addComponent(self._t) self.addComponent(hl) def selectedTabChange(self, event): selected = event.getTabSheet().getSelectedTab() c = self._t.getTab(selected).getCaption() self.getWindow().showNotification('Selected tab: ' + c) def buttonClick(self, event): if self._toggleEnabled == event.getButton(): # toggleEnabled clicked self._t2.setEnabled(not self._t2.isEnabled()) if self._t2.isEnabled(): self._toggleEnabled.setCaption('Disable \'Notes\' tab') else: self._toggleEnabled.setCaption('Enable \'Notes\' tab') else: # toggleVisible clicked self._t3.setVisible(not self._t3.isVisible()) if self._t3.isVisible(): self._toggleVisible.setCaption('Hide \'Issues\' tab') else: self._toggleVisible.setCaption('Show \'Issues\' tab') self._t.requestRepaint()
def setFeature(self, feature): from muntjac.demo.sampler.SamplerApplication import SamplerApplication if feature != self._currentFeature: self._currentFeature = feature self._right.removeAllComponents() self._left.removeAllComponents() self._left.addComponent(self._controls) self._title.setValue('<span>' + feature.getName() + '</span>') if feature.getSinceVersion().isNew(): self._title.addStyleName('new') else: self._title.removeStyleName('new') self._left.addComponent(self.getExampleFor(feature)) self._right.setCaption('Description and Resources') # Do not show parent description if it's directly inside the root alll = SamplerApplication.getAllFeatures() parent = alll.getParent(feature) isRoot = alll.getParent(parent) is None desc = parent.getDescription() hasParentDesc = False if parent is not None and not isRoot: parentLabel = Label(parent.getDescription()) if desc is not None and desc != '': parentLabel.setContentMode(Label.CONTENT_XHTML) self._right.addComponent(parentLabel) hasParentDesc = True desc = feature.getDescription() if desc is not None and desc != '': # Sample description uses additional decorations if a parent # description is found l = Label(("<div class=\"outer-deco\"><div class=\"deco\">" "<span class=\"deco\"></span>") + desc + "</div></div>", Label.CONTENT_XHTML) self._right.addComponent(l) if hasParentDesc: l.setStyleName('sample-description') else: l.setStyleName('description') # open src in new window -link self._showSrc.setTargetName(self._currentFeature.getFragmentName()) er = ExternalResource(self.getApplication().getURL() + 'src/' + self._currentFeature.getFragmentName()) self._showSrc.setResource(er) resources = feature.getRelatedResources() if resources is not None: res = VerticalLayout() self.caption = Label("<span>Additional Resources</span>", Label.CONTENT_XHTML) self.caption.setStyleName('section') self.caption.setWidth('100%') res.addComponent(self.caption) res.setMargin(False, False, True, False) for r in resources: l = Link(r.getName(), r) l.setIcon( ThemeResource('../runo/icons/16/note.png') ) res.addComponent(l) self._right.addComponent(res) apis = feature.getRelatedAPI() if apis is not None: api = VerticalLayout() self.caption = Label("<span>API Documentation</span>", Label.CONTENT_XHTML) self.caption.setStyleName('section') self.caption.setWidth('100%') api.addComponent(self.caption) api.setMargin(False, False, True, False) for r in apis: l = Link(r.getName(), r) ic = ThemeResource('../runo/icons/16/document-txt.png') l.setIcon(ic) api.addComponent(l) self._right.addComponent(api) features = feature.getRelatedFeatures() if features is not None: rel = VerticalLayout() self.caption = Label("<span>Related Samples</span>", Label.CONTENT_XHTML) self.caption.setStyleName('section') self.caption.setWidth('100%') rel.addComponent(self.caption) rel.setMargin(False, False, True, False) for c in features: f = SamplerApplication.getFeatureFor(c) if f is not None: er = ExternalResource(self.getApplication().getURL() + '#' + f.getFragmentName()) al = ActiveLink(f.getName(), er) if isinstance(f, FeatureSet): ic = ThemeResource('../sampler/icons/category.gif') else: ic = ThemeResource('../sampler/icons/sample.png') al.setIcon(ic) al.addListener(LinkListener(self, f), ILinkActivatedListener) rel.addComponent(al) self._right.addComponent(rel)
class FeatureView(HorizontalLayout): _MSG_SHOW_SRC = 'View Source' def __init__(self): super(FeatureView, self).__init__() self._right = None self._left = None self._controls = None self._title = Label("", Label.CONTENT_XHTML) self._showSrc = None self._exampleCache = dict() self._currentFeature = None self._srcWindow = None self.setWidth('100%') self.setMargin(True) self.setSpacing(True) self.setStyleName('sample-view') self._left = VerticalLayout() self._left.setWidth('100%') self._left.setSpacing(True) self._left.setMargin(False) self.addComponent(self._left) self.setExpandRatio(self._left, 1) rightLayout = VerticalLayout() self._right = Panel(rightLayout) rightLayout.setMargin(True, False, False, False) self._right.setStyleName(Reindeer.PANEL_LIGHT) self._right.addStyleName('feature-info') self._right.setWidth('319px') self.addComponent(self._right) self._controls = HorizontalLayout() self._controls.setWidth('100%') self._controls.setStyleName('feature-controls') self._title.setStyleName('title') self._controls.addComponent(self._title) self._controls.setExpandRatio(self._title, 1) resetExample = NativeButton('Reset', ResetListener(self)) resetExample.setStyleName(BaseTheme.BUTTON_LINK) resetExample.addStyleName('reset') resetExample.setDescription('Reset Sample') self._controls.addComponent(resetExample) self._showSrc = ActiveLink() self._showSrc.setDescription('Right / middle / ctrl / shift -click for browser window/tab') self._showSrc.addListener(ShowSrcListener(self), ILinkActivatedListener) self._showSrc.setCaption(self._MSG_SHOW_SRC) self._showSrc.addStyleName('showcode') self._showSrc.setTargetBorder(Link.TARGET_BORDER_NONE) self._controls.addComponent(self._showSrc) def showSource(self, source): if self._srcWindow is None: self._srcWindow = Window('Python source') self._srcWindow.getContent().setSizeUndefined() self._srcWindow.setWidth('70%') self._srcWindow.setHeight('60%') self._srcWindow.setPositionX(100) self._srcWindow.setPositionY(100) self._srcWindow.removeAllComponents() self._srcWindow.addComponent( CodeLabel(source) ) if self._srcWindow.getParent() is None: self.getWindow().addWindow(self._srcWindow) def resetExample(self): if self._currentFeature is not None: w = self.getWindow() w.removeSubwindows() f = self._currentFeature self._currentFeature = None if f in self._exampleCache: del self._exampleCache[f] self.setFeature(f) def setFeature(self, feature): from muntjac.demo.sampler.SamplerApplication import SamplerApplication if feature != self._currentFeature: self._currentFeature = feature self._right.removeAllComponents() self._left.removeAllComponents() self._left.addComponent(self._controls) self._title.setValue('<span>' + feature.getName() + '</span>') if feature.getSinceVersion().isNew(): self._title.addStyleName('new') else: self._title.removeStyleName('new') self._left.addComponent(self.getExampleFor(feature)) self._right.setCaption('Description and Resources') # Do not show parent description if it's directly inside the root alll = SamplerApplication.getAllFeatures() parent = alll.getParent(feature) isRoot = alll.getParent(parent) is None desc = parent.getDescription() hasParentDesc = False if parent is not None and not isRoot: parentLabel = Label(parent.getDescription()) if desc is not None and desc != '': parentLabel.setContentMode(Label.CONTENT_XHTML) self._right.addComponent(parentLabel) hasParentDesc = True desc = feature.getDescription() if desc is not None and desc != '': # Sample description uses additional decorations if a parent # description is found l = Label(("<div class=\"outer-deco\"><div class=\"deco\">" "<span class=\"deco\"></span>") + desc + "</div></div>", Label.CONTENT_XHTML) self._right.addComponent(l) if hasParentDesc: l.setStyleName('sample-description') else: l.setStyleName('description') # open src in new window -link self._showSrc.setTargetName(self._currentFeature.getFragmentName()) er = ExternalResource(self.getApplication().getURL() + 'src/' + self._currentFeature.getFragmentName()) self._showSrc.setResource(er) resources = feature.getRelatedResources() if resources is not None: res = VerticalLayout() self.caption = Label("<span>Additional Resources</span>", Label.CONTENT_XHTML) self.caption.setStyleName('section') self.caption.setWidth('100%') res.addComponent(self.caption) res.setMargin(False, False, True, False) for r in resources: l = Link(r.getName(), r) l.setIcon( ThemeResource('../runo/icons/16/note.png') ) res.addComponent(l) self._right.addComponent(res) apis = feature.getRelatedAPI() if apis is not None: api = VerticalLayout() self.caption = Label("<span>API Documentation</span>", Label.CONTENT_XHTML) self.caption.setStyleName('section') self.caption.setWidth('100%') api.addComponent(self.caption) api.setMargin(False, False, True, False) for r in apis: l = Link(r.getName(), r) ic = ThemeResource('../runo/icons/16/document-txt.png') l.setIcon(ic) api.addComponent(l) self._right.addComponent(api) features = feature.getRelatedFeatures() if features is not None: rel = VerticalLayout() self.caption = Label("<span>Related Samples</span>", Label.CONTENT_XHTML) self.caption.setStyleName('section') self.caption.setWidth('100%') rel.addComponent(self.caption) rel.setMargin(False, False, True, False) for c in features: f = SamplerApplication.getFeatureFor(c) if f is not None: er = ExternalResource(self.getApplication().getURL() + '#' + f.getFragmentName()) al = ActiveLink(f.getName(), er) if isinstance(f, FeatureSet): ic = ThemeResource('../sampler/icons/category.gif') else: ic = ThemeResource('../sampler/icons/sample.png') al.setIcon(ic) al.addListener(LinkListener(self, f), ILinkActivatedListener) rel.addComponent(al) self._right.addComponent(rel) def getExampleFor(self, f): ex = self._exampleCache.get(f) if ex is None: ex = f.getExample() self._exampleCache[f] = ex return ex
def init(self): # We'll build the whole UI here, since the application will not # contain any logic. Otherwise it would be more practical to # separate parts of the UI into different classes and methods. # Main (browser) window, needed in all Muntjac applications rootLayout = VerticalLayout() root = Window('MuntjacTunes', rootLayout) # We'll attach the window to the browser view already here, so # we won't forget it later. self.setMainWindow(root) root.showNotification(('This is an example of how you can do layouts ' 'in Muntjac.<br/>It is not a working sound player.'), Notification.TYPE_HUMANIZED_MESSAGE) # Our root window contains one VerticalLayout, let's make # sure it's 100% sized, and remove unwanted margins rootLayout.setSizeFull() rootLayout.setMargin(False) # Top area, containing playback and volume controls, play status, # view modes and search top = HorizontalLayout() top.setWidth('100%') top.setMargin(False, True, False, True) # Enable horizontal margins top.setSpacing(True) # Let's attach that one straight away too root.addComponent(top) # Create the placeholders for all the components in the top area playback = HorizontalLayout() volume = HorizontalLayout() status = HorizontalLayout() viewmodes = HorizontalLayout() search = ComboBox() # Add the components and align them properly top.addComponent(playback) top.addComponent(volume) top.addComponent(status) top.addComponent(viewmodes) top.addComponent(search) top.setComponentAlignment(playback, Alignment.MIDDLE_LEFT) top.setComponentAlignment(volume, Alignment.MIDDLE_LEFT) top.setComponentAlignment(status, Alignment.MIDDLE_CENTER) top.setComponentAlignment(viewmodes, Alignment.MIDDLE_LEFT) top.setComponentAlignment(search, Alignment.MIDDLE_LEFT) # We want our status area to expand if the user resizes the root # window, and we want it to accommodate as much space as there is # available. All other components in the top layout should stay fixed # sized, so we don't need to specify any expand ratios for them (they # will automatically revert to zero after the following line). top.setExpandRatio(status, 1.0) # Playback controls prev = NativeButton('Previous') play = NativeButton('Play/pause') nextt = NativeButton('Next') playback.addComponent(prev) playback.addComponent(play) playback.addComponent(nextt) # Set spacing between the buttons playback.setSpacing(True) # Volume controls mute = NativeButton('mute') vol = Slider() vol.setOrientation(Slider.ORIENTATION_HORIZONTAL) vol.setWidth('100px') maxx = NativeButton('max') volume.addComponent(mute) volume.addComponent(vol) volume.addComponent(maxx) # Status area status.setWidth('80%') status.setSpacing(True) toggleVisualization = NativeButton('Mode') timeFromStart = Label('0:00') # We'll need another layout to show currently playing track and # progress trackDetails = VerticalLayout() trackDetails.setWidth('100%') track = Label('Track Name') album = Label('Album Name - Artist') track.setWidth(None) album.setWidth(None) progress = Slider() progress.setOrientation(Slider.ORIENTATION_HORIZONTAL) progress.setWidth('100%') trackDetails.addComponent(track) trackDetails.addComponent(album) trackDetails.addComponent(progress) trackDetails.setComponentAlignment(track, Alignment.TOP_CENTER) trackDetails.setComponentAlignment(album, Alignment.TOP_CENTER) timeToEnd = Label('-4:46') jumpToTrack = NativeButton('Show') # Place all components to the status layout and align them properly status.addComponent(toggleVisualization) status.setComponentAlignment(toggleVisualization, Alignment.MIDDLE_LEFT) status.addComponent(timeFromStart) status.setComponentAlignment(timeFromStart, Alignment.BOTTOM_LEFT) status.addComponent(trackDetails) status.addComponent(timeToEnd) status.setComponentAlignment(timeToEnd, Alignment.BOTTOM_LEFT) status.addComponent(jumpToTrack) status.setComponentAlignment(jumpToTrack, Alignment.MIDDLE_LEFT) # Then remember to specify the expand ratio status.setExpandRatio(trackDetails, 1.0) # View mode buttons viewAsTable = NativeButton('Table') viewAsGrid = NativeButton('Grid') coverflow = NativeButton('Coverflow') viewmodes.addComponent(viewAsTable) viewmodes.addComponent(viewAsGrid) viewmodes.addComponent(coverflow) # That covers the top bar. Now let's move on to the sidebar # and track listing # We'll need one splitpanel to separate the sidebar and track listing bottom = HorizontalSplitPanel() root.addComponent(bottom) # The splitpanel is by default 100% x 100%, but we'll need to # adjust our main window layout to accommodate the height root.getContent().setExpandRatio(bottom, 1.0) # Give the sidebar less space than the listing bottom.setSplitPosition(200, ISizeable.UNITS_PIXELS) # Let's add some content to the sidebar # First, we need a layout to but all components in sidebar = VerticalLayout() sidebar.setSizeFull() bottom.setFirstComponent(sidebar) # Then we need some labels and buttons, and an album cover image The # labels and buttons go into their own vertical layout, since we want # the 'sidebar' layout to be expanding (cover image in the bottom). # VerticalLayout is by default 100% wide. selections = VerticalLayout() library = Label('Library') music = NativeButton('Music') music.setWidth('100%') store = Label('Store') muntjacTunesStore = NativeButton('MuntjacTunes Store') muntjacTunesStore.setWidth('100%') purchased = NativeButton('Purchased') purchased.setWidth('100%') playlists = Label('Playlists') genius = NativeButton('Geniues') genius.setWidth('100%') recent = NativeButton('Recently Added') recent.setWidth('100%') # Lets add them to the 'selections' layout selections.addComponent(library) selections.addComponent(music) selections.addComponent(store) selections.addComponent(muntjacTunesStore) selections.addComponent(purchased) selections.addComponent(playlists) selections.addComponent(genius) selections.addComponent(recent) # Then add the selections to the sidebar, and set it expanding sidebar.addComponent(selections) sidebar.setExpandRatio(selections, 1.0) # Then comes the cover artwork (we'll add the actual image in the # themeing section) cover = Embedded('Currently Playing') sidebar.addComponent(cover) # And lastly, we need the track listing table It should fill the whole # left side of our bottom layout listing = Table() listing.setSizeFull() listing.setSelectable(True) bottom.setSecondComponent(listing) # Add the table headers listing.addContainerProperty('Name', str, '') listing.addContainerProperty('Time', str, '0:00') listing.addContainerProperty('Artist', str, '') listing.addContainerProperty('Album', str, '') listing.addContainerProperty('Genre', str, '') listing.addContainerProperty('Rating', NativeSelect, NativeSelect()) # Lets populate the table with random data tracks = ['Red Flag', 'Millstone', 'Not The Sun', 'Breath', 'Here We Are', 'Deep Heaven', 'Her Voice Resides', 'Natural Tan', 'End It All', 'Kings', 'Daylight Slaving', 'Mad Man', 'Resolve', 'Teargas', 'African Air', 'Passing Bird'] times = ['4:12', '6:03', '5:43', '4:32', '3:42', '4:45', '2:56', '9:34', '2:10', '3:44', '5:49', '6:30', '5:18', '7:42', '3:13', '2:52'] artists = ['Billy Talent', 'Brand New', 'Breaking Benjamin', 'Becoming The Archetype', 'Bullet For My Valentine', 'Chasing Victory', 'Chimaira', 'Danko Jones', 'Deadlock', 'Deftones', 'From Autumn To Ashes', 'Haste The Day', 'Four Year Strong', 'In Flames', 'Kemopetrol', 'John Legend'] albums = ['Once Again', 'The Caitiff Choir', 'The Devil And God', 'Light Grenades', 'Dicthonomy', 'Back In Black', 'Dreamer', 'Come Clarity', 'Year Zero', 'Frames', 'Fortress', 'Phobia', 'The Poison', 'Manifesto', 'White Pony', 'The Big Dirty'] genres = ['Rock', 'Metal', 'Hardcore', 'Indie', 'Pop', 'Alternative', 'Blues', 'Jazz', 'Hip Hop', 'Electronica', 'Punk', 'Hard Rock', 'Dance', 'R\'n\'B', 'Gospel', 'Country'] for i in range(100): s = NativeSelect() s.addItem('1 star') s.addItem('2 stars') s.addItem('3 stars') s.addItem('4 stars') s.addItem('5 stars') s.select('%d stars' % (i % 5)) index = i % 16 listing.addItem([tracks[index], times[index], artists[index], albums[index], genres[index], s], i) # We'll align the track time column to right as well listing.setColumnAlignment('Time', Table.ALIGN_RIGHT) # TODO: the footer # Now what's left to do? Themeing of course. self.setTheme('vaadintunes') # Let's give a namespace to our application window. This way, if # someone uses the same theme for different applications, we don't # get unwanted style conflicts. root.setStyleName('tTunes') top.setStyleName('top') top.setHeight('75px') # Same as the background image height playback.setStyleName('playback') playback.setMargin(False, True, False, False) # Add right-side margin play.setStyleName('play') nextt.setStyleName('next') prev.setStyleName('prev') playback.setComponentAlignment(prev, Alignment.MIDDLE_LEFT) playback.setComponentAlignment(nextt, Alignment.MIDDLE_LEFT) volume.setStyleName('volume') mute.setStyleName('mute') maxx.setStyleName('max') vol.setWidth('78px') status.setStyleName('status') status.setMargin(True) status.setHeight('46px') # Height of the background image toggleVisualization.setStyleName('toggle-vis') jumpToTrack.setStyleName('jump') viewAsTable.setStyleName('viewmode-table') viewAsGrid.setStyleName('viewmode-grid') coverflow.setStyleName('viewmode-coverflow') sidebar.setStyleName('sidebar') music.setStyleName('selected') cover.setSource(ThemeResource('images/album-cover.jpg')) # Because this is an image, it will retain it's aspect ratio cover.setWidth('100%')
class FeatureView(HorizontalLayout): _MSG_SHOW_SRC = 'View Source' def __init__(self): super(FeatureView, self).__init__() self._right = None self._left = None self._controls = None self._title = Label("", Label.CONTENT_XHTML) self._showSrc = None self._exampleCache = dict() self._currentFeature = None self._srcWindow = None self.setWidth('100%') self.setMargin(True) self.setSpacing(True) self.setStyleName('sample-view') self._left = VerticalLayout() self._left.setWidth('100%') self._left.setSpacing(True) self._left.setMargin(False) self.addComponent(self._left) self.setExpandRatio(self._left, 1) rightLayout = VerticalLayout() self._right = Panel(rightLayout) rightLayout.setMargin(True, False, False, False) self._right.setStyleName(Reindeer.PANEL_LIGHT) self._right.addStyleName('feature-info') self._right.setWidth('319px') self.addComponent(self._right) self._controls = HorizontalLayout() self._controls.setWidth('100%') self._controls.setStyleName('feature-controls') self._title.setStyleName('title') self._controls.addComponent(self._title) self._controls.setExpandRatio(self._title, 1) resetExample = NativeButton('Reset', ResetListener(self)) resetExample.setStyleName(BaseTheme.BUTTON_LINK) resetExample.addStyleName('reset') resetExample.setDescription('Reset Sample') self._controls.addComponent(resetExample) self._showSrc = ActiveLink() self._showSrc.setDescription( 'Right / middle / ctrl / shift -click for browser window/tab') self._showSrc.addListener(ShowSrcListener(self), ILinkActivatedListener) self._showSrc.setCaption(self._MSG_SHOW_SRC) self._showSrc.addStyleName('showcode') self._showSrc.setTargetBorder(Link.TARGET_BORDER_NONE) self._controls.addComponent(self._showSrc) def showSource(self, source): if self._srcWindow is None: self._srcWindow = Window('Python source') self._srcWindow.getContent().setSizeUndefined() self._srcWindow.setWidth('70%') self._srcWindow.setHeight('60%') self._srcWindow.setPositionX(100) self._srcWindow.setPositionY(100) self._srcWindow.removeAllComponents() self._srcWindow.addComponent(CodeLabel(source)) if self._srcWindow.getParent() is None: self.getWindow().addWindow(self._srcWindow) def resetExample(self): if self._currentFeature is not None: w = self.getWindow() w.removeSubwindows() f = self._currentFeature self._currentFeature = None if f in self._exampleCache: del self._exampleCache[f] self.setFeature(f) def setFeature(self, feature): from muntjac.demo.sampler.SamplerApplication import SamplerApplication if feature != self._currentFeature: self._currentFeature = feature self._right.removeAllComponents() self._left.removeAllComponents() self._left.addComponent(self._controls) self._title.setValue('<span>' + feature.getName() + '</span>') # if feature.getSinceVersion().isNew(): # self._title.addStyleName('new') # else: # self._title.removeStyleName('new') self._left.addComponent(self.getExampleFor(feature)) self._right.setCaption('Description and Resources') # Do not show parent description if it's directly inside the root alll = SamplerApplication.getAllFeatures() parent = alll.getParent(feature) isRoot = alll.getParent(parent) is None desc = parent.getDescription() hasParentDesc = False if parent is not None and not isRoot: parentLabel = Label(parent.getDescription()) if desc is not None and desc != '': parentLabel.setContentMode(Label.CONTENT_XHTML) self._right.addComponent(parentLabel) hasParentDesc = True desc = feature.getDescription() if desc is not None and desc != '': # Sample description uses additional decorations if a parent # description is found l = Label( ("<div class=\"outer-deco\"><div class=\"deco\">" "<span class=\"deco\"></span>") + desc + "</div></div>", Label.CONTENT_XHTML) self._right.addComponent(l) if hasParentDesc: l.setStyleName('sample-description') else: l.setStyleName('description') # open src in new window -link self._showSrc.setTargetName(self._currentFeature.getFragmentName()) er = ExternalResource(self.getApplication().getURL() + 'src/' + self._currentFeature.getFragmentName()) self._showSrc.setResource(er) resources = feature.getRelatedResources() if resources is not None: res = VerticalLayout() self.caption = Label("<span>Additional Resources</span>", Label.CONTENT_XHTML) self.caption.setStyleName('section') self.caption.setWidth('100%') res.addComponent(self.caption) res.setMargin(False, False, True, False) for r in resources: l = Link(r.getName(), r) l.setIcon(ThemeResource('../runo/icons/16/note.png')) res.addComponent(l) self._right.addComponent(res) apis = feature.getRelatedAPI() if apis is not None: api = VerticalLayout() self.caption = Label("<span>API Documentation</span>", Label.CONTENT_XHTML) self.caption.setStyleName('section') self.caption.setWidth('100%') api.addComponent(self.caption) api.setMargin(False, False, True, False) for r in apis: l = Link(r.getName(), r) ic = ThemeResource('../runo/icons/16/document-txt.png') l.setIcon(ic) api.addComponent(l) self._right.addComponent(api) features = feature.getRelatedFeatures() if features is not None: rel = VerticalLayout() self.caption = Label("<span>Related Samples</span>", Label.CONTENT_XHTML) self.caption.setStyleName('section') self.caption.setWidth('100%') rel.addComponent(self.caption) rel.setMargin(False, False, True, False) for c in features: f = SamplerApplication.getFeatureFor(c) if f is not None: er = ExternalResource(self.getApplication().getURL() + '#' + f.getFragmentName()) al = ActiveLink(f.getName(), er) if isinstance(f, FeatureSet): ic = ThemeResource('../sampler/icons/category.gif') else: ic = ThemeResource('../sampler/icons/sample.png') al.setIcon(ic) al.addListener(LinkListener(self, f), ILinkActivatedListener) rel.addComponent(al) self._right.addComponent(rel) def getExampleFor(self, f): ex = self._exampleCache.get(f) if ex is None: ex = f.getExample() self._exampleCache[f] = ex return ex
def setFeature(self, feature): from muntjac.demo.sampler.SamplerApplication import SamplerApplication if feature != self._currentFeature: self._currentFeature = feature self._right.removeAllComponents() self._left.removeAllComponents() self._left.addComponent(self._controls) self._title.setValue('<span>' + feature.getName() + '</span>') # if feature.getSinceVersion().isNew(): # self._title.addStyleName('new') # else: # self._title.removeStyleName('new') self._left.addComponent(self.getExampleFor(feature)) self._right.setCaption('Description and Resources') # Do not show parent description if it's directly inside the root alll = SamplerApplication.getAllFeatures() parent = alll.getParent(feature) isRoot = alll.getParent(parent) is None desc = parent.getDescription() hasParentDesc = False if parent is not None and not isRoot: parentLabel = Label(parent.getDescription()) if desc is not None and desc != '': parentLabel.setContentMode(Label.CONTENT_XHTML) self._right.addComponent(parentLabel) hasParentDesc = True desc = feature.getDescription() if desc is not None and desc != '': # Sample description uses additional decorations if a parent # description is found l = Label( ("<div class=\"outer-deco\"><div class=\"deco\">" "<span class=\"deco\"></span>") + desc + "</div></div>", Label.CONTENT_XHTML) self._right.addComponent(l) if hasParentDesc: l.setStyleName('sample-description') else: l.setStyleName('description') # open src in new window -link self._showSrc.setTargetName(self._currentFeature.getFragmentName()) er = ExternalResource(self.getApplication().getURL() + 'src/' + self._currentFeature.getFragmentName()) self._showSrc.setResource(er) resources = feature.getRelatedResources() if resources is not None: res = VerticalLayout() self.caption = Label("<span>Additional Resources</span>", Label.CONTENT_XHTML) self.caption.setStyleName('section') self.caption.setWidth('100%') res.addComponent(self.caption) res.setMargin(False, False, True, False) for r in resources: l = Link(r.getName(), r) l.setIcon(ThemeResource('../runo/icons/16/note.png')) res.addComponent(l) self._right.addComponent(res) apis = feature.getRelatedAPI() if apis is not None: api = VerticalLayout() self.caption = Label("<span>API Documentation</span>", Label.CONTENT_XHTML) self.caption.setStyleName('section') self.caption.setWidth('100%') api.addComponent(self.caption) api.setMargin(False, False, True, False) for r in apis: l = Link(r.getName(), r) ic = ThemeResource('../runo/icons/16/document-txt.png') l.setIcon(ic) api.addComponent(l) self._right.addComponent(api) features = feature.getRelatedFeatures() if features is not None: rel = VerticalLayout() self.caption = Label("<span>Related Samples</span>", Label.CONTENT_XHTML) self.caption.setStyleName('section') self.caption.setWidth('100%') rel.addComponent(self.caption) rel.setMargin(False, False, True, False) for c in features: f = SamplerApplication.getFeatureFor(c) if f is not None: er = ExternalResource(self.getApplication().getURL() + '#' + f.getFragmentName()) al = ActiveLink(f.getName(), er) if isinstance(f, FeatureSet): ic = ThemeResource('../sampler/icons/category.gif') else: ic = ThemeResource('../sampler/icons/sample.png') al.setIcon(ic) al.addListener(LinkListener(self, f), ILinkActivatedListener) rel.addComponent(al) self._right.addComponent(rel)
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' )