| 27 | self.lbl.set_text('Thread result:' + str(self.my_thread_result)) |
| 28 | |
| 29 | def main(self): |
| 30 | # margin 0px auto allows to center the app to the screen |
| 31 | wid = gui.VBox(width=300, height=200, margin='0px auto') |
| 32 | self.lbl = gui.Label('Thread result:', width='80%', height='50%') |
| 33 | self.lbl.style['margin'] = 'auto' |
| 34 | |
| 35 | bt = gui.Button('Stop algorithm', width=200, height=30) |
| 36 | bt.style['margin'] = 'auto 50px' |
| 37 | bt.style['background-color'] = 'red' |
| 38 | |
| 39 | wid.append(self.lbl) |
| 40 | wid.append(bt) |
| 41 | |
| 42 | self.thread_alive_flag = True |
| 43 | self.my_thread_result = 0 |
| 44 | # Here I start a parallel thread that executes my algorithm for a long time |
| 45 | t = threading.Thread(target=self.my_intensive_long_time_algorithm) |
| 46 | t.start() |
| 47 | |
| 48 | bt.onclick.do(self.on_button_pressed) |
| 49 | |
| 50 | # returning the root widget |
| 51 | return wid |
| 52 | |
| 53 | def my_intensive_long_time_algorithm(self): |
| 54 | while self.thread_alive_flag: |