예제 #1
0
 def plot_image(self, img):
     cv = FigureCanvas(plt.figure(figsize=(5, 3)))
     cv.setWindowTitle(self.filename)
     plt.imshow(img)
     plt.title(self.filename)
     plt.gca().axis('off')
     cv.show()
예제 #2
0
def main():
        pos_label = QLabel("Position: ", w)
        pos_label.move(35, 30)
        position = QLineEdit(str(getCurrent("inches")), w)
        position.move(102, 20)
        position.resize(70, 30)
        inches = QLabel("inches", w)
        inches.move(177, 30)

        go = QPushButton('Focus', w)
        go.move(100, 60)

        refresh = QPushButton('Refresh', w)
        refresh.move(20, 60)

        stopper = QPushButton('Stop', w)
        stopper.move(20, 100)

        resetter = QPushButton('Reset', w)
        resetter.move(100, 100)

        center_label = QLabel("Best Focus Position: ", w)
        center_label.move(20, 170)
        center.setText("0.6819") # default
        center.move(160, 160)
        center.resize(70, 30)

        cdomain_label = QLabel("Course Step Range: ", w)
        cdomain_label.move(270, 210)
        cdomain.setText("1") # default
        cdomain.move(400, 200)
        cdomain.resize(70, 30)

        cnum_label = QLabel("Course Step #: ", w)
        cnum_label.move(270, 250)
        cnum = QLineEdit(w)
        cnum.setText("4") # default
        cnum.move(400, 240)
        cnum.resize(70, 30)

        fnum_label = QLabel("Fine Step #: ", w)
        fnum_label.move(20, 250)
        fnum = QLineEdit(w)
        fnum.setText("3") # default
        fnum.move(160, 240)
        fnum.resize(70, 30)

        fdomain_label = QLabel("Fine Step Range: ", w)
        fdomain_label.move(20, 210)
        fdomain = QLineEdit(w)
        fdomain.setText("0.8") # default
        fdomain.move(160, 200)
        fdomain.resize(70, 30)

        time_delay = QLabel("Integration Time: ", w)
        time_delay.move(270, 170)
        delay.setText("2") # default time
        delay.move(400, 160)
        delay.resize(70, 30)

        simulate = QPushButton("Simulate Graph", w)
        simulate.move(20, 290)

        scan_button = QPushButton("Start Scan", w)
        scan_button.move(395, 290)

        figure = plt.figure(figsize = (20, 10))
        plt.ylabel('Distance')
        plt.xlabel('Time')
        canvas = FigureCanvas(figure)
        canvas.setWindowTitle("Simulated Graph")

        # Set window size.
        w.resize(490, 610)

        logOutput.setReadOnly(True)
        logOutput.setLineWrapMode(QTextEdit.NoWrap)
        logOutput.move(20, 340)
        logOutput.resize(450, 250)

        # Action Functions
        @pyqtSlot()
        def start_scan():
                dataGather(float(center.text()), float(fdomain.text()), float(fnum.text()), float(cdomain.text()), float(cnum.text()))
                ani = animation.FuncAnimation(fig, animate, interval=1000)
                plt.show()
                scanner(float(center.text()), float(cdomain.text()))

        def reset():
                goto(0)
                logOutput.append("Resetting to 0 inches.\n")

        def repos():
                value = float(position.text())
                goto(stepConverter(value))
                logOutput.append("Focusing to " + str(value) + " inches.\n")

        def updater():
                position.setText(str(getCurrent("inches")))

        def plot():
                dataGather(float(center.text()), float(fdomain.text()), float(fnum.text()), float(cdomain.text()), float(cnum.text()))

                # create an axis
                ax = figure.add_subplot(111)
                ax.clear()
                
                ax.hold(False)
                
                ax.plot(xcoords, ycoords, '.-')

                ax.set_ylim([0, 1.8])
                # ax.set_xlim([0, 250])

                tick_spacing = 0.2
                ax.yaxis.set_major_locator(ticker.MultipleLocator(tick_spacing))

                plt.ylabel('Position (Inches)')
                plt.xlabel('Time (s)')

                # refresh canvas
                canvas.draw()
                canvas.show()
                

        # Connect signals to buttons
        scan_button.clicked.connect(start_scan)
        stopper.clicked.connect(stop)
        resetter.clicked.connect(reset)

        refresh.clicked.connect(updater)
        go.clicked.connect(repos)
        simulate.clicked.connect(plot)

        # Show the window and run the app
        w.show()
        app.exec_()
        port.close()