示例#1
0
    def init(self):
        main = Window("CSS Tools Add-on Test")
        self.setMainWindow(main)

        testWindow = Window("Normal Window")
        testWindow.addComponent(Label("<p>This window is used as the component to measure.</p>", Label.CONTENT_XHTML))
        main.addWindow(testWindow)
        testWindow.center()

        title = Label("CSS Properties to Retrieve")
        title.addStyleName(Reindeer.LABEL_H2)
        main.addComponent(title)

        target = NativeSelect("Target Component")
        main.addComponent(target)

        get = Button("Refresh Properties", GetClickListener(self, target))
        main.addComponent(get)

        main.addComponent(self.buildLabels())

        target.addItem(main.getContent())
        target.setItemCaption(main.getContent(), "Root layout")
        target.addItem(testWindow)
        target.setItemCaption(testWindow, "Sub window")
        target.addItem(get)
        target.setItemCaption(get, "The '" + get.getCaption() + "' Button")
        target.setNullSelectionAllowed(False)
        target.select(testWindow)
示例#2
0
    def init(self):
        # Application.init is called once for each application. Here it
        # creates the UI and connects it to the business logic.

        # Create the main layout for our application (4 columns, 5 rows)
        layout = GridLayout(4, 5)

        # Create the main window for the application using the main layout.
        # The main window is shown when the application is starts.
        self.setMainWindow(Window('Calculator Application', layout))

        # Create a result label that over all 4 columns in the first row
        layout.addComponent(self._display, 0, 0, 3, 0)

        # The operations for the calculator in the order they appear on the
        # screen (left to right, top to bottom)
        operations = ['7', '8', '9', '/', '4', '5', '6',
                '*', '1', '2', '3', '-', '0', '=', 'C', '+']

        for caption in operations:
            # Create a button and use this application for event handling
            button = Button(caption)
            button.addListener(self)

            # Add the button to our main layout
            layout.addComponent(button)
示例#3
0
    def create(self, parent):
        """ Creates the underlying Button control.

        """
        self.widget = Button()
        self.widget.setImmediate(True)
        parent.addComponent(self.widget)
示例#4
0
    def init(self):
        main = Window('CSS Tools Add-on Test')
        self.setMainWindow(main)

        testWindow = Window('Normal Window')
        testWindow.addComponent(
            Label("<p>This window is used as the component to measure.</p>",
                  Label.CONTENT_XHTML))
        main.addWindow(testWindow)
        testWindow.center()

        title = Label('CSS Properties to Retrieve')
        title.addStyleName(Reindeer.LABEL_H2)
        main.addComponent(title)

        target = NativeSelect('Target Component')
        main.addComponent(target)

        get = Button('Refresh Properties', GetClickListener(self, target))
        main.addComponent(get)

        main.addComponent(self.buildLabels())

        target.addItem(main.getContent())
        target.setItemCaption(main.getContent(), 'Root layout')
        target.addItem(testWindow)
        target.setItemCaption(testWindow, 'Sub window')
        target.addItem(get)
        target.setItemCaption(get, 'The \'' + get.getCaption() + '\' Button')
        target.setNullSelectionAllowed(False)
        target.select(testWindow)
示例#5
0
    def __init__(self):
        super(AccordionDisabledExample, self).__init__()

        self.setSpacing(True)

        self._l1 = Label('There are no previously saved actions.')
        self._l2 = Label('There are no saved notes.')
        self._l3 = Label('There are currently no issues.')

        self._a = Accordion()
        self._a.setHeight('300px')
        self._a.setWidth('400px')
        self._t1 = self._a.addTab(self._l1, 'Saved actions', self._icon1)
        self._t2 = self._a.addTab(self._l2, 'Notes', self._icon2)
        self._t3 = self._a.addTab(self._l3, 'Issues', self._icon3)
        self._a.addListener(self, tab_sheet.ISelectedTabChangeListener)

        self._b1 = Button('Disable \'Notes\' tab')
        self._b2 = Button('Hide \'Issues\' tab')
        self._b1.addListener(self, button.IClickListener)
        self._b2.addListener(self, button.IClickListener)

        hl = HorizontalLayout()
        hl.setSpacing(True)
        hl.addComponent(self._b1)
        hl.addComponent(self._b2)

        self.addComponent(self._a)
        self.addComponent(hl)
