Home | Trees | Indices | Help |
|
---|
|
1 # Copyright (C) 2012 Vaadin Ltd. 2 # Copyright (C) 2012 Richard Lincoln 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 16 import time 17 18 from threading import Thread 19 20 from muntjac.application import Application 21 from muntjac.ui.window import Window 22 from muntjac.ui.panel import Panel 23 from muntjac.ui.horizontal_layout import HorizontalLayout 24 from muntjac.addon.refresher.refresher import Refresher 25 from muntjac.ui.label import Label 26 from muntjac.ui import button 27 from muntjac.ui.button import Button 28 29 SLEEP_TIME_IN_MILLIS = 1000 # a second 303257 58 68 69 79 8034 mainWindow = Window('Refresher') 35 self.setMainWindow(mainWindow) 36 panel = Panel('Refresher example') 37 layout = HorizontalLayout() 38 refresher = Refresher() 39 label = Label('0') 40 thread = CounterThread(label) 41 thread.start() 42 label.setData(0) 43 panel.addComponent(refresher) 44 panel.addComponent(Label("<div style='margin-bottom:10px'>" 45 + "The Refresher allows you to affect the UI " 46 + "from external threads without " 47 + "<a href='http://vaadin.com/forum/-/message_boards/message/69792' target='_blank'>" 48 + "the ProgressIndicator hack</a>.</div>", Label.CONTENT_XHTML)) 49 panel.addComponent(layout) 50 layout.setSpacing(True) 51 layout.addComponent(Button('Start Counting', 52 StartClickListener(refresher, thread))) 53 layout.addComponent(Button('Stop Counting', 54 StopClickListener(refresher, thread))) 55 layout.addComponent(label) 56 mainWindow.setContent(panel)82111 112 113 if __name__ == '__main__': 114 from muntjac.main import muntjac 115 muntjac(RefresherApplication, nogui=True, debug=True, 116 contextRoot='.') 11784 super(CounterThread, self).__init__() 85 self._renderLabel = renderLabel 86 renderLabel.setData(1) 87 self._running = False8890 startTime = 1000 * time.time() 91 lifetime = 1000 * 60 92 # live for a minute. 93 try: 94 while 1000 * time.time() < startTime + lifetime: 95 if self._running: 96 # synchronize with the application, to avoid concurrent 97 # edits on the label's value. 98 number = self._renderLabel.getData() 99 self._renderLabel.setValue(number) 100 self._renderLabel.setData(number + 1) 101 time.sleep(SLEEP_TIME_IN_MILLIS) 102 self._renderLabel.setValue('[ counter thread expired ]') 103 except KeyboardInterrupt: 104 self._renderLabel.setValue('[ counter thread interrupted ]')105 108
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Sat Apr 20 16:01:44 2013 | http://epydoc.sourceforge.net |