#!/usr/bin/env python

import sys
from PyQt4 import QtGui, QtCore
from Jixi.jSerialThread import jRead
import Jixi.jStatus
import serial

class mainWindow(QtGui.QMainWindow):

    def __init__(self):
        super(mainWindow, self).__init__()
        self.setWindowIcon(QtGui.QIcon('web.png'))
        self.statusBar().showMessage('Ready')
        c = QtGui.QWidget()
        self.setCentralWidget(c)

        vbox = QtGui.QVBoxLayout()
        c.setLayout(vbox)

        self.tw = QtGui.QTextEdit(self)
        self.tw.setReadOnly(True)

        vbox.addWidget(self.tw)

        self.port = serial.Serial('xport')
        self.readThread = jRead(self.port)
        self.readThread.start()
        self.connect(self.readThread, QtCore.SIGNAL("read_data(QString)"), self.read_data)

        self.show()

    def read_data(self, txt):
        self.tw.append('Rcvd> '+txt)
        if (txt == '?'):
            self.port.write('<Idle,MPos:0.000,0.000,0.000,WPos:0.000,0.000,0.000>\n')

app = QtGui.QApplication(sys.argv)
w = mainWindow()
sys.exit(app.exec_())


