class LabelRichExample(VerticalLayout, IClickListener): def __init__(self): super(LabelRichExample, self).__init__() self.setSpacing(True) self._editor = RichTextArea() self._richText = Label('<h1>Rich text example</h1>' '<p>The <b>quick</b> brown fox jumps <sup>over</sup> ' 'the <b>lazy</b> dog.</p>' '<p>This text can be edited with the <i>Edit</i> -button</p>') self._richText.setContentMode(Label.CONTENT_XHTML) self.addComponent(self._richText) self._b = Button('Edit') self._b.addListener(self, IClickListener) self.addComponent(self._b) self._editor.setWidth('100%') def buttonClick(self, event): if self.getComponentIterator().next() == self._richText: self._editor.setValue(self._richText.getValue()) self.replaceComponent(self._richText, self._editor) self._b.setCaption('Apply') else: self._richText.setValue(self._editor.getValue()) self.replaceComponent(self._editor, self._richText) self._b.setCaption('Edit')
class TextAreaExample(HorizontalLayout, IValueChangeListener): _initialText = 'The quick brown fox jumps over the lazy dog.' def __init__(self): super(TextAreaExample, self).__init__() self.setSpacing(True) self.setWidth('100%') self._editor = TextArea(None, self._initialText) self._editor.setRows(20) self._editor.setColumns(20) self._editor.addListener(self, IValueChangeListener) self._editor.setImmediate(True) self.addComponent(self._editor) # the TextArea is immediate, and it's valueCahnge updates the Label, # so this button actually does nothing self.addComponent(Button('>')) self._plainText = Label(self._initialText) self._plainText.setContentMode(Label.CONTENT_XHTML) self.addComponent(self._plainText) self.setExpandRatio(self._plainText, 1) # Catch the valuechange event of the textfield and update the value of the # label component def valueChange(self, event): text = self._editor.getValue() if text is not None: # replace newline with BR, because we're using Label.CONTENT_XHTML text = text.replace('\n', '<br/>') self._plainText.setValue(text)
class LabelRichExample(VerticalLayout, IClickListener): def __init__(self): super(LabelRichExample, self).__init__() self.setSpacing(True) self._editor = RichTextArea() self._richText = Label( '<h1>Rich text example</h1>' '<p>The <b>quick</b> brown fox jumps <sup>over</sup> ' 'the <b>lazy</b> dog.</p>' '<p>This text can be edited with the <i>Edit</i> -button</p>') self._richText.setContentMode(Label.CONTENT_XHTML) self.addComponent(self._richText) self._b = Button('Edit') self._b.addListener(self, IClickListener) self.addComponent(self._b) self._editor.setWidth('100%') def buttonClick(self, event): if self.getComponentIterator().next() == self._richText: self._editor.setValue(self._richText.getValue()) self.replaceComponent(self._richText, self._editor) self._b.setCaption('Apply') else: self._richText.setValue(self._editor.getValue()) self.replaceComponent(self._editor, self._richText) self._b.setCaption('Edit')
def __init__(self): super(LabelPlainExample, self).__init__() self.setSpacing(True) plainText = Label('This is an example of a Label' ' component. The content mode of this label is set' ' to CONTENT_TEXT. This means that it will display' ' the content text as is. HTML and XML special characters' ' (<,>,&) are escaped properly to allow displaying them.') plainText.setContentMode(Label.CONTENT_TEXT) self.addComponent(plainText)
def __init__(self): super(LabelPlainExample, self).__init__() self.setSpacing(True) plainText = Label( 'This is an example of a Label' ' component. The content mode of this label is set' ' to CONTENT_TEXT. This means that it will display' ' the content text as is. HTML and XML special characters' ' (<,>,&) are escaped properly to allow displaying them.') plainText.setContentMode(Label.CONTENT_TEXT) self.addComponent(plainText)
def __init__(self): super(LabelPreformattedExample, self).__init__() self.setSpacing(True) preformattedText = Label('This is an example of a Label component.\n' '\nThe content mode of this label is set' '\nto CONTENT_PREFORMATTED. This means' '\nthat it will display the content text' '\nusing a fixed-width font. You also have' '\nto insert the line breaks yourself.\n' '\n\tHTML and XML special characters' '\n\t(<,>,&) are escaped properly to' '\n\tallow displaying them.') preformattedText.setContentMode(Label.CONTENT_PREFORMATTED) self.addComponent(preformattedText)
def __init__(self): super(LabelPreformattedExample, self).__init__() self.setSpacing(True) preformattedText = Label('This is an example of a Label component.\n' '\nThe content mode of this label is set' '\nto CONTENT_PREFORMATTED. This means' '\nthat it will display the content text' '\nusing a fixed-width font. You also have' '\nto insert the line breaks yourself.\n' '\n\tHTML and XML special characters' '\n\t(<,>,&) are escaped properly to' '\n\tallow displaying them.') preformattedText.setContentMode(Label.CONTENT_PREFORMATTED) self.addComponent(preformattedText)
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()
class MuntjacHtml(MuntjacControl, AbstractTkHtml): """ A Muntjac implementation of Html. """ #-------------------------------------------------------------------------- # Setup methods #-------------------------------------------------------------------------- def create(self, parent): """ Creates the underlying widget to display HTML. """ self.widget = Label() self.widget.setContentMode(Label.CONTENT_XHTML) parent.addComponent(self.widget) def initialize(self): """ Initializes the attributes of the control. """ super(MuntjacHtml, self).initialize() self.set_page_source(self.shell_obj.source) #-------------------------------------------------------------------------- # Implementation #-------------------------------------------------------------------------- def shell_source_changed(self, source): """ The change handler for the 'source' attribute. """ self.set_page_source(source) def set_page_source(self, source): """ Sets the page source for the underlying control. """ self.widget.setValue(source)
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 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)