Exemple #1
0
    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)
Exemple #2
0
    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 __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(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)
Exemple #5
0
 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)
Exemple #6
0
 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 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)
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())
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())
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 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)