def on_closing(self): # Try to stop handler and let it do its thing before shutting down MessageHandler.stop_handler() if self.msg_handler is not None: self.msg_handler.join() # TODO Should this be removed and hopefully that the thread will be closed eventually? self.root.destroy()
def btn_callback(self): if not self.is_connected: # Attempt to connect - check that the port is still connected if self.comports.get() in PortManager.serial_ports(): # Port is still up n runnin' self.btn["text"] = "Disconnect" self.comports.config(state="disabled") # Connect to the Arduino and start processing self.msg_handler = Thread(target=MessageHandler.message_handler, args=(self.comports.get(),)) self.msg_handler.start() # Change da flag fool! self.is_connected = True else: # Port not found - refresh list self.load_ports() else: # Disconnect from Arduino MessageHandler.stop_handler() self.msg_handler.join() # Change the flag BACK! self.is_connected = False # Disconnect. Refresh port list self.btn["text"] = "Connect" self.comports.config(state="enabled") self.load_ports()