def __init__(self): super(ShortcutBasicsExample, self).__init__() self.setSpacing(True) # Firstname input with an input prompt for demo clarity firstname = TextField('Firstname') firstname.setInputPrompt('ALT-SHIFT-F to focus') self.addComponent(firstname) # Add global shortcut that focuses the field firstname.addShortcutListener( FocusShortcut(firstname, KeyCode.F, ModifierKey.ALT, ModifierKey.SHIFT)) # Lastname input with an input prompt for demo clarity lastname = TextField('Lastname') lastname.setInputPrompt('ALT-SHIFT-L to focus') self.addComponent(lastname) # Add global shortcut that focuses the field lastname.addShortcutListener( FocusShortcut(lastname, KeyCode.L, ModifierKey.ALT, ModifierKey.SHIFT)) # Button with a simple click-listener enter = Button('Enter', EnterListener(self)) self.addComponent(enter) enter.setStyleName('primary') # make it look like it's default # Add global shortcut using the built-in helper enter.setClickShortcut(KeyCode.ENTER)
def __init__(self): super(ValidationExample, self).__init__() self._usernames = set() self.setSpacing(True) pin = TextField('PIN') pin.setWidth('50px') # optional; validate at once instead of when clicking 'save' (e.g) pin.setImmediate(True) self.addComponent(pin) # add the validator pin.addValidator( StringLengthValidator('Must be 4-6 characters', 4, 6, False)) username = TextField('Username') # optional; validate at once instead of when clicking 'save' (e.g) username.setImmediate(True) self.addComponent(username) usernameValidator = CompositeValidator() username.addValidator(usernameValidator) usernameValidator.addValidator( StringLengthValidator('Username' ' must be at least 4 characters', 4, 255, False)) usernameValidator.addValidator(UsernameValidator(self)) username.addListener(UsernameListener(self), IValueChangeListener)
def createHorizontal(self, recurse): wl = WeeLayout(Direction.HORIZONTAL) wl.setSizeFull() # wl.setHeight("100%"); wl.addComponent(TextField('Top'), Alignment.TOP_LEFT) wl.addComponent(TextField('Middle'), Alignment.MIDDLE_LEFT) tf = TextField('Bottom') tf.setHeight('50%') wl.addComponent(tf, Alignment.BOTTOM_LEFT) if recurse > 0: recurse -= 1 wl.addComponent(self.createVertical(recurse)) return wl
def createVertical(self, recurse): wl = WeeLayout(Direction.VERTICAL) wl.setSizeFull() # wl.setWidth("100%") # wl.setHeight("50%") wl.addComponent(TextField('Left'), Alignment.TOP_LEFT) wl.addComponent(TextField('Center'), Alignment.TOP_CENTER) tf = TextField('Right') tf.setWidth('50%') wl.addComponent(tf, Alignment.TOP_RIGHT) if recurse > 0: recurse -= 1 wl.addComponent(self.createHorizontal(recurse)) return wl
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(TextFieldInputPromptExample, self).__init__() # add some 'air' to the layout self.setSpacing(True) self.setMargin(True, False, False, False) # Username field + input prompt username = TextField() username.setInputPrompt('Username') # configure & add to layout username.setImmediate(True) username.addListener(self, IValueChangeListener) self.addComponent(username) # Password field + input prompt password = PasswordField() password.setInputPrompt('Password') # configure & add to layout password.setImmediate(True) password.addListener(self, IValueChangeListener) self.addComponent(password) # Comment field + input prompt comment = TextArea() comment.setInputPrompt('Comment') # configure & add to layout comment.setRows(3) comment.setImmediate(True) comment.addListener(self, IValueChangeListener) self.addComponent(comment)
def __init__(self): super(NotificationHumanizedExample, self).__init__() self.setSpacing(True) self.setWidth(None) # layout will grow with content caption = TextField('Caption', 'Document saved') caption.setWidth('200px') self.addComponent(caption) description = TextField('Description', 'Invoices-2008.csv') description.setWidth('300px') self.addComponent(description) l = ShowListener(self, caption, description) show = Button('Show notification', l) self.addComponent(show) self.setComponentAlignment(show, Alignment.MIDDLE_RIGHT)
def createPanel(self, number): p = Panel('Panel %d' % number) p.getContent().setSpacing(True) # Let's create a customized shortcut that jumps to the next field p.addAction(NextFieldListener("Next field", KeyCode.ARROW_DOWN, None)) # Firstname input with an input prompt for demo clarity firstname = TextField('Firstname') firstname.setInputPrompt('ALT-SHIFT-F to focus') p.addComponent(firstname) # Using firstname.addShortcutListener() would add globally, # but we want the shortcut only in this panel: p.addAction( FocusShortcut(firstname, KeyCode.F, ModifierKey.ALT, ModifierKey.SHIFT)) # additinally we'll add a global shortcut for this field using the # shorthand notation (^1 == CTRL-1,NextFieldListener etc) firstname.addShortcutListener( FocusShortcut(firstname, 'Focus panel &_' + str(number))) p.setDescription('CTRL-' + str(number) + ' to focus') # Lastname input with an input prompt for demo clarity lastname = TextField('Lastname') lastname.setInputPrompt('ALT-SHIFT-L to focus') p.addComponent(lastname) # Using firstname.addShortcutListener() would add globally, # but we want the shortcut only in this panel: p.addAction( FocusShortcut(lastname, KeyCode.L, ModifierKey.ALT, ModifierKey.SHIFT)) # Button with a simple click-listener save = Button('Save', SaveListener(self, p)) p.addComponent(save) # setClickShortcut() would add global shortcut, instead we # 'scope' the shortcut to the panel: p.addAction( ClickShortcut(save, KeyCode.S, ModifierKey.ALT, ModifierKey.SHIFT)) return p
def __init__(self): super(TextFieldSingleExample, self).__init__() self.setSpacing(True) self._editor = TextField('Echo this:') self._editor.addListener(self, IValueChangeListener) self._editor.setImmediate(True) # editor.setColumns(5) # guarantees that at least 5 chars fit self.addComponent(self._editor)
def initFilteringControls(self): for pn in self._visibleCols: sf = TextField() self._bottomLeftCorner.addComponent(sf) sf.setWidth("100%") sf.setValue(pn) sf.setImmediate(True) self._bottomLeftCorner.setExpandRatio(sf, 1) sf.addCallback(onFilterChange, property.ValueChangeEvent, pn, sf, self)
def createCoreHorizontal(self, recurse): l = HorizontalLayout() l.setSizeFull() tf = TextField('Top') l.addComponent(tf) l.setComponentAlignment(tf, Alignment.TOP_LEFT) tf = TextField('Middle') l.addComponent(tf) l.setComponentAlignment(tf, Alignment.MIDDLE_LEFT) tf = TextField('Bottom') l.addComponent(tf) tf.setWidth('50%') l.setComponentAlignment(tf, Alignment.BOTTOM_LEFT) if recurse > 0: recurse -= 1 createCoreVertical = self.createCoreVertical(recurse) l.addComponent(createCoreVertical) l.setExpandRatio(createCoreVertical, 1) return l
def __init__(self): # this is a VerticalLayout super(VerticalLayoutBasicExample, self).__init__() # let's add some components for i in range(5): tf = TextField('Row %d' % (i + 1)) tf.setWidth('300px') # Add the component to the VerticalLayout self.addComponent(tf)
def __init__(self): super(ErrorsExample, self).__init__() self.setSpacing(True) self.addComponent( Label('<h3>Errors in caption</h3>', Label.CONTENT_XHTML)) self.addComponent( Label('Error indicators are usually placed on the ' 'right side of the component\'s caption.')) inpt = TextField('Field caption') inpt.setComponentError(UserError('This field is never satisfied')) self.addComponent(inpt) self.addComponent( Label('<h3>Errors without caption</h3>', Label.CONTENT_XHTML)) self.addComponent( Label('If the component has no caption, the error ' 'indicator is usually placed on the right side of the ' 'component.')) inpt = TextField() inpt.setInputPrompt('This field has an error') inpt.setComponentError(UserError('This field is never satisfied.')) self.addComponent(inpt) self.addComponent( Label('<h3>Error icon placement depends on the ' 'layout</h3>', Label.CONTENT_XHTML)) self.addComponent( Label('FormLayout for example places the error ' 'between the component caption and the actual field.')) fl = FormLayout() fl.setMargin(False) fl.setSpacing(False) self.addComponent(fl) inpt = TextField('Field caption') inpt.setInputPrompt('This field has an error') inpt.setComponentError(UserError('This field is never satisfied.')) fl.addComponent(inpt)
def __init__(self): super(NotificationTrayExample, self).__init__() self.setSpacing(True) self.setWidth(None) # layout will grow with content caption = TextField('Caption', 'New message') caption.setWidth('200px') self.addComponent(caption) description = TextField('Description', '<b>John:</b> Could you ' 'upload Invoices-2008.csv so that...') description.setWidth('300px') self.addComponent(description) l = ShowListener(self, caption, description) show = Button('Show notification', l) self.addComponent(show) self.setComponentAlignment(show, Alignment.MIDDLE_RIGHT)
def createCoreVertical(self, recurse): """Same with core layouts""" l = VerticalLayout() l.setSizeFull() tf = TextField('Left') l.addComponent(tf) l.setComponentAlignment(tf, Alignment.TOP_LEFT) tf = TextField('Center') l.addComponent(tf) l.setComponentAlignment(tf, Alignment.TOP_CENTER) tf = TextField('Right') l.addComponent(tf) tf.setWidth('50%') l.setComponentAlignment(tf, Alignment.TOP_RIGHT) if recurse > 0: recurse -= 1 createCoreHorizontal = self.createCoreHorizontal(recurse) l.addComponent(createCoreHorizontal) l.setExpandRatio(createCoreHorizontal, 1) return l
def __init__(self): super(NotificationErrorExample, self).__init__() self.setSpacing(True) self.setWidth(None) # layout will grow with content caption = TextField('Caption', 'Upload failed') caption.setWidth('200px') self.addComponent(caption) description = TextField('Description', 'Invoices-2008.csv could not ' 'be read.<br/>' 'Perhaps the file is damaged, or in the wrong format?<br/>' 'Try re-exporting and uploading the file again.') description.setWidth('300px') self.addComponent(description) l = ShowListener(self, caption, description) show = Button('Show notification', l) self.addComponent(show) self.setComponentAlignment(show, Alignment.MIDDLE_RIGHT)
def __init__(self): super(HorizontalLayoutBasicExample, self).__init__() # First TextField tf = TextField() tf.setWidth('70px') self.addComponent(tf) # A dash dash = Label('-') self.addComponent(dash) self.setComponentAlignment(dash, Alignment.MIDDLE_LEFT) # Second TextField tf = TextField() tf.setWidth('70px') self.addComponent(tf) # Another dash dash = Label('-') self.addComponent(dash) self.setComponentAlignment(dash, Alignment.MIDDLE_LEFT) # Third TextField tf = TextField() tf.setWidth('70px') self.addComponent(tf) # Yet another dash dash = Label('-') self.addComponent(dash) self.setComponentAlignment(dash, Alignment.MIDDLE_LEFT) # Forth and last TextField tf = TextField() tf.setWidth('70px') self.addComponent(tf)
def __init__(self): super(NotificationCustomExample, self).__init__() self.setSpacing(True) caption = TextField('Caption', 'Message sent') caption.setDescription(('Main info; a short caption-only ' 'notification is often most effective.')) caption.setWidth('200px') self.addComponent(caption) description = RichTextArea() description.setWidth('100%') description.setValue('<p>to <i>[email protected]</i></p>') description.setCaption('Description') description.setDescription(('Additional information; ' 'try to keep it short.')) self.addComponent(description) horiz = HorizontalLayout() horiz.setSpacing(True) self.addComponent(horiz) position = NativeSelect('Position') position.setNullSelectionAllowed(False) horiz.addComponent(position) self.initPositionItems(position) style = NativeSelect('Style') style.setNullSelectionAllowed(False) horiz.addComponent(style) self.initTypeItems(style) delay = Slider('Delay (msec), -1 means click to hide') delay.setDescription( ('Delay before fading<br/>Pull all the way to ' 'the left to get -1, which means forever (click to hide).')) delay.setWidth('100%') # 'description' will push width delay.setMin(Notification.DELAY_FOREVER) delay.setMax(10000) self.addComponent(delay) # TODO icon select l = ShowListener(self, caption, description, style, position, delay) show = Button('Show notification', l) self.addComponent(show) self.setComponentAlignment(show, Alignment.MIDDLE_RIGHT)
def __init__(self): super(TreeSingleSelectExample, self).__init__() self.setSpacing(True) # Create the Tree,a dd to layout self._tree = Tree('Hardware Inventory') self.addComponent(self._tree) # Contents from a (prefilled example) hierarchical container: self._tree.setContainerDataSource(ExampleUtil.getHardwareContainer()) # Add Valuechangelistener and Actionhandler self._tree.addListener(self, IValueChangeListener) # Add actions (context menu) self._tree.addActionHandler(self) # Cause valueChange immediately when the user selects self._tree.setImmediate(True) # Set tree to show the 'name' property as caption for items self._tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME) self._tree.setItemCaptionMode( AbstractSelect.ITEM_CAPTION_MODE_PROPERTY) # Expand whole tree for idd in self._tree.rootItemIds(): self._tree.expandItemsRecursively(idd) # Create the 'editor bar' (textfield and button in a horizontallayout) self._editBar = HorizontalLayout() self._editBar.setMargin(False, False, False, True) self._editBar.setEnabled(False) self.addComponent(self._editBar) # textfield self._editor = TextField('Item name') self._editor.setImmediate(True) self._editBar.addComponent(self._editor) # apply-button self._change = Button('Apply', self) #, 'buttonClick') FIXME: listener self._editBar.addComponent(self._change) self._editBar.setComponentAlignment(self._change, Alignment.BOTTOM_LEFT)
def __init__(self): self._root = VerticalLayout() self._tf = TextField('Edit me') self._root.setSizeUndefined() self._root.setSpacing(True) self._root.setMargin(True) self._root.addComponent( Label( ('The changes made to any components ' 'inside the popup are reflected automatically when the popup ' 'is closed, but you might want to provide explicit action ' 'buttons for the user, like \"Save\" or \"Close\".'))) self._root.addComponent(self._tf) self._tf.setValue('Initial dynamic content') self._tf.setWidth('300px')
def __init__(self): super(TextFieldSecretExample, self).__init__() self.setSizeUndefined() # let content 'push' size self.setSpacing(True) # Username self._username = TextField('Username') self.addComponent(self._username) # Password self._password = PasswordField('Password') self.addComponent(self._password) # Login button loginButton = Button('Login', LoginListener(self)) self.addComponent(loginButton) self.setComponentAlignment(loginButton, Alignment.TOP_RIGHT)
def __init__(self): super(CustomLayoutsExample, self).__init__() self.setMargin(True) # Create the custom layout and set it as a component in # the current layout custom = CustomLayout('../../sampler/layouts/examplecustomlayout') self.addComponent(custom) # Create components and bind them to the location tags # in the custom layout. username = TextField() custom.addComponent(username, 'username') password = PasswordField() custom.addComponent(password, 'password') ok = Button('Login') custom.addComponent(ok, 'okbutton')
def __init__(self): super(TextFieldTextChangeEventExample, self).__init__() nameContainer = ExampleUtil.getNameContainer() filterField = TextField('Filter') filterField.setTextChangeEventMode(TextChangeEventMode.LAZY) filterField.setTextChangeTimeout(200) filterField.addListener(FilterListener(nameContainer), ITextChangeListener) table = Table(None, nameContainer) table.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_HIDDEN) self.setSpacing(False) self.addComponent(filterField) self.addComponent(table) filterField.setWidth('150px') table.setWidth('150px')
def createChildComponentClickableLayout(self): # Create a grid layout with click events layout = GridLayout(5, 2) layout.addStyleName('border') layout.setSpacing(True) layout.setWidth('90%') layout.setMargin(True) # Add some components to the layout layout.addComponent( Label( '<b>Clickable layout events include a ' 'reference to the child component beneath the click. ' 'Try clicking anywhere in this layout.</b>', Label.CONTENT_RAW), 0, 0, 4, 0) layout.addComponent(TextField(None, 'Click here')) layout.addComponent(Link('Click here', None)) select = Select(None, ['Click here']) select.select('Click here') layout.addComponent(select) # Listen for layout click event layout.addListener(GridListener(self), ILayoutClickListener) return layout
def create(self, parent): """ Creates the underlying TextField. """ self.widget = TextField() parent.addComponent(self.widget)