<s> import time <EOL> from threading import Thread <EOL> from muntjac . application import Application <EOL> from muntjac . ui . window import Window <EOL> from muntjac . ui . panel import Panel <EOL> from muntjac . ui . horizontal_layout import HorizontalLayout <EOL> from muntjac . addon . refresher . refresher import Refresher <EOL> from muntjac . ui . label import Label <EOL> from muntjac . ui import button <EOL> from muntjac . ui . button import Button <EOL> SLEEP_TIME_IN_MILLIS = <NUM_LIT:1000> <EOL> class RefresherApplication ( Application ) : <EOL> def init ( self ) : <EOL> mainWindow = Window ( '<STR_LIT>' ) <EOL> self . setMainWindow ( mainWindow ) <EOL> panel = Panel ( '<STR_LIT>' ) <EOL> layout = HorizontalLayout ( ) <EOL> refresher = Refresher ( ) <EOL> label = Label ( '<STR_LIT:0>' ) <EOL> thread = CounterThread ( label ) <EOL> thread . start ( ) <EOL> label . setData ( <NUM_LIT:0> ) <EOL> panel . addComponent ( refresher ) <EOL> panel . addComponent ( Label ( "<STR_LIT>" <EOL> + "<STR_LIT>" <EOL> + "<STR_LIT>" <EOL> + "<STR_LIT>" <EOL> + "<STR_LIT>" , Label . CONTENT_XHTML ) ) <EOL> panel . addComponent ( layout ) <EOL> layout . setSpacing ( True ) <EOL> layout . addComponent ( Button ( '<STR_LIT>' , <EOL> StartClickListener ( refresher , thread ) ) ) <EOL> layout . addComponent ( Button ( '<STR_LIT>' , <EOL> StopClickListener ( refresher , thread ) ) ) <EOL> layout . addComponent ( label ) <EOL> mainWindow . setContent ( panel ) <EOL> class StartClickListener ( button . IClickListener ) : <EOL> def __init__ ( self , refresher , thread ) : <EOL> self . refresher = refresher <EOL> self . thread = thread <EOL> def buttonClick ( self , event ) : <EOL> self . refresher . setRefreshInterval ( SLEEP_TIME_IN_MILLIS ) <EOL> self . thread . startCounting ( ) <EOL> class StopClickListener ( button . IClickListener ) : <EOL> def __init__ ( self , refresher , thread ) : <EOL> self . refresher = refresher <EOL> self . thread = thread <EOL> def buttonClick ( self , event ) : <EOL> self . refresher . setRefreshInterval ( <NUM_LIT:0> ) <EOL> self . thread . stopCounting ( ) <EOL> class CounterThread ( Thread ) : <EOL> def __init__ ( self , renderLabel ) : <EOL> super ( CounterThread , self ) . __init__ ( ) <EOL> self . _renderLabel = renderLabel <EOL> renderLabel . setData ( <NUM_LIT:1> ) <EOL> self . _running = False <EOL> def run ( self ) : <EOL> startTime = <NUM_LIT:1000> * time . time ( ) <EOL> lifetime = <NUM_LIT:1000> * <NUM_LIT> <EOL> try : <EOL> while <NUM_LIT:1000> * time . time ( ) < startTime + lifetime : <EOL> if self . _running : <EOL> number = self . _renderLabel . getData ( ) <EOL> self . _renderLabel . setValue ( number ) <EOL> self . _renderLabel . setData ( number + <NUM_LIT:1> ) <EOL> time . sleep ( SLEEP_TIME_IN_MILLIS ) <EOL> self . _renderLabel . setValue ( '<STR_LIT>' ) <EOL> except KeyboardInterrupt : <EOL> self . _renderLabel . setValue ( '<STR_LIT>' ) <EOL> def startCounting ( self ) : <EOL> self . _running = True <EOL> def stopCounting ( self ) : <EOL> self . _running = False <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from muntjac . main import muntjac <EOL> muntjac ( RefresherApplication , nogui = True , debug = True , <EOL> contextRoot = '<STR_LIT:.>' ) </s>
