self.status = "stopped"
# UI: header
- self.startbutton = QPushButton("Start")
- self.startbutton.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
- self.connect(self.startbutton, SIGNAL('clicked()'), self.start_thread)
-
- self.stopbutton = QPushButton("Stop")
- self.stopbutton.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
- self.stopbutton.setEnabled(False)
- self.connect(self.stopbutton, SIGNAL('clicked()'), self.stop_thread)
+ self.togglebutton = QPushButton("Start")
+ self.togglebutton.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
+ self.connect(self.togglebutton, SIGNAL('clicked()'), self.toggle_thread)
self.statuswidget = QLabel()
self.statuswidget.setWordWrap(True)
self.monitorwidget = QLabel()
header = QHBoxLayout()
- header.addWidget(self.startbutton)
- header.addWidget(self.stopbutton)
+ header.addWidget(self.togglebutton)
header.addWidget(self.statuswidget)
self.layout = QVBoxLayout()
def __del__(self):
self.thread = None
- def start_thread(self):
- if self.thread is not None:
- return
-
- self.startbutton.setEnabled(False)
- self.stopbutton.setEnabled(True)
-
- self.thread = GPSThread(self.addr, self.name, self)
- self.connect(self.thread, SIGNAL("status_updated(QString)"), self.update_status)
- self.connect(self.thread, SIGNAL("data_updated(QString)"), self.update_monitor)
- self.connect(self.thread, SIGNAL("finished()"), self.gc_thread)
- self.thread.start()
-
- def stop_thread(self):
+ def toggle_thread(self):
if self.thread is None:
- return
+ self.togglebutton.setText("Stop")
- self.stopbutton.setEnabled(False)
- self.thread.stop()
+ self.thread = GPSThread(self.addr, self.name, self)
+ self.connect(self.thread, SIGNAL("status_updated(QString)"), self.update_status)
+ self.connect(self.thread, SIGNAL("data_updated(QString)"), self.update_monitor)
+ self.connect(self.thread, SIGNAL("finished()"), self.gc_thread)
+ self.thread.start()
+ else:
+ self.togglebutton.setEnabled(False)
+ self.thread.stop()
def gc_thread(self):
self.thread = None # join
- self.startbutton.setEnabled(True)
- self.stopbutton.setEnabled(False)
+ self.togglebutton.setText("Start")
+ self.togglebutton.setEnabled(True)
self.update_status()
def update_status(self, status = None):
if status is not None:
self.status = status
- self.statuswidget.setText("%s: %s" % (self.name, self.status))
+ self.statuswidget.setText("%s\n%s" % (self.name, self.status))
def update_monitor(self, data = None):
self.monitorwidget.setText(data)