示例#6
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)
示例#7
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)
示例#8
0
    def __init__(self):
        super(SubwindowExample, self).__init__()

        # Create the window
        self._subwindow = Window('A subwindow')

        # Configure the windows layout; by default a VerticalLayout
        layout = self._subwindow.getContent()
        layout.setMargin(True)
        layout.setSpacing(True)

        # Add some content; a label and a close-button
        message = Label('This is a subwindow')
        self._subwindow.addComponent(message)

        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.TOP_RIGHT)

        # Add a button for opening the subwindow
        opn = Button('Open subwindow', OpenListener(self))
        self.addComponent(opn)
    def __init__(self):
        super(TreeMultiSelectExample, self).__init__()

        self.setSpacing(True)

        # Create new Tree object using a hierarchical container from
        # ExampleUtil class
        self._tree = Tree('Hardware Inventory',
                          ExampleUtil.getHardwareContainer())

        # Set multiselect mode
        self._tree.setMultiSelect(True)
        self._tree.setImmediate(True)

        self._tree.addListener(TreeListener(self), IValueChangeListener)

        # Add Actionhandler
        self._tree.addActionHandler(self)

        # 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 'delete button', inline click-listener
        self._deleteButton = Button('Delete', DeleteListener(self))
        self._deleteButton.setEnabled(False)
        self.addComponent(self._deleteButton)
        self.addComponent(self._tree)
    def createComponents(self):
        components = list()

        label = Label('This is a long text block that will wrap.')
        label.setWidth('120px')
        components.append(label)

        image = Embedded('', ThemeResource('../runo/icons/64/document.png'))
        components.append(image)

        documentLayout = CssLayout()
        documentLayout.setWidth('19px')
        for _ in range(5):
            e = Embedded(None, ThemeResource('../runo/icons/16/document.png'))
            e.setHeight('16px')
            e.setWidth('16px')
            documentLayout.addComponent(e)
        components.append(documentLayout)

        buttonLayout = VerticalLayout()
        button = Button('Button')

        button.addListener(ButtonClickListener(self), IClickListener)
        buttonLayout.addComponent(button)
        buttonLayout.setComponentAlignment(button, Alignment.MIDDLE_CENTER)
        components.append(buttonLayout)

        return components
示例#11
0
    def __init__(self):
        super(PanelLightExample, self).__init__()

        self.setSpacing(True)
        self.setSpacing(True)

        # Panel 1 - with caption
        self._panel = Panel('This is a light Panel')
        self._panel.setStyleName(Reindeer.PANEL_LIGHT)
        self._panel.setHeight('200px')  # we want scrollbars
        # let's adjust the panels default layout (a VerticalLayout)
        layout = self._panel.getContent()
        layout.setMargin(True)  # we want a margin
        layout.setSpacing(True)
        # and spacing between components
        self.addComponent(self._panel)

        # Let's add a few rows to provoke scrollbars:
        for _ in range(20):
            l = Label('The quick brown fox jumps over the lazy dog.')
            self._panel.addComponent(l)

        # Caption toggle:
        b = Button('Toggle caption')
        b.addListener(self, IClickListener)
        self.addComponent(b)
示例#12
0
    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(AccordionDisabledExample, self).__init__()

        self.setSpacing(True)

        self._l1 = Label('There are no previously saved actions.')
        self._l2 = Label('There are no saved notes.')
        self._l3 = Label('There are currently no issues.')

        self._a = Accordion()
        self._a.setHeight('300px')
        self._a.setWidth('400px')
        self._t1 = self._a.addTab(self._l1, 'Saved actions', self._icon1)
        self._t2 = self._a.addTab(self._l2, 'Notes', self._icon2)
        self._t3 = self._a.addTab(self._l3, 'Issues', self._icon3)
        self._a.addListener(self, tab_sheet.ISelectedTabChangeListener)

        self._b1 = Button('Disable \'Notes\' tab')
        self._b2 = Button('Hide \'Issues\' tab')
        self._b1.addListener(self, button.IClickListener)
        self._b2.addListener(self, button.IClickListener)

        hl = HorizontalLayout()
        hl.setSpacing(True)
        hl.addComponent(self._b1)
        hl.addComponent(self._b2)

        self.addComponent(self._a)
        self.addComponent(hl)
    def __init__(self):
        super(MenuBarHiddenItemsExample, self).__init__()

        self._menubar = MenuBar()

        menuCommand = MenuCommand(self)

        # Save reference to individual items so we can add sub-menu
        # items to them
        f = self._menubar.addItem('File', None)
        newItem = f.addItem('New', None)
        f.addItem('Open f...', menuCommand)
        f.addSeparator()
        newItem.addItem('File', menuCommand)
        newItem.addItem('Folder', menuCommand)
        newItem.addItem('Project...', menuCommand)
        f.addItem('Close', menuCommand)
        f.addItem('Close All', menuCommand)
        f.addSeparator()
        f.addItem('Save', menuCommand)
        f.addItem('Save As...', menuCommand)
        f.addItem('Save All', menuCommand)

        edit = self._menubar.addItem('Edit', None)
        edit.addItem('Undo', menuCommand)

        redo = edit.addItem('Redo', menuCommand)
        redo.setEnabled(False)

        edit.addSeparator()
        edit.addItem('Cut', menuCommand)
        edit.addItem('Copy', menuCommand)
        edit.addItem('Paste', menuCommand)
        edit.addSeparator()

        find = edit.addItem('Find/Replace', menuCommand)

        # Actions can be added inline as well, of course
        find.addItem('Google Search', SearchCommand(self))
        find.addSeparator()
        find.addItem('Find/Replace...', menuCommand)
        find.addItem('Find Next', menuCommand)
        find.addItem('Find Previous', menuCommand)

        view = self._menubar.addItem('View', None)
        view.addItem('Show/Hide Status Bar', menuCommand)
        view.addItem('Customize Toolbar...', menuCommand)
        view.addSeparator()
        view.addItem('Actual Size', menuCommand)
        view.addItem('Zoom In', menuCommand)
        view.addItem('Zoom Out', menuCommand)

        self.addComponent(self._menubar)
        self.addComponent( Button('Hide File menu', HideListener(f)) )

        l = RedoListener(redo)
        self.addComponent( Button('Enable Edit -> Redo action', l) )
        self.setSpacing(True)
