示例#1
0
    def __init__(self):
        super(FormAdvancedLayoutExample, self).__init__()

        # the 'POJO' we're editing.
        # The Person class is imported from the basic form example.
        self._person = Person()  # a person POJO
        personItem = BeanItem(self._person)  # item from POJO

        # Create the Form
        personForm = FormWithComplexLayout(personItem, self)

        # Add form to layout
        self.addComponent(personForm)

        # The cancel / apply buttons
        buttons = HorizontalLayout()
        buttons.setSpacing(True)

        discardChanges = Button("Discard changes", DiscardListener(personForm))
        discardChanges.setStyleName(BaseTheme.BUTTON_LINK)
        buttons.addComponent(discardChanges)
        buttons.setComponentAlignment(discardChanges, Alignment.MIDDLE_LEFT)

        aply = Button("Apply", ApplyListener(personForm))
        buttons.addComponent(aply)
        personForm.getFooter().setMargin(True)
        personForm.getFooter().addComponent(buttons)

        # button for showing the internal state of the POJO
        l = InternalStateListener(self)
        showPojoState = Button("Show POJO internal state", l)
        self.addComponent(showPojoState)
示例#2
0
    def __init__(self):
        super(FormAdvancedLayoutExample, self).__init__()

        # the 'POJO' we're editing.
        # The Person class is imported from the basic form example.
        self._person = Person()  # a person POJO
        personItem = BeanItem(self._person)  # item from POJO

        # Create the Form
        personForm = FormWithComplexLayout(personItem, self)

        # Add form to layout
        self.addComponent(personForm)

        # The cancel / apply buttons
        buttons = HorizontalLayout()
        buttons.setSpacing(True)

        discardChanges = Button('Discard changes', DiscardListener(personForm))
        discardChanges.setStyleName(BaseTheme.BUTTON_LINK)
        buttons.addComponent(discardChanges)
        buttons.setComponentAlignment(discardChanges, Alignment.MIDDLE_LEFT)

        aply = Button('Apply', ApplyListener(personForm))
        buttons.addComponent(aply)
        personForm.getFooter().setMargin(True)
        personForm.getFooter().addComponent(buttons)

        # button for showing the internal state of the POJO
        l = InternalStateListener(self)
        showPojoState = Button('Show POJO internal state', l)
        self.addComponent(showPojoState)
示例#3
0
    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(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)
示例#5
0
class ProgressIndicatorsExample(VerticalLayout):

    def __init__(self):
        super(ProgressIndicatorsExample, self).__init__()

        self.setSpacing(True)

        self.addComponent(Label('<strong>Normal mode</strong> '
                'Runs for 20 seconds', Label.CONTENT_XHTML))
        hl = HorizontalLayout()
        hl.setSpacing(True)
        self.addComponent(hl)

        # Add a normal progress indicator
        self._pi1 = ProgressIndicator()
        self._pi1.setIndeterminate(False)
        self._pi1.setEnabled(False)
        hl.addComponent(self._pi1)
        hl.setComponentAlignment(self._pi1, Alignment.MIDDLE_LEFT)

        self._startButton1 = Button('Start normal', NormalListener(self))
        self._startButton1.setStyleName('small')
        hl.addComponent(self._startButton1)
        self.addComponent(Label('<strong>Indeterminate mode</strong> '
                'Runs for 10 seconds', Label.CONTENT_XHTML))
        hl = HorizontalLayout()
        hl.setSpacing(True)
        self.addComponent(hl)

        # Add an indeterminate progress indicator
        self._pi2 = ProgressIndicator()
        self._pi2.setIndeterminate(True)
        self._pi2.setPollingInterval(5000)
        self._pi2.setEnabled(False)
        hl.addComponent(self._pi2)

        l = IndeterminateListener(self)
        self._startButton2 = Button('Start indeterminate', l)
        self._startButton2.setStyleName('small')
        hl.addComponent(self._startButton2)


    def prosessed(self):
        i = self._worker1.getCurrent()
        if i == Worker1.MAX:
            self._pi1.setEnabled(False)
            self._startButton1.setEnabled(True)
            self._pi1.setValue(1.0)
        else:
            self._pi1.setValue(i / self.Worker1.MAX)


    def prosessed2(self):
        self._pi2.setEnabled(False)
        self._startButton2.setEnabled(True)
