예제 #1
0
class Form(QtWidgets.QWidget):

    formClosed = QtCore.Signal(str)

    def __init__(self):

        QtWidgets.QWidget.__init__(self)
        self.form = Ui_Form()
        self.form.setupUi(self)
        self.team = Team()
        self.form.teamWidgetLayout.addWidget(self.team)
        self.form.cancel_btn.clicked.connect(self.cancel)
        self.form.save_btn.clicked.connect(self.save)
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

    def currentValues(self):
        values = []
        values.append(self.form.title_edit_3.text())
        date = self.form.dateTime_edit_3.dateTime()
        dateTime = QtCore.QDateTime.ToString(date, "yyyy-MM-ddTHH:mm:ss")
        values.append(dateTime)
        values.append(self.form.lig_combo_5.currentText)
        values.append(self.form.location_combo_3.currentText)
        values.append(self.form.description_edit_5.toPlainText)
        teams = []

    def cancel(self):
        msg_box = QMessageBox()
        msg_box.setText(
            "If you cancel without saving current form, all your changes will be lost!"
        )
        msg_box.setInformativeText("Do you want to cancel?")
        msg_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
        msg_box.setDefaultButton(QMessageBox.Yes)
        msg_box.buttonClicked.connect(self.msgBtn)
        msg_box.exec_()

    def save(self):
        msg_box = QMessageBox()
        msg_box.setText("This form has been modified.")
        msg_box.setInformativeText("Do you want to save your changes?")
        msg_box.setStandardButtons(QMessageBox.Save | QMessageBox.Discard
                                   | QMessageBox.Cancel)
        msg_box.setDefaultButton(QMessageBox.Save)
        msg_box.buttonClicked.connect(self.msgBtn)
        msg_box.exec_()

    def msgBtn(self, btn):
        if btn.text() == "&Yes":
            self.formClosed.emit("close")
        elif btn.text() == "Save":
            self.formClosed.emit("save")
        elif btn.text() == "Don't Save":
            self.formClosed.emit("close")
