class SortableLayout(CustomComponent): def __init__(self, horizontal): super(SortableLayout, self).__init__() self._horizontal = horizontal if horizontal: self._layout = HorizontalLayout() else: self._layout = VerticalLayout() self._dropHandler = ReorderLayoutDropHandler(self._layout) pane = DragAndDropWrapper(self._layout) self.setCompositionRoot(pane) def addComponent(self, component): wrapper = WrappedComponent(component, self._dropHandler) wrapper.setSizeUndefined() if self._horizontal: component.setHeight('100%') wrapper.setHeight('100%') else: component.setWidth('100%') wrapper.setWidth('100%') self._layout.addComponent(wrapper)
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() )
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 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()
def __init__(self, horizontal): super(SortableLayout, self).__init__() self._horizontal = horizontal if horizontal: self._layout = HorizontalLayout() else: self._layout = VerticalLayout() self._dropHandler = ReorderLayoutDropHandler(self._layout) pane = DragAndDropWrapper(self._layout) self.setCompositionRoot(pane)
def __init__(self): super(PlotWindow, self).__init__() self.mainLayout = VerticalLayout() self.setContent(self.mainLayout) self.setCaption('Basic Example') infoBar = HorizontalLayout() self.mainLayout.addComponent(infoBar) infoBar.setHeight('50px') infoBar.setWidth('100%') self.showPlot()
def __init__(self): super(WebLayoutWindow, self).__init__() # Our main layout is a horizontal layout main = HorizontalLayout() main.setMargin(True) main.setSpacing(True) self.setContent(main) # Tree to the left tree = Tree() tree.setContainerDataSource(ExampleUtil.getHardwareContainer()) tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME) for idd in tree.rootItemIds(): tree.expandItemsRecursively(idd) self.addComponent(tree) # vertically divide the right area left = VerticalLayout() left.setSpacing(True) self.addComponent(left) # table on top tbl = Table() tbl.setWidth('500px') tbl.setContainerDataSource(ExampleUtil.getISO3166Container()) tbl.setSortDisabled(True) tbl.setPageLength(7) left.addComponent(tbl) # Label on bottom text = Label(ExampleUtil.lorem, Label.CONTENT_XHTML) text.setWidth('500px') # some limit is good for text left.addComponent(text)
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 initLayout(self): splitPanel = HorizontalSplitPanel() self.setMainWindow(Window('Address Book', splitPanel)) left = VerticalLayout() left.setSizeFull() left.addComponent(self._contactList) self._contactList.setSizeFull() left.setExpandRatio(self._contactList, 1) splitPanel.addComponent(left) splitPanel.addComponent(self._contactEditor) self._contactEditor.setSizeFull() self._contactEditor.getLayout().setMargin(True) self._contactEditor.setImmediate(True) self._bottomLeftCorner.setWidth('100%') left.addComponent(self._bottomLeftCorner)
def __init__(self): super(ApplicationLayoutWindow, self).__init__() # Our main layout is a horizontal layout main = HorizontalLayout() main.setSizeFull() self.setContent(main) # Tree to the left treePanel = Panel() # for scrollbars treePanel.setStyleName(Reindeer.PANEL_LIGHT) treePanel.setHeight('100%') treePanel.setWidth(None) treePanel.getContent().setSizeUndefined() self.addComponent(treePanel) tree = Tree() tree.setContainerDataSource(ExampleUtil.getHardwareContainer()) tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME) for idd in tree.rootItemIds(): tree.expandItemsRecursively(idd) treePanel.addComponent(tree) # vertically divide the right area left = VerticalLayout() left.setSizeFull() self.addComponent(left) main.setExpandRatio(left, 1.0) # use all available space # table on top tbl = Table() tbl.setWidth('100%') tbl.setContainerDataSource(ExampleUtil.getISO3166Container()) tbl.setSortDisabled(True) tbl.setPageLength(7) left.addComponent(tbl) # Label on bottom textPanel = Panel() # for scrollbars textPanel.setStyleName(Reindeer.PANEL_LIGHT) textPanel.setSizeFull() left.addComponent(textPanel) left.setExpandRatio(textPanel, 1.0) # use all available space text = Label(ExampleUtil.lorem, Label.CONTENT_XHTML) text.setWidth('500px') # some limit is good for text textPanel.addComponent(text)
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 splitRecursive(self, deep): l = None if self._core: l = VerticalLayout() if self._vertical else HorizontalLayout() else: if self._vertical: l = WeeLayout(Direction.VERTICAL) else: l = WeeLayout(Direction.HORIZONTAL) l.setSizeFull() if self._core: c = l b = NativeButton('One') b.setSizeFull() c.addComponent(b) c.setExpandRatio(b, 1) if deep > 0: deep -= 1 c2 = self.splitRecursive(deep) c.addComponent(c2) c.setExpandRatio(c2, 9) else: wl = l wl.setClipping(True) b = NativeButton('Button') b.setSizeFull() if self._vertical: b.setHeight('10%') else: b.setWidth('10%') l.addComponent(b) if deep > 0: deep -= 1 w = self.splitRecursive(deep) if self._vertical: w.setHeight('90%') else: w.setWidth('90%') l.addComponent(w) else: b.setSizeFull() return l
def __init__(self): super(WebLayoutWindow, self).__init__() # Our main layout is a horizontal layout main = HorizontalLayout() main.setMargin(True) main.setSpacing(True) self.setContent(main) # Tree to the left tree = Tree() tree.setContainerDataSource( ExampleUtil.getHardwareContainer() ) tree.setItemCaptionPropertyId( ExampleUtil.hw_PROPERTY_NAME ) for idd in tree.rootItemIds(): tree.expandItemsRecursively(idd) self.addComponent(tree) # vertically divide the right area left = VerticalLayout() left.setSpacing(True) self.addComponent(left) # table on top tbl = Table() tbl.setWidth('500px') tbl.setContainerDataSource( ExampleUtil.getISO3166Container() ) tbl.setSortDisabled(True) tbl.setPageLength(7) left.addComponent(tbl) # Label on bottom text = Label(ExampleUtil.lorem, Label.CONTENT_XHTML) text.setWidth('500px') # some limit is good for text left.addComponent(text)
def initLayout(self): splitPanel = HorizontalSplitPanel() self.setMainWindow(Window('Address Book', splitPanel)) left = VerticalLayout() left.setSizeFull() left.addComponent(self._contactList) self._contactList.setSizeFull() left.setExpandRatio(self._contactList, 1) splitPanel.addComponent(left) splitPanel.addComponent(self._contactEditor) self._contactEditor.setSizeFull() self._contactEditor.getLayout().setMargin(True) self._contactEditor.setImmediate(True) self._bottomLeftCorner.setWidth('100%') left.addComponent(self._bottomLeftCorner)
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 __init__(self): super(ApplicationLayoutWindow, self).__init__() # Our main layout is a horizontal layout main = HorizontalLayout() main.setSizeFull() self.setContent(main) # Tree to the left treePanel = Panel() # for scrollbars treePanel.setStyleName(Reindeer.PANEL_LIGHT) treePanel.setHeight('100%') treePanel.setWidth(None) treePanel.getContent().setSizeUndefined() self.addComponent(treePanel) tree = Tree() tree.setContainerDataSource(ExampleUtil.getHardwareContainer()) tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME) for idd in tree.rootItemIds(): tree.expandItemsRecursively(idd) treePanel.addComponent(tree) # vertically divide the right area left = VerticalLayout() left.setSizeFull() self.addComponent(left) main.setExpandRatio(left, 1.0) # use all available space # table on top tbl = Table() tbl.setWidth('100%') tbl.setContainerDataSource(ExampleUtil.getISO3166Container()) tbl.setSortDisabled(True) tbl.setPageLength(7) left.addComponent(tbl) # Label on bottom textPanel = Panel() # for scrollbars textPanel.setStyleName(Reindeer.PANEL_LIGHT) textPanel.setSizeFull() left.addComponent(textPanel) left.setExpandRatio(textPanel, 1.0) # use all available space text = Label(ExampleUtil.lorem, Label.CONTENT_XHTML) text.setWidth('500px') # some limit is good for text textPanel.addComponent(text)
def splitRecursive(self, deep): l = None if self._core: l = VerticalLayout() if self._vertical else HorizontalLayout() else: if self._vertical: l = WeeLayout(Direction.VERTICAL) else: l = WeeLayout(Direction.HORIZONTAL) l.setSizeFull() if self._core: c = l b = NativeButton('One') b.setSizeFull() c.addComponent(b) c.setExpandRatio(b, 1) if deep > 0: deep -= 1 c2 = self.splitRecursive(deep) c.addComponent(c2) c.setExpandRatio(c2, 9) else: wl = l wl.setClipping(True) b = NativeButton('Button') b.setSizeFull() if self._vertical: b.setHeight('10%') else: b.setWidth('10%') l.addComponent(b) if deep > 0: deep -= 1 w = self.splitRecursive(deep) if self._vertical: w.setHeight('90%') else: w.setWidth('90%') l.addComponent(w) else: b.setSizeFull() return l
def createComponents(self): components = list() label = Label('This is a long text block that will wrap.') label.setWidth('120px') components.append(label) image = Embedded('', ThemeResource('../runo/icons/64/document.png')) components.append(image) documentLayout = CssLayout() documentLayout.setWidth('19px') for _ in range(5): e = Embedded(None, ThemeResource('../runo/icons/16/document.png')) e.setHeight('16px') e.setWidth('16px') documentLayout.addComponent(e) components.append(documentLayout) buttonLayout = VerticalLayout() button = Button('Button') button.addListener(ButtonClickListener(self), IClickListener) buttonLayout.addComponent(button) buttonLayout.setComponentAlignment(button, Alignment.MIDDLE_CENTER) components.append(buttonLayout) return components
def __init__(self): super(PlotWindow, self).__init__() self.mainLayout = VerticalLayout() self.setContent(self.mainLayout) self.setCaption('Basic Example') infoBar = HorizontalLayout() self.mainLayout.addComponent(infoBar) infoBar.setHeight('50px') infoBar.setWidth('100%') self.showPlot()
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 _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))
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)
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 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, 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 __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 __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)
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)
class PlotWindow(Window): _TREE_ITEM_CAPTION_PROP_ID = 'PlotChartWindow' _SEPARATOR = '|' def __init__(self): super(PlotWindow, self).__init__() self.mainLayout = VerticalLayout() self.setContent(self.mainLayout) self.setCaption('Basic Example') infoBar = HorizontalLayout() self.mainLayout.addComponent(infoBar) infoBar.setHeight('50px') infoBar.setWidth('100%') self.showPlot() @classmethod def getPoints(cls, series, values): if len(values) > 0 and isinstance(values[0], (float, int)): points = OrderedSet() for value in values: points.add(DecimalPoint(series, value)) return points else: points = OrderedSet() for value in values: y = None if len(value) == 0: continue if len(value) == 2: x = value[0] y = value[1] else: x = value[0] points.add(DecimalPoint(series, x, y)) return points def showPlot(self): chartConfig = InvientChartsConfig() chartConfig.getGeneralChartConfig().setType(SeriesType.LINE) chartConfig.getGeneralChartConfig().setZoomType(ZoomType.XY) chartConfig.getTitle().setText('Invient Test') chartConfig.getSubtitle().setText('Numpy Random') xAxis = NumberXAxis() xAxis.setTitle(AxisTitle('Data #')) xAxis.setStartOnTick(True) xAxis.setEndOnTick(True) xAxis.setShowLastLabel(True) xAxesSet = set() xAxesSet.add(xAxis) chartConfig.setXAxes(xAxesSet) yAxis = NumberYAxis() yAxis.setTitle(AxisTitle('Value')) yAxesSet = set() yAxesSet.add(yAxis) chartConfig.setYAxes(yAxesSet) legend = Legend() legend.setLayout(Layout.VERTICAL) legendPos = Position() legendPos.setAlign(HorzAlign.LEFT) legendPos.setVertAlign(VertAlign.TOP) legendPos.setX(100) legendPos.setY(70) legend.setPosition(legendPos) legend.setFloating(True) legend.setBorderWidth(1) legend.setBackgroundColor(RGB(255, 255, 255)) chartConfig.setLegend(legend) plotCfg = LineConfig() marker = SymbolMarker(False) plotCfg.setMarker(marker) plotCfg.setColor(RGBA(223, 83, 83, 0.5)) plotCfg.setAllowPointSelect(False) plotCfg.setEnableMouseTracking( False) # Controls whether or not you can highlight a dataset plotCfg.setAnimation(False) chartConfig.addSeriesConfig(plotCfg) series = XYSeries('Set 1', plotCfg) series.setSeriesPoints(self.setData(series)) chart = InvientCharts(chartConfig) chart.addSeries(series) self.addChart(chart) def setData(self, series): return self.getPoints(series, N.random.rand(250)) def addChart(self, chart, isPrepend=False, isRegisterEvents=True, isRegisterSVGEvent=True, isSetHeight=True): chart.setSizeFull() chart.setStyleName('v-chart-min-width') if isSetHeight: chart.setHeight('410px') self.mainLayout.removeAllComponents() # Add chart self.mainLayout.addComponent(chart)
def createCoreVertical(self, recurse): """Same with core layouts""" l = VerticalLayout() l.setSizeFull() tf = TextField('Left') l.addComponent(tf) l.setComponentAlignment(tf, Alignment.TOP_LEFT) tf = TextField('Center') l.addComponent(tf) l.setComponentAlignment(tf, Alignment.TOP_CENTER) tf = TextField('Right') l.addComponent(tf) tf.setWidth('50%') l.setComponentAlignment(tf, Alignment.TOP_RIGHT) if recurse > 0: recurse -= 1 createCoreHorizontal = self.createCoreHorizontal(recurse) l.addComponent(createCoreHorizontal) l.setExpandRatio(createCoreHorizontal, 1) return l
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 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 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, ui, parent, is_subpanel): """Initialise the object. """ self.ui = ui history = ui.history view = ui.view # Reset any existing history listeners. if history is not None: history.on_trait_change(self._on_undoable, 'undoable', remove=True) history.on_trait_change(self._on_redoable, 'redoable', remove=True) history.on_trait_change(self._on_revertable, 'undoable', remove=True) # Determine if we need any buttons or an 'undo' history. buttons = [self.coerce_button(button) for button in view.buttons] nr_buttons = len(buttons) has_buttons = (not is_subpanel and (nr_buttons != 1 or not self.is_button(buttons[0], ''))) if nr_buttons == 0: if view.undo: self.check_button(buttons, UndoButton) if view.revert: self.check_button(buttons, RevertButton) if view.help: self.check_button(buttons, HelpButton) if not is_subpanel and (history is None): for button in buttons: if (self.is_button(button, 'Undo') or self.is_button(button, 'Revert')): history = ui.history = UndoHistory() break # Create the panel. self.control = panel(ui) # Suppress the title if this is a subpanel or if we think it should be # superceded by the title of an "outer" widget (eg. a dock widget). title = view.title if (is_subpanel or (isinstance(parent, Window) and not isinstance(parent.getParent(), Window)) or isinstance(parent, TabSheet)): title = "" if title != "" or has_buttons: layout = VerticalLayout() # Handle any view title. if title != "": layout.addWidget(heading_text(None, text=view.title).control) layout.addComponent(self.control) self.control = layout # Add any buttons. if has_buttons: # Add the special function buttons bbox = HorizontalLayout() for button in buttons: if self.is_button(button, 'Undo'): self.undo = self.add_button(button, bbox, self._on_undo, False, 'Undo') self.redo = self.add_button(button, bbox, self._on_redo, False, 'Redo') history.on_trait_change(self._on_undoable, 'undoable', dispatch = 'ui') history.on_trait_change(self._on_redoable, 'redoable', dispatch = 'ui') elif self.is_button(button, 'Revert'): self.revert = self.add_button(button, bbox, self._on_revert, False) history.on_trait_change(self._on_revertable, 'undoable', dispatch = 'ui') elif self.is_button(button, 'Help'): self.add_button(button, bbox, self._on_help) elif not self.is_button(button, ''): self.add_button(button, bbox) layout.addComponent(bbox)
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 __init__(self): super(TabSheetScrollingExample, 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') self._t.addTab(l1, 'Saved actions', self._icon1) self._t.addTab(l2, 'Notes', self._icon2) self._t.addTab(l3, 'Issues', self._icon3) self._t.addTab(l4, 'Comments', self._icon2) self._t.addTab(l5, 'Feedback', self._icon2) self._t.addListener(self, ISelectedTabChangeListener) self.addComponent(self._t)
def __init__(self, app): super(SamplerWindow, self).__init__() self._app = app self._currentList = FeatureGrid(self._app) self._featureView = FeatureView() self._currentFeature = ObjectProperty(None, Feature) self._mainSplit = None self._navigationTree = None # self._webAnalytics = GoogleAnalytics('UA-658457-6', 'none') # "backbutton" self._uriFragmentUtility = UriFragmentUtility() # breadcrumbs self._breadcrumbs = BreadCrumbs(self) self._previousSample = None self._nextSample = None self._search = None self.theme = None # Main top/expanded-bottom layout mainExpand = VerticalLayout() self.setContent(mainExpand) self.setSizeFull() mainExpand.setSizeFull() self.setCaption(self._TITLE) self.setTheme(self._app._currentApplicationTheme) # topbar (navigation) nav = HorizontalLayout() mainExpand.addComponent(nav) nav.setHeight('44px') nav.setWidth('100%') nav.setStyleName('topbar') nav.setSpacing(True) nav.setMargin(False, True, False, False) # Upper left logo logo = self.createLogo() nav.addComponent(logo) nav.setComponentAlignment(logo, Alignment.MIDDLE_LEFT) # Breadcrumbs nav.addComponent(self._breadcrumbs) nav.setExpandRatio(self._breadcrumbs, 1) nav.setComponentAlignment(self._breadcrumbs, Alignment.MIDDLE_LEFT) # invisible analytics -component # nav.addComponent(self._webAnalytics) # "backbutton" nav.addComponent(self._uriFragmentUtility) self._uriFragmentUtility.addListener(UriListener(self), IFragmentChangedListener) # Main left/right split; hidden menu tree self._mainSplit = HorizontalSplitPanel() self._mainSplit.setSizeFull() self._mainSplit.setStyleName('main-split') mainExpand.addComponent(self._mainSplit) mainExpand.setExpandRatio(self._mainSplit, 1) # Select theme themeSelect = self.createThemeSelect() nav.addComponent(themeSelect) nav.setComponentAlignment(themeSelect, Alignment.MIDDLE_LEFT) # Layouts for top area buttons quicknav = HorizontalLayout() arrows = HorizontalLayout() nav.addComponent(quicknav) nav.addComponent(arrows) nav.setComponentAlignment(quicknav, Alignment.MIDDLE_LEFT) nav.setComponentAlignment(arrows, Alignment.MIDDLE_LEFT) quicknav.setStyleName('segment') arrows.setStyleName('segment') # Previous sample self._previousSample = self.createPrevButton() arrows.addComponent(self._previousSample) # Next sample self._nextSample = self.createNextButton() arrows.addComponent(self._nextSample) # "Search" combobox searchComponent = self.createSearch() quicknav.addComponent(searchComponent) # Menu tree, initially shown menuLayout = CssLayout() allSamples = ActiveLink('All Samples', ExternalResource('#')) menuLayout.addComponent(allSamples) self._navigationTree = self.createMenuTree() menuLayout.addComponent(self._navigationTree) self._mainSplit.setFirstComponent(menuLayout) # Show / hide tree treeSwitch = self.createTreeSwitch() quicknav.addComponent(treeSwitch) self.addListener(WindowCloseListener(self, self._app), window.ICloseListener) self.updateFeatureList(self._currentList)
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): 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 createCoreVertical(self, recurse): """Same with core layouts""" l = VerticalLayout() l.setSizeFull() tf = TextField('Left') l.addComponent(tf) l.setComponentAlignment(tf, Alignment.TOP_LEFT) tf = TextField('Center') l.addComponent(tf) l.setComponentAlignment(tf, Alignment.TOP_CENTER) tf = TextField('Right') l.addComponent(tf) tf.setWidth('50%') l.setComponentAlignment(tf, Alignment.TOP_RIGHT) if recurse > 0: recurse -= 1 createCoreHorizontal = self.createCoreHorizontal(recurse) l.addComponent(createCoreHorizontal) l.setExpandRatio(createCoreHorizontal, 1) return l
def __init__(self, app): super(SamplerWindow, self).__init__() self._app = app self._currentList = FeatureGrid(self._app) self._featureView = FeatureView() self._currentFeature = ObjectProperty(None, Feature) self._mainSplit = None self._navigationTree = None # self._webAnalytics = GoogleAnalytics('UA-658457-6', 'none') # "backbutton" self._uriFragmentUtility = UriFragmentUtility() # breadcrumbs self._breadcrumbs = BreadCrumbs(self) self._previousSample = None self._nextSample = None self._search = None self.theme = None # Main top/expanded-bottom layout mainExpand = VerticalLayout() self.setContent(mainExpand) self.setSizeFull() mainExpand.setSizeFull() self.setCaption(self._TITLE) self.setTheme(self._app._currentApplicationTheme) # topbar (navigation) nav = HorizontalLayout() mainExpand.addComponent(nav) nav.setHeight('44px') nav.setWidth('100%') nav.setStyleName('topbar') nav.setSpacing(True) nav.setMargin(False, True, False, False) # Upper left logo logo = self.createLogo() nav.addComponent(logo) nav.setComponentAlignment(logo, Alignment.MIDDLE_LEFT) # Breadcrumbs nav.addComponent(self._breadcrumbs) nav.setExpandRatio(self._breadcrumbs, 1) nav.setComponentAlignment(self._breadcrumbs, Alignment.MIDDLE_LEFT) # invisible analytics -component # nav.addComponent(self._webAnalytics) # "backbutton" nav.addComponent(self._uriFragmentUtility) self._uriFragmentUtility.addListener(UriListener(self), IFragmentChangedListener) # Main left/right split; hidden menu tree self._mainSplit = HorizontalSplitPanel() self._mainSplit.setSizeFull() self._mainSplit.setStyleName('main-split') mainExpand.addComponent(self._mainSplit) mainExpand.setExpandRatio(self._mainSplit, 1) # Select theme themeSelect = self.createThemeSelect() nav.addComponent(themeSelect) nav.setComponentAlignment(themeSelect, Alignment.MIDDLE_LEFT) # Layouts for top area buttons quicknav = HorizontalLayout() arrows = HorizontalLayout() nav.addComponent(quicknav) nav.addComponent(arrows) nav.setComponentAlignment(quicknav, Alignment.MIDDLE_LEFT) nav.setComponentAlignment(arrows, Alignment.MIDDLE_LEFT) quicknav.setStyleName('segment') arrows.setStyleName('segment') # Previous sample self._previousSample = self.createPrevButton() arrows.addComponent(self._previousSample) # Next sample self._nextSample = self.createNextButton() arrows.addComponent(self._nextSample) # "Search" combobox searchComponent = self.createSearch() quicknav.addComponent(searchComponent) # Menu tree, initially shown menuLayout = CssLayout() allSamples = ActiveLink('All Samples', ExternalResource('#')) menuLayout.addComponent(allSamples) self._navigationTree = self.createMenuTree() menuLayout.addComponent(self._navigationTree) self._mainSplit.setFirstComponent(menuLayout) # Show / hide tree treeSwitch = self.createTreeSwitch() quicknav.addComponent(treeSwitch) self.addListener(WindowCloseListener(self, self._app), window.ICloseListener) self.updateFeatureList(self._currentList)
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%')
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
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
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 __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)