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)
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 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)
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 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)