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)
class SamplerWindow(Window): """The main window for Sampler, contains the full application UI.""" _TITLE = 'Muntjac Sampler' 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 detach(self): super(SamplerWindow, self).detach() self._search.setContainerDataSource(None) self._navigationTree.setContainerDataSource(None) def removeSubwindows(self): wins = self.getChildWindows() if None is not wins: for w in wins: self.removeWindow(w) def setFeature(self, arg): """Displays a Feature(Set) or displays a Feature(Set) matching the given path, or the main view if no matching Feature(Set) is found. @param arg: Either the Feature(Set) to show or the path of the Feature(Set) to show """ if isinstance(arg, basestring): path = arg f = FeatureSet.FEATURES.getFeature(path) self.setFeature(f) else: f = arg if f == FeatureSet.FEATURES: # "All" is no longer in the tree, use null instead f = None self._currentFeature.setValue(f) fragment = f.getFragmentName() if f is not None else '' # self._webAnalytics.trackPageview(fragment) self._uriFragmentUtility.setFragment(fragment, False) self._breadcrumbs.setPath( self._app.getFullPathFor(f) ) self._previousSample.setEnabled(f is not None) self._nextSample.setEnabled(not self._app._allFeatures.isLastId(f)) self.updateFeatureList(self._currentList) self.setCaption((f.getName() + ': ' if f is not None else '') + self._TITLE) # SamplerWindow helpers def createSearch(self): self._search = ComboBox() self._search.setWidth('160px') self._search.setNewItemsAllowed(False) self._search.setFilteringMode(ComboBox.FILTERINGMODE_CONTAINS) self._search.setNullSelectionAllowed(True) self._search.setImmediate(True) self._search.setInputPrompt('Search samples...') self._search.setContainerDataSource( self._app._allFeatures ) for idd in self._app._allFeatures.getItemIds(): if isinstance(idd, FeatureSet): pass # FIXME: 'SamplerApplication' has no attribute 'getResourceAsStream' # self._search.setItemIcon(idd, # ClassResource('folder.gif', self._app)) self._search.addListener(SearchListener(self), prop.IValueChangeListener) # TODO add icons for section/sample # PopupView pv = new PopupView("", search) { public void # changeVariables(Object source, Map variables) { # super.changeVariables(source, variables); if (isPopupVisible()) { # search.focus(); } } }; pv = PopupView('<span></span>', self._search) pv.addListener(PopupListener(self), IPopupVisibilityListener) pv.setStyleName('quickjump') pv.setDescription('Quick jump') return pv def createThemeSelect(self): self.theme = ComboBox() self.theme.setWidth('32px') self.theme.setNewItemsAllowed(False) self.theme.setFilteringMode(ComboBox.FILTERINGMODE_CONTAINS) self.theme.setImmediate(True) self.theme.setNullSelectionAllowed(False) for themeName in self._app._THEMES: idd = self._app._SAMPLER_THEME_NAME + '-' + themeName self.theme.addItem(idd) self.theme.setItemCaption(idd, themeName[:1].upper() + (themeName[1:]) + ' theme') self.theme.setItemIcon(idd, _EMPTY_THEME_ICON) currentWindowTheme = self.getTheme() self.theme.setValue(currentWindowTheme) self.theme.setItemIcon(currentWindowTheme, _SELECTED_THEME_ICON) self.theme.addListener(ThemeChangeListener(self, self._app), prop.IValueChangeListener) self.theme.setStyleName('theme-select') self.theme.setDescription('Select Theme') return self.theme def createLogo(self): logo = NativeButton('', LogoClickListener(self)) logo.setDescription('Home') logo.setStyleName(BaseTheme.BUTTON_LINK) logo.addStyleName('logo') return logo def createNextButton(self): b = NativeButton('', NextClickListener(self, self._app)) b.setStyleName('next') b.setDescription('Jump to the next sample') return b def createPrevButton(self): b = NativeButton('', PrevClickListener(self, self._app)) b.setEnabled(False) b.setStyleName('previous') b.setDescription('Jump to the previous sample') return b def createTreeSwitch(self): b = NativeButton() b.setStyleName('tree-switch') b.addStyleName('down') b.setDescription('Toggle sample tree visibility') b.addListener(TreeClickListener(self), button.IClickListener) self._mainSplit.setSplitPosition(250, ISizeable.UNITS_PIXELS) return b def createMenuTree(self): tree = Tree() tree.setImmediate(True) tree.setStyleName('menu') tree.setContainerDataSource(self._app._allFeatures) self._currentFeature.addListener(FeatureChangeListener(self, tree), prop.IValueChangeListener) for f in FeatureSet.FEATURES.getFeatures(): tree.expandItemsRecursively(f) tree.expandItemsRecursively(FeatureSet.FEATURES) tree.addListener(TreeChangeListener(self), prop.IValueChangeListener) tree.setItemStyleGenerator(TreeStyleGenerator()) return tree def updateFeatureList(self, lst): self._currentList = lst val = self._currentFeature.getValue() if val is None: self._currentList.setFeatureContainer(self._app._allFeatures) self._mainSplit.setSecondComponent(self._currentList) elif isinstance(val, FeatureSet): self._currentList.setFeatureContainer(val.getContainer(True)) self._mainSplit.setSecondComponent(self._currentList) else: self._mainSplit.setSecondComponent(self._featureView) self._featureView.setFeature(val)
class SamplerWindow(Window): """The main window for Sampler, contains the full application UI.""" _TITLE = 'Muntjac Sampler' 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 detach(self): super(SamplerWindow, self).detach() self._search.setContainerDataSource(None) self._navigationTree.setContainerDataSource(None) def removeSubwindows(self): wins = self.getChildWindows() if None is not wins: for w in wins: self.removeWindow(w) def setFeature(self, arg): """Displays a Feature(Set) or displays a Feature(Set) matching the given path, or the main view if no matching Feature(Set) is found. @param arg: Either the Feature(Set) to show or the path of the Feature(Set) to show """ if isinstance(arg, basestring): path = arg f = FeatureSet.FEATURES.getFeature(path) self.setFeature(f) else: f = arg if f == FeatureSet.FEATURES: # "All" is no longer in the tree, use null instead f = None self._currentFeature.setValue(f) fragment = f.getFragmentName() if f is not None else '' # self._webAnalytics.trackPageview(fragment) self._uriFragmentUtility.setFragment(fragment, False) self._breadcrumbs.setPath(self._app.getFullPathFor(f)) self._previousSample.setEnabled(f is not None) self._nextSample.setEnabled(not self._app._allFeatures.isLastId(f)) self.updateFeatureList(self._currentList) self.setCaption((f.getName() + ': ' if f is not None else '') + self._TITLE) # SamplerWindow helpers def createSearch(self): self._search = ComboBox() self._search.setWidth('160px') self._search.setNewItemsAllowed(False) self._search.setFilteringMode(ComboBox.FILTERINGMODE_CONTAINS) self._search.setNullSelectionAllowed(True) self._search.setImmediate(True) self._search.setInputPrompt('Search samples...') self._search.setContainerDataSource(self._app._allFeatures) for idd in self._app._allFeatures.getItemIds(): if isinstance(idd, FeatureSet): pass # FIXME: 'SamplerApplication' has no attribute 'getResourceAsStream' # self._search.setItemIcon(idd, # ClassResource('folder.gif', self._app)) self._search.addListener(SearchListener(self), prop.IValueChangeListener) # TODO add icons for section/sample # PopupView pv = new PopupView("", search) { public void # changeVariables(Object source, Map variables) { # super.changeVariables(source, variables); if (isPopupVisible()) { # search.focus(); } } }; pv = PopupView('<span></span>', self._search) pv.addListener(PopupListener(self), IPopupVisibilityListener) pv.setStyleName('quickjump') pv.setDescription('Quick jump') return pv def createThemeSelect(self): self.theme = ComboBox() self.theme.setWidth('32px') self.theme.setNewItemsAllowed(False) self.theme.setFilteringMode(ComboBox.FILTERINGMODE_CONTAINS) self.theme.setImmediate(True) self.theme.setNullSelectionAllowed(False) for themeName in self._app._THEMES: idd = self._app._SAMPLER_THEME_NAME + '-' + themeName self.theme.addItem(idd) self.theme.setItemCaption( idd, themeName[:1].upper() + (themeName[1:]) + ' theme') self.theme.setItemIcon(idd, _EMPTY_THEME_ICON) currentWindowTheme = self.getTheme() self.theme.setValue(currentWindowTheme) self.theme.setItemIcon(currentWindowTheme, _SELECTED_THEME_ICON) self.theme.addListener(ThemeChangeListener(self, self._app), prop.IValueChangeListener) self.theme.setStyleName('theme-select') self.theme.setDescription('Select Theme') return self.theme def createLogo(self): logo = NativeButton('', LogoClickListener(self)) logo.setDescription('Home') logo.setStyleName(BaseTheme.BUTTON_LINK) logo.addStyleName('logo') return logo def createNextButton(self): b = NativeButton('', NextClickListener(self, self._app)) b.setStyleName('next') b.setDescription('Jump to the next sample') return b def createPrevButton(self): b = NativeButton('', PrevClickListener(self, self._app)) b.setEnabled(False) b.setStyleName('previous') b.setDescription('Jump to the previous sample') return b def createTreeSwitch(self): b = NativeButton() b.setStyleName('tree-switch') b.addStyleName('down') b.setDescription('Toggle sample tree visibility') b.addListener(TreeClickListener(self), button.IClickListener) self._mainSplit.setSplitPosition(250, ISizeable.UNITS_PIXELS) return b def createMenuTree(self): tree = Tree() tree.setImmediate(True) tree.setStyleName('menu') tree.setContainerDataSource(self._app._allFeatures) self._currentFeature.addListener(FeatureChangeListener(self, tree), prop.IValueChangeListener) for f in FeatureSet.FEATURES.getFeatures(): tree.expandItemsRecursively(f) tree.expandItemsRecursively(FeatureSet.FEATURES) tree.addListener(TreeChangeListener(self), prop.IValueChangeListener) tree.setItemStyleGenerator(TreeStyleGenerator()) return tree def updateFeatureList(self, lst): self._currentList = lst val = self._currentFeature.getValue() if val is None: self._currentList.setFeatureContainer(self._app._allFeatures) self._mainSplit.setSecondComponent(self._currentList) elif isinstance(val, FeatureSet): self._currentList.setFeatureContainer(val.getContainer(True)) self._mainSplit.setSecondComponent(self._currentList) else: self._mainSplit.setSecondComponent(self._featureView) self._featureView.setFeature(val)