示例#15
0
    def initContactAddRemoveButtons(self):
        # New item button
        newItem = Button('+')
        newItem.addCallback(onNew, ClickEvent, self)
        self._bottomLeftCorner.addComponent(newItem)

        # Remove item button
        self._contactRemovalButton = Button('-')
        self._contactRemovalButton.addCallback(onRemove, ClickEvent, self)
        self._contactRemovalButton.setVisible(False)
        self._bottomLeftCorner.addComponent(self._contactRemovalButton)
示例#16
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)
示例#17
0
    def __init__(self):
        super(TableStylingExample, self).__init__()

        self.setSpacing(True)

        self._table = Table()
        self._markedRows = dict()
        self._markedCells = dict()

        self.addComponent(self._table)

        # set a style name, so we can style rows and cells
        self._table.setStyleName('contacts')

        # size
        self._table.setWidth('100%')
        self._table.setPageLength(7)

        # connect data source
        self._table.setContainerDataSource(ExampleUtil.getPersonContainer())

        # Generate the email-link from firstname & lastname
        self._table.addGeneratedColumn('Email', TableColumnGenerator(self))

        # turn on column reordering and collapsing
        self._table.setColumnReorderingAllowed(True)
        self._table.setColumnCollapsingAllowed(True)

        # Actions (a.k.a context menu)
        self._table.addActionHandler( TableActionHandler(self) )

        # style generator
        self._table.setCellStyleGenerator( TableStyleGenerator(self) )

        # toggle cell 'marked' styling when double-clicked
        self._table.addListener(TableClickListener(self), IItemClickListener)

        # Editing

        # we don't want to update container before pressing 'save':
        self._table.setWriteThrough(False)

        # edit button
        editButton = Button('Edit')
        self.addComponent(editButton)

        editButton.addListener(EditListener(self, editButton),
                button.IClickListener)

        self.setComponentAlignment(editButton, Alignment.TOP_RIGHT)
示例#18
0
    def __init__(self):
        super(TableStylingExample, self).__init__()

        self.setSpacing(True)

        self._table = Table()
        self._markedRows = dict()
        self._markedCells = dict()

        self.addComponent(self._table)

        # set a style name, so we can style rows and cells
        self._table.setStyleName('contacts')

        # size
        self._table.setWidth('100%')
        self._table.setPageLength(7)

        # connect data source
        self._table.setContainerDataSource(ExampleUtil.getPersonContainer())

        # Generate the email-link from firstname & lastname
        self._table.addGeneratedColumn('Email', TableColumnGenerator(self))

        # turn on column reordering and collapsing
        self._table.setColumnReorderingAllowed(True)
        self._table.setColumnCollapsingAllowed(True)

        # Actions (a.k.a context menu)
        self._table.addActionHandler( TableActionHandler(self) )

        # style generator
        self._table.setCellStyleGenerator( TableStyleGenerator(self) )

        # toggle cell 'marked' styling when double-clicked
        self._table.addListener(TableClickListener(self), IItemClickListener)

        # Editing

        # we don't want to update container before pressing 'save':
        self._table.setWriteThrough(False)

        # edit button
        editButton = Button('Edit')
        self.addComponent(editButton)

        editButton.addListener(EditListener(self, editButton),
                button.IClickListener)

        self.setComponentAlignment(editButton, Alignment.TOP_RIGHT)
示例#19
0
    def create(self, parent):
        """ Creates the underlying Button control.

        """
        self.widget = Button()
        self.widget.setImmediate(True)
        parent.addComponent(self.widget)
示例#20
0
    def __init__(self):
        super(LayoutSpacingExample, self).__init__()

        # Create a grid layout.
        self.grid = GridLayout(3, 3)

        # Enable sp for the example layout (this is the one we'll toggle
        # with the checkbox)
        self.grid.setSpacing(False)

        # CheckBox for toggling sp on and off
        self.sp = CheckBox("Spacing enabled")
        #        self.sp.setValue(True)  # FIXME:
        self.sp.setImmediate(True)

        self.sp.addListener(self, IClickListener)
        self.addComponent(self.sp)

        # Add the layout to the containing layout.
        self.addComponent(self.grid)

        # Populate the layout with components.
        for i in range(9):
            self.grid.addComponent(Button('Component %d' % (i + 1)))

        self.setSpacing(True)  # enable sp for the example itself
示例#21
0
    def __init__(self):
        super(TreeMultiSelectExample, self).__init__()

        self.setSpacing(True)

        # Create new Tree object using a hierarchical container from
        # ExampleUtil class
        self._tree = Tree('Hardware Inventory',
                ExampleUtil.getHardwareContainer())

        # Set multiselect mode
        self._tree.setMultiSelect(True)
        self._tree.setImmediate(True)

        self._tree.addListener(TreeListener(self), IValueChangeListener)

        # Add Actionhandler
        self._tree.addActionHandler(self)

        # 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 'delete button', inline click-listener
        self._deleteButton = Button('Delete', DeleteListener(self))
        self._deleteButton.setEnabled(False)
        self.addComponent(self._deleteButton)
        self.addComponent(self._tree)
