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(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, editor): TextField.__init__(self, editor.str_value) # self.setReadOnly(True) self._editor = editor self.addListener(self, IFocusListener)
class TextEditor ( Editor, IValueChangeListener ): """ Base class for text style editors, which displays an editable text field, containing a text representation of the object trait value. """ #--------------------------------------------------------------------------- # Finishes initializing the editor by creating the underlying toolkit # widget: #--------------------------------------------------------------------------- def init ( self, parent ): """ Finishes initializing the editor by creating the underlying toolkit widget. """ self.control = TextField() self.control.setValue( str(self.str_value) ) self.control.addListener(self, IValueChangeListener) self.set_tooltip() #--------------------------------------------------------------------------- # Handles the user changing the contents of the edit control: #--------------------------------------------------------------------------- def valueChange(self, event): """ Handles the user changing the contents of the edit control. """ try: self.value = unicode(self.control.getValue()) except TraitError: pass
class PopupTextField(popup_view.IContent): 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 getMinimizedValueAsHTML(self): return str(self._tf.getValue()) def getPopupComponent(self): return self._root
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 __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(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 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 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.addListener(TextChangeListener(pn, sf, self), IValueChangeListener)
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)
class ReadonlyEditor ( Editor ): """ Read-only style of editor for Boolean values, which displays static text of either "True" or "False". """ #--------------------------------------------------------------------------- # Finishes initializing the editor by creating the underlying toolkit # widget: #--------------------------------------------------------------------------- def init ( self, parent ): """ Finishes initializing the editor by creating the underlying toolkit widget. """ self.control = TextField() # self.control.setReadOnly(True) self.control.setEnabled(False) self.control.setWidth('100%') #--------------------------------------------------------------------------- # Updates the editor when the object trait changes external to the editor: # # (Should normally be overridden in a subclass) #--------------------------------------------------------------------------- def update_editor ( self ): """ Updates the editor when the object trait changes externally to the editor. """ if self.value: self.control.setValue('True') else: self.control.setValue('False')
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, parent ): """ Finishes initializing the editor by creating the underlying toolkit widget. """ self.control = TextField() # self.control.setReadOnly(True) self.control.setEnabled(False) self.control.setWidth('100%')
def init ( self, parent ): """ Finishes initializing the editor by creating the underlying toolkit widget. """ self.control = TextField() self.control.setValue( str(self.str_value) ) self.control.addListener(self, IValueChangeListener) self.set_tooltip()
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): 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')
class TextFieldSingleExample(VerticalLayout, IValueChangeListener): 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) # Catch the valuechange event of the textfield and update the value of the # label component def valueChange(self, event): # Show the new value we received self.getWindow().showNotification(self._editor.getValue())
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 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 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 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(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 __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(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(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 __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): 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(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(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(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 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 __init__(self): super(NotificationWarningExample, self).__init__() self.setSpacing(True) self.setWidth(None) # layout will grow with content caption = TextField('Caption', 'Upload canceled') caption.setWidth('200px') self.addComponent(caption) description = TextField('Description', 'Invoices-2008.csv will not be processed') 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)
class TreeSingleSelectExample(HorizontalLayout, IValueChangeListener, button.IClickListener, action.IHandler): # Actions for the context menu _ACTION_ADD = Action('Add child item') _ACTION_DELETE = Action('Delete') 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 valueChange(self, event): if event.getProperty().getValue() is not None: # If something is selected from the tree, get it's 'name' and # insert it into the textfield val = self._tree.getItem( event.getProperty().getValue()).getItemProperty( ExampleUtil.hw_PROPERTY_NAME) self._editor.setValue(val) self._editor.requestRepaint() self._editBar.setEnabled(True) else: self._editor.setValue('') self._editBar.setEnabled(False) def buttonClick(self, event): # If the edited value contains something, set it to be the item's new # 'name' property if not (self._editor.getValue() == ''): item = self._tree.getItem(self._tree.getValue()) name = item.getItemProperty(ExampleUtil.hw_PROPERTY_NAME) name.setValue(self._editor.getValue()) # Returns the set of available actions def getActions(self, target, sender): return [self._ACTION_ADD, self._ACTION_DELETE] # Handle actions def handleAction(self, a, sender, target): if a == self._ACTION_ADD: # Allow children for the target item, and expand it self._tree.setChildrenAllowed(target, True) self._tree.expandItem(target) # Create new item, set parent, disallow children (= leaf node) itemId = self._tree.addItem() self._tree.setParent(itemId, target) self._tree.setChildrenAllowed(itemId, False) # Set the name for this item (we use it as item caption) item = self._tree.getItem(itemId) name = item.getItemProperty(ExampleUtil.hw_PROPERTY_NAME) name.setValue('New Item') elif a == self._ACTION_DELETE: parent = self._tree.getParent(target) self._tree.removeItem(target) # If the deleted object's parent has no more children, set it's # childrenallowed property to false (= leaf node) if parent is not None and len(self._tree.getChildren(parent)) == 0: self._tree.setChildrenAllowed(parent, False)
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)
class MuntjacField(MuntjacControl, AbstractTkField): """ A Muntjac implementation of a Field which uses a TextField to provide a single line of editable text. """ #-------------------------------------------------------------------------- # SetupMethods #-------------------------------------------------------------------------- def create(self, parent): """ Creates the underlying TextField. """ self.widget = TextField() parent.addComponent(self.widget) def initialize(self): """ Initializes the attributes of the Muntjac widget. """ super(MuntjacField, self).initialize() shell = self.shell_obj self.set_read_only(shell.read_only) self.set_placeholder_text(shell.placeholder_text) text = shell.field_text if text is not None: self.set_text(text) shell._modified = False self.set_cursor_position(shell.cursor_position) self.set_password_mode(shell.password_mode) self.set_max_length(shell.max_length) def bind(self): """ Binds the event handlers for the TextField. """ super(MuntjacField, self).bind() # widget = self.widget # widget.textEdited.connect(self.on_text_edited) # widget.textChanged.connect(self.on_text_changed) # widget.returnPressed.connect(self.on_return_pressed) # widget.selectionChanged.connect(self.on_selection_changed) # widget.cursorPositionChanged.connect(self.on_cursor_changed) #-------------------------------------------------------------------------- # Shell Object Change Handlers #-------------------------------------------------------------------------- def shell_max_length_changed(self, max_length): """ The change handler for the 'max_length' attribute on the shell object. """ self.set_max_length(max_length) def shell_read_only_changed(self, read_only): """ The change handler for the 'read_only' attribute on the shell object. """ self.set_read_only(read_only) def shell_placeholder_text_changed(self, placeholder_text): """ The change handler for the 'placeholder_text' attribute on the shell object. """ self.set_placeholder_text(placeholder_text) def shell_cursor_position_changed(self, cursor_position): """ The change handler for the 'cursor_position' attribute on the shell object. """ if not guard.guarded(self, 'updating_cursor'): self.set_cursor_position(cursor_position) def shell_field_text_changed(self, text): """ The change handler for the 'field_text' attribute on the shell object. """ if text is not None: if not guard.guarded(self, 'updating_text'): self.set_text(text) self.shell_obj._modified = False def shell_password_mode_changed(self, mode): """ The change handler for the 'password_mode' attribute on the shell object. """ self.set_password_mode(mode) #-------------------------------------------------------------------------- # Manipulation Methods #-------------------------------------------------------------------------- def set_selection(self, start, end): """ Sets the selection in the widget between the start and end positions, inclusive. """ self.widget.setSelectionRange(start, end - start) def select_all(self): """ Select all the text in the line edit. If there is no text in the line edit, the selection will be empty. """ self.widget.selectAll() def deselect(self): """ Deselect any selected text. Sets a selection with start == stop to deselect the current selection. The cursor is placed at the beginning of selection. """ self.widget.setSelectionRange(0, 0) def clear(self): """ Clear the line edit of all text. """ self.widget.setValue('') def backspace(self): """ Simple backspace functionality. If no text is selected, deletes the character to the left of the cursor. Otherwise, it deletes the selected text. """ # FIXME: get selection pos = self.widget.getCursorPosition() val = self.widget.getValue() if (len(val) > 0) and 0 < pos <= len(val): new_val = val[:pos - 1] + val[pos:] self.widget.setValue(new_val) def delete(self): """ Simple delete functionality. If no text is selected, deletes the character to the right of the cursor. Otherwise, it deletes the selected text. """ # FIXME: get selection pos = self.widget.getCursorPosition() val = self.widget.getValue() if (len(val) > 0) and 0 <= pos < len(val): new_val = val[:pos] + val[pos + 1:] self.widget.setValue(new_val) def end(self, mark=False): """ Moves the cursor to the end of the line. Arguments --------- mark : bool, optional If True, select the text from the current position to the end of the line edit. Defaults to False. """ widget = self.widget if mark: start = widget.getCursorPosition() end = len(widget.getValue()) widget.setSelectionRange(start, end) else: end = len(widget.getValue()) widget.setCursorPosition(end) def home(self, mark=False): """ Moves the cursor to the beginning of the line. Arguments --------- mark : bool, optional If True, select the text from the current position to the beginning of the line edit. Defaults to False. """ widget = self.widget if mark: start = 0 end = widget.getCursorPosition() widget.setSelectionRange(start, end) else: widget.setCursorPosition(0) def cut(self): """ Cuts the selected text from the line edit. Copies the selected text to the clipboard then deletes the selected text from the line edit. """ pass def copy(self): """ Copies the selected text to the clipboard. """ pass def paste(self): """ Paste the contents of the clipboard into the line edit. Inserts the contents of the clipboard into the line edit at the current cursor position, replacing any selected text. """ pass def insert(self, text): """ Insert the text into the line edit. Inserts the given text at the current cursor position, replacing any selected text. Arguments --------- text : str The text to insert into the line edit. """ widget = self.widget pos = widget.getCursorPosition() val = widget.getValue() new_val = val[:pos] + text + val[pos:] self.widget.setValue(new_val) def undo(self): """ Undoes the last operation. """ pass def redo(self): """ Redoes the last operation """ pass #-------------------------------------------------------------------------- # Signal Handlers #-------------------------------------------------------------------------- def on_text_edited(self): """ The event handler for when the user edits the text through the ui. """ # The textEdited signal will be emitted along with the # textChanged signal if the user edits from the ui. In # that case, we only want to do one update. if not guard.guarded(self, 'updating_text'): with guard(self, 'updating_text'): shell = self.shell_obj text = self.widget.getValue() shell.field_text = text shell.text_edited = text shell._modified = True def on_text_changed(self): """ The event handler for when the user edits the text programmatically. """ # The textEdited signal will be emitted along with the # textChanged signal if the user edits from the ui. In # that case, we only want to do one update. if not guard.guarded(self, 'updating_text'): with guard(self, 'updating_text'): shell = self.shell_obj text = self.widget.getValue() shell.field_text = text def on_return_pressed(self): """ The event handler for the return pressed event. """ self.shell_obj.return_pressed = True def on_selection_changed(self): """ The event handler for a selection event. """ # with guard(self, 'updating_selection'): # self.shell_obj._selected_text = self.widget.selectedText() pass def on_cursor_changed(self): """ The event handler for a cursor change event. """ with guard(self, 'updating_cursor'): self.shell_obj.cursor_position = self.widget.getCursorPosition() #-------------------------------------------------------------------------- # Update methods #-------------------------------------------------------------------------- def set_text(self, text): """ Updates the text control with the new text from the shell object. """ self.widget.setValue(text) def set_max_length(self, max_length): """ Set the max length of the control to max_length. If the max length is <= 0 or > 32767 then the control will be set to hold 32kb of text. """ if (max_length <= 0) or (max_length > 32767): max_length = 32767 self.widget.setMaxLength(max_length) def set_read_only(self, read_only): """ Sets read only state of the widget. """ self.widget.setReadOnly(read_only) def set_placeholder_text(self, placeholder_text): """ Sets the placeholder text in the widget. """ self.widget.setInputPrompt(placeholder_text) def set_cursor_position(self, cursor_position): """ Sets the cursor position of the widget. """ self.widget.setCursorPosition(cursor_position) def set_password_mode(self, password_mode): """ Sets the password mode of the wiget. """ self.widget.setSecret(_PASSWORD_MODES[password_mode])
def create(self, parent): """ Creates the underlying TextField. """ self.widget = TextField() parent.addComponent(self.widget)
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)
class TreeSingleSelectExample(HorizontalLayout, IValueChangeListener, button.IClickListener, action.IHandler): # Actions for the context menu _ACTION_ADD = Action('Add child item') _ACTION_DELETE = Action('Delete') 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 valueChange(self, event): if event.getProperty().getValue() is not None: # If something is selected from the tree, get it's 'name' and # insert it into the textfield val = self._tree.getItem( event.getProperty().getValue()).getItemProperty( ExampleUtil.hw_PROPERTY_NAME) self._editor.setValue(val) self._editor.requestRepaint() self._editBar.setEnabled(True) else: self._editor.setValue('') self._editBar.setEnabled(False) def buttonClick(self, event): # If the edited value contains something, set it to be the item's new # 'name' property if not (self._editor.getValue() == ''): item = self._tree.getItem(self._tree.getValue()) name = item.getItemProperty(ExampleUtil.hw_PROPERTY_NAME) name.setValue(self._editor.getValue()) # Returns the set of available actions def getActions(self, target, sender): return [self._ACTION_ADD, self._ACTION_DELETE] # Handle actions def handleAction(self, a, sender, target): if a == self._ACTION_ADD: # Allow children for the target item, and expand it self._tree.setChildrenAllowed(target, True) self._tree.expandItem(target) # Create new item, set parent, disallow children (= leaf node) itemId = self._tree.addItem() self._tree.setParent(itemId, target) self._tree.setChildrenAllowed(itemId, False) # Set the name for this item (we use it as item caption) item = self._tree.getItem(itemId) name = item.getItemProperty(ExampleUtil.hw_PROPERTY_NAME) name.setValue('New Item') elif a == self._ACTION_DELETE: parent = self._tree.getParent(target) self._tree.removeItem(target) # If the deleted object's parent has no more children, set it's # childrenallowed property to false (= leaf node) if parent is not None and len(self._tree.getChildren(parent)) == 0: self._tree.setChildrenAllowed(parent, False)
class MuntjacField(MuntjacControl, AbstractTkField): """ A Muntjac implementation of a Field which uses a TextField to provide a single line of editable text. """ # -------------------------------------------------------------------------- # SetupMethods # -------------------------------------------------------------------------- def create(self, parent): """ Creates the underlying TextField. """ self.widget = TextField() parent.addComponent(self.widget) def initialize(self): """ Initializes the attributes of the Muntjac widget. """ super(MuntjacField, self).initialize() shell = self.shell_obj self.set_read_only(shell.read_only) self.set_placeholder_text(shell.placeholder_text) text = shell.field_text if text is not None: self.set_text(text) shell._modified = False self.set_cursor_position(shell.cursor_position) self.set_password_mode(shell.password_mode) self.set_max_length(shell.max_length) def bind(self): """ Binds the event handlers for the TextField. """ super(MuntjacField, self).bind() # widget = self.widget # widget.textEdited.connect(self.on_text_edited) # widget.textChanged.connect(self.on_text_changed) # widget.returnPressed.connect(self.on_return_pressed) # widget.selectionChanged.connect(self.on_selection_changed) # widget.cursorPositionChanged.connect(self.on_cursor_changed) # -------------------------------------------------------------------------- # Shell Object Change Handlers # -------------------------------------------------------------------------- def shell_max_length_changed(self, max_length): """ The change handler for the 'max_length' attribute on the shell object. """ self.set_max_length(max_length) def shell_read_only_changed(self, read_only): """ The change handler for the 'read_only' attribute on the shell object. """ self.set_read_only(read_only) def shell_placeholder_text_changed(self, placeholder_text): """ The change handler for the 'placeholder_text' attribute on the shell object. """ self.set_placeholder_text(placeholder_text) def shell_cursor_position_changed(self, cursor_position): """ The change handler for the 'cursor_position' attribute on the shell object. """ if not guard.guarded(self, "updating_cursor"): self.set_cursor_position(cursor_position) def shell_field_text_changed(self, text): """ The change handler for the 'field_text' attribute on the shell object. """ if text is not None: if not guard.guarded(self, "updating_text"): self.set_text(text) self.shell_obj._modified = False def shell_password_mode_changed(self, mode): """ The change handler for the 'password_mode' attribute on the shell object. """ self.set_password_mode(mode) # -------------------------------------------------------------------------- # Manipulation Methods # -------------------------------------------------------------------------- def set_selection(self, start, end): """ Sets the selection in the widget between the start and end positions, inclusive. """ self.widget.setSelectionRange(start, end - start) def select_all(self): """ Select all the text in the line edit. If there is no text in the line edit, the selection will be empty. """ self.widget.selectAll() def deselect(self): """ Deselect any selected text. Sets a selection with start == stop to deselect the current selection. The cursor is placed at the beginning of selection. """ self.widget.setSelectionRange(0, 0) def clear(self): """ Clear the line edit of all text. """ self.widget.setValue("") def backspace(self): """ Simple backspace functionality. If no text is selected, deletes the character to the left of the cursor. Otherwise, it deletes the selected text. """ # FIXME: get selection pos = self.widget.getCursorPosition() val = self.widget.getValue() if (len(val) > 0) and 0 < pos <= len(val): new_val = val[: pos - 1] + val[pos:] self.widget.setValue(new_val) def delete(self): """ Simple delete functionality. If no text is selected, deletes the character to the right of the cursor. Otherwise, it deletes the selected text. """ # FIXME: get selection pos = self.widget.getCursorPosition() val = self.widget.getValue() if (len(val) > 0) and 0 <= pos < len(val): new_val = val[:pos] + val[pos + 1 :] self.widget.setValue(new_val) def end(self, mark=False): """ Moves the cursor to the end of the line. Arguments --------- mark : bool, optional If True, select the text from the current position to the end of the line edit. Defaults to False. """ widget = self.widget if mark: start = widget.getCursorPosition() end = len(widget.getValue()) widget.setSelectionRange(start, end) else: end = len(widget.getValue()) widget.setCursorPosition(end) def home(self, mark=False): """ Moves the cursor to the beginning of the line. Arguments --------- mark : bool, optional If True, select the text from the current position to the beginning of the line edit. Defaults to False. """ widget = self.widget if mark: start = 0 end = widget.getCursorPosition() widget.setSelectionRange(start, end) else: widget.setCursorPosition(0) def cut(self): """ Cuts the selected text from the line edit. Copies the selected text to the clipboard then deletes the selected text from the line edit. """ pass def copy(self): """ Copies the selected text to the clipboard. """ pass def paste(self): """ Paste the contents of the clipboard into the line edit. Inserts the contents of the clipboard into the line edit at the current cursor position, replacing any selected text. """ pass def insert(self, text): """ Insert the text into the line edit. Inserts the given text at the current cursor position, replacing any selected text. Arguments --------- text : str The text to insert into the line edit. """ widget = self.widget pos = widget.getCursorPosition() val = widget.getValue() new_val = val[:pos] + text + val[pos:] self.widget.setValue(new_val) def undo(self): """ Undoes the last operation. """ pass def redo(self): """ Redoes the last operation """ pass # -------------------------------------------------------------------------- # Signal Handlers # -------------------------------------------------------------------------- def on_text_edited(self): """ The event handler for when the user edits the text through the ui. """ # The textEdited signal will be emitted along with the # textChanged signal if the user edits from the ui. In # that case, we only want to do one update. if not guard.guarded(self, "updating_text"): with guard(self, "updating_text"): shell = self.shell_obj text = self.widget.getValue() shell.field_text = text shell.text_edited = text shell._modified = True def on_text_changed(self): """ The event handler for when the user edits the text programmatically. """ # The textEdited signal will be emitted along with the # textChanged signal if the user edits from the ui. In # that case, we only want to do one update. if not guard.guarded(self, "updating_text"): with guard(self, "updating_text"): shell = self.shell_obj text = self.widget.getValue() shell.field_text = text def on_return_pressed(self): """ The event handler for the return pressed event. """ self.shell_obj.return_pressed = True def on_selection_changed(self): """ The event handler for a selection event. """ # with guard(self, 'updating_selection'): # self.shell_obj._selected_text = self.widget.selectedText() pass def on_cursor_changed(self): """ The event handler for a cursor change event. """ with guard(self, "updating_cursor"): self.shell_obj.cursor_position = self.widget.getCursorPosition() # -------------------------------------------------------------------------- # Update methods # -------------------------------------------------------------------------- def set_text(self, text): """ Updates the text control with the new text from the shell object. """ self.widget.setValue(text) def set_max_length(self, max_length): """ Set the max length of the control to max_length. If the max length is <= 0 or > 32767 then the control will be set to hold 32kb of text. """ if (max_length <= 0) or (max_length > 32767): max_length = 32767 self.widget.setMaxLength(max_length) def set_read_only(self, read_only): """ Sets read only state of the widget. """ self.widget.setReadOnly(read_only) def set_placeholder_text(self, placeholder_text): """ Sets the placeholder text in the widget. """ self.widget.setInputPrompt(placeholder_text) def set_cursor_position(self, cursor_position): """ Sets the cursor position of the widget. """ self.widget.setCursorPosition(cursor_position) def set_password_mode(self, password_mode): """ Sets the password mode of the wiget. """ self.widget.setSecret(_PASSWORD_MODES[password_mode])
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(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)