def createComponents(self): components = list() label = Label('This is a long text block that will wrap.') label.setWidth('120px') components.append(label) image = Embedded('', ThemeResource('../runo/icons/64/document.png')) components.append(image) documentLayout = CssLayout() documentLayout.setWidth('19px') for _ in range(5): e = Embedded(None, ThemeResource('../runo/icons/16/document.png')) e.setHeight('16px') e.setWidth('16px') documentLayout.addComponent(e) components.append(documentLayout) buttonLayout = VerticalLayout() button = Button('Button') button.addListener(ButtonClickListener(self), IClickListener) buttonLayout.addComponent(button) buttonLayout.setComponentAlignment(button, Alignment.MIDDLE_CENTER) components.append(buttonLayout) return components
class AccordionIconsExample(HorizontalLayout, ISelectedTabChangeListener): _icon1 = ThemeResource('../sampler/icons/action_save.gif') _icon2 = ThemeResource('../sampler/icons/comment_yellow.gif') _icon3 = ThemeResource('../sampler/icons/icon_info.gif') def __init__(self): super(AccordionIconsExample, self).__init__() self.setSpacing(True) l1 = Label('There are no previously saved actions.') l2 = Label('There are no saved notes.') l3 = Label('There are currently no issues.') self._a = Accordion() self._a.setHeight('300px') self._a.setWidth('400px') self._a.addTab(l1, 'Saved actions', self._icon1) self._a.addTab(l2, 'Notes', self._icon2) self._a.addTab(l3, 'Issues', self._icon3) self._a.addListener(self, ISelectedTabChangeListener) self.addComponent(self._a) def selectedTabChange(self, event): tabsheet = event.getTabSheet() tab = tabsheet.getTab(tabsheet.getSelectedTab()) if tab is not None: self.getWindow().showNotification('Selected tab: ' + tab.getCaption())
class AccordionDisabledExample(VerticalLayout, tab_sheet.ISelectedTabChangeListener, button.IClickListener): _icon1 = ThemeResource('../sampler/icons/action_save.gif') _icon2 = ThemeResource('../sampler/icons/comment_yellow.gif') _icon3 = ThemeResource('../sampler/icons/icon_info.gif') def __init__(self): super(AccordionDisabledExample, self).__init__() self.setSpacing(True) self._l1 = Label('There are no previously saved actions.') self._l2 = Label('There are no saved notes.') self._l3 = Label('There are currently no issues.') self._a = Accordion() self._a.setHeight('300px') self._a.setWidth('400px') self._t1 = self._a.addTab(self._l1, 'Saved actions', self._icon1) self._t2 = self._a.addTab(self._l2, 'Notes', self._icon2) self._t3 = self._a.addTab(self._l3, 'Issues', self._icon3) self._a.addListener(self, tab_sheet.ISelectedTabChangeListener) self._b1 = Button('Disable \'Notes\' tab') self._b2 = Button('Hide \'Issues\' tab') self._b1.addListener(self, button.IClickListener) self._b2.addListener(self, button.IClickListener) hl = HorizontalLayout() hl.setSpacing(True) hl.addComponent(self._b1) hl.addComponent(self._b2) self.addComponent(self._a) self.addComponent(hl) def selectedTabChange(self, event): c = self._a.getTab(event.getTabSheet().getSelectedTab()).getCaption() self.getWindow().showNotification('Selected tab: ' + c) def buttonClick(self, event): if self._b1 == event.getButton(): # b1 clicked if self._t2.isEnabled(): self._t2.setEnabled(False) self._b1.setCaption('Enable \'Notes\' tab') else: self._t2.setEnabled(True) self._b1.setCaption('Disable \'Notes\' tab') else: # b2 clicked if self._t3.isVisible(): self._t3.setVisible(False) self._b2.setCaption('Show \'Issues\' tab') else: self._t3.setVisible(True) self._b2.setCaption('Hide \'Issues\' tab') self._a.requestRepaint()
def __init__(self): super(MenuBarWithIconsExample, self).__init__() self._menubar = MenuBar() menuCommand = MenuCommand(self) # Save reference to individual items so we can add sub-menu items to # them f = self._menubar.addItem('File', None) newItem = f.addItem('New', None) f.addItem('Open file...', ThemeResource('../runo/icons/16/folder.png'), menuCommand) f.addSeparator() newItem.addItem('File', ThemeResource('../runo/icons/16/document.png'), menuCommand) newItem.addItem('Folder', ThemeResource('../runo/icons/16/folder.png'), menuCommand) newItem.addItem('Project...', ThemeResource('../runo/icons/16/globe.png'), menuCommand) f.addItem('Close', menuCommand) f.addItem('Close All', menuCommand) f.addSeparator() f.addItem('Save', menuCommand) f.addItem('Save As...', menuCommand) f.addItem('Save All', menuCommand) edit = self._menubar.addItem('Edit', None) edit.addItem('Undo', menuCommand) edit.addItem('Redo', menuCommand).setEnabled(False) edit.addSeparator() edit.addItem('Cut', menuCommand) edit.addItem('Copy', menuCommand) edit.addItem('Paste', menuCommand) edit.addSeparator() find = edit.addItem('Find/Replace', menuCommand) # Actions can be added inline as well, of course find.addItem('Google Search', SearchCommand(self)) find.addSeparator() find.addItem('Find/Replace...', menuCommand) find.addItem('Find Next', menuCommand) find.addItem('Find Previous', menuCommand) view = self._menubar.addItem('View', ThemeResource('../runo/icons/16/user.png'), None) view.addItem('Show/Hide Status Bar', menuCommand) view.addItem('Customize Toolbar...', menuCommand) view.addSeparator() view.addItem('Actual Size', menuCommand) view.addItem('Zoom In', menuCommand) view.addItem('Zoom Out', menuCommand) self.addComponent(self._menubar)
class TabSheetScrollingExample(VerticalLayout, ISelectedTabChangeListener): _icon1 = ThemeResource('../sampler/icons/action_save.gif') _icon2 = ThemeResource('../sampler/icons/comment_yellow.gif') _icon3 = ThemeResource('../sampler/icons/icon_info.gif') def __init__(self): super(TabSheetScrollingExample, self).__init__() # Tab 1 content l1 = VerticalLayout() l1.setMargin(True) l1.addComponent(Label('There are no previously saved actions.')) # Tab 2 content l2 = VerticalLayout() l2.setMargin(True) l2.addComponent(Label('There are no saved notes.')) # Tab 3 content l3 = VerticalLayout() l3.setMargin(True) l3.addComponent(Label('There are currently no issues.')) # Tab 4 content l4 = VerticalLayout() l4.setMargin(True) l4.addComponent(Label('There are no comments.')) # Tab 5 content l5 = VerticalLayout() l5.setMargin(True) l5.addComponent(Label('There is no new feedback.')) self._t = TabSheet() self._t.setHeight('200px') self._t.setWidth('400px') self._t.addTab(l1, 'Saved actions', self._icon1) self._t.addTab(l2, 'Notes', self._icon2) self._t.addTab(l3, 'Issues', self._icon3) self._t.addTab(l4, 'Comments', self._icon2) self._t.addTab(l5, 'Feedback', self._icon2) self._t.addListener(self, ISelectedTabChangeListener) self.addComponent(self._t) def selectedTabChange(self, event): tabsheet = event.getTabSheet() tab = tabsheet.getTab(tabsheet.getSelectedTab()) if tab is not None: self.getWindow().showNotification('Selected tab: ' + tab.getCaption())
class LinkNoDecorationsExample(VerticalLayout): _CAPTION = 'Open Google in new window' _TOOLTIP = 'http://www.google.com (opens in new window)' _ICON = ThemeResource('../sampler/icons/icon_world.gif') def __init__(self): super(LinkNoDecorationsExample, self).__init__() self.setSpacing(True) # Link w/ text and tooltip l = Link(self._CAPTION, ExternalResource('http://www.google.com')) l.setTargetName('_blank') l.setTargetBorder(Link.TARGET_BORDER_NONE) l.setDescription(self._TOOLTIP) self.addComponent(l) # Link w/ text, icon and tooltip l = Link(self._CAPTION, ExternalResource('http://www.google.com')) l.setTargetName('_blank') l.setTargetBorder(Link.TARGET_BORDER_NONE) l.setDescription(self._TOOLTIP) l.setIcon(self._ICON) self.addComponent(l) # Link w/ icon and tooltip l = Link() l.setResource(ExternalResource('http://www.google.com')) l.setTargetName('_blank') l.setTargetBorder(Link.TARGET_BORDER_NONE) l.setDescription(self._TOOLTIP) l.setIcon(self._ICON) self.addComponent(l)
class LinkCurrentWindowExample(VerticalLayout): _CAPTION = 'Open Google' _TOOLTIP = 'http://www.google.com' _ICON = ThemeResource('../sampler/icons/icon_world.gif') def __init__(self): super(LinkCurrentWindowExample, self).__init__() self.setSpacing(True) # Link w/ text and tooltip l = Link(self._CAPTION, ExternalResource('http://www.google.com')) l.setDescription(self._TOOLTIP) self.addComponent(l) # Link w/ text, icon and tooltip l = Link(self._CAPTION, ExternalResource('http://www.google.com')) l.setDescription(self._TOOLTIP) l.setIcon(self._ICON) self.addComponent(l) # Link w/ icon and tooltip l = Link() l.setResource(ExternalResource('http://www.google.com')) l.setDescription(self._TOOLTIP) l.setIcon(self._ICON) self.addComponent(l)
def getHardwareContainer(cls): item = None itemId = 0 # Increasing numbering for itemId:s # Create new container hwContainer = HierarchicalContainer() # Create containerproperty for name hwContainer.addContainerProperty(cls.hw_PROPERTY_NAME, str, None) # Create containerproperty for icon hwContainer.addContainerProperty( cls.hw_PROPERTY_ICON, ThemeResource, ThemeResource('../runo/icons/16/document.png')) for i in range(len(cls._hardware)): # Add new item item = hwContainer.addItem(itemId) # Add name property for item v = cls._hardware[i][0] item.getItemProperty(cls.hw_PROPERTY_NAME).setValue(v) # Allow children hwContainer.setChildrenAllowed(itemId, True) itemId += 1 for j in range(1, len(cls._hardware[i])): if j == 1: v = ThemeResource('../runo/icons/16/folder.png') item.getItemProperty(cls.hw_PROPERTY_ICON).setValue(v) # Add child items item = hwContainer.addItem(itemId) v = cls._hardware[i][j] item.getItemProperty(cls.hw_PROPERTY_NAME).setValue(v) hwContainer.setParent(itemId, itemId - j) hwContainer.setChildrenAllowed(itemId, False) itemId += 1 return hwContainer
def __init__(self): super(PackageIconsExample, self).__init__() self._icons = ['arrow-down.png', 'arrow-left.png', 'arrow-right.png', 'arrow-up.png', 'attention.png', 'calendar.png', 'cancel.png', 'document.png', 'document-add.png', 'document-delete.png', 'document-doc.png', 'document-image.png', 'document-pdf.png', 'document-ppt.png', 'document-txt.png', 'document-web.png', 'document-xsl.png', 'email.png', 'email-reply.png', 'email-send.png', 'folder.png', 'folder-add.png', 'folder-delete.png', 'globe.png', 'help.png', 'lock.png', 'note.png', 'ok.png', 'reload.png', 'settings.png', 'trash.png', 'trash-full.png', 'user.png', 'users.png'] self._sizes = ['16', '32', '64'] self.setSpacing(True) tabSheet = TabSheet() tabSheet.setStyleName(Reindeer.TABSHEET_MINIMAL) for size in self._sizes: iconsSideBySide = 2 if size == '64' else 3 grid = GridLayout(iconsSideBySide * 2, 1) grid.setSpacing(True) grid.setMargin(True) tabSheet.addTab(grid, size + 'x' + size, None) tabSheet.addComponent(grid) for icon in self._icons: res = ThemeResource('../runo/icons/' + size + '/' + icon) e = Embedded(None, res) # Set size to avoid flickering when loading e.setWidth(size + 'px') e.setHeight(size + 'px') name = Label(icon) if size == '64': name.setWidth('185px') else: name.setWidth('150px') grid.addComponent(e) grid.addComponent(name) grid.setComponentAlignment(name, Alignment.MIDDLE_LEFT) self.addComponent(tabSheet)
def fillIso3166Container(cls, container): container.addContainerProperty(cls.iso3166_PROPERTY_NAME, str, None) container.addContainerProperty(cls.iso3166_PROPERTY_SHORT, str, None) container.addContainerProperty(cls.iso3166_PROPERTY_FLAG, IResource, None) i = 0 while i < len(cls.iso3166): name = cls.iso3166[i] i += 1 idd = cls.iso3166[i] item = container.addItem(idd) item.getItemProperty(cls.iso3166_PROPERTY_NAME).setValue(name) item.getItemProperty(cls.iso3166_PROPERTY_SHORT).setValue(idd) v = ThemeResource('../sampler/flags/' + idd.lower() + '.gif') item.getItemProperty(cls.iso3166_PROPERTY_FLAG).setValue(v) i += 1 container.sort([cls.iso3166_PROPERTY_NAME], [True])
class CheckBoxesExample(VerticalLayout, IClickListener): _CAPTION = 'Allow HTML' _TOOLTIP = 'Allow/disallow HTML in comments' _ICON = ThemeResource('../sampler/icons/page_code.gif') def __init__(self): super(CheckBoxesExample, self).__init__() self.setSpacing(True) # Button w/ text and tooltip cb = CheckBox(self._CAPTION) cb.setDescription(self._TOOLTIP) cb.setImmediate(True) cb.addListener(self, IClickListener) # react to clicks self.addComponent(cb) # Button w/ text, icon and tooltip cb = CheckBox(self._CAPTION) cb.setDescription(self._TOOLTIP) cb.setIcon(self._ICON) cb.setImmediate(True) cb.addListener(self, IClickListener) # react to clicks self.addComponent(cb) # Button w/ icon and tooltip cb = CheckBox() cb.setDescription(self._TOOLTIP) cb.setIcon(self._ICON) cb.setImmediate(True) cb.addListener(self, IClickListener) # react to clicks self.addComponent(cb) # Shows a notification when a checkbox is clicked. def buttonClick(self, event): enabled = event.getButton().booleanValue() self.getWindow().showNotification( 'HTML ' + ('enabled' if enabled else 'disabled'))
class ButtonLinkExample(VerticalLayout, button.IClickListener): _CAPTION = 'Help' _TOOLTIP = 'Show help' _ICON = ThemeResource('../sampler/icons/icon_info.gif') _NOTIFICATION = 'Help clicked' def __init__(self): super(ButtonLinkExample, self).__init__() self.setSpacing(True) # Button w/ text and tooltip b = Button(self._CAPTION) b.setStyleName(BaseTheme.BUTTON_LINK) b.setDescription(self._TOOLTIP) b.addListener(self, button.IClickListener) # react to clicks self.addComponent(b) # Button w/ text, icon and tooltip b = Button(self._CAPTION) b.setStyleName(BaseTheme.BUTTON_LINK) b.setDescription(self._TOOLTIP) b.setIcon(self._ICON) b.addListener(self, button.IClickListener) # react to clicks self.addComponent(b) # Button w/ icon and tooltip b = Button() b.setStyleName(BaseTheme.BUTTON_LINK) b.setDescription(self._TOOLTIP) b.setIcon(self._ICON) b.addListener(self, button.IClickListener) # react to clicks self.addComponent(b) # Shows a notification when a button is clicked. def buttonClick(self, event): self.getWindow().showNotification(self._NOTIFICATION)
def __init__(self): super(IconsExample, self).__init__() self.setSpacing(True) # Button w/ icon button = Button('Save') button.setIcon(ThemeResource('../sampler/icons/action_save.gif')) self.addComponent(button) # Label l = Label('Icons are very handy') l.setCaption('Comment') l.setIcon(ThemeResource('../sampler/icons/comment_yellow.gif')) self.addComponent(l) # Panel w/ links p = Panel('Handy links') p.setIcon(ThemeResource('../sampler/icons/icon_info.gif')) self.addComponent(p) lnk = Link('http://vaadin.com', ExternalResource('http://www.vaadin.com')) lnk.setIcon(ThemeResource('../sampler/icons/icon_world.gif')) p.addComponent(lnk) lnk = Link('http://vaadin.com/learn', ExternalResource('http://www.vaadin.com/learn')) lnk.setIcon(ThemeResource('../sampler/icons/icon_world.gif')) p.addComponent(lnk) lnk = Link('http://dev.vaadin.com/', ExternalResource('http://dev.vaadin.com/')) lnk.setIcon(ThemeResource('../sampler/icons/icon_world.gif')) p.addComponent(lnk) lnk = Link('http://vaadin.com/forum', ExternalResource('http://vaadin.com/forum')) lnk.setIcon(ThemeResource('../sampler/icons/icon_world.gif')) p.addComponent(lnk)
class TabSheetDisabledExample(VerticalLayout, tab_sheet.ISelectedTabChangeListener, button.IClickListener): _icon1 = ThemeResource('../sampler/icons/action_save.gif') _icon2 = ThemeResource('../sampler/icons/comment_yellow.gif') _icon3 = ThemeResource('../sampler/icons/icon_info.gif') def __init__(self): super(TabSheetDisabledExample, self).__init__() self.setSpacing(True) # Tab 1 content self._l1 = VerticalLayout() self._l1.setMargin(True) self._l1.addComponent(Label('There are no previously saved actions.')) # Tab 2 content self._l2 = VerticalLayout() self._l2.setMargin(True) self._l2.addComponent(Label('There are no saved notes.')) # Tab 3 content self._l3 = VerticalLayout() self._l3.setMargin(True) self._l3.addComponent(Label('There are currently no issues.')) self._t = TabSheet() self._t.setHeight('200px') self._t.setWidth('400px') self._t1 = self._t.addTab(self._l1, 'Saved actions', self._icon1) self._t2 = self._t.addTab(self._l2, 'Notes', self._icon2) self._t3 = self._t.addTab(self._l3, 'Issues', self._icon3) self._t.addListener(self, tab_sheet.ISelectedTabChangeListener) self._toggleEnabled = Button('Disable \'Notes\' tab') self._toggleEnabled.addListener(self, button.IClickListener) self._toggleVisible = Button('Hide \'Issues\' tab') self._toggleVisible.addListener(self, button.IClickListener) hl = HorizontalLayout() hl.setSpacing(True) hl.addComponent(self._toggleEnabled) hl.addComponent(self._toggleVisible) self.addComponent(self._t) self.addComponent(hl) def selectedTabChange(self, event): selected = event.getTabSheet().getSelectedTab() c = self._t.getTab(selected).getCaption() self.getWindow().showNotification('Selected tab: ' + c) def buttonClick(self, event): if self._toggleEnabled == event.getButton(): # toggleEnabled clicked self._t2.setEnabled(not self._t2.isEnabled()) if self._t2.isEnabled(): self._toggleEnabled.setCaption('Disable \'Notes\' tab') else: self._toggleEnabled.setCaption('Enable \'Notes\' tab') else: # toggleVisible clicked self._t3.setVisible(not self._t3.isVisible()) if self._t3.isVisible(): self._toggleVisible.setCaption('Hide \'Issues\' tab') else: self._toggleVisible.setCaption('Show \'Issues\' tab') self._t.requestRepaint()
class FileTypeResolver(object): """Utility class that can figure out mime-types and icons related to files. Note : The icons are associated purely to mime-types, so a file may not have a custom icon accessible with this class. @author: Vaadin Ltd. @author: Richard Lincoln @version: @VERSION@ """ #: Default icon given if no icon is specified for a mime-type. DEFAULT_ICON = ThemeResource('../runo/icons/16/document.png') #: Default mime-type. DEFAULT_MIME_TYPE = 'application/octet-stream' #: Initial file extension to mime-type mapping. _initialExtToMIMEMap = \ ('application/cu-seeme csm cu,' 'application/dsptype tsp,' 'application/futuresplash spl,' 'application/mac-binhex40 hqx,' 'application/msaccess mdb,' 'application/msword doc dot,' 'application/octet-stream bin,' 'application/oda oda,' 'application/pdf pdf,' 'application/pgp-signature pgp,' 'application/postscript ps ai eps,' 'application/rtf rtf,' 'application/vnd.ms-excel xls xlb,' 'application/vnd.ms-powerpoint ppt pps pot,' 'application/vnd.wap.wmlc wmlc,' 'application/vnd.wap.wmlscriptc wmlsc,' 'application/wordperfect5.1 wp5,' 'application/zip zip,' 'application/x-123 wk,' 'application/x-bcpio bcpio,' 'application/x-chess-pgn pgn,' 'application/x-cpio cpio,' 'application/x-debian-package deb,' 'application/x-director dcr dir dxr,' 'application/x-dms dms,' 'application/x-dvi dvi,' 'application/x-xfig fig,' 'application/x-font pfa pfb gsf pcf pcf.Z,' 'application/x-gnumeric gnumeric,' 'application/x-gtar gtar tgz taz,' 'application/x-hdf hdf,' 'application/x-httpd-php phtml pht php,' 'application/x-httpd-php3 php3,' 'application/x-httpd-php3-source phps,' 'application/x-httpd-php3-preprocessed php3p,' 'application/x-httpd-php4 php4,' 'application/x-ica ica,' 'application/x-java-archive jar,' 'application/x-java-serialized-object ser,' 'application/x-java-vm class,' 'application/x-javascript js,' 'application/x-kchart chrt,' 'application/x-killustrator kil,' 'application/x-kpresenter kpr kpt,' 'application/x-kspread ksp,' 'application/x-kword kwd kwt,' 'application/x-latex latex,' 'application/x-lha lha,' 'application/x-lzh lzh,' 'application/x-lzx lzx,' 'application/x-maker frm maker frame fm fb book fbdoc,' 'application/x-mif mif,' 'application/x-msdos-program com exe bat dll,' 'application/x-msi msi,' 'application/x-netcdf nc cdf,' 'application/x-ns-proxy-autoconfig pac,' 'application/x-object o,' 'application/x-ogg ogg,' 'application/x-oz-application oza,' 'application/x-perl pl pm,' 'application/x-pkcs7-crl crl,' 'application/x-redhat-package-manager rpm,' 'application/x-shar shar,' 'application/x-shockwave-flash swf swfl,' 'application/x-star-office sdd sda,' 'application/x-stuffit sit,' 'application/x-sv4cpio sv4cpio,' 'application/x-sv4crc sv4crc,' 'application/x-tar tar,' 'application/x-tex-gf gf,' 'application/x-tex-pk pk PK,' 'application/x-texinfo texinfo texi,' 'application/x-trash ~ % bak old sik,' 'application/x-troff t tr roff,' 'application/x-troff-man man,' 'application/x-troff-me me,' 'application/x-troff-ms ms,' 'application/x-ustar ustar,' 'application/x-wais-source src,' 'application/x-wingz wz,' 'application/x-x509-ca-cert crt,' 'audio/basic au snd,' 'audio/midi mid midi,' 'audio/mpeg mpga mpega mp2 mp3,' 'audio/mpegurl m3u,' 'audio/prs.sid sid,' 'audio/x-aiff aif aiff aifc,' 'audio/x-gsm gsm,' 'audio/x-pn-realaudio ra rm ram,' 'audio/x-scpls pls,' 'audio/x-wav wav,' 'audio/ogg ogg,' 'audio/mp4 m4a,' 'audio/x-aac aac,' 'image/bitmap bmp,' 'image/gif gif,' 'image/ief ief,' 'image/jpeg jpeg jpg jpe,' 'image/pcx pcx,' 'image/png png,' 'image/svg+xml svg svgz,' 'image/tiff tiff tif,' 'image/vnd.wap.wbmp wbmp,' 'image/x-cmu-raster ras,' 'image/x-coreldraw cdr,' 'image/x-coreldrawpattern pat,' 'image/x-coreldrawtemplate cdt,' 'image/x-corelphotopaint cpt,' 'image/x-jng jng,' 'image/x-portable-anymap pnm,' 'image/x-portable-bitmap pbm,' 'image/x-portable-graymap pgm,' 'image/x-portable-pixmap ppm,' 'image/x-rgb rgb,' 'image/x-xbitmap xbm,' 'image/x-xpixmap xpm,' 'image/x-xwindowdump xwd,' 'text/comma-separated-values csv,' 'text/css css,' 'text/html htm html xhtml,' 'text/mathml mml,' 'text/plain txt text diff,' 'text/richtext rtx,' 'text/tab-separated-values tsv,' 'text/vnd.wap.wml wml,' 'text/vnd.wap.wmlscript wmls,' 'text/xml xml,' 'text/x-c++hdr h++ hpp hxx hh,' 'text/x-c++src c++ cpp cxx cc,' 'text/x-chdr h,' 'text/x-csh csh,' 'text/x-csrc c,' 'text/x-java java,' 'text/x-moc moc,' 'text/x-pascal p pas,' 'text/x-setext etx,' 'text/x-sh sh,' 'text/x-tcl tcl tk,' 'text/x-tex tex ltx sty cls,' 'text/x-vcalendar vcs,' 'text/x-vcard vcf,' 'video/dl dl,' 'video/fli fli,' 'video/gl gl,' 'video/mpeg mpeg mpg mpe,' 'video/quicktime qt mov,' 'video/x-mng mng,' 'video/x-ms-asf asf asx,' 'video/x-msvideo avi,' 'video/x-sgi-movie movie,' 'video/ogg ogv,' 'video/mp4 mp4,' 'x-world/x-vrml vrm vrml wrl') #: File extension to MIME type mapping. All extensions are in lower case. _extToMIMEMap = dict() #: MIME type to Icon mapping. _MIMEToIconMap = dict() @classmethod def getMIMEType(cls, file_or_filename): """Gets the mime-type of a file. Currently the mime-type is resolved based only on the file name extension. @param file_or_filename: the file or name of the file whose mime-type is requested. @return: mime-type string """ # Checks for nulls if isinstance(file_or_filename, basestring): fileName = file_or_filename # Calculates the extension of the file dotIndex = fileName.find('.') while dotIndex >= 0 and fileName.find('.', dotIndex + 1) >= 0: dotIndex = fileName.find('.', dotIndex + 1) dotIndex += 1 if len(fileName) > dotIndex: ext = fileName[dotIndex:] # Ignore any query parameters queryStringStart = ext.find('?') if queryStringStart > 0: ext = ext[:queryStringStart] # Return type from extension map, if found typ = cls._extToMIMEMap.get(ext.lower()) if typ is not None: return typ return cls.DEFAULT_MIME_TYPE else: raise NotImplementedError fd = file_or_filename if fd is None: raise ValueError, 'File can not be null' # Directories if isdir(fd): # Drives if fd.getParentFile() is None: return 'inode/drive' else: return 'inode/directory' # Return type from extension return cls.getMIMEType(fd.getName()) @classmethod def getIcon(cls, file_or_filename): """Gets the descriptive icon representing file, based on the filename. First the mime-type for the given filename is resolved, and then the corresponding icon is fetched from the internal icon storage. If it is not found the default icon is returned. @param file_or_filename: the file or name of the file whose icon is requested. @return: the icon corresponding to the given file """ return cls.getIconByMimeType(cls.getMIMEType(file_or_filename)) @classmethod def getIconByMimeType(cls, mimeType): icon = cls._MIMEToIconMap.get(mimeType) if icon is not None: return icon # If nothing is known about the file-type, general file # icon is used return cls.DEFAULT_ICON @classmethod def addExtension(cls, extension, MIMEType): """Adds a mime-type mapping for the given filename extension. If the extension is already in the internal mapping it is overwritten. @param extension: the filename extension to be associated with C{MIMEType}. @param MIMEType: the new mime-type for C{extension}. """ cls._extToMIMEMap[extension.lower()] = MIMEType @classmethod def addIcon(cls, MIMEType, icon): """Adds a icon for the given mime-type. If the mime-type also has a corresponding icon, it is replaced with the new icon. @param MIMEType: the mime-type whose icon is to be changed. @param icon: the new icon to be associated with C{MIMEType}. """ cls._MIMEToIconMap[MIMEType] = icon @classmethod def getExtensionToMIMETypeMapping(cls): """Gets the internal file extension to mime-type mapping. @return: unmodifiable map containing the current file extension to mime-type mapping """ return dict(cls._extToMIMEMap) @classmethod def getMIMETypeToIconMapping(cls): """Gets the internal mime-type to icon mapping. @return: map containing the current mime-type to icon mapping """ return dict(cls._MIMEToIconMap)
@classmethod def getExtensionToMIMETypeMapping(cls): """Gets the internal file extension to mime-type mapping. @return: unmodifiable map containing the current file extension to mime-type mapping """ return dict(cls._extToMIMEMap) @classmethod def getMIMETypeToIconMapping(cls): """Gets the internal mime-type to icon mapping. @return: map containing the current mime-type to icon mapping """ return dict(cls._MIMEToIconMap) # Initialize extension to MIME map lines = FileTypeResolver._initialExtToMIMEMap.split(',') for line in lines: exts = line.split() typ = exts[0] for ext in exts[1:]: FileTypeResolver.addExtension(ext, typ) # Initialize Icons folder = ThemeResource('../runo/icons/16/folder.png') FileTypeResolver.addIcon('inode/drive', folder) FileTypeResolver.addIcon('inode/directory', folder)
res = self._sampleIconCache.get(resId) if res is None: res = ThemeResource('../sampler/icons/sampleicons/' + resId) self._sampleIconCache[resId] = res return res @classmethod def getAllFeatures(cls): return cls._allFeatures def close(self): self.removeWindow(self.getMainWindow()) super(SamplerApplication, self).close() _EMPTY_THEME_ICON = ThemeResource('../sampler/sampler/icon-empty.png') _SELECTED_THEME_ICON = ThemeResource('../sampler/sampler/select-bullet.png') 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()
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%')
def getSampleIcon(self, resId): res = self._sampleIconCache.get(resId) if res is None: res = ThemeResource('../sampler/icons/sampleicons/' + resId) self._sampleIconCache[resId] = res return res
def __init__(self): super(TableMainFeaturesExample, self).__init__() self._markedRows = set() self._table = Table('ISO-3166 Country Codes and flags') self.addComponent(self._table) # Label to indicate current selection selected = Label('No selection') self.addComponent(selected) # set a style name, so we can style rows and cells self._table.setStyleName('iso3166') # size self._table.setWidth('100%') self._table.setHeight('170px') # selectable self._table.setSelectable(True) self._table.setMultiSelect(True) # react at once when something is selected self._table.setImmediate(True) # connect data source self._table.setContainerDataSource(ExampleUtil.getISO3166Container()) # turn on column reordering and collapsing self._table.setColumnReorderingAllowed(True) self._table.setColumnCollapsingAllowed(True) # set column headers self._table.setColumnHeaders(['Country', 'Code', 'Icon file']) # Icons for column headers self._table.setColumnIcon( ExampleUtil.iso3166_PROPERTY_FLAG, ThemeResource('../sampler/icons/action_save.gif')) self._table.setColumnIcon( ExampleUtil.iso3166_PROPERTY_NAME, ThemeResource('../sampler/icons/icon_get_world.gif')) self._table.setColumnIcon( ExampleUtil.iso3166_PROPERTY_SHORT, ThemeResource('../sampler/icons/page_code.gif')) # Column alignment self._table.setColumnAlignment(ExampleUtil.iso3166_PROPERTY_SHORT, Table.ALIGN_CENTER) # Column width self._table.setColumnExpandRatio(ExampleUtil.iso3166_PROPERTY_NAME, 1) self._table.setColumnWidth(ExampleUtil.iso3166_PROPERTY_SHORT, 70) # Collapse one column - the user can make it visible again self._table.setColumnCollapsed(ExampleUtil.iso3166_PROPERTY_FLAG, True) # show row header w/ icon self._table.setRowHeaderMode(Table.ROW_HEADER_MODE_ICON_ONLY) self._table.setItemIconPropertyId(ExampleUtil.iso3166_PROPERTY_FLAG) # Actions (a.k.a context menu) self._table.addActionHandler(TableActionHandler(self)) # style generator self._table.setCellStyleGenerator(TableStyleGenerator(self)) # listen for valueChange, a.k.a 'select' and update the label self._table.addListener(TableChangeListener(self, selected), IValueChangeListener)
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 __init__(self): super(ImageEmbedExample, self).__init__() e = Embedded('Image from a theme resource', ThemeResource('../runo/icons/64/document.png')) self.addComponent(e)
class ButtonPushExample(HorizontalLayout, IClickListener): _CAPTION = 'Save' _TOOLTIP = 'Save changes' _ICON = ThemeResource('../sampler/icons/action_save.gif') _NOTIFICATION = 'Changes have been saved' def __init__(self): super(ButtonPushExample, self).__init__() # Normal buttons (more themable) buttons = VerticalLayout() buttons.setSpacing(True) buttons.setMargin(False, True, False, False) self.addComponent(buttons) buttons.addComponent(Label("<h3>Normal buttons</h3>", Label.CONTENT_XHTML)) # Button w/ text and tooltip b = Button(self._CAPTION) b.setDescription(self._TOOLTIP) b.addListener(self, IClickListener) # react to clicks buttons.addComponent(b) # Button w/ text, icon and tooltip b = Button(self._CAPTION) b.setDescription(self._TOOLTIP) b.setIcon(self._ICON) b.addListener(self, IClickListener) # react to clicks buttons.addComponent(b) # Button w/ icon and tooltip b = Button() b.setDescription(self._TOOLTIP) b.setIcon(self._ICON) b.addListener(self, IClickListener) # react to clicks buttons.addComponent(b) # NativeButtons buttons = VerticalLayout() buttons.setSpacing(True) buttons.setMargin(False, False, False, True) self.addComponent(buttons) buttons.addComponent(Label("<h3>Native buttons</h3>", Label.CONTENT_XHTML)); # NativeButton w/ text and tooltip b = NativeButton(self._CAPTION) b.setDescription(self._TOOLTIP) b.addListener(self, IClickListener) # react to clicks buttons.addComponent(b) # NativeButton w/ text, icon and tooltip b = NativeButton(self._CAPTION) b.setDescription(self._TOOLTIP) b.setIcon(self._ICON) b.addListener(self, IClickListener) # react to clicks buttons.addComponent(b) # NativeButton w/ icon and tooltip b = NativeButton() b.setDescription(self._TOOLTIP) b.setIcon(self._ICON) b.addListener(self, IClickListener) # react to clicks buttons.addComponent(b) # Shows a notification when a button is clicked. def buttonClick(self, event): self.getWindow().showNotification(self._NOTIFICATION)