示例#22
0
    def __init__(self):
        super(SubwindowCloseExample, self).__init__()

        self._closableWindow = CheckBox('Allow user to close the window', True)
        self._closableWindow.setImmediate(True)

        self._closableWindow.addListener(ClosableChangeListener(self),
                IValueChangeListener)

        # Create the window
        self._subwindow = Window('A subwindow w/ close-listener')

        self._subwindow.addListener(CloseListener(self), ICloseListener)

        # Configure the windws layout; by default a VerticalLayout
        layout = self._subwindow.getContent()
        layout.setMargin(True)
        layout.setSpacing(True)

        # Add some content; a label and a close-button
        message = Label('This is a subwindow with a close-listener.')
        self._subwindow.addComponent(message)

        # Add a button for opening the subwindow
        self._openCloseButton = Button("Open window", ClickListener(self))

        self.setSpacing(True)
        self.addComponent(self._closableWindow)
        self.addComponent(self._openCloseButton)
示例#23
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)
示例#24
0
    def initContactAddRemoveButtons(self):
        # New item button
        newItem = Button('+', NewItemListener(self))
        self._bottomLeftCorner.addComponent(newItem)

        # Remove item button
        self._contactRemovalButton = Button('-', RemoveItemListener(self))
        self._contactRemovalButton.setVisible(False)
        self._bottomLeftCorner.addComponent(self._contactRemovalButton)
示例#25
0
    def init(self):

        layout = GridLayout(4, 5)

        self.setMainWindow(Window('Calculator Application', layout))

        layout.addComponent(self._display, 0, 0, 3, 0)

        operations = ['7', '8', '9', '/', '4', '5', '6',
                '*', '1', '2', '3', '-', '0', '=', 'C', '+']

        for caption in operations:
            # Create a button and use this application for event handling
            button = Button(caption)
            button.addListener(self)

            # Add the button to our main layout
            layout.addComponent(button)
示例#26
0
 def init ( self, parent ):
     """ Finishes initializing the editor by creating the underlying toolkit
         widget.
     """
     label = self.factory.label or self.item.get_label(self.ui)
     self.control = Button( str(self.string_value(label)) )
     self.sync_value(self.factory.label_value, 'label', 'from')
     self.control.addListener(self, IClickListener)
     self.set_tooltip()
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)
示例#28
0
    def __init__(self):
        super(LabelRichExample, self).__init__()

        self.setSpacing(True)

        self._editor = RichTextArea()
        self._richText = Label(
            '<h1>Rich text example</h1>'
            '<p>The <b>quick</b> brown fox jumps <sup>over</sup> '
            'the <b>lazy</b> dog.</p>'
            '<p>This text can be edited with the <i>Edit</i> -button</p>')
        self._richText.setContentMode(Label.CONTENT_XHTML)
        self.addComponent(self._richText)

        self._b = Button('Edit')
        self._b.addListener(self, IClickListener)
        self.addComponent(self._b)

        self._editor.setWidth('100%')
示例#29
0
    def __init__(self):
        super(TabSheetDisabledExample, self).__init__()

        self.setSpacing(True)

        # Tab 1 content
        self._l1 = VerticalLayout()
        self._l1.setMargin(True)
        self._l1.addComponent(Label('There are no previously saved actions.'))

        # Tab 2 content
        self._l2 = VerticalLayout()
        self._l2.setMargin(True)
        self._l2.addComponent(Label('There are no saved notes.'))

        # Tab 3 content
        self._l3 = VerticalLayout()
        self._l3.setMargin(True)
        self._l3.addComponent(Label('There are currently no issues.'))

        self._t = TabSheet()
        self._t.setHeight('200px')
        self._t.setWidth('400px')

        self._t1 = self._t.addTab(self._l1, 'Saved actions', self._icon1)
        self._t2 = self._t.addTab(self._l2, 'Notes', self._icon2)
        self._t3 = self._t.addTab(self._l3, 'Issues', self._icon3)

        self._t.addListener(self, tab_sheet.ISelectedTabChangeListener)

        self._toggleEnabled = Button('Disable \'Notes\' tab')
        self._toggleEnabled.addListener(self, button.IClickListener)

        self._toggleVisible = Button('Hide \'Issues\' tab')
        self._toggleVisible.addListener(self, button.IClickListener)

        hl = HorizontalLayout()
        hl.setSpacing(True)
        hl.addComponent(self._toggleEnabled)
        hl.addComponent(self._toggleVisible)

        self.addComponent(self._t)
        self.addComponent(hl)
示例#30
0
    def __init__(self):
        super(TabSheetDisabledExample, self).__init__()

        self.setSpacing(True)

        # Tab 1 content
        self._l1 = VerticalLayout()
        self._l1.setMargin(True)
        self._l1.addComponent(Label('There are no previously saved actions.'))

        # Tab 2 content
        self._l2 = VerticalLayout()
        self._l2.setMargin(True)
        self._l2.addComponent(Label('There are no saved notes.'))

        # Tab 3 content
        self._l3 = VerticalLayout()
        self._l3.setMargin(True)
        self._l3.addComponent(Label('There are currently no issues.'))

        self._t = TabSheet()
        self._t.setHeight('200px')
        self._t.setWidth('400px')

        self._t1 = self._t.addTab(self._l1, 'Saved actions', self._icon1)
        self._t2 = self._t.addTab(self._l2, 'Notes', self._icon2)
        self._t3 = self._t.addTab(self._l3, 'Issues', self._icon3)

        self._t.addListener(self, tab_sheet.ISelectedTabChangeListener)

        self._toggleEnabled = Button('Disable \'Notes\' tab')
        self._toggleEnabled.addListener(self, button.IClickListener)

        self._toggleVisible = Button('Hide \'Issues\' tab')
        self._toggleVisible.addListener(self, button.IClickListener)

        hl = HorizontalLayout()
        hl.setSpacing(True)
        hl.addComponent(self._toggleEnabled)
        hl.addComponent(self._toggleVisible)

        self.addComponent(self._t)
        self.addComponent(hl)