예제 #2
0
class MainWindow(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.ui = Ui_Form()
        self.ui.setupUi(self)

        #set timer for time
        self.timer_time = QtCore.QTimer(self)
        self.timer_time.setInterval(1000)
        self.timer_time.timeout.connect(self.update_time)
        self.timer_time.start()

        #set timer for weather
        self.timer_weather = QtCore.QTimer(self)
        self.timer_weather.setInterval(1800000)
        self.timer_weather.timeout.connect(self.update_weather)
        self.timer_weather.start()

        # update data first time
        self.update_time()
        self.update_weather()

    def update_time(self):
        cur_time = QtCore.QDateTime.currentDateTime()
        self.ui.dateTimeEdit_time.setDateTime(cur_time)

    def update_weather(self):
        cur_weather = get_weather_lib.cur_weather()
        cur_weather.get_weather()
        self.ui.lcdNumber_temp.display(float(cur_weather.get_temp()))
        self.ui.lcdNumber_hum.display(float(cur_weather.get_hum()))
        self.ui.lcdNumber_pres.display(float(cur_weather.get_pres()))

        title, descr = cur_weather.get_weather_text()
        #self.ui.label_weather_text.setText(title)
        self.ui.label_weather_descr_text.setText(descr)

        self.ui.label_cloud_text.setText(str(cur_weather.get_clouds()) + '%')

        speed, dest = cur_weather.get_wind_text()
        self.ui.label_wind_speed_text.setText(str(speed) + u' м/с')
        self.ui.label_wind_dest_text.setText(str(dest))

        date_of_data = datetime.datetime.fromtimestamp(cur_weather.get_timestamp())
        self.ui.label_time_date.setText(str(date_of_data) + ' UTC')

    # http://stackoverflow.com/questions/5506781/pyqt4-application-on-windows-is-crashing-on-exit
    def closeEvent(self, event):
        sys.exit(0)
예제 #3
0
class VigenereCipher(QWidget):
    def __init__(self):
        super(VigenereCipher, self).__init__()
        self.ui = Ui_Form()
        self.ui.setupUi(self)
        self.ui.encryptButton.clicked.connect(self.encryptSignal)
        self.ui.decryptButton.clicked.connect(self.decryptSignal)

    @Slot()
    def encryptSignal(self):
        plaintext = self.ui.plaintextEncrypt.toPlainText()
        key = self.ui.keyword.text()
        ciphertext = VigenereCore.encrypt(plaintext, key)
        self.ui.ciphertextEncrypt.setPlainText(ciphertext)

    @Slot()
    def decryptSignal(self):
        ciphertext = self.ui.ciphertextDecrypt.toPlainText()
        key = self.ui.keyword.text()
        plaintext = VigenereCore.decrypt(ciphertext, key)
        self.ui.plaintextDecrypt.setPlainText(plaintext)
예제 #4
0
class gui(QtGui.QMainWindow):
    def __init__(self, prefix):
        QtGui.QMainWindow.__init__(self)
        self.prefix = prefix
        # setup the ui
        self.ui = Ui_Form()
        self.ui.setupUi(self)
        # setup the button actions
        self.bActions = {
            self.ui.go: (self.go, "go"),
            self.ui.stop: (self.stop, "stop")
        }
        pre = os.path.dirname(sys.argv[0]) + "/button_"

        # and connect them
        for button, f, name in [(self.ui.go, self.go, "go"),
                                (self.ui.stop, self.stop, "stop")]:
            self.connect(button, QtCore.SIGNAL("clicked()"), f)
            pix = QPixmap(pre + name + ".png")
            button.releasedIcon = QIcon(pix)
            button.pressedIcon = QIcon(pre + name + "_down.png")
            button.setIcon(button.releasedIcon)
            button.setIconSize(pix.size())
            button.setMask(QRegion(pix.mask()).translated(8, 6))

            def pressedAction(button=button):
                button.setIcon(button.pressedIcon)

            button.pressedAction = pressedAction
            self.connect(button, QtCore.SIGNAL("pressed()"),
                         button.pressedAction)

            def releasedAction(button=button):
                button.setIcon(button.releasedIcon)

            button.releasedAction = releasedAction
            self.connect(button, QtCore.SIGNAL("released()"),
                         button.releasedAction)
        # setup the lineEdit actions
        self.lActions = {}
        for line, pv, pvrbv in \
                [ (self.ui.V,  self.prefix + ":MOTOR.VELO", self.prefix + ":MOTOR.VELO"),
                  (self.ui.TA, self.prefix + ":MOTOR.ACCL", self.prefix + ":MOTOR.ACCL"),
                  (self.ui.P,  self.prefix + ":P", self.prefix + ":P:RBV"),
                  (self.ui.I,  self.prefix + ":I", self.prefix + ":I:RBV")]:

            def f(string, self=self, pv=pv):
                caput(pv, float(string))
                self.computeTime()

            self.lActions[line] = f

            def monitor(value, self=self, line=line):
                if not line.isModified() or not line.hasFocus():
                    line.setText(str(value))
                self.computeTime()

            camonitor(pvrbv, monitor)
        # and connect them
        for line, f in self.lActions.items():
            self.connect(line, QtCore.SIGNAL("textChanged(const QString &) "),
                         f)
        # make a position plot
        playout = QtGui.QVBoxLayout(self.ui.pFrame)
        self.pPlot = plot(self.ui.pFrame)
        playout.addWidget(self.pPlot)
        self.pPlot.setAxisTitle(QwtPlot.xBottom, "Time (s)")
        self.pPlot.setAxisTitle(QwtPlot.yLeft, 'Position (mm)')
        self.pPlot.setAxisTitle(QwtPlot.yRight, "Position Error (mm)")
        # make a velocity plot
        vlayout = QtGui.QVBoxLayout(self.ui.vFrame)
        self.vPlot = plot(self.ui.vFrame)
        vlayout.addWidget(self.vPlot)
        self.vPlot.setAxisTitle(QwtPlot.xBottom, "Time (s)")
        self.vPlot.setAxisTitle(QwtPlot.yLeft, 'Velocity (mm/s)')
        # store the arrays
        self.arrays = {}
        # set some monitors on the array
        self.arrayFuncs = {}
        for i, pv in enumerate([
                self.prefix + ":GATHER:DEMANDPOSN",
                self.prefix + ":GATHER:POSN",
                self.prefix + ":GATHER:DEMANDVELO",
                self.prefix + ":GATHER:VELO", self.prefix + ":GATHER:FERR",
                self.prefix + ":GATHER:TIME"
        ]):

            def f(value, self=self, i=i):
                if i in (0, 1, 4):
                    factor = caget(self.prefix + ":MOTOR.MRES")
                elif i in (2, 3):
                    factor = 1000 * caget(self.prefix + ":MOTOR.MRES")
                else:
                    factor = 0.001
                if i == 4 and self.arrays.has_key(4) and max(
                        abs(self.arrays[4])) > 0.0:
                    # old following error
                    self.arrays[6] = self.arrays[4]
                self.arrays[i] = value * factor
                self.updateArray(i)

            self.arrayFuncs[pv] = f
        # plot some curves
        self.olderror = self.pPlot.makeCurve("Old Posn Error",
                                             y2=True,
                                             col=Qt.darkRed,
                                             width=1)
        self.curves = [
            self.pPlot.makeCurve("Demand Posn", col=Qt.darkBlue, width=3),
            self.pPlot.makeCurve("Actual Posn", col=Qt.green, width=1),
            self.vPlot.makeCurve("Demand Velocity", col=Qt.darkBlue, width=3),
            self.vPlot.makeCurve("Actual Velocity", col=Qt.green, width=1),
            self.pPlot.makeCurve("Posn Error", y2=True, col=Qt.red, width=2)
        ]
        for pv, f in self.arrayFuncs.items():
            camonitor(pv, f)
        # add tracking
        self.connect(Spy(self.pPlot.canvas()), QtCore.SIGNAL("MouseMove"),
                     self.showPCoordinates)
        self.connect(Spy(self.vPlot.canvas()), QtCore.SIGNAL("MouseMove"),
                     self.showVCoordinates)
        self.should_go = False
        # connect up the other buttons
        self.pPlot.autoscaleButton = QtGui.QPushButton(self.pPlot)
        self.pPlot.autoscaleButton.setText("Autoscale")
        self.pPlot.autoscaleButton.setCheckable(True)
        font = QtGui.QFont()
        font.setFamily("Sans Serif")
        font.setPointSize(10)
        self.pPlot.autoscaleButton.setFont(font)
        self.connect(self.ui.printScreen, QtCore.SIGNAL("clicked()"),
                     self.printScreen)
        self.connect(self.pPlot.autoscaleButton,
                     QtCore.SIGNAL("toggled(bool)"), self.pPlot.setAutoscale)
        self.connect(self.ui.defaults, QtCore.SIGNAL("clicked()"),
                     self.defaults)
        self.ui.D.setFocus()
        self.go_timer = QtCore.QTimer()

    def computeTime(self):
        vals = dict(D=100.0, V=1.0, TA=0.0)
        for k in vals:
            v = self.ui.__dict__[k].text()
            try:
                vals[k] = float(v)
            except ValueError:
                pass
        if vals["V"] == 0.0:
            vals["V"] = 0.00001
        self.ui.time.setText("%.2f" %
                             ((vals["D"] / vals["V"] + vals["TA"]) * 2))

    def printScreen(self):
        self.ui.progressBar.setValue(0)
        printer = QtGui.QPrinter(QtGui.QPrinter.HighResolution)
        printer.setOrientation(printer.Landscape)
        printer.setPrinterName("dh.g.col.2")
        p = QPainter()
        p.begin(printer)
        p.setFont(QtGui.QFont("arial", 16, QtGui.QFont.Bold))
        r = printer.pageRect()
        pix = QPixmap.grabWidget(self)
        sf = min(
            float(r.size().width()) / pix.size().width(),
            float(r.size().height()) / pix.size().height())
        p.drawPixmap(0, 0, int(pix.size().width() * sf),
                     int(pix.size().height() * sf), pix)
        p.end()
        self.ui.progressBar.setValue(100)
        self.statusBar().showMessage("Screenshot will be printed shortly")

    def updateArray(self, i):
        pchanged = False
        vchanged = False
        pvals = (0, 1, 4)
        if i != 5:
            if self.arrays.has_key(5):
                self.curves[i].setData(self.arrays[5], self.arrays[i])
                if i == 4 and self.arrays.has_key(6):
                    self.olderror.setData(self.arrays[5], self.arrays[6])
                if i in pvals:
                    pchanged = True
                else:
                    vchanged = True
        else:
            for i in range(5):
                if self.arrays.has_key(i):
                    self.curves[i].setData(self.arrays[5], self.arrays[i])
                    if i in pvals:
                        pchanged = True
                    else:
                        vchanged = True
            if self.arrays.has_key(6):
                self.olderror.setData(self.arrays[5], self.arrays[6])

        if pchanged:
            self.pPlot.setAutoscale(self.pPlot.autoscale)
            if self.arrays.has_key(4):
                self.ui.error.setText("%.4f" % abs(self.arrays[4]).mean())
        if vchanged:
            self.vPlot.setAutoscale(self.vPlot.autoscale)

    def tick(self):
        state = caget(self.prefix + ":GATHER:STATE")
        if state == "MONITOR_INPUT":
            self.ui.progressBar.setValue(100)
            self.stop()
            self.timer.stop()
        elif self.ui.progressBar.value() < 99:
            self.ui.progressBar.setValue(self.ui.progressBar.value() + 1)

    def defaults(self):
        self.ui.V.setText(str(50))
        self.ui.TA.setText(str(1))
        self.ui.P.setText(str(0))
        self.ui.I.setText(str(0))

    def go(self):
        if self.ui.progressBar.value() != 100:
            return
        caput(self.prefix + ":GATHER:PORT", "pmac1port")
        caput(self.prefix + ":GATHER:MOTOR", self.prefix + ":MOTOR")
        caput(self.prefix + ":MOTOR", 0)
        self.ui.progressBar.setValue(0)
        self.go_countdown = 50
        self.connect(self.go_timer, QtCore.SIGNAL("timeout()"), self.do_go)
        self.go_timer.start(200)

    def do_go(self):
        if caget(self.prefix + ":MOTOR.RBV") < 0.001:
            self.go_countdown = 0
        if self.go_countdown == 0:
            try:
                val = float(str(self.ui.D.text()))
            except ValueError:
                val = 10
                self.ui.D.setText("10")
            caput(self.prefix + ":GATHER:DEMAND", val)
            tSample = caget(self.prefix + ":GATHER:TSAMPLE.B")
            accl = caget(self.prefix + ":MOTOR.ACCL")
            tMove = max(accl + (val / caget(self.prefix + ":MOTOR.VELO")),
                        2 * accl)
            tMove = 2 * tMove + caget(self.prefix + ":GATHER:DELAY") + 0.5
            sPeriod = int(tMove * 1000.0 / (1024.0 * tSample)) + 1
            caput(self.prefix + ":GATHER:SPERIOD", sPeriod)
            cothread.Sleep(0.2)
            # timer tick in ms
            tick = sPeriod * tSample * 10.24 + 30
            self.timer = QtCore.QTimer()
            self.connect(self.timer, QtCore.SIGNAL("timeout()"), self.tick)
            caput(self.prefix + ":GATHER:STATE", "EXECUTE")
            caput(self.prefix + ":GATHER:EXECUTE", 1)
            self.timer.start(tick)
            self.go_countdown = 50
            self.go_timer.stop()
        else:
            self.go_countdown -= 1

    def stop(self):
        caput(self.prefix + ":GATHER:ASYN.AOUT", "&1A")
        caput(self.prefix + ":MOTOR:KILL.PROC", 1)
        caput(self.prefix + ":MOTOR.STOP", 1)
        caput(self.prefix + ":GATHER:EXECUTE", 0)
        self.ui.progressBar.setValue(100)

    def showCoordinates(self, plot, text, position):
        self.statusBar().showMessage(
            text % (plot.invTransform(Qwt.QwtPlot.xBottom, position.x()),
                    plot.invTransform(Qwt.QwtPlot.yLeft, position.y())))

    def showPCoordinates(self, position):
        self.showCoordinates(self.pPlot, 'Time = %f, Position = %f', position)

    def showVCoordinates(self, position):
        self.showCoordinates(self.vPlot, 'Time = %f, Velocity = %f', position)
예제 #5
0
class gui(QtGui.QMainWindow):
    def __init__(self, prefix):
        QtGui.QMainWindow.__init__(self)
        self.prefix = prefix
        # setup the ui
        self.ui = Ui_Form()    
        self.ui.setupUi(self)
        # setup the button actions
        self.bActions = {self.ui.go: (self.go, "go"), self.ui.stop: (self.stop, "stop")}
        pre = os.path.dirname(sys.argv[0])+"/button_"
            
        # and connect them
        for button, f, name in [(self.ui.go, self.go, "go"), 
                                (self.ui.stop, self.stop, "stop")]:
            self.connect(button, QtCore.SIGNAL("clicked()"), f)
            pix = QPixmap(pre + name + ".png")
            button.releasedIcon = QIcon(pix)
            button.pressedIcon = QIcon(pre + name + "_down.png")
            button.setIcon(button.releasedIcon)
            button.setIconSize(pix.size())
            button.setMask(QRegion(pix.mask()).translated(8,6))            
            def pressedAction(button = button):
                button.setIcon(button.pressedIcon)
            button.pressedAction = pressedAction        
            self.connect(button, QtCore.SIGNAL("pressed()"), button.pressedAction)                    
            def releasedAction(button = button):
                button.setIcon(button.releasedIcon)
            button.releasedAction = releasedAction            
            self.connect(button, QtCore.SIGNAL("released()"), button.releasedAction)                                                
        # setup the lineEdit actions
        self.lActions = {}
        for line, pv, pvrbv in \
                [ (self.ui.V,  self.prefix + ":MOTOR.VELO", self.prefix + ":MOTOR.VELO"),
                  (self.ui.TA, self.prefix + ":MOTOR.ACCL", self.prefix + ":MOTOR.ACCL"),
                  (self.ui.P,  self.prefix + ":P", self.prefix + ":P:RBV"),
                  (self.ui.I,  self.prefix + ":I", self.prefix + ":I:RBV")]:
            def f(string, self = self, pv = pv):
                caput(pv, float(string))
                self.computeTime()
            self.lActions[line] = f
            def monitor(value, self = self, line = line):    
                if not line.isModified() or not line.hasFocus():            
                    line.setText(str(value))
                self.computeTime()                    
            camonitor(pvrbv, monitor)
        # and connect them            
        for line, f in self.lActions.items():
            self.connect(line, QtCore.SIGNAL("textChanged(const QString &) "), f)        
        # make a position plot
        playout = QtGui.QVBoxLayout(self.ui.pFrame)                
        self.pPlot = plot(self.ui.pFrame)
        playout.addWidget(self.pPlot)    
        self.pPlot.setAxisTitle(QwtPlot.xBottom, "Time (s)")
        self.pPlot.setAxisTitle(QwtPlot.yLeft, 'Position (mm)')
        self.pPlot.setAxisTitle(QwtPlot.yRight, "Position Error (mm)")                
        # make a velocity plot
        vlayout = QtGui.QVBoxLayout(self.ui.vFrame)
        self.vPlot = plot(self.ui.vFrame)
        vlayout.addWidget(self.vPlot)    
        self.vPlot.setAxisTitle(QwtPlot.xBottom, "Time (s)")
        self.vPlot.setAxisTitle(QwtPlot.yLeft, 'Velocity (mm/s)')        
        # store the arrays
        self.arrays = {}        
        # set some monitors on the array
        self.arrayFuncs = {}
        for i,pv in enumerate([self.prefix + ":GATHER:DEMANDPOSN",
                               self.prefix + ":GATHER:POSN",
                               self.prefix + ":GATHER:DEMANDVELO",
                               self.prefix + ":GATHER:VELO",
                               self.prefix + ":GATHER:FERR",                               
                               self.prefix + ":GATHER:TIME"]):
            def f(value, self=self, i=i):
                if i in (0,1,4):
                    factor = caget(self.prefix + ":MOTOR.MRES")
                elif i in (2,3):
                    factor = 1000 * caget(self.prefix + ":MOTOR.MRES")
                else:
                    factor = 0.001
                if i==4 and self.arrays.has_key(4) and max(abs(self.arrays[4])) > 0.0:
                    # old following error
                    self.arrays[6] = self.arrays[4]
                self.arrays[i] = value *  factor
                self.updateArray(i)
            self.arrayFuncs[pv] = f
        # plot some curves
        self.olderror = self.pPlot.makeCurve("Old Posn Error", y2=True, col=Qt.darkRed, width = 1)
        self.curves = [
            self.pPlot.makeCurve("Demand Posn", col=Qt.darkBlue, width = 3),
            self.pPlot.makeCurve("Actual Posn", col=Qt.green, width = 1),
            self.vPlot.makeCurve("Demand Velocity", col=Qt.darkBlue, width = 3),      
            self.vPlot.makeCurve("Actual Velocity", col=Qt.green, width = 1),
            self.pPlot.makeCurve("Posn Error", y2=True, col=Qt.red, width = 2)]
        for pv, f in self.arrayFuncs.items():
            camonitor(pv, f)
        # add tracking
        self.connect(Spy(self.pPlot.canvas()), QtCore.SIGNAL("MouseMove"), self.showPCoordinates) 
        self.connect(Spy(self.vPlot.canvas()), QtCore.SIGNAL("MouseMove"), self.showVCoordinates) 
        self.should_go = False        
        # connect up the other buttons
        self.pPlot.autoscaleButton = QtGui.QPushButton(self.pPlot)
        self.pPlot.autoscaleButton.setText("Autoscale")
        self.pPlot.autoscaleButton.setCheckable(True)
        font = QtGui.QFont()
        font.setFamily("Sans Serif")
        font.setPointSize(10)
        self.pPlot.autoscaleButton.setFont(font)
        self.connect(self.ui.printScreen, QtCore.SIGNAL("clicked()"), self.printScreen)
        self.connect(self.pPlot.autoscaleButton, QtCore.SIGNAL("toggled(bool)"), self.pPlot.setAutoscale)  
        self.connect(self.ui.defaults, QtCore.SIGNAL("clicked()"), self.defaults)        
        self.ui.D.setFocus()      
        self.go_timer = QtCore.QTimer()               
     
    def computeTime(self):
        vals = dict(D=100.0, V=1.0, TA=0.0)
        for k in vals:
            v = self.ui.__dict__[k].text()
            try:
                vals[k] = float(v)
            except ValueError:
                pass 
        if vals["V"] == 0.0:
            vals["V"] = 0.00001
        self.ui.time.setText("%.2f" % ((vals["D"] / vals["V"] + vals["TA"]) * 2))
                      
    def printScreen(self):
        self.ui.progressBar.setValue(0)      
        printer = QtGui.QPrinter(QtGui.QPrinter.HighResolution)
        printer.setOrientation(printer.Landscape)
        printer.setPrinterName("dh.g.col.2")
        p = QPainter()
        p.begin(printer)
        p.setFont(QtGui.QFont("arial",16,QtGui.QFont.Bold))
        r = printer.pageRect()
        pix = QPixmap.grabWidget(self)        
        sf = min(float(r.size().width()) / pix.size().width(), float(r.size().height()) / pix.size().height())
        p.drawPixmap(0, 0, int(pix.size().width() * sf), int(pix.size().height() * sf), pix)
        p.end()
        self.ui.progressBar.setValue(100)    
        self.statusBar().showMessage("Screenshot will be printed shortly")            
        
                                               
    def updateArray(self, i):
        pchanged = False
        vchanged = False
        pvals = (0,1,4)
        if i != 5:
            if self.arrays.has_key(5):
                self.curves[i].setData(self.arrays[5], self.arrays[i])
                if i==4 and self.arrays.has_key(6):
                    self.olderror.setData(self.arrays[5], self.arrays[6])                
                if i in pvals:
                    pchanged = True
                else:
                    vchanged = True                    
        else:
            for i in range(5):
                if self.arrays.has_key(i):
                    self.curves[i].setData(self.arrays[5], self.arrays[i])
                    if i in pvals:
                        pchanged = True
                    else:
                        vchanged = True
            if self.arrays.has_key(6):
                self.olderror.setData(self.arrays[5], self.arrays[6])
                        
        if pchanged:            
            self.pPlot.setAutoscale(self.pPlot.autoscale)
            if self.arrays.has_key(4):
                self.ui.error.setText("%.4f" % abs(self.arrays[4]).mean())            
        if vchanged:
            self.vPlot.setAutoscale(self.vPlot.autoscale)
                                                          
    def tick(self):
        state = caget(self.prefix + ":GATHER:STATE")
        if state == "MONITOR_INPUT":            
            self.ui.progressBar.setValue(100)
            self.stop()
            self.timer.stop()
        elif self.ui.progressBar.value() < 99:
            self.ui.progressBar.setValue(self.ui.progressBar.value() + 1)

    def defaults(self):
        self.ui.V.setText(str(50))
        self.ui.TA.setText(str(1))
        self.ui.P.setText(str(0))
        self.ui.I.setText(str(0))

    def go(self):
        if self.ui.progressBar.value() != 100:
            return
        caput(self.prefix + ":GATHER:PORT", "pmac1port")
        caput(self.prefix + ":GATHER:MOTOR", self.prefix + ":MOTOR")
        caput(self.prefix + ":MOTOR", 0)
        self.ui.progressBar.setValue(0)  
        self.go_countdown = 50       
        self.connect(self.go_timer, QtCore.SIGNAL("timeout()"), self.do_go)
        self.go_timer.start(200)        

    def do_go(self):
        if caget(self.prefix + ":MOTOR.RBV") < 0.001:
            self.go_countdown = 0
        if self.go_countdown == 0:
            try:
                val = float(str(self.ui.D.text()))
            except ValueError:
                val = 10
                self.ui.D.setText("10")
            caput(self.prefix + ":GATHER:DEMAND", val)
            tSample = caget(self.prefix + ":GATHER:TSAMPLE.B")
            accl = caget(self.prefix + ":MOTOR.ACCL")
            tMove = max(accl + (val / caget(self.prefix + ":MOTOR.VELO")), 2*accl)
            tMove = 2*tMove + caget(self.prefix + ":GATHER:DELAY") + 0.5
            sPeriod = int(tMove * 1000.0 / (1024.0 * tSample)) + 1
            caput(self.prefix + ":GATHER:SPERIOD", sPeriod)
            cothread.Sleep(0.2)                
            # timer tick in ms
            tick = sPeriod * tSample * 10.24 + 30
            self.timer = QtCore.QTimer()              
            self.connect(self.timer, QtCore.SIGNAL("timeout()"), self.tick)
            caput(self.prefix + ":GATHER:STATE", "EXECUTE")
            caput(self.prefix + ":GATHER:EXECUTE", 1)
            self.timer.start(tick)
            self.go_countdown = 50            
            self.go_timer.stop()
        else:
            self.go_countdown -= 1
        
    def stop(self):
        caput(self.prefix + ":GATHER:ASYN.AOUT", "&1A")     
        caput(self.prefix + ":MOTOR:KILL.PROC", 1)            
        caput(self.prefix + ":MOTOR.STOP", 1)    
        caput(self.prefix + ":GATHER:EXECUTE", 0)                     
        self.ui.progressBar.setValue(100)        

    def showCoordinates(self, plot, text, position):
        self.statusBar().showMessage(text % 
            (plot.invTransform(Qwt.QwtPlot.xBottom, position.x()),
             plot.invTransform(Qwt.QwtPlot.yLeft, position.y())))        
                            
    def showPCoordinates(self, position):
        self.showCoordinates(self.pPlot, 'Time = %f, Position = %f', position)

    def showVCoordinates(self, position):
        self.showCoordinates(self.vPlot, 'Time = %f, Velocity = %f', position)