def __init__(self): super(ExpandingComponentExample, self).__init__() self.setSpacing(True) # Basic scenario: single expanded component layout = HorizontalLayout() layout.setWidth('100%') # make the layout grow with the window size self.addComponent(layout) naturalButton = Button('Natural') naturalButton.setDescription('This button does not have an explicit ' 'size - instead, its size depends on it\'s content - a.k.a ' '<i>natural size.</i>') layout.addComponent(naturalButton) expandedButton = Button('Expanded') expandedButton.setWidth('100%') expandedButton.setDescription('The width of this button is set to ' '100% and expanded, and will thus occupy the space left over ' 'by the other components.') layout.addComponent(expandedButton) layout.setExpandRatio(expandedButton, 1.0) sizedButton = Button('Explicit') sizedButton.setWidth('150px') sizedButton.setDescription('This button is explicitly set to be ' '150 pixels wide.') layout.addComponent(sizedButton) # Ratio example layout = HorizontalLayout() layout.setWidth('100%') # make the layout grow with the window size self.addComponent(layout) naturalButton = Button('Natural') naturalButton.setDescription('This button does not have an explicit ' 'size - instead, its size depends on it\'s content - a.k.a ' '<i>natural size.</i>') layout.addComponent(naturalButton) expandedButton1 = Button('Ratio 1.0') expandedButton1.setWidth('100%') expandedButton1.setDescription('The width of this button is set to ' '100% and expanded with a ratio of 1.0, and will in this ' 'example occupy 1:3 of the leftover space.') layout.addComponent(expandedButton1) layout.setExpandRatio(expandedButton1, 1.0) expandedButton2 = Button('Ratio 2.0') expandedButton2.setWidth('100%') expandedButton2.setDescription('The width of this button is set to ' '100% and expanded with a ratio of 2.0, and will in this ' 'example occupy 2:3 of the leftover space.') layout.addComponent(expandedButton2) layout.setExpandRatio(expandedButton2, 2.0)
def __init__(self): super(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()
class SimpleAddressBook(Application): _fields = [ 'First Name', 'Last Name', 'Company', 'Mobile Phone', 'Work Phone', 'Home Phone', 'Work Email', 'Home Email', 'Street', 'Zip', 'City', 'State', 'Country' ] _visibleCols = ['Last Name', 'First Name', 'Company'] def __init__(self): super(SimpleAddressBook, self).__init__() self._contactList = Table() self._contactEditor = Form() self._bottomLeftCorner = HorizontalLayout() self._contactRemovalButton = None self._addressBookData = self.createDummyData() def init(self): self.initLayout() self.initContactAddRemoveButtons() self.initAddressList() self.initFilteringControls() 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 initContactAddRemoveButtons(self): # New item button newItem = Button('+') newItem.addCallback(onNew, ClickEvent, self) self._bottomLeftCorner.addComponent(newItem) # Remove item button self._contactRemovalButton = Button('-') self._contactRemovalButton.addCallback(onRemove, ClickEvent, self) self._contactRemovalButton.setVisible(False) self._bottomLeftCorner.addComponent(self._contactRemovalButton) def initAddressList(self): self._contactList.setContainerDataSource(self._addressBookData) self._contactList.setVisibleColumns(self._visibleCols) self._contactList.setSelectable(True) self._contactList.setImmediate(True) self._contactList.addCallback(onContactChange, field.ValueChangeEvent, self) return self._visibleCols def initFilteringControls(self): for pn in self._visibleCols: sf = TextField() self._bottomLeftCorner.addComponent(sf) sf.setWidth("100%") sf.setValue(pn) sf.setImmediate(True) self._bottomLeftCorner.setExpandRatio(sf, 1) sf.addCallback(onFilterChange, property.ValueChangeEvent, pn, sf, self) @classmethod def createDummyData(cls): fnames = [ 'Peter', 'Alice', 'Joshua', 'Mike', 'Olivia', 'Nina', 'Alex', 'Rita', 'Dan', 'Umberto', 'Henrik', 'Rene', 'Lisa', 'Marge' ] lnames = [ 'Smith', 'Gordon', 'Simpson', 'Brown', 'Clavel', 'Simons', 'Verne', 'Scott', 'Allison', 'Gates', 'Rowling', 'Barks', 'Ross', 'Schneider', 'Tate' ] ic = IndexedContainer() for p in cls._fields: ic.addContainerProperty(p, str, '') for _ in range(1000): idd = ic.addItem() fname = fnames[int(len(fnames) * random())] ic.getContainerProperty(idd, 'First Name').setValue(fname) lname = lnames[int(len(lnames) * random())] ic.getContainerProperty(idd, 'Last Name').setValue(lname) return ic
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%')
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 SimpleAddressBook(Application): _fields = ['First Name', 'Last Name', 'Company', 'Mobile Phone', 'Work Phone', 'Home Phone', 'Work Email', 'Home Email', 'Street', 'Zip', 'City', 'State', 'Country'] _visibleCols = ['Last Name', 'First Name', 'Company'] def __init__(self): super(SimpleAddressBook, self).__init__() self._contactList = Table() self._contactEditor = Form() self._bottomLeftCorner = HorizontalLayout() self._contactRemovalButton = None self._addressBookData = self.createDummyData() def init(self): self.initLayout() self.initContactAddRemoveButtons() self.initAddressList() self.initFilteringControls() 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 initContactAddRemoveButtons(self): # New item button newItem = Button('+') newItem.addCallback(onNew, ClickEvent, self) self._bottomLeftCorner.addComponent(newItem) # Remove item button self._contactRemovalButton = Button('-') self._contactRemovalButton.addCallback(onRemove, ClickEvent, self) self._contactRemovalButton.setVisible(False) self._bottomLeftCorner.addComponent(self._contactRemovalButton) def initAddressList(self): self._contactList.setContainerDataSource(self._addressBookData) self._contactList.setVisibleColumns(self._visibleCols) self._contactList.setSelectable(True) self._contactList.setImmediate(True) self._contactList.addCallback(onContactChange, field.ValueChangeEvent, self) return self._visibleCols def initFilteringControls(self): for pn in self._visibleCols: sf = TextField() self._bottomLeftCorner.addComponent(sf) sf.setWidth("100%") sf.setValue(pn) sf.setImmediate(True) self._bottomLeftCorner.setExpandRatio(sf, 1) sf.addCallback(onFilterChange, property.ValueChangeEvent, pn, sf, self) @classmethod def createDummyData(cls): fnames = ['Peter', 'Alice', 'Joshua', 'Mike', 'Olivia', 'Nina', 'Alex', 'Rita', 'Dan', 'Umberto', 'Henrik', 'Rene', 'Lisa', 'Marge'] lnames = ['Smith', 'Gordon', 'Simpson', 'Brown', 'Clavel', 'Simons', 'Verne', 'Scott', 'Allison', 'Gates', 'Rowling', 'Barks', 'Ross', 'Schneider', 'Tate'] ic = IndexedContainer() for p in cls._fields: ic.addContainerProperty(p, str, '') for _ in range(1000): idd = ic.addItem() fname = fnames[int( len(fnames) * random() )] ic.getContainerProperty(idd, 'First Name').setValue(fname) lname = lnames[int( len(lnames) * random() )] ic.getContainerProperty(idd, 'Last Name').setValue(lname) return ic
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