コード例 #1
0
    def testRemovingLastRow(self):
        grid = GridLayout(2, 1)
        grid.addComponent(Label('Col1'))
        grid.addComponent(Label('Col2'))

        try:
            # Removing the last row in the grid
            grid.removeRow(0)
        except ValueError:
            # Removing the last row should not throw a ValueError
            self.fail('removeRow(0) threw an ValueError '
                      'when removing the last row')

        # The column amount should be preserved
        self.assertEquals(2, grid.getColumns())

        # There should be one row left
        self.assertEquals(1, grid.getRows())

        # There should be no component left in the grid layout
        self.assertEquals(grid.getComponent(0, 0), None,
                          'A component should not be left in the layout')
        self.assertEquals(grid.getComponent(1, 0), None,
                          'A component should not be left in the layout')

        # The cursor should be in the first cell
        self.assertEquals(0, grid.getCursorX())
        self.assertEquals(0, grid.getCursorY())
コード例 #2
0
    def testGetTabByPosition(self):
        tabSheet = TabSheet()
        tab1 = tabSheet.addTab(Label('aaa'))
        tab2 = tabSheet.addTab(Label('bbb'))
        tab3 = tabSheet.addTab(Label('ccc'))

        self.assertEquals(tab1, tabSheet.getTab(0))
        self.assertEquals(tab2, tabSheet.getTab(1))
        self.assertEquals(tab3, tabSheet.getTab(2))
コード例 #3
0
    def testAbsoluteLayoutDetachListener(self):
        # Add a component to detach
        comp = Label()
        self._absolutelayout.addComponent(comp)

        # Reset state variables (since they are set by the attach listener)
        self.resetVariables()

        # Detach the component -> triggers the detach listener
        self._absolutelayout.removeComponent(comp)

        # Detach counter should get incremented
        self.assertEquals(1, self._detachCounter)

        # The detached component should be the label
        self.assertEquals(comp, self._detachedComponent)

        # The detached target should be the layout
        self.assertEquals(self._absolutelayout, self._detachedTarget)

        # The detached component should not be found in the container
        self.assertFalse(self._foundInContainer)

        # The component position should be null
        self.assertIsNone(self._componentPosition)
コード例 #4
0
    def testOrderedLayoutDetachListener(self):
        # Add a component to detach
        comp = Label()
        self._olayout.addComponent(comp)

        # Reset state variables (since they are set by the attach listener)
        self.resetVariables()

        # Detach the component -> triggers the detach listener
        self._olayout.removeComponent(comp)

        # Detach counter should get incremented
        self.assertEquals(1, self._detachCounter)

        # The detached component should be the label
        self.assertEquals(comp, self._detachedComponent)

        # The detached target should be the layout
        self.assertEquals(self._olayout, self._detachedTarget)

        # The detached component should not be found in the container
        self.assertFalse(self._foundInContainer)

        # The index of the component should be -1
        self.assertEquals(-1, self._indexOfComponent)
コード例 #5
0
    def testAddTabWithComponentOnly(self):
        tabSheet = TabSheet()
        tab1 = tabSheet.addTab(Label('aaa'))
        tab2 = tabSheet.addTab(Label('bbb'))
        tab3 = tabSheet.addTab(Label('ccc'))

        # Check right order of tabs
        self.assertEquals(0, tabSheet.getTabPosition(tab1))
        self.assertEquals(1, tabSheet.getTabPosition(tab2))
        self.assertEquals(2, tabSheet.getTabPosition(tab3))

        # Calling addTab with existing component does not move tab
        tabSheet.addTab(tab1.getComponent())

        # Check right order of tabs
        self.assertEquals(0, tabSheet.getTabPosition(tab1))
        self.assertEquals(1, tabSheet.getTabPosition(tab2))
        self.assertEquals(2, tabSheet.getTabPosition(tab3))
コード例 #6
0
 def testAddExistingComponent(self):
     c = Label('abc')
     tabSheet = TabSheet()
     tabSheet.addComponent(c)
     tabSheet.addComponent(c)
     itr = tabSheet.getComponentIterator()
     self.assertEquals(c, itr.next())
     self.assertRaises(StopIteration, itr.next)
     self.assertNotEquals(tabSheet.getTab(c), None)
コード例 #7
0
    def testRemoveComponentFromWrongContainer(self, componentContainer=None):
        if componentContainer is None:
            containerClasses = MuntjacClasses.\
                getComponentContainersSupportingAddRemoveComponent()

            # No default constructor, special case
            containerClasses.remove(CustomLayout)
            self.testRemoveComponentFromWrongContainer(CustomLayout('dummy'))

            for c in containerClasses:
                self.testRemoveComponentFromWrongContainer( c() )
        else:
            hl = HorizontalLayout()
            label = Label()
            hl.addComponent(label)

            componentContainer.removeComponent(label)
            self.assertEquals(hl, label.getParent(), ('Parent no longer ' +
                    'correct for ' + componentContainer.__class__.__name__))