class ProgressIndicatorsExample(VerticalLayout):
    def __init__(self):
        super(ProgressIndicatorsExample, self).__init__()

        self.setSpacing(True)

        self.addComponent(
            Label('<strong>Normal mode</strong> '
                  'Runs for 20 seconds', Label.CONTENT_XHTML))
        hl = HorizontalLayout()
        hl.setSpacing(True)
        self.addComponent(hl)

        # Add a normal progress indicator
        self._pi1 = ProgressIndicator()
        self._pi1.setIndeterminate(False)
        self._pi1.setEnabled(False)
        hl.addComponent(self._pi1)
        hl.setComponentAlignment(self._pi1, Alignment.MIDDLE_LEFT)

        self._startButton1 = Button('Start normal', NormalListener(self))
        self._startButton1.setStyleName('small')
        hl.addComponent(self._startButton1)
        self.addComponent(
            Label('<strong>Indeterminate mode</strong> '
                  'Runs for 10 seconds', Label.CONTENT_XHTML))
        hl = HorizontalLayout()
        hl.setSpacing(True)
        self.addComponent(hl)

        # Add an indeterminate progress indicator
        self._pi2 = ProgressIndicator()
        self._pi2.setIndeterminate(True)
        self._pi2.setPollingInterval(5000)
        self._pi2.setEnabled(False)
        hl.addComponent(self._pi2)

        l = IndeterminateListener(self)
        self._startButton2 = Button('Start indeterminate', l)
        self._startButton2.setStyleName('small')
        hl.addComponent(self._startButton2)

    def prosessed(self):
        i = self._worker1.getCurrent()
        if i == Worker1.MAX:
            self._pi1.setEnabled(False)
            self._startButton1.setEnabled(True)
            self._pi1.setValue(1.0)
        else:
            self._pi1.setValue(i / self.Worker1.MAX)

    def prosessed2(self):
        self._pi2.setEnabled(False)
        self._startButton2.setEnabled(True)
示例#7
0
    def __init__(self):
        super(ImmediateUploadExample, self).__init__()

        self.setSpacing(True)

        self._status = Label('Please select a file to upload')
        self._pi = ProgressIndicator()
        self._receiver = MyReceiver()
        self._progressLayout = HorizontalLayout()
        self._upload = Upload(None, self._receiver)

        # Slow down the upload
        self._receiver.setSlow(True)
        self.addComponent(self._status)
        self.addComponent(self._upload)
        self.addComponent(self._progressLayout)

        # Make uploading start immediately when file is selected
        self._upload.setImmediate(True)
        self._upload.setButtonCaption('Select file')

        self._progressLayout.setSpacing(True)
        self._progressLayout.setVisible(False)
        self._progressLayout.addComponent(self._pi)
        self._progressLayout.setComponentAlignment(self._pi,
                Alignment.MIDDLE_LEFT)

        cancelProcessing = Button('Cancel')
        cancelProcessing.addListener(CancelListener(self),
                button.IClickListener)
        cancelProcessing.setStyleName('small')
        self._progressLayout.addComponent(cancelProcessing)

        # =========== Add needed listener for the upload component: start,
        # progress, finish, success, fail ===========

        self._upload.addListener(StartedListener(self),
                upload.IStartedListener)

        self._upload.addListener(ProgressListener(self),
                upload.IProgressListener)

        self._upload.addListener(SucceededListener(self),
                upload.ISucceededListener)

        self._upload.addListener(FailedListener(self),
                upload.IFailedListener)

        self._upload.addListener(FinishedListener(self),
                upload.IFinishedListener)
示例#8
0
    def __init__(self):
        super(ImmediateUploadExample, self).__init__()

        self.setSpacing(True)

        self._status = Label('Please select a file to upload')
        self._pi = ProgressIndicator()
        self._receiver = MyReceiver()
        self._progressLayout = HorizontalLayout()
        self._upload = Upload(None, self._receiver)

        # Slow down the upload
        self._receiver.setSlow(True)
        self.addComponent(self._status)
        self.addComponent(self._upload)
        self.addComponent(self._progressLayout)

        # Make uploading start immediately when file is selected
        self._upload.setImmediate(True)
        self._upload.setButtonCaption('Select file')

        self._progressLayout.setSpacing(True)
        self._progressLayout.setVisible(False)
        self._progressLayout.addComponent(self._pi)
        self._progressLayout.setComponentAlignment(self._pi,
                                                   Alignment.MIDDLE_LEFT)

        cancelProcessing = Button('Cancel')
        cancelProcessing.addListener(CancelListener(self),
                                     button.IClickListener)
        cancelProcessing.setStyleName('small')
        self._progressLayout.addComponent(cancelProcessing)

        # =========== Add needed listener for the upload component: start,
        # progress, finish, success, fail ===========

        self._upload.addListener(StartedListener(self),
                                 upload.IStartedListener)

        self._upload.addListener(ProgressListener(self),
                                 upload.IProgressListener)

        self._upload.addListener(SucceededListener(self),
                                 upload.ISucceededListener)

        self._upload.addListener(FailedListener(self), upload.IFailedListener)

        self._upload.addListener(FinishedListener(self),
                                 upload.IFinishedListener)