示例#31
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)
    def __init__(self):
        super(ApplicationLayoutExample, self).__init__()

        self.setMargin(True)

        self._win = ApplicationLayoutWindow()
        self._open = Button('Open sample in subwindow')

        # We'll open this example in a separate window, configure it
        self._win.setWidth('70%')
        self._win.setHeight('70%')
        self._win.center()

        self._win.addListener(WindowCloseListener(self), ICloseListener)
        # 'open sample' button
        self.addComponent(self._open)

        self._open.addListener(ClickListener(self), IClickListener)
        self.addComponent(
            Label('Don\'t worry: the content of the window '
                  'is not supposed to make sense...'))
    def __init__(self):
        super(AbsoluteLayoutBasicExample, self).__init__()

        self.setMargin(True)

        # Add a border to the layout with CSS to indicate its boundaries
        self.addStyleName('border')

        # allow border to show (100% would clip the right side border)
        self.setWidth('99%')
        self.setHeight('300px')
        self.addComponent(Button('Top: 10px, left: 10px'),
                          'top:10px; left:10px')
        self.addComponent(Button('Top: 10px, right: 40px'),
                          'top:10px; right:40px')
        self.addComponent(Button('Bottom: 0, left: 50%'), 'bottom:0; left:50%')
        self.addComponent(Button('Top: 50%, right: 50%'), 'top:50%; right:50%')

        # Components can overflow out of the container, but they will be
        # clipped. Negative values do not work currently (see issue #4479)
        self.addComponent(Button('Top: 50%, right: 50%'), 'top:50%; right:50%')
示例#34
0
class LabelRichExample(VerticalLayout, IClickListener):

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

        self.setSpacing(True)

        self._editor = RichTextArea()
        self._richText = Label('<h1>Rich text example</h1>'
                '<p>The <b>quick</b> brown fox jumps <sup>over</sup> '
                'the <b>lazy</b> dog.</p>'
                '<p>This text can be edited with the <i>Edit</i> -button</p>')
        self._richText.setContentMode(Label.CONTENT_XHTML)
        self.addComponent(self._richText)

        self._b = Button('Edit')
        self._b.addListener(self, IClickListener)
        self.addComponent(self._b)

        self._editor.setWidth('100%')


    def buttonClick(self, event):
        if self.getComponentIterator().next() == self._richText:
            self._editor.setValue(self._richText.getValue())
            self.replaceComponent(self._richText, self._editor)
            self._b.setCaption('Apply')
        else:
            self._richText.setValue(self._editor.getValue())
            self.replaceComponent(self._editor, self._richText)
            self._b.setCaption('Edit')
示例#35
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(SubwindowPositionedExample, self).__init__()

        self.setSpacing(True)
        # Create the window
        self._subwindow = Window('A positioned subwindow')

        # let's give it a size (optional)
        self._subwindow.setWidth('300px')
        self._subwindow.setHeight('200px')

        # Configure the windows layout; by default a VerticalLayout
        layout = self._subwindow.getContent()
        layout.setMargin(True)
        layout.setSpacing(True)

        # make it fill the whole window
        layout.setSizeFull()

        # Add some content; a label and a close-button
        message = Label('This is a positioned window')
        self._subwindow.addComponent(message)

        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 buttons for opening the subwindow
        fifty = Button('Open window at position 50x50', OpenListener50(self))
        self.addComponent(fifty)

        onefifty = Button('Open window at position 150x200',
                          OpenListener150(self))
        self.addComponent(onefifty)

        center = Button('Open centered window', CenterListener(self))
        self.addComponent(center)
示例#37
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)
示例#38
0
class LabelRichExample(VerticalLayout, IClickListener):
    def __init__(self):
        super(LabelRichExample, self).__init__()

        self.setSpacing(True)

        self._editor = RichTextArea()
        self._richText = Label(
            '<h1>Rich text example</h1>'
            '<p>The <b>quick</b> brown fox jumps <sup>over</sup> '
            'the <b>lazy</b> dog.</p>'
            '<p>This text can be edited with the <i>Edit</i> -button</p>')
        self._richText.setContentMode(Label.CONTENT_XHTML)
        self.addComponent(self._richText)

        self._b = Button('Edit')
        self._b.addListener(self, IClickListener)
        self.addComponent(self._b)

        self._editor.setWidth('100%')

    def buttonClick(self, event):
        if self.getComponentIterator().next() == self._richText:
            self._editor.setValue(self._richText.getValue())
            self.replaceComponent(self._richText, self._editor)
            self._b.setCaption('Apply')
        else:
            self._richText.setValue(self._editor.getValue())
            self.replaceComponent(self._editor, self._richText)
            self._b.setCaption('Edit')
