Merge start/stop buttons into one
authorDmitry Marakasov <amdmi3@amdmi3.ru>
Thu, 29 Apr 2010 00:24:34 +0000 (04:24 +0400)
committerDmitry Marakasov <amdmi3@amdmi3.ru>
Thu, 29 Apr 2010 00:24:34 +0000 (04:24 +0400)
TODO
nmea.py
uberlogger.py

diff --git a/TODO b/TODO
index 7143475..f9f283f 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,4 +1,3 @@
-- Single start/stop button
 - Table for GPS widgets
 - Clean exit
 - Enable bluetooth on start
diff --git a/nmea.py b/nmea.py
index 2082128..2d698eb 100644 (file)
--- a/nmea.py
+++ b/nmea.py
@@ -16,6 +16,7 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with UberLogger.  If not, see <http://www.gnu.org/licenses/>.
+#
 
 import re
 
index a656749..f3caa7f 100755 (executable)
@@ -181,14 +181,9 @@ class ContainerWidget(QWidget):
                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)
@@ -196,8 +191,7 @@ class ContainerWidget(QWidget):
                self.monitorwidget = QLabel()
 
                header = QHBoxLayout()
-               header.addWidget(self.startbutton)
-               header.addWidget(self.stopbutton)
+               header.addWidget(self.togglebutton)
                header.addWidget(self.statuswidget)
 
                self.layout = QVBoxLayout()
@@ -212,37 +206,30 @@ class ContainerWidget(QWidget):
        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)