示例#9
0
    def __init__(self):
        super(FormPojoExample, self).__init__()

        self._person = Person()  # a person POJO
        personItem = BeanItem(self._person)  # item from POJO

        # Create the Form
        personForm = Form()
        personForm.setCaption('Personal details')
        personForm.setWriteThrough(False)  # we want explicit 'apply'
        personForm.setInvalidCommitted(False)  # no invalid values in datamodel

        # FieldFactory for customizing the fields and adding validators
        personForm.setFormFieldFactory(PersonFieldFactory(self))
        personForm.setItemDataSource(personItem)  # bind to POJO via BeanItem

        # Determines which properties are shown, and in which order:
        personForm.setVisibleItemProperties(['firstName', 'lastName',
                'countryCode', 'password', 'birthdate', 'shoesize', 'uuid'])

        # Add form to layout
        self.addComponent(personForm)

        # The cancel / apply buttons
        buttons = HorizontalLayout()
        buttons.setSpacing(True)

        discardChanges = Button('Discard changes', DiscardListener(personForm))
        discardChanges.setStyleName(BaseTheme.BUTTON_LINK)
        buttons.addComponent(discardChanges)
        buttons.setComponentAlignment(discardChanges, Alignment.MIDDLE_LEFT)

        aply = Button('Apply', ApplyListener(personForm))
        buttons.addComponent(aply)
        personForm.getFooter().addComponent(buttons)
        personForm.getFooter().setMargin(False, False, True, True)

        # button for showing the internal state of the POJO
        l = InternalStateListener(self)
        showPojoState = Button('Show POJO internal state', l)
        self.addComponent(showPojoState)
示例#10
0
    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)
示例#11
0
    def __init__(self):
        super(TooltipsExample, self).__init__()

        self.setSpacing(True)

        # Plain tooltip (description)
        plain = Button("Mouse over for plain tooltip")
        plain.setStyleName(BaseTheme.BUTTON_LINK)
        # add the tooltip:
        plain.setDescription("A simple plaintext tooltip")
        self.addComponent(plain)

        # Richtext tooltip (description)
        rich = Button("Mouse over for richtext tooltip")
        rich.setStyleName(BaseTheme.BUTTON_LINK)
        # add the tooltip:
        rich.setDescription(
            (
                '<h2><img src="../VAADIN/themes/sampler/'
                'icons/comment_yellow.gif"/>A richtext tooltip</h2>'
                "<ul>"
                "<li>HTML formatting</li><li>Images<br/>"
                "</li><li>etc...</li></ul>"
            )
        )
        self.addComponent(rich)

        # Edit
        rte = RichTextArea()
        rte.setValue(("Click <b>" + self._editTxt + "</b> to edit this tooltip, then <b>" + self._applyTxt + "</b>"))
        rte.setVisible(False)  # hide editor initially
        rte.setWidth("100%")
        self.addComponent(rte)

        aply = Button(self._editTxt, EditListener(self, rte))
        aply.setDescription(rte.getValue())
        self.addComponent(aply)
示例#12
0
    def __init__(self):
        super(TooltipsExample, self).__init__()

        self.setSpacing(True)

        # Plain tooltip (description)
        plain = Button('Mouse over for plain tooltip')
        plain.setStyleName(BaseTheme.BUTTON_LINK)
        # add the tooltip:
        plain.setDescription('A simple plaintext tooltip')
        self.addComponent(plain)

        # Richtext tooltip (description)
        rich = Button('Mouse over for richtext tooltip')
        rich.setStyleName(BaseTheme.BUTTON_LINK)
        # add the tooltip:
        rich.setDescription(
            ('<h2><img src=\"../VAADIN/themes/sampler/'
             'icons/comment_yellow.gif\"/>A richtext tooltip</h2>'
             '<ul>'
             '<li>HTML formatting</li><li>Images<br/>'
             '</li><li>etc...</li></ul>'))
        self.addComponent(rich)

        # Edit
        rte = RichTextArea()
        rte.setValue(
            ('Click <b>' + self._editTxt +
             '</b> to edit this tooltip, then <b>' + self._applyTxt + '</b>'))
        rte.setVisible(False)  # hide editor initially
        rte.setWidth('100%')
        self.addComponent(rte)

        aply = Button(self._editTxt, EditListener(self, rte))
        aply.setDescription(rte.getValue())
        self.addComponent(aply)