コード例 #8
0
    def testRemoveComponentFromWrongContainer(self, componentContainer=None):
        if componentContainer is None:
            containerClasses = MuntjacClasses.\
                getComponentContainersSupportingAddRemoveComponent()

            # No default constructor, special case
            containerClasses.remove(CustomLayout)
            self.testRemoveComponentFromWrongContainer(CustomLayout('dummy'))

            for c in containerClasses:
                self.testRemoveComponentFromWrongContainer( c() )
        else:
            hl = HorizontalLayout()
            label = Label()
            hl.addComponent(label)

            componentContainer.removeComponent(label)
            self.assertEquals(hl, label.getParent(), ('Parent no longer ' +
                    'correct for ' + componentContainer.__class__.__name__))
コード例 #9
0
 def init(self):
     mainWindow = Window('Refresher Database Example')
     self.setMainWindow(mainWindow)
     # present with a loading contents.
     self._content = Label('please wait while the database is queried')
     mainWindow.addComponent(self._content)
     # the Refresher polls automatically
     refresher = Refresher()
     refresher.addListener(DatabaseListener(self))
     mainWindow.addComponent(refresher)
     DatabaseQueryProcess(self).start()
コード例 #10
0
    def testAddTabWithAllParameters(self):
        tabSheet = TabSheet()
        tab1 = tabSheet.addTab(Label('aaa'))
        tab2 = tabSheet.addTab(Label('bbb'))
        tab3 = tabSheet.addTab(Label('ccc'))
        tab4 = tabSheet.addTab(Label('ddd'), 'ddd', None, 1)
        tab5 = tabSheet.addTab(Label('eee'), 'eee', None, 3)

        self.assertEquals(0, tabSheet.getTabPosition(tab1))
        self.assertEquals(1, tabSheet.getTabPosition(tab4))
        self.assertEquals(2, tabSheet.getTabPosition(tab2))
        self.assertEquals(3, tabSheet.getTabPosition(tab5))
        self.assertEquals(4, tabSheet.getTabPosition(tab3))

        # Calling addTab with existing component does not move tab
        tabSheet.addTab(tab1.getComponent(), 'xxx', None, 3)
        self.assertEquals(0, tabSheet.getTabPosition(tab1))
        self.assertEquals(1, tabSheet.getTabPosition(tab4))
        self.assertEquals(2, tabSheet.getTabPosition(tab2))
        self.assertEquals(3, tabSheet.getTabPosition(tab5))
        self.assertEquals(4, tabSheet.getTabPosition(tab3))
コード例 #11
0
 def init(self):
     mainWindow = Window('Refresher')
     self.setMainWindow(mainWindow)
     panel = Panel('Refresher example')
     layout = HorizontalLayout()
     refresher = Refresher()
     label = Label('0')
     thread = CounterThread(label)
     thread.start()
     label.setData(0)
     panel.addComponent(refresher)
     panel.addComponent(Label("<div style='margin-bottom:10px'>"
             + "The Refresher allows you to affect the UI "
             + "from external threads without "
             + "<a href='http://vaadin.com/forum/-/message_boards/message/69792' target='_blank'>"
             + "the ProgressIndicator hack</a>.</div>", Label.CONTENT_XHTML))
     panel.addComponent(layout)
     layout.setSpacing(True)
     layout.addComponent(Button('Start Counting',
                 StartClickListener(refresher, thread)))
     layout.addComponent(Button('Stop Counting',
                 StopClickListener(refresher, thread)))
     layout.addComponent(label)
     mainWindow.setContent(panel)
コード例 #12
0
    def testCSSLayoutAttachListener(self):
        # Reset state variables
        self.resetVariables()

        # Add component -> Should trigger attach listener
        comp = Label()
        self._csslayout.addComponent(comp)

        # Attach counter should get incremented
        self.assertEquals(1, self._attachCounter)

        # The attached component should be the label
        self.assertEquals(comp, self._attachedComponent)

        # The attached target should be the layout
        self.assertEquals(self._csslayout, self._attachTarget)

        # The attached component should be found in the container
        self.assertTrue(self._foundInContainer)
コード例 #13
0
 def testGetComponentFromTab(self):
     c = Label('abc')
     tabSheet = TabSheet()
     tab = tabSheet.addTab(c)
     self.assertEquals(c, tab.getComponent())
コード例 #14
0
 def testPopupVisibilityListenerAddGetRemove(self):
     self._testListenerAddGetRemove(PopupView, PopupVisibilityEvent,
                                    IPopupVisibilityListener,
                                    PopupView('', Label()))