示例#39
0
class ApplicationLayoutExample(VerticalLayout):

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

        self.setMargin(True)

        self._win = ApplicationLayoutWindow()
        self._open = Button('Open sample in subwindow')

        # We'll open this example in a separate window, configure it
        self._win.setWidth('70%')
        self._win.setHeight('70%')
        self._win.center()

        self._win.addListener(WindowCloseListener(self), ICloseListener)
        # 'open sample' button
        self.addComponent(self._open)

        self._open.addListener(ClickListener(self), IClickListener)
        self.addComponent(Label('Don\'t worry: the content of the window '
                'is not supposed to make sense...'))
示例#40
0
    def __init__(self):
        super(VerticalLayout, self).__init__()

        self._win = WebLayoutWindow()
        self._open = Button('Open sample in subwindow')

        self.setMargin(True)

        # We'll open this example in a separate window, configure it
        self._win.setWidth('70%')
        self._win.setHeight('70%')
        self._win.center()

        # Allow opening window again when closed
        self._win.addListener(WindowListener(self), window.ICloseListener)

        # 'open sample' button
        self.addComponent(self._open)

        self._open.addListener(OpenListener(self), button.IClickListener)
        self.addComponent(
            Label('Don\'t worry: the content of the window '
                  'is not supposed to make sense...'))
示例#41
0
class WebLayoutExample(VerticalLayout):

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

        self._win = WebLayoutWindow()
        self._open = Button('Open sample in subwindow')

        self.setMargin(True)

        # We'll open this example in a separate window, configure it
        self._win.setWidth('70%')
        self._win.setHeight('70%')
        self._win.center()

        # Allow opening window again when closed
        self._win.addListener(WindowListener(self), window.ICloseListener)

        # 'open sample' button
        self.addComponent(self._open)

        self._open.addListener(OpenListener(self), button.IClickListener)
        self.addComponent(Label('Don\'t worry: the content of the window '
                'is not supposed to make sense...'))
示例#42
0
    def __init__(self):
        super(IconsExample, self).__init__()

        self.setSpacing(True)

        # Button w/ icon
        button = Button('Save')
        button.setIcon(ThemeResource('../sampler/icons/action_save.gif'))
        self.addComponent(button)

        # Label
        l = Label('Icons are very handy')
        l.setCaption('Comment')
        l.setIcon(ThemeResource('../sampler/icons/comment_yellow.gif'))
        self.addComponent(l)

        # Panel w/ links
        p = Panel('Handy links')
        p.setIcon(ThemeResource('../sampler/icons/icon_info.gif'))
        self.addComponent(p)
        lnk = Link('http://vaadin.com',
                   ExternalResource('http://www.vaadin.com'))
        lnk.setIcon(ThemeResource('../sampler/icons/icon_world.gif'))
        p.addComponent(lnk)
        lnk = Link('http://vaadin.com/learn',
                   ExternalResource('http://www.vaadin.com/learn'))
        lnk.setIcon(ThemeResource('../sampler/icons/icon_world.gif'))
        p.addComponent(lnk)
        lnk = Link('http://dev.vaadin.com/',
                   ExternalResource('http://dev.vaadin.com/'))
        lnk.setIcon(ThemeResource('../sampler/icons/icon_world.gif'))
        p.addComponent(lnk)
        lnk = Link('http://vaadin.com/forum',
                   ExternalResource('http://vaadin.com/forum'))
        lnk.setIcon(ThemeResource('../sampler/icons/icon_world.gif'))
        p.addComponent(lnk)
示例#43
0
    def __init__(self):
        super(IconsExample, self).__init__()

        self.setSpacing(True)

        # Button w/ icon
        button = Button('Save')
        button.setIcon(ThemeResource('../sampler/icons/action_save.gif'))
        self.addComponent(button)

        # Label
        l = Label('Icons are very handy')
        l.setCaption('Comment')
        l.setIcon(ThemeResource('../sampler/icons/comment_yellow.gif'))
        self.addComponent(l)

        # Panel w/ links
        p = Panel('Handy links')
        p.setIcon(ThemeResource('../sampler/icons/icon_info.gif'))
        self.addComponent(p)
        lnk = Link('http://vaadin.com',
                ExternalResource('http://www.vaadin.com'))
        lnk.setIcon(ThemeResource('../sampler/icons/icon_world.gif'))
        p.addComponent(lnk)
        lnk = Link('http://vaadin.com/learn',
                ExternalResource('http://www.vaadin.com/learn'))
        lnk.setIcon(ThemeResource('../sampler/icons/icon_world.gif'))
        p.addComponent(lnk)
        lnk = Link('http://dev.vaadin.com/',
                ExternalResource('http://dev.vaadin.com/'))
        lnk.setIcon(ThemeResource('../sampler/icons/icon_world.gif'))
        p.addComponent(lnk)
        lnk = Link('http://vaadin.com/forum',
                ExternalResource('http://vaadin.com/forum'))
        lnk.setIcon(ThemeResource('../sampler/icons/icon_world.gif'))
        p.addComponent(lnk)