示例#13
0
    def __init__(self):
        super(ProminentPrimaryActionExample, self).__init__()

        self.setSpacing(True)

        # Cancel / Save
        horiz = HorizontalLayout()
        horiz.setCaption('Save/cancel example:')
        horiz.setSpacing(True)
        horiz.setMargin(True)
        self.addComponent(horiz)
        secondary = Button('Cancel', self)
        secondary.setStyleName(BaseTheme.BUTTON_LINK)
        horiz.addComponent(secondary)
        primary = Button('Save', self)
        horiz.addComponent(primary)

        # Sign up / Sign in
        horiz = HorizontalLayout()
        horiz.setCaption('Sign up example:')
        horiz.setSpacing(True)
        horiz.setMargin(True)
        self.addComponent(horiz)
        primary = Button('Sign up', self)
        primary.addStyleName('primary')
        horiz.addComponent(primary)
        secondary = Button('or Sign in', self)
        secondary.setStyleName(BaseTheme.BUTTON_LINK)
        horiz.addComponent(secondary)
        horiz.setComponentAlignment(secondary, Alignment.MIDDLE_LEFT)

        # Login / Forgot password?
        vert = VerticalLayout()
        vert.setCaption('Login example:')
        vert.setSizeUndefined()
        vert.setSpacing(True)
        vert.setMargin(True)
        self.addComponent(vert)
        primary = Button('Login', self)
        vert.addComponent(primary)
        vert.setComponentAlignment(primary, Alignment.BOTTOM_RIGHT)
        secondary = Button('Forgot your password?', self)
        secondary.setStyleName(BaseTheme.BUTTON_LINK)
        vert.addComponent(secondary)
        vert.setComponentAlignment(secondary, Alignment.BOTTOM_RIGHT)
    def __init__(self):
        super(ProminentPrimaryActionExample, self).__init__()

        self.setSpacing(True)

        # Cancel / Save
        horiz = HorizontalLayout()
        horiz.setCaption('Save/cancel example:')
        horiz.setSpacing(True)
        horiz.setMargin(True)
        self.addComponent(horiz)
        secondary = Button('Cancel', self)
        secondary.setStyleName(BaseTheme.BUTTON_LINK)
        horiz.addComponent(secondary)
        primary = Button('Save', self)
        horiz.addComponent(primary)

        # Sign up / Sign in
        horiz = HorizontalLayout()
        horiz.setCaption('Sign up example:')
        horiz.setSpacing(True)
        horiz.setMargin(True)
        self.addComponent(horiz)
        primary = Button('Sign up', self)
        primary.addStyleName('primary')
        horiz.addComponent(primary)
        secondary = Button('or Sign in', self)
        secondary.setStyleName(BaseTheme.BUTTON_LINK)
        horiz.addComponent(secondary)
        horiz.setComponentAlignment(secondary, Alignment.MIDDLE_LEFT)

        # Login / Forgot password?
        vert = VerticalLayout()
        vert.setCaption('Login example:')
        vert.setSizeUndefined()
        vert.setSpacing(True)
        vert.setMargin(True)
        self.addComponent(vert)
        primary = Button('Login', self)
        vert.addComponent(primary)
        vert.setComponentAlignment(primary, Alignment.BOTTOM_RIGHT)
        secondary = Button('Forgot your password?', self)
        secondary.setStyleName(BaseTheme.BUTTON_LINK)
        vert.addComponent(secondary)
        vert.setComponentAlignment(secondary, Alignment.BOTTOM_RIGHT)
    def __init__(self):
        super(UploadWithProgressMonitoringExample, self).__init__()

        self.setSpacing(True)

        self._state = Label()
        self._result = Label()
        self._fileName = Label()
        self._textualProgress = Label()
        self._pi = ProgressIndicator()
        self._counter = LineBreakCounter()
        self._upload = Upload(None, self._counter)

        self.addComponent(Label('Upload a file and we\'ll count the number '
                'of line break characters (\\n) found in it.'))

        # make analyzing start immediatedly when file is selected
        self._upload.setImmediate(True)
        self._upload.setButtonCaption('Upload File')
        self.addComponent(self._upload)

        handBrake = CheckBox('Simulate slow server')
        handBrake.setValue(True)
        self._counter.setSlow(True)
        handBrake.setDescription('Sleep for 100ms after each kilobyte to '
                'simulate slower processing/bandwidth. This is to show '
                'progress indicator even with rather small files.')
        handBrake.addListener(HandBrakeListener(self), button.IClickListener)

        cancelProcessing = Button('Cancel')
        cancelProcessing.addListener(CancelListener(self),
                button.IClickListener)
        cancelProcessing.setVisible(False)
        cancelProcessing.setStyleName('small')

        handBrake.setImmediate(True)
        self.addComponent(handBrake)

        p = Panel('Status')
        p.setSizeUndefined()

        l = FormLayout()
        l.setMargin(True)
        p.setContent(l)

        stateLayout = HorizontalLayout()
        stateLayout.setSpacing(True)
        stateLayout.addComponent(self._state)
        stateLayout.addComponent(cancelProcessing)
        stateLayout.setCaption('Current state')
        self._state.setValue('Idle')
        l.addComponent(stateLayout)

        self._fileName.setCaption('File name')
        l.addComponent(self._fileName)

        self._result.setCaption('Line breaks counted')
        l.addComponent(self._result)

        self._pi.setCaption('Progress')
        self._pi.setVisible(False)
        l.addComponent(self._pi)
        self._textualProgress.setVisible(False)
        l.addComponent(self._textualProgress)

        self.addComponent(p)

        self._upload.addListener(StartedListener(self),
                upload.IStartedListener)

        self._upload.addListener(ProgressListener(self),
                upload.IProgressListener)

        self._upload.addListener(SucceededListener(self),
                upload.ISucceededListener)

        self._upload.addListener(FailedListener(self),
                upload.IFailedListener)

        self._upload.addListener(FinishedListener(self),
                upload.IFinishedListener)
    def __init__(self):
        super(UploadWithProgressMonitoringExample, self).__init__()

        self.setSpacing(True)

        self._state = Label()
        self._result = Label()
        self._fileName = Label()
        self._textualProgress = Label()
        self._pi = ProgressIndicator()
        self._counter = LineBreakCounter()
        self._upload = Upload(None, self._counter)

        self.addComponent(
            Label('Upload a file and we\'ll count the number '
                  'of line break characters (\\n) found in it.'))

        # make analyzing start immediatedly when file is selected
        self._upload.setImmediate(True)
        self._upload.setButtonCaption('Upload File')
        self.addComponent(self._upload)

        handBrake = CheckBox('Simulate slow server')
        handBrake.setValue(True)
        self._counter.setSlow(True)
        handBrake.setDescription(
            'Sleep for 100ms after each kilobyte to '
            'simulate slower processing/bandwidth. This is to show '
            'progress indicator even with rather small files.')
        handBrake.addListener(HandBrakeListener(self), button.IClickListener)

        cancelProcessing = Button('Cancel')
        cancelProcessing.addListener(CancelListener(self),
                                     button.IClickListener)
        cancelProcessing.setVisible(False)
        cancelProcessing.setStyleName('small')

        handBrake.setImmediate(True)
        self.addComponent(handBrake)

        p = Panel('Status')
        p.setSizeUndefined()

        l = FormLayout()
        l.setMargin(True)
        p.setContent(l)

        stateLayout = HorizontalLayout()
        stateLayout.setSpacing(True)
        stateLayout.addComponent(self._state)
        stateLayout.addComponent(cancelProcessing)
        stateLayout.setCaption('Current state')
        self._state.setValue('Idle')
        l.addComponent(stateLayout)

        self._fileName.setCaption('File name')
        l.addComponent(self._fileName)

        self._result.setCaption('Line breaks counted')
        l.addComponent(self._result)

        self._pi.setCaption('Progress')
        self._pi.setVisible(False)
        l.addComponent(self._pi)
        self._textualProgress.setVisible(False)
        l.addComponent(self._textualProgress)

        self.addComponent(p)

        self._upload.addListener(StartedListener(self),
                                 upload.IStartedListener)

        self._upload.addListener(ProgressListener(self),
                                 upload.IProgressListener)

        self._upload.addListener(SucceededListener(self),
                                 upload.ISucceededListener)

        self._upload.addListener(FailedListener(self), upload.IFailedListener)

        self._upload.addListener(FinishedListener(self),
                                 upload.IFinishedListener)