{"metadata":{"language_info":{"name":"python","version":"3.7.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kernelspec":{"name":"python3","display_name":"Python 3 (ipykernel)","language":"python"}},"nbformat_minor":5,"nbformat":4,"cells":[{"cell_type":"code","source":"import ipywidgets as widgets\nfrom IPython.display import display, Javascript\nfrom traitlets import Unicode, validate\nimport time\nimport threading\n\nclass Timer():\n\n def __init__(self,limit=180):\n #self.value = Unicode('00:00:00').tag(sync=True)\n self.labwidg = widgets.Button(description=\"00:00:00\",layout=lay(120,50))\n self.labwidg.on_click(self.threadTimer)\n #self.labwidg.style.button_color = \"gree\"\n #widgets.Label('00:00:00')\n #display(self.labwidg)\n self.limit = limit\n self.stopTimer = False\n self.thread = None\n self.buttonState = \"Start\"\n def timeit(self, limit=180):\n #display(self)\n hours = 0\n mins = 0\n secs = 0\n for i in range(1,(limit*60+1)):\n if(self.buttonState == \"Start\"):\n self.labwidg.button_style=\"primary\"\n #self.labwidg.style.font_weight = \"50px\"\n elif(self.buttonState == \"Stop\"):\n self.labwidg.button_style=\"success\"\n #self.labwidg.style.font_weight = \"50px\"\n elif(self.buttonState == \"Reset\"):\n self.labwidg.button_style=\"warning\"\n #self.labwidg.style.font_weight = \"50px\"\n if(self.stopTimer):\n self.stopTimer = False\n self.thread = None\n break\n if i%60 == 0:\n if i%3600 == 0:\n secs = 0\n mins = 0\n hours += 1\n else:\n secs = 0\n mins += 1\n else:\n secs += 1\n time.sleep(.0167)\n self.labwidg.description = '{hour:02}:{minute:02}:{second:02}'.\\\n format(hour=hours,minute=mins,second=secs)\n #def twrap(self,b,limit=180):\n # self.timeit(limit=limit)\n def threadTimer(self,b):\n #b.description = self.buttonState\n if(self.buttonState == \"Start\"):\n if(self.thread == None):\n self.thread = threading.Thread(target=self.timeit,args=(self.limit,))\n self.thread.start()\n self.buttonState = \"Stop\"\n elif(self.buttonState == \"Stop\"):\n if(self.thread != None):\n self.stopTimer=True\n self.buttonState = \"Reset\"\n else:\n self.labwidg.description = '00:00:00'\n self.Thread = None\n self.stopTimer=False\n self.buttonState = \"Start\"\n def stopTime(self,b):\n self.stopTimer=True\n\n#def startTimer(b,timer):\n #, args=(,))\ndef lay(width,height):\n return widgets.Layout(width=str(width)+\"px\",height=str(height)+\"px\")\ndef display_timer():\n timer = Timer()\n display(timer.labwidg)","metadata":{"trusted":true},"execution_count":1,"outputs":[],"id":"2ea844a3-5e44-4b25-bd1e-68cecc4181e1"},{"cell_type":"code","source":"display_timer()","metadata":{"trusted":true},"execution_count":2,"outputs":[{"output_type":"display_data","data":{"text/plain":"Button(description='00:00:00', layout=Layout(height='50px', width='120px'), style=ButtonStyle())","application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"b7e91488eada4b43a2b45085ad7fe570"}},"metadata":{}}],"id":"90bd83d6-e52f-4f6c-b883-d49f4b17268c"},{"cell_type":"code","source":"print(\"interview start\")","metadata":{"trusted":true},"execution_count":3,"outputs":[{"name":"stdout","text":"interview start\n","output_type":"stream"}],"id":"09799eb8-d25a-492e-960a-335f41451f4c"},{"cell_type":"code","source":"print(\"interview start\")","metadata":{"trusted":true},"execution_count":null,"outputs":[],"id":"ea55ac3b-fa19-4a10-81f3-154b47204b33"},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[],"id":"1cc654f5-9999-4d75-be8f-787faad4b1a7"}]}