def testAddSubWindow(self): app = TestApp() app.init() subWindow = Window("Sub window") mainWindow = app.getMainWindow() mainWindow.addWindow(subWindow) # Added to main window so the parent of the sub window should be the # main window self.assertEquals(subWindow.getParent(), mainWindow) # Try to add the same sub window to another window try: mainWindow.addWindow(subWindow) self.assertTrue(False, "Window.addWindow did not throw the " "expected exception") except ValueError: # Should throw an exception as it has already been added to the # main window pass try: w = Window() w.addWindow(subWindow) self.assertTrue(False, "Window.addWindow did not throw the " "expected exception") except ValueError: # Should throw an exception as it has already been added to the # main window pass
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()
def testAddSubWindow(self): app = TestApp() app.init() subWindow = Window('Sub window') mainWindow = app.getMainWindow() mainWindow.addWindow(subWindow) # Added to main window so the parent of the sub window should be the # main window self.assertEquals(subWindow.getParent(), mainWindow) # Try to add the same sub window to another window try: mainWindow.addWindow(subWindow) self.assertTrue( False, 'Window.addWindow did not throw the ' 'expected exception') except ValueError: # Should throw an exception as it has already been added to the # main window pass try: w = Window() w.addWindow(subWindow) self.assertTrue( False, 'Window.addWindow did not throw the ' 'expected exception') except ValueError: # Should throw an exception as it has already been added to the # main window pass
def testRemoveSubWindow(self): app = TestApp() app.init() subWindow = Window("Sub window") mainWindow = app.getMainWindow() mainWindow.addWindow(subWindow) # Added to main window so the parent of the sub window should be the # main window self.assertEquals(subWindow.getParent(), mainWindow) # Remove from the wrong window, should result in an exception removed = subWindow.removeWindow(subWindow) self.assertFalse(removed, "Window was removed even though it should " "not have been") # Parent should still be set self.assertEquals(subWindow.getParent(), mainWindow) # Remove from the main window and assert it has been removed removed = mainWindow.removeWindow(subWindow) self.assertTrue(removed, "Window was not removed correctly") self.assertEquals(subWindow.getParent(), None)
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)
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()
def testRemoveSubWindow(self): app = TestApp() app.init() subWindow = Window('Sub window') mainWindow = app.getMainWindow() mainWindow.addWindow(subWindow) # Added to main window so the parent of the sub window should be the # main window self.assertEquals(subWindow.getParent(), mainWindow) # Remove from the wrong window, should result in an exception removed = subWindow.removeWindow(subWindow) self.assertFalse( removed, 'Window was removed even though it should ' 'not have been') # Parent should still be set self.assertEquals(subWindow.getParent(), mainWindow) # Remove from the main window and assert it has been removed removed = mainWindow.removeWindow(subWindow) self.assertTrue(removed, 'Window was not removed correctly') self.assertEquals(subWindow.getParent(), None)
def init(self): # This is called whenever a colorpicker popup is closed main = Window() main.setWidth('1000px') self.setMainWindow(main) # Create an instance of the preview and add it to the window # self._display = Embedded('Color preview') self._display = Canvas() self._display.setWidth('270px') self._display.setHeight('270px') # Add the foreground and background colorpickers to a layout self._mainLayout = mainLayout = HorizontalLayout() mainLayout.setMargin(True) mainLayout.setSpacing(True) main.setContent(mainLayout) layout = VerticalLayout() layout.setWidth('450px') layout.setSpacing(True) optPanel = Panel('Customize the color picker popup window', GridLayout(3, 2)) optPanel.getContent().setSizeFull() optPanel.getContent().setMargin(True) optPanel.getContent().setSpacing(True) self._rgbBox.addListener(RgbClickListener(self), IClickListener) self._rgbBox.setValue(self._rgbVisible) self._rgbBox.setImmediate(True) optPanel.getContent().addComponent(self._rgbBox) self._hsvBox.addListener(HsvClickListener(self), IClickListener) self._hsvBox.setValue(self._hsvVisible) self._hsvBox.setImmediate(True) optPanel.getContent().addComponent(self._hsvBox) self._swaBox.addListener(SwaClickListener(self), IClickListener) self._swaBox.setValue(self._swaVisible) self._swaBox.setImmediate(True) optPanel.getContent().addComponent(self._swaBox) self._hisBox.addListener(HisClickListener(self), IClickListener) self._hisBox.setValue(self._historyVisible) self._hisBox.setImmediate(True) optPanel.getContent().addComponent(self._hisBox) self._txtBox.addListener(TxtClickListener(self), IClickListener) self._txtBox.setValue(self._txtfieldVisible) self._txtBox.setImmediate(True) optPanel.getContent().addComponent(self._txtBox) layout.addComponent(optPanel) panel1 = Panel( 'Button like colorpicker with current color and CSS code', HorizontalLayout()) panel1.getContent().setSizeFull() panel1.getContent().setMargin(True) self._colorpicker1 = ColorPicker('Foreground', self._foregroundColor) self._colorpicker1.setWidth('100px') self._colorpicker1.addListener(self) panel1.addComponent(self._colorpicker1) panel1.getContent().setComponentAlignment(self._colorpicker1, Alignment.MIDDLE_CENTER) self._colorpicker2 = ColorPicker('Background', self._backgroundColor) self._colorpicker2.addListener(self) self._colorpicker2.setWidth('100px') panel1.addComponent(self._colorpicker2) panel1.getContent().setComponentAlignment(self._colorpicker2, Alignment.MIDDLE_CENTER) layout.addComponent(panel1) panel2 = Panel( 'Button like colorpicker with current color and custom caption', HorizontalLayout()) panel2.getContent().setSizeFull() panel2.getContent().setMargin(True) self._colorpicker3 = ColorPicker('Foreground', self._foregroundColor) self._colorpicker3.addListener(self) self._colorpicker3.setWidth('120px') self._colorpicker3.setButtonCaption('Foreground') panel2.addComponent(self._colorpicker3) panel2.getContent().setComponentAlignment(self._colorpicker3, Alignment.MIDDLE_CENTER) self._colorpicker4 = ColorPicker('Background', self._backgroundColor) self._colorpicker4.addListener(self) self._colorpicker4.setWidth('120px') self._colorpicker4.setButtonCaption('Background') panel2.addComponent(self._colorpicker4) panel2.getContent().setComponentAlignment(self._colorpicker4, Alignment.MIDDLE_CENTER) layout.addComponent(panel2) panel3 = Panel('Color area color picker with caption', HorizontalLayout()) panel3.getContent().setSizeFull() panel3.getContent().setMargin(True) self._colorpicker5 = ColorPicker('Foreground', self._foregroundColor) self._colorpicker5.setCaption('Foreground') self._colorpicker5.addListener(self) self._colorpicker5.setButtonStyle(ButtonStyle.BUTTON_AREA) panel3.addComponent(self._colorpicker5) panel3.getContent().setComponentAlignment(self._colorpicker5, Alignment.MIDDLE_CENTER) self._colorpicker6 = ColorPicker('Background', self._backgroundColor) self._colorpicker6.setCaption('Background') self._colorpicker6.addListener(self) self._colorpicker6.setButtonStyle(ButtonStyle.BUTTON_AREA) panel3.addComponent(self._colorpicker6) panel3.getContent().setComponentAlignment(self._colorpicker6, Alignment.MIDDLE_CENTER) layout.addComponent(panel3) mainLayout.addComponent(layout) mainLayout.addComponent(self._display) self.updateDisplay(self._foregroundColor, self._backgroundColor)
def init(self): main = Window('Muntjac') main.setTheme('sampler-reindeer') self.setMainWindow(main) main.addComponent(Example())
def setUp(self): super(TestWindow, self).setUp() self.mox = mox.Mox() self._window = Window()
class TestWindow(TestCase): def setUp(self): super(TestWindow, self).setUp() self.mox = mox.Mox() self._window = Window() def testCloseListener(self): cl = self.mox.CreateMock(window.ICloseListener) # Expectations cl.windowClose(mox.IsA(window.CloseEvent)) # Start actual test mox.Replay(cl) # Add listener and send a close event -> should end up in listener once self._window.addListener(cl, window.ICloseListener) self.sendClose(self._window) # Ensure listener was called once mox.Verify(cl) # Remove the listener and send close event -> should not end up in # listener self._window.removeListener(cl, window.ICloseListener) self.sendClose(self._window) # Ensure listener still has been called only once mox.Verify(cl) def testResizeListener(self): rl = self.mox.CreateMock(window.IResizeListener) # Expectations rl.windowResized(mox.IsA(window.ResizeEvent)) # Start actual test mox.Replay(rl) # Add listener and send a resize event -> should end up # in listener once self._window.addListener(rl, window.IResizeListener) self.sendResize(self._window) # Ensure listener was called once mox.Verify(rl) # Remove the listener and send close event -> should not # end up in listener self._window.removeListener(rl, window.IResizeListener) self.sendResize(self._window) # Ensure listener still has been called only once mox.Verify(rl) def sendResize(self, window2): variables = dict() variables['height'] = 1234 self._window.changeVariables(self._window, variables) @classmethod def sendClose(cls, window): variables = dict() variables['close'] = True window.changeVariables(window, variables)
def init(self): w = Window('Main window') self.setMainWindow(w)
def init(self): # This is called whenever a colorpicker popup is closed main = Window() main.setWidth('1000px') self.setMainWindow(main) # Create an instance of the preview and add it to the window # self._display = Embedded('Color preview') self._display = Canvas() self._display.setWidth('270px') self._display.setHeight('270px') # Add the foreground and background colorpickers to a layout self._mainLayout = mainLayout = HorizontalLayout() mainLayout.setMargin(True) mainLayout.setSpacing(True) main.setContent(mainLayout) layout = VerticalLayout() layout.setWidth('450px') layout.setSpacing(True) optPanel = Panel('Customize the color picker popup window', GridLayout(3, 2)) optPanel.getContent().setSizeFull() optPanel.getContent().setMargin(True) optPanel.getContent().setSpacing(True) self._rgbBox.addListener(RgbClickListener(self), IClickListener) self._rgbBox.setValue(self._rgbVisible) self._rgbBox.setImmediate(True) optPanel.getContent().addComponent(self._rgbBox) self._hsvBox.addListener(HsvClickListener(self), IClickListener) self._hsvBox.setValue(self._hsvVisible) self._hsvBox.setImmediate(True) optPanel.getContent().addComponent(self._hsvBox) self._swaBox.addListener(SwaClickListener(self), IClickListener) self._swaBox.setValue(self._swaVisible) self._swaBox.setImmediate(True) optPanel.getContent().addComponent(self._swaBox) self._hisBox.addListener(HisClickListener(self), IClickListener) self._hisBox.setValue(self._historyVisible) self._hisBox.setImmediate(True) optPanel.getContent().addComponent(self._hisBox) self._txtBox.addListener(TxtClickListener(self), IClickListener) self._txtBox.setValue(self._txtfieldVisible) self._txtBox.setImmediate(True) optPanel.getContent().addComponent(self._txtBox) layout.addComponent(optPanel) panel1 = Panel( 'Button like colorpicker with current color and CSS code', HorizontalLayout()) panel1.getContent().setSizeFull() panel1.getContent().setMargin(True) self._colorpicker1 = ColorPicker('Foreground', self._foregroundColor) self._colorpicker1.setWidth('100px') self._colorpicker1.addListener(self) panel1.addComponent(self._colorpicker1) panel1.getContent().setComponentAlignment(self._colorpicker1, Alignment.MIDDLE_CENTER) self._colorpicker2 = ColorPicker('Background', self._backgroundColor) self._colorpicker2.addListener(self) self._colorpicker2.setWidth('100px') panel1.addComponent(self._colorpicker2) panel1.getContent().setComponentAlignment(self._colorpicker2, Alignment.MIDDLE_CENTER) layout.addComponent(panel1) panel2 = Panel( 'Button like colorpicker with current color and custom caption', HorizontalLayout()) panel2.getContent().setSizeFull() panel2.getContent().setMargin(True) self._colorpicker3 = ColorPicker('Foreground', self._foregroundColor) self._colorpicker3.addListener(self) self._colorpicker3.setWidth('120px') self._colorpicker3.setButtonCaption('Foreground') panel2.addComponent(self._colorpicker3) panel2.getContent().setComponentAlignment(self._colorpicker3, Alignment.MIDDLE_CENTER) self._colorpicker4 = ColorPicker('Background', self._backgroundColor) self._colorpicker4.addListener(self) self._colorpicker4.setWidth('120px') self._colorpicker4.setButtonCaption('Background') panel2.addComponent(self._colorpicker4) panel2.getContent().setComponentAlignment(self._colorpicker4, Alignment.MIDDLE_CENTER) layout.addComponent(panel2) panel3 = Panel( 'Color area color picker with caption', HorizontalLayout()) panel3.getContent().setSizeFull() panel3.getContent().setMargin(True) self._colorpicker5 = ColorPicker('Foreground', self._foregroundColor) self._colorpicker5.setCaption('Foreground') self._colorpicker5.addListener(self) self._colorpicker5.setButtonStyle(ButtonStyle.BUTTON_AREA) panel3.addComponent(self._colorpicker5) panel3.getContent().setComponentAlignment(self._colorpicker5, Alignment.MIDDLE_CENTER) self._colorpicker6 = ColorPicker('Background', self._backgroundColor) self._colorpicker6.setCaption('Background') self._colorpicker6.addListener(self) self._colorpicker6.setButtonStyle(ButtonStyle.BUTTON_AREA) panel3.addComponent(self._colorpicker6) panel3.getContent().setComponentAlignment(self._colorpicker6, Alignment.MIDDLE_CENTER) layout.addComponent(panel3) mainLayout.addComponent(layout) mainLayout.addComponent(self._display) self.updateDisplay(self._foregroundColor, self._backgroundColor)