示例#44
0
文件: ui_base.py 项目: rwl/traitsui
    def add_button ( self, action, bbox, method=None, enabled=True,
                     name=None, default=False ):
        """ Creates a button.
        """
        ui = self.ui
        if ((action.defined_when != '') and
            (not ui.eval_when( action.defined_when ))):
            return None

        if name is None:
            name = action.name
        id     = action.id
        button = Button( str(name) )
        bbox.addComponent(button)

        bbox.setComponentAlignment(button, Alignment.MIDDLE_RIGHT)

        if default:
            button.focus()
        button.setEnabled(enabled)
        if (method is None) or (action.enabled_when != '') or (id != ''):
            editor = ButtonEditor( ui      = ui,
                                   action  = action,
                                   control = button )
            if id != '':
                ui.info.bind( id, editor )
            if action.visible_when != '':
                ui.add_visible( action.visible_when, editor )
            if action.enabled_when != '':
                ui.add_enabled( action.enabled_when, editor )
            if method is None:
                method = editor.perform

        if method is not None:
            button.addCallback(method, ClickEvent)

        if action.tooltip != '':
            button.setDescription(action.tooltip)

        return button
示例#45
0
    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)
示例#46
0
    def initContactAddRemoveButtons(self):
        # New item button
        newItem = Button('+')
        newItem.addCallback(onNew, ClickEvent, self)
        self._bottomLeftCorner.addComponent(newItem)

        # Remove item button
        self._contactRemovalButton = Button('-')
        self._contactRemovalButton.addCallback(onRemove, ClickEvent, self)
        self._contactRemovalButton.setVisible(False)
        self._bottomLeftCorner.addComponent(self._contactRemovalButton)
示例#47
0
    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 __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)
示例#49
0
    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)
示例#51
0
    def __init__(self):
        super(LabelRichExample, self).__init__()

        self.setSpacing(True)

        self._editor = RichTextArea()
        self._richText = Label('<h1>Rich text example</h1>'
                '<p>The <b>quick</b> brown fox jumps <sup>over</sup> '
                'the <b>lazy</b> dog.</p>'
                '<p>This text can be edited with the <i>Edit</i> -button</p>')
        self._richText.setContentMode(Label.CONTENT_XHTML)
        self.addComponent(self._richText)

        self._b = Button('Edit')
        self._b.addListener(self, IClickListener)
        self.addComponent(self._b)

        self._editor.setWidth('100%')
示例#52
0
class TreeMultiSelectExample(VerticalLayout, action.IHandler):

    _ACTION_ADD = Action('Add child item')
    _ACTION_DELETE = Action('Delete')
    _ACTIONS = [_ACTION_ADD, _ACTION_DELETE]

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

        self.setSpacing(True)

        # Create new Tree object using a hierarchical container from
        # ExampleUtil class
        self._tree = Tree('Hardware Inventory',
                ExampleUtil.getHardwareContainer())

        # Set multiselect mode
        self._tree.setMultiSelect(True)
        self._tree.setImmediate(True)

        self._tree.addListener(TreeListener(self), IValueChangeListener)

        # Add Actionhandler
        self._tree.addActionHandler(self)

        # 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 'delete button', inline click-listener
        self._deleteButton = Button('Delete', DeleteListener(self))
        self._deleteButton.setEnabled(False)
        self.addComponent(self._deleteButton)
        self.addComponent(self._tree)


    # Returns the set of available actions
    def getActions(self, target, sender):
        return self._ACTIONS


    # Handle actions
    def handleAction(self, a, sender, target):
        if a == self._ACTION_ADD:
            # Allow children for the target item
            self._tree.setChildrenAllowed(target, True)
            # Create new item, disallow children, add name, set parent
            itemId = self._tree.addItem()
            self._tree.setChildrenAllowed(itemId, False)
            newItemName = 'New Item # %d' % itemId
            item = self._tree.getItem(itemId)
            p = item.getItemProperty(ExampleUtil.hw_PROPERTY_NAME)
            p.setValue(newItemName)
            self._tree.setParent(itemId, target)
            self._tree.expandItem(target)
        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
            if parent is not None and len(self._tree.getChildren(parent)) == 0:
                self._tree.setChildrenAllowed(parent, False)
示例#53
0
    def __init__(self):
        super(ButtonPushExample, self).__init__()

        # Normal buttons (more themable)
        buttons = VerticalLayout()
        buttons.setSpacing(True)
        buttons.setMargin(False, True, False, False)
        self.addComponent(buttons)
        buttons.addComponent(Label("<h3>Normal buttons</h3>",
                Label.CONTENT_XHTML))

        # Button w/ text and tooltip
        b = Button(self._CAPTION)
        b.setDescription(self._TOOLTIP)
        b.addListener(self, IClickListener)  # react to clicks
        buttons.addComponent(b)

        # Button w/ text, icon and tooltip
        b = Button(self._CAPTION)
        b.setDescription(self._TOOLTIP)
        b.setIcon(self._ICON)
        b.addListener(self, IClickListener)  # react to clicks
        buttons.addComponent(b)

        # Button w/ icon and tooltip
        b = Button()
        b.setDescription(self._TOOLTIP)
        b.setIcon(self._ICON)
        b.addListener(self, IClickListener)  # react to clicks
        buttons.addComponent(b)

        # NativeButtons
        buttons = VerticalLayout()
        buttons.setSpacing(True)
        buttons.setMargin(False, False, False, True)
        self.addComponent(buttons)
        buttons.addComponent(Label("<h3>Native buttons</h3>",
                Label.CONTENT_XHTML));

        # NativeButton w/ text and tooltip
        b = NativeButton(self._CAPTION)
        b.setDescription(self._TOOLTIP)
        b.addListener(self, IClickListener)  # react to clicks
        buttons.addComponent(b)

        # NativeButton w/ text, icon and tooltip
        b = NativeButton(self._CAPTION)
        b.setDescription(self._TOOLTIP)
        b.setIcon(self._ICON)
        b.addListener(self, IClickListener)  # react to clicks
        buttons.addComponent(b)

        # NativeButton w/ icon and tooltip
        b = NativeButton()
        b.setDescription(self._TOOLTIP)
        b.setIcon(self._ICON)
        b.addListener(self, IClickListener)  # react to clicks
        buttons.addComponent(b)
示例#54
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)
    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)
示例#56
0
    def __init__(self):
        super(ExpandingComponentExample, self).__init__()

        self.setSpacing(True)

        # Basic scenario: single expanded component
        layout = HorizontalLayout()
        layout.setWidth('100%')  # make the layout grow with the window size
        self.addComponent(layout)

        naturalButton = Button('Natural')
        naturalButton.setDescription('This button does not have an explicit '
                'size - instead, its size depends on it\'s content - a.k.a '
                '<i>natural size.</i>')
        layout.addComponent(naturalButton)

        expandedButton = Button('Expanded')
        expandedButton.setWidth('100%')
        expandedButton.setDescription('The width of this button is set to '
                '100% and expanded, and will thus occupy the space left over '
                'by the other components.')
        layout.addComponent(expandedButton)
        layout.setExpandRatio(expandedButton, 1.0)

        sizedButton = Button('Explicit')
        sizedButton.setWidth('150px')
        sizedButton.setDescription('This button is explicitly set to be '
                '150 pixels wide.')
        layout.addComponent(sizedButton)


        # Ratio example
        layout = HorizontalLayout()
        layout.setWidth('100%')  # make the layout grow with the window size
        self.addComponent(layout)

        naturalButton = Button('Natural')
        naturalButton.setDescription('This button does not have an explicit '
                'size - instead, its size depends on it\'s content - a.k.a '
                '<i>natural size.</i>')
        layout.addComponent(naturalButton)

        expandedButton1 = Button('Ratio 1.0')
        expandedButton1.setWidth('100%')
        expandedButton1.setDescription('The width of this button is set to '
                '100% and expanded with a ratio of 1.0, and will in this '
                'example occupy 1:3 of the leftover space.')
        layout.addComponent(expandedButton1)
        layout.setExpandRatio(expandedButton1, 1.0)

        expandedButton2 = Button('Ratio 2.0')
        expandedButton2.setWidth('100%')
        expandedButton2.setDescription('The width of this button is set to '
                '100% and expanded with a ratio of 2.0, and will in this '
                'example occupy 2:3 of the leftover space.')
        layout.addComponent(expandedButton2)
        layout.setExpandRatio(expandedButton2, 2.0)
示例#57
0
class TabSheetDisabledExample(VerticalLayout,
            tab_sheet.ISelectedTabChangeListener, button.IClickListener):

    _icon1 = ThemeResource('../sampler/icons/action_save.gif')
    _icon2 = ThemeResource('../sampler/icons/comment_yellow.gif')
    _icon3 = ThemeResource('../sampler/icons/icon_info.gif')

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

        self.setSpacing(True)

        # Tab 1 content
        self._l1 = VerticalLayout()
        self._l1.setMargin(True)
        self._l1.addComponent(Label('There are no previously saved actions.'))

        # Tab 2 content
        self._l2 = VerticalLayout()
        self._l2.setMargin(True)
        self._l2.addComponent(Label('There are no saved notes.'))

        # Tab 3 content
        self._l3 = VerticalLayout()
        self._l3.setMargin(True)
        self._l3.addComponent(Label('There are currently no issues.'))

        self._t = TabSheet()
        self._t.setHeight('200px')
        self._t.setWidth('400px')

        self._t1 = self._t.addTab(self._l1, 'Saved actions', self._icon1)
        self._t2 = self._t.addTab(self._l2, 'Notes', self._icon2)
        self._t3 = self._t.addTab(self._l3, 'Issues', self._icon3)

        self._t.addListener(self, tab_sheet.ISelectedTabChangeListener)

        self._toggleEnabled = Button('Disable \'Notes\' tab')
        self._toggleEnabled.addListener(self, button.IClickListener)

        self._toggleVisible = Button('Hide \'Issues\' tab')
        self._toggleVisible.addListener(self, button.IClickListener)

        hl = HorizontalLayout()
        hl.setSpacing(True)
        hl.addComponent(self._toggleEnabled)
        hl.addComponent(self._toggleVisible)

        self.addComponent(self._t)
        self.addComponent(hl)


    def selectedTabChange(self, event):
        selected = event.getTabSheet().getSelectedTab()
        c = self._t.getTab(selected).getCaption()
        self.getWindow().showNotification('Selected tab: ' + c)


    def buttonClick(self, event):
        if self._toggleEnabled == event.getButton():
            # toggleEnabled clicked
            self._t2.setEnabled(not self._t2.isEnabled())
            if self._t2.isEnabled():
                self._toggleEnabled.setCaption('Disable \'Notes\' tab')
            else:
                self._toggleEnabled.setCaption('Enable \'Notes\' tab')
        else:
            # toggleVisible clicked
            self._t3.setVisible(not self._t3.isVisible())
            if self._t3.isVisible():
                self._toggleVisible.setCaption('Hide \'Issues\' tab')
            else:
                self._toggleVisible.setCaption('Show \'Issues\' tab')
        self._t.requestRepaint()