def __init__(self): super(SubwindowAutoSizedExample, self).__init__() # Create the window self._subwindow = Window('Automatically sized subwindow') # Configure the windws layout; by default a VerticalLayout layout = self._subwindow.getContent() layout.setMargin(True) layout.setSpacing(True) # make it undefined for auto-sizing window layout.setSizeUndefined() # Add some content; for _ in range(7): tf = TextField() tf.setWidth('400px') self._subwindow.addComponent(tf) close = Button('Close', CloseListener(self)) # The components added to the window are actually added to the window's # layout; you can use either. Alignments are set using the layout layout.addComponent(close) layout.setComponentAlignment(close, Alignment.BOTTOM_RIGHT) # Add a button for opening the subwindow opn = Button('Open sized window', OpenListener(self)) self.addComponent(opn)
class SubwindowAutoSizedExample(VerticalLayout): def __init__(self): super(SubwindowAutoSizedExample, self).__init__() # Create the window self._subwindow = Window('Automatically sized subwindow') # Configure the windws layout; by default a VerticalLayout layout = self._subwindow.getContent() layout.setMargin(True) layout.setSpacing(True) # make it undefined for auto-sizing window layout.setSizeUndefined() # Add some content; for _ in range(7): tf = TextField() tf.setWidth('400px') self._subwindow.addComponent(tf) close = Button('Close', CloseListener(self)) # The components added to the window are actually added to the window's # layout; you can use either. Alignments are set using the layout layout.addComponent(close) layout.setComponentAlignment(close, Alignment.BOTTOM_RIGHT) # Add a button for opening the subwindow opn = Button('Open sized window', OpenListener(self)) self.addComponent(opn)
def __init__(self): super(SubwindowExample, self).__init__() # Create the window self._subwindow = Window('A subwindow') # Configure the windows layout; by default a VerticalLayout layout = self._subwindow.getContent() layout.setMargin(True) layout.setSpacing(True) # Add some content; a label and a close-button message = Label('This is a subwindow') self._subwindow.addComponent(message) close = Button('Close', CloseListener(self)) # The components added to the window are actually added to the window's # layout; you can use either. Alignments are set using the layout layout.addComponent(close) layout.setComponentAlignment(close, Alignment.TOP_RIGHT) # Add a button for opening the subwindow opn = Button('Open subwindow', OpenListener(self)) self.addComponent(opn)
class SubwindowCloseExample(VerticalLayout): _openWindowText = 'Open a window' _closeWindowText = 'Close the window' def __init__(self): super(SubwindowCloseExample, self).__init__() self._closableWindow = CheckBox('Allow user to close the window', True) self._closableWindow.setImmediate(True) self._closableWindow.addListener(ClosableChangeListener(self), IValueChangeListener) # Create the window self._subwindow = Window('A subwindow w/ close-listener') self._subwindow.addListener(CloseListener(self), ICloseListener) # Configure the windws layout; by default a VerticalLayout layout = self._subwindow.getContent() layout.setMargin(True) layout.setSpacing(True) # Add some content; a label and a close-button message = Label('This is a subwindow with a close-listener.') self._subwindow.addComponent(message) # Add a button for opening the subwindow self._openCloseButton = Button("Open window", ClickListener(self)) self.setSpacing(True) self.addComponent(self._closableWindow) self.addComponent(self._openCloseButton)
def create(self, parent): """ Creates the underlying Window control. """ # self.widget = MResizingDialog(parent) self.widget = Window() parent.addComponent(self.widget)
class SubwindowModalExample(VerticalLayout): def __init__(self): super(SubwindowModalExample, self).__init__() # Create the window... self._subwindow = Window('A modal subwindow') # ...and make it modal self._subwindow.setModal(True) # Configure the windws layout; by default a VerticalLayout layout = self._subwindow.getContent() layout.setMargin(True) layout.setSpacing(True) # Add some content; a label and a close-button message = Label('This is a modal subwindow.') self._subwindow.addComponent(message) close = Button('Close', CloseListener(self)) # The components added to the window are actually added to the window's # layout; you can use either. Alignments are set using the layout layout.addComponent(close) layout.setComponentAlignment(close, Alignment.TOP_RIGHT) # Add a button for opening the subwindow opn = Button('Open modal window', OpenListener(self)) self.addComponent(opn)
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 init(self): """Init is invoked on application load (when a user accesses the application for the first time). """ # Main window is the primary browser window main = Window('Hello window') self.setMainWindow(main) # "Hello world" text is added to window as a Label component main.addComponent(Label('Hello World!'))
def init(self): """Init is invoked on application load (when a user accesses the application for the first time). """ # Main window is the primary browser window main = Window('Hello window') self.setMainWindow(main) # "Hello world" text is added to window as a Label component main.addComponent( Label('Hello World!') )
def create(self, parent): """ Creates the underlying Muntjac widget. """ # self.widget = MResizingFrame(parent) self.widget = Window() if parent is not None: parent.addComponent(self.widget) else: app = SingletonApplication.get() mw = app.getMainWindow() mw.addWindow(self.widget)
def init(self): mainWindow = Window("Color Picker Demo Application") label = Label("Hello Muntjac user") mainWindow.addComponent(label) self.setMainWindow(mainWindow) # Create the color picker cp = ColorPicker("Our ColorPicker", Color.RED) mainWindow.addComponent(cp) # Set the button caption cp.setButtonCaption("Our color")
def init(self): mainWindow = Window('Weelayout Application') self.setMainWindow(mainWindow) # mainWindow.setContent(self.splitRecursive(2)) # mainWindow.setContent(self.undefinedWithRelativeSizes()) # mainWindow.setContent(self.splitView()) # mainWindow.setContent(self.createVertical(2)) # mainWindow.setContent(self.createCoreVertical(2)) # mainWindow.setContent(self.createHorizontal(2)) mainWindow.setContent(self.createCoreHorizontal(2)) self.setTheme('test')
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 init(self): self.setMainWindow(Window(self.__class__.__name__)) canvas = Canvas() canvas.setWidth('400px') canvas.setHeight('400px') # Draw some shapes to the canvas canvas.saveContext() canvas.clear() canvas.translate(175, 175) canvas.scale(1.6, 1.6) for i in range(1, 6): canvas.saveContext() canvas.setFillStyle('rgb(%d,%d,255)' % (51 * i, 255 - (51 * i))) for _ in range(i * 6): canvas.rotate((math.pi * 2) / (i * 6)) canvas.beginPath() canvas.arc(0, i * 12.5, 5, 0, math.pi * 2, True) canvas.fill() canvas.restoreContext() canvas.restoreContext() canvas.drawImage( 'http://www.google.ru/intl/en_com/images/srpr/logo1w.png', 10, 10) self.getMainWindow().addComponent(canvas)
def __init__(self): super(SubwindowSizedExample, self).__init__() # Create the window self._subwindow = Window('A sized subwindow') self._subwindow.setWidth('500px') self._subwindow.setHeight('80%') # Configure the windws layout; by default a VerticalLayout layout = self._subwindow.getContent() layout.setMargin(True) layout.setSpacing(True) # make it fill the whole window layout.setSizeFull() # Add some content; a label and a close-button message = Label('This is a sized window') self._subwindow.addComponent(message) close = Button('Close', CloseListener(self)) # The components added to the window are actually added to the window's # layout; you can use either. Alignments are set using the layout layout.addComponent(close) layout.setComponentAlignment(close, Alignment.BOTTOM_RIGHT) # Add a button for opening the subwindow opn = Button('Open sized window', OpenListener(self)) self.addComponent(opn)
def init(self): # Application.init is called once for each application. Here it # creates the UI and connects it to the business logic. # Create the main layout for our application (4 columns, 5 rows) layout = GridLayout(4, 5) # Create the main window for the application using the main layout. # The main window is shown when the application is starts. self.setMainWindow(Window('Calculator Application', layout)) # Create a result label that over all 4 columns in the first row layout.addComponent(self._display, 0, 0, 3, 0) # The operations for the calculator in the order they appear on the # screen (left to right, top to bottom) operations = ['7', '8', '9', '/', '4', '5', '6', '*', '1', '2', '3', '-', '0', '=', 'C', '+'] for caption in operations: # Create a button and use this application for event handling button = Button(caption) button.addListener(self) # Add the button to our main layout layout.addComponent(button)
def buttonClick(self, event): app = self._app #event.getButton().getApplication() map2 = GoogleMap(app, (22.3, 60.4522), 8) map2.setHeight('240px') map2.setWidth('240px') w = Window('popup') w.addComponent(map2) w.setHeight('300px') w.setWidth('300px') app.getMainWindow().addWindow(w)
def __init__(self): super(SubwindowPositionedExample, self).__init__() self.setSpacing(True) # Create the window self._subwindow = Window('A positioned subwindow') # let's give it a size (optional) self._subwindow.setWidth('300px') self._subwindow.setHeight('200px') # Configure the windows layout; by default a VerticalLayout layout = self._subwindow.getContent() layout.setMargin(True) layout.setSpacing(True) # make it fill the whole window layout.setSizeFull() # Add some content; a label and a close-button message = Label('This is a positioned window') self._subwindow.addComponent(message) close = Button('Close', CloseListener(self)) # The components added to the window are actually added to the window's # layout; you can use either. Alignments are set using the layout layout.addComponent(close) layout.setComponentAlignment(close, Alignment.BOTTOM_RIGHT) # Add buttons for opening the subwindow fifty = Button('Open window at position 50x50', OpenListener50(self)) self.addComponent(fifty) onefifty = Button('Open window at position 150x200', OpenListener150(self)) self.addComponent(onefifty) center = Button('Open centered window', CenterListener(self)) self.addComponent(center)
def init(self): # super(GoogleMapWidgetApp, self).__init__() self.setMainWindow(Window('Google Map add-on demo')) # Create a new map instance centered on the IT Mill offices self._googleMap = GoogleMap(self, (22.3, 60.4522), 8) self._googleMap.setWidth('640px') self._googleMap.setHeight('480px') # Create a marker at the IT Mill offices self._mark1 = BasicMarker(1L, (22.3, 60.4522), 'Test marker 1') self._mark2 = BasicMarker(2L, (22.4, 60.4522), 'Test marker 2') self._mark3 = BasicMarker(4L, (22.6, 60.4522), 'Test marker 3') self._mark4 = BasicMarker(5L, (22.7, 60.4522), 'Test marker 4') l = MarkerClickListener(self) self._googleMap.addListener(l, IMarkerClickListener) # Marker with information window pupup self._mark5 = BasicMarker(6L, (22.8, 60.4522), 'Marker 5') self._mark5.setInfoWindowContent(self._googleMap, Label('Hello Marker 5!')) content = Label('Hello Marker 2!') content.setWidth('60px') self._mark2.setInfoWindowContent(self._googleMap, content) self._googleMap.addMarker(self._mark1) self._googleMap.addMarker(self._mark2) self._googleMap.addMarker(self._mark3) self._googleMap.addMarker(self._mark4) self._googleMap.addMarker(self._mark5) self.getMainWindow().getContent().addComponent(self._googleMap) # Add a Marker click listener to catch marker click events. # Note, works only if marker has information window content l = MarkerClickListener2(self) self._googleMap.addListener(l, IMarkerClickListener) # Add a MarkerMovedListener to catch events when a marker is dragged to # a new location l = MarkerMovedListener(self) self._googleMap.addListener(l, IMarkerMovedListener) l = MapMoveListener(self) self._googleMap.addListener(l, IMapMoveListener) self._googleMap.addControl(MapControl.MapTypeControl) self.addTestButtons() # Add buttons that trigger tests map features
def buttonClick(self, event): app = self._app#event.getButton().getApplication() map2 = GoogleMap(app, (22.3, 60.4522), 8) map2.setHeight('240px') map2.setWidth('240px') w = Window('popup') w.addComponent(map2) w.setHeight('300px') w.setWidth('300px') app.getMainWindow().addWindow(w)
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 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)
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
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 MuntjacWindow(MuntjacContainer, AbstractTkWindow): """ A Muntjac implementation of a Window. MuntjacWindow uses a Window to create a simple top level window which contains other child widgets and layouts. """ _initializing = False #-------------------------------------------------------------------------- # Setup methods #-------------------------------------------------------------------------- def create(self, parent): """ Creates the underlying Muntjac widget. """ # self.widget = MResizingFrame(parent) self.widget = Window() if parent is not None: parent.addComponent(self.widget) else: app = SingletonApplication.get() mw = app.getMainWindow() mw.addWindow(self.widget) def initialize(self): """ Intializes the attributes on the Window. """ self._initializing = True try: super(MuntjacWindow, self).initialize() self.set_title(self.shell_obj.title) finally: self._initializing = False #-------------------------------------------------------------------------- # Implementation #-------------------------------------------------------------------------- def shell_title_changed(self, title): """ The change handler for the 'title' attribute. """ self.set_title(title) #-------------------------------------------------------------------------- # Widget Update Methods #-------------------------------------------------------------------------- def set_title(self, title): """ Sets the title of the Window. """ self.widget.setCaption(title) def set_visible(self, visible): """ Overridden from the parent class to raise the window to the front if it should be shown. """ # Don't show the window if we're not initializing. if not self._initializing: if visible: self.widget.setVisible(True) # self.widget.raise_() else: self.widget.setVisible(False)
def init(self): main = Window("CSS Tools Add-on Test") self.setMainWindow(main) testWindow = Window("Normal Window") testWindow.addComponent(Label("<p>This window is used as the component to measure.</p>", Label.CONTENT_XHTML)) main.addWindow(testWindow) testWindow.center() title = Label("CSS Properties to Retrieve") title.addStyleName(Reindeer.LABEL_H2) main.addComponent(title) target = NativeSelect("Target Component") main.addComponent(target) get = Button("Refresh Properties", GetClickListener(self, target)) main.addComponent(get) main.addComponent(self.buildLabels()) target.addItem(main.getContent()) target.setItemCaption(main.getContent(), "Root layout") target.addItem(testWindow) target.setItemCaption(testWindow, "Sub window") target.addItem(get) target.setItemCaption(get, "The '" + get.getCaption() + "' Button") target.setNullSelectionAllowed(False) target.select(testWindow)
def init(self): main = Window('CSS Tools Add-on Test') self.setMainWindow(main) testWindow = Window('Normal Window') testWindow.addComponent( Label("<p>This window is used as the component to measure.</p>", Label.CONTENT_XHTML)) main.addWindow(testWindow) testWindow.center() title = Label('CSS Properties to Retrieve') title.addStyleName(Reindeer.LABEL_H2) main.addComponent(title) target = NativeSelect('Target Component') main.addComponent(target) get = Button('Refresh Properties', GetClickListener(self, target)) main.addComponent(get) main.addComponent(self.buildLabels()) target.addItem(main.getContent()) target.setItemCaption(main.getContent(), 'Root layout') target.addItem(testWindow) target.setItemCaption(testWindow, 'Sub window') target.addItem(get) target.setItemCaption(get, 'The \'' + get.getCaption() + '\' Button') target.setNullSelectionAllowed(False) target.select(testWindow)
def init(self): mainWindow = Window('CodeMirror Sample Application') hl = GridLayout(2, 5) hl.setSpacing(True) mainWindow.addComponent(hl) # #1 code = CodeMirror('Your Code', CodeMode.TEXT) code.setValue(self._SAMPLE_CODE) code.setWidth('500px') code.setHeight('350px') hl.addComponent(code) # #2 code2 = CodeMirror('Your Code Too', CodeMode.PYTHON) code2.setValue(self._SAMPLE_CODE) # code2.setWidth('400px') # code2.setHeight('300px') hl.addComponent(code2) codeMode = Select('Select your mode') for cs in CodeMode.values(): codeMode.addItem(cs) codeMode.setNewItemsAllowed(False) codeMode.setNullSelectionAllowed(False) codeMode.setImmediate(True) hl.addComponent(codeMode) l = CodeModeChangeListener(code, codeMode) codeMode.addListener(l, IValueChangeListener) codeMode.setValue(CodeMode.TEXT) codeMode = Select('Select your mode too') for cs in CodeMode.values(): codeMode.addItem(cs) codeMode.setNewItemsAllowed(False) codeMode.setNullSelectionAllowed(False) codeMode.setImmediate(True) hl.addComponent(codeMode) l = CodeModeChangeListener(code2, codeMode) codeMode.addListener(l, IValueChangeListener) codeMode.setValue(CodeMode.PYTHON) codeTheme = Select('Select your theme') for ct in CodeTheme.values(): codeTheme.addItem(ct) codeTheme.setNewItemsAllowed(False) codeTheme.setImmediate(True) hl.addComponent(codeTheme) l = CodeThemeChangeListener(code, codeTheme) codeTheme.addListener(l, IValueChangeListener) codeTheme.setValue(CodeTheme.DEFAULT) codeTheme = Select('Select your theme too') for ct in CodeTheme.values(): codeTheme.addItem(ct) codeTheme.setNewItemsAllowed(False) codeTheme.setImmediate(True) hl.addComponent(codeTheme) l = CodeThemeChangeListener(code2, codeTheme) codeTheme.addListener(l, IValueChangeListener) codeTheme.setValue(CodeTheme.ECLIPSE) l = CopyClickListener(code, code2) hl.addComponent(Button('copy to -->', l)) l = CopyClickListener(code2, code) hl.addComponent(Button('<- copy to', l)) l = ShowLineNumbersListener(code) cb = CheckBox("Show line numbers", l) cb.setImmediate(True) hl.addComponent(cb) l = ShowLineNumbersListener(code2) cb = CheckBox("Show line numbers", l) cb.setImmediate(True) hl.addComponent(cb) self.setMainWindow(mainWindow)
class MuntjacDialog(MuntjacWindow, AbstractTkDialog): """ A Muntjac implementation of a Dialog. This class creates a simple top-level dialog. """ #-------------------------------------------------------------------------- # Setup methods #-------------------------------------------------------------------------- def create(self, parent): """ Creates the underlying Window control. """ # self.widget = MResizingDialog(parent) self.widget = Window() parent.addComponent(self.widget) def initialize(self): """ Intializes the attributes on the QDialog. """ super(MuntjacDialog, self).initialize() self.widget.finished.connect(self._on_close) #--------------------------------------------------------------------------- # Implementation #--------------------------------------------------------------------------- def accept(self): """ Accept and close the dialog, sending the 'finished' signal. """ self._close_dialog('accepted') def reject(self): """ Reject and close the dialog, sending the 'finished' signal. """ self._close_dialog('rejected') #-------------------------------------------------------------------------- # Event Handlers #-------------------------------------------------------------------------- def _on_close(self, result): """ The event handler for the dialog's finished signal. This translates from a QDialog result into an Enaml result enum value. The default result is rejection. """ self.reject() #-------------------------------------------------------------------------- # Widget Update Methods #-------------------------------------------------------------------------- def set_visible(self, visible): """ Overridden from the parent class to properly launch and close the dialog. """ if not self._initializing: widget = self.widget shell = self.shell_obj if visible: shell.trait_set(_active=True, opened=True) # Muntjac cannot distinguish between app modal and # window modal, so we only get one kind. widget.setModal(True) widget.exec_() else: self.reject() #-------------------------------------------------------------------------- # Helper Methods #-------------------------------------------------------------------------- def _close_dialog(self, result): """ Destroy the dialog, fire events, and set status attributes. """ if self.widget: self.widget.close() self.shell_obj.trait_set(_result=result, _active=False, closed=result)