Esempio n. 1
0
class CurveDemo(QMainWindow):
    def __init__(self, *args):
        QMainWindow.__init__(self, *args)

        self.plot = DataPlot(self)
        self.plot.setContentsMargins(5, 5, 5, 0)
        self.setCentralWidget(self.plot)
        print(type(self.plot.signal_showinfo))
        # signal slot connect
        self.plot.signal_showinfo.connect(self.showInfo)

        font = QFont()
        font.setFamily("Calibri")  #,Consolas
        font.setPointSize(16)

        font2 = QFont()
        font2.setFamily("Calibri")
        font2.setPointSize(14)

        self.plot.setFont(font2)

        #  add toolbar
        toolBar = QToolBar(self)
        self.addToolBar(toolBar)
        # label COM
        lbl_COM = QLabel("COM:", toolBar)
        lbl_COM.setFont(font)
        lbl_COM.setStyleSheet("")
        toolBar.addWidget(lbl_COM)

        #lineEdit_COM
        self.lineEdit_COM = QLineEdit(str(config.Port))
        self.lineEdit_COM.setFont(font2)
        self.lineEdit_COM.setMinimumWidth(50)
        toolBar.addWidget(self.lineEdit_COM)

        # label baudrate
        lbl_baud = QLabel("BAUD Rate:", toolBar)
        lbl_baud.setFont(font)
        lbl_baud.setStyleSheet("")
        toolBar.addWidget(lbl_baud)

        #lineEdit_baud
        self.lineEdit_baud = QLineEdit(str(config.BaudRate))
        self.lineEdit_baud.setMinimumWidth(100)
        self.lineEdit_baud.setFont(font2)
        toolBar.addWidget(self.lineEdit_baud)

        # Connect device,              QIcon(const QString &filename);     // 从图像文件构造图标
        btnConnect = QToolButton(toolBar)
        btnConnect.setText("Connect")
        btnConnect.setFont(font2)
        btnConnect.setIcon(QIcon('./icon/Connect.png'))
        btnConnect.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnConnect)
        btnConnect.clicked.connect(self.GetComSettings_Connect)

        # disConnect device
        btnDisConnect = QToolButton(toolBar)
        btnDisConnect.setText("DisConnect")
        btnDisConnect.setFont(font2)
        btnDisConnect.setIcon(QIcon('./icon/Disconnect.jfif'))
        btnDisConnect.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnDisConnect)

        btnDisConnect.clicked.connect(self.plot.DisConnect)

        toolBar.addSeparator()

        # Start timer
        btnStartTimer = QToolButton(toolBar)
        btnStartTimer.setText("Start Timer")
        btnStartTimer.setFont(font2)
        btnStartTimer.setIcon(QIcon('./icon/start.jfif'))
        btnStartTimer.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnStartTimer)
        btnStartTimer.clicked.connect(self.plot.StartTimer)

        # Stop timer
        btnStopTimer = QToolButton(toolBar)
        btnStopTimer.setText("Stop Timer")
        btnStopTimer.setFont(font2)
        btnStopTimer.setIcon(QIcon('./icon/stop.jfif'))
        btnStopTimer.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnStopTimer)
        btnStopTimer.clicked.connect(self.plot.StopTimer)

        toolBar.addSeparator()

        #X_LOWER
        lbl_x_lower = QLabel("X-Lower:", toolBar)
        lbl_x_lower.setFont(font)

        toolBar.addWidget(lbl_x_lower)

        self.LineEdit_x_lower = QLineEdit(str(0), toolBar)
        self.LineEdit_x_lower.setFont(font2)

        toolBar.addWidget(self.LineEdit_x_lower)

        #X_Upper
        lbl_x_upper = QLabel("X-Upper:", toolBar)
        lbl_x_upper.setFont(font)

        toolBar.addWidget(lbl_x_upper)

        self.LineEdit_x_upper = QLineEdit(str(config.X_upper), toolBar)
        self.LineEdit_x_upper.setFont(font2)

        toolBar.addWidget(self.LineEdit_x_upper)

        #X_interval
        lbl_x_inteval = QLabel("X-Interval(s):", toolBar)
        lbl_x_inteval.setFont(font)

        toolBar.addWidget(lbl_x_inteval)

        self.LineEdit_x_interval = QLineEdit(str(config.X_grid_interval),
                                             toolBar)
        self.LineEdit_x_interval.setFont(font2)

        toolBar.addWidget(self.LineEdit_x_interval)

        # Y_Lower
        lbl_y_lower = QLabel("Y-Lower:", toolBar)
        lbl_y_lower.setFont(font)

        toolBar.addWidget(lbl_y_lower)

        self.LineEdit_y_Lower = QLineEdit(str(config.Y_lower), toolBar)
        self.LineEdit_y_Lower.setFont(font2)

        toolBar.addWidget(self.LineEdit_y_Lower)

        # Y_Upper
        lbl_y_uppwer = QLabel("Y-Upper:", toolBar)
        lbl_y_uppwer.setFont(font)

        toolBar.addWidget(lbl_y_uppwer)

        self.LineEdit_Y_Upper = QLineEdit(str(config.Y_upper), toolBar)
        self.LineEdit_Y_Upper.setFont(font2)

        toolBar.addWidget(self.LineEdit_Y_Upper)
        # Y-Interval
        lbl_Y_Interval = QLabel("Y-Interval:", toolBar)
        lbl_Y_Interval.setFont(font)

        toolBar.addWidget(lbl_Y_Interval)

        self.LineEdit_y_interval = QLineEdit(str(config.Y_grid_interval),
                                             toolBar)
        self.LineEdit_y_interval.setFont(font2)

        toolBar.addWidget(self.LineEdit_y_interval)

        # Set axis para
        btnSet = QToolButton(toolBar)
        btnSet.setText("Set Paras")
        btnSet.setFont(font2)
        btnSet.setIcon(QIcon('./icon/Settings.jfif'))
        btnSet.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnSet)
        btnSet.clicked.connect(self.SetParas)

        toolBar.addSeparator()

        # add print btn to toolbar
        btnPrint = QToolButton(toolBar)
        btnPrint.setText("Print")
        btnPrint.setFont(font2)
        btnPrint.setIcon(QIcon('./icon/print.jfif'))
        btnPrint.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnPrint)
        btnPrint.clicked.connect(self.print_)

        # add Export btn to toolbar
        btnExport = QToolButton(toolBar)
        btnExport.setText("Export")
        btnExport.setFont(font2)
        btnExport.setIcon(QIcon('./icon/snapshot.jfif'))
        btnExport.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnExport)
        btnExport.clicked.connect(self.exportDocument)

        toolBar.addSeparator()

        self.statusBar()
        self.showInfo("Show info here ......")

    # get UI settings
    def SetParas(self):
        '''
        y_lower,y_upper,y_interval,x_interval,X-Upper,x_lower
        '''
        self.plot.setPara(int(self.LineEdit_y_Lower.text()),
                          int(self.LineEdit_Y_Upper.text()),
                          int(self.LineEdit_y_interval.text()),
                          int(self.LineEdit_x_interval.text()),
                          int(self.LineEdit_x_upper.text()),
                          int(self.LineEdit_x_lower.text()))

    # get COM settings
    def GetComSettings_Connect(self):
        '''
            com, baud
        '''
        self.showInfo(
            'COM:%s, BaudRate: %d' %
            (self.lineEdit_COM.text(), int(self.lineEdit_baud.text())))
        self.plot.Connect(self.lineEdit_COM.text(),
                          int(self.lineEdit_baud.text()))

    def print_(self):
        printer = QPrinter(QPrinter.HighResolution)

        printer.setCreator('Bode example')
        printer.setOrientation(QPrinter.Landscape)
        printer.setColorMode(QPrinter.Color)

        docName = str(self.plot.title().text())
        if not docName:
            docName.replace('\n', ' -- ')
            printer.setDocName(docName)

        dialog = QPrintDialog(printer)
        if dialog.exec_():
            renderer = QwtPlotRenderer()
            if (QPrinter.GrayScale == printer.colorMode()):
                renderer.setDiscardFlag(QwtPlotRenderer.DiscardBackground)
                renderer.setDiscardFlag(
                    QwtPlotRenderer.DiscardCanvasBackground)
                renderer.setDiscardFlag(QwtPlotRenderer.DiscardCanvasFrame)
                renderer.setLayoutFlag(QwtPlotRenderer.FrameWithScales)
            renderer.renderTo(self.plot, printer)

    def exportDocument(self):
        renderer = QwtPlotRenderer(self.plot)
        renderer.exportTo(self.plot,
                          "./export/export_%d" % (datetime.datetime.now()))

    def showInfo(self, text=""):
        self.statusBar().showMessage(text)

    def moved(self, point):
        info = "x =%g, y =%g" % (
            self.plot.invTransform(QwtPlot.xBottom, point.x()),
            self.plot.invTransform(QwtPlot.yLeft, point.y()),
            #self.plot.invTransform(QwtPlot.yRight, point.y())
        )
        self.showInfo(info)

    def selected(self, _):
        self.showInfo()
class CurveDemo(QMainWindow):
    def __init__(self, *args):
        QMainWindow.__init__(self, *args)

        self.plot = DataPlot(self)
        self.plot.setContentsMargins(5, 5, 5, 0)
        self.setCentralWidget(self.plot)

        # signal slot connect
        self.plot.signal_showinfo.connect(self.showInfo)

        font = QFont()
        font.setFamily("Calibri")  #,Consolas
        font.setPointSize(16)

        font2 = QFont()
        font2.setFamily("Calibri")
        font2.setPointSize(12)

        self.plot.setFont(font2)

        #  add toolbar
        toolBar = QToolBar(self)
        toolBar.setOrientation(Qt.Vertical)
        self.addToolBar(toolBar)
        # label COM
        lbl_COM = QLabel("COM:", toolBar)
        lbl_COM.setFont(font2)
        lbl_COM.setStyleSheet("")
        toolBar.addWidget(lbl_COM)

        #lineEdit_COM
        self.lineEdit_COM = QLineEdit(str(config.Port))
        self.lineEdit_COM.setFont(font2)
        #self.lineEdit_COM.setMinimumWidth(100)
        toolBar.addWidget(self.lineEdit_COM)

        # label baudrate
        lbl_baud = QLabel("BAUD Rate:", toolBar)
        lbl_baud.setFont(font2)
        lbl_baud.setStyleSheet("")
        toolBar.addWidget(lbl_baud)

        #lineEdit_baud
        self.lineEdit_baud = QLineEdit(str(config.BaudRate))
        #self.lineEdit_baud.setMinimumWidth(100)
        self.lineEdit_baud.setFont(font2)
        toolBar.addWidget(self.lineEdit_baud)

        # Connect device,              QIcon(const QString &filename);     // 从图像文件构造图标
        btnConnect = QToolButton(toolBar)
        btnConnect.setText("Connect")
        btnConnect.setFont(font2)
        btnConnect.setIcon(QIcon('./icon/Connect.png'))
        btnConnect.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnConnect)
        btnConnect.clicked.connect(self.GetComSettings_Connect)

        # disConnect device
        btnDisConnect = QToolButton(toolBar)
        btnDisConnect.setText("DisConnect")
        btnDisConnect.setFont(font2)
        btnDisConnect.setIcon(QIcon('./icon/Disconnect.jfif'))
        btnDisConnect.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnDisConnect)

        btnDisConnect.clicked.connect(self.plot.DisConnect)

        toolBar.addSeparator()

        # Start timer
        btnStartTimer = QToolButton(toolBar)
        btnStartTimer.setText("Start Timer")
        btnStartTimer.setFont(font2)
        btnStartTimer.setIcon(QIcon('./icon/start.jfif'))
        btnStartTimer.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnStartTimer)
        btnStartTimer.clicked.connect(self.plot.StartTimer)

        # Stop timer
        btnStopTimer = QToolButton(toolBar)
        btnStopTimer.setText("Stop Timer")
        btnStopTimer.setFont(font2)
        btnStopTimer.setIcon(QIcon('./icon/stop.jfif'))
        btnStopTimer.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnStopTimer)
        btnStopTimer.clicked.connect(self.plot.StopTimer)

        toolBar.addSeparator()

        #X_LOWER
        lbl_x_lower = QLabel("X-Lower:", toolBar)
        lbl_x_lower.setFont(font2)

        toolBar.addWidget(lbl_x_lower)

        self.LineEdit_x_lower = QLineEdit(str(config.X_lower), toolBar)
        self.LineEdit_x_lower.setFont(font2)

        toolBar.addWidget(self.LineEdit_x_lower)

        #X_Upper
        lbl_x_upper = QLabel("X-Upper:", toolBar)
        lbl_x_upper.setFont(font2)

        toolBar.addWidget(lbl_x_upper)

        self.LineEdit_x_upper = QLineEdit(str(config.X_upper), toolBar)
        self.LineEdit_x_upper.setFont(font2)

        toolBar.addWidget(self.LineEdit_x_upper)

        #X_interval
        lbl_x_inteval = QLabel("X-Interval(s):", toolBar)
        lbl_x_inteval.setFont(font2)

        toolBar.addWidget(lbl_x_inteval)

        self.LineEdit_x_interval = QLineEdit(str(config.X_grid_interval),
                                             toolBar)
        self.LineEdit_x_interval.setFont(font2)

        toolBar.addWidget(self.LineEdit_x_interval)

        # Y_Lower
        lbl_y_lower = QLabel("Y-Lower:", toolBar)
        lbl_y_lower.setFont(font2)

        toolBar.addWidget(lbl_y_lower)

        self.LineEdit_y_Lower = QLineEdit(str(config.Y_lower), toolBar)
        self.LineEdit_y_Lower.setFont(font2)

        toolBar.addWidget(self.LineEdit_y_Lower)

        # Y_Upper
        lbl_y_uppwer = QLabel("Y-Upper:", toolBar)
        lbl_y_uppwer.setFont(font2)

        toolBar.addWidget(lbl_y_uppwer)

        self.LineEdit_Y_Upper = QLineEdit(str(config.Y_upper), toolBar)
        self.LineEdit_Y_Upper.setFont(font2)

        toolBar.addWidget(self.LineEdit_Y_Upper)
        # Y-Interval
        lbl_Y_Interval = QLabel("Y-Interval:", toolBar)
        lbl_Y_Interval.setFont(font2)

        toolBar.addWidget(lbl_Y_Interval)

        self.LineEdit_y_interval = QLineEdit(str(config.Y_grid_interval),
                                             toolBar)
        self.LineEdit_y_interval.setFont(font2)

        toolBar.addWidget(self.LineEdit_y_interval)

        # Set axis para
        btnSet = QToolButton(toolBar)
        btnSet.setText("Set Paras")
        btnSet.setFont(font2)
        btnSet.setIcon(QIcon('./icon/Settings.jfif'))
        btnSet.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnSet)
        btnSet.clicked.connect(self.SetParas)

        toolBar.addSeparator()

        # add print btn to toolbar
        btnPrint = QToolButton(toolBar)
        btnPrint.setText("Print")
        btnPrint.setFont(font2)
        btnPrint.setIcon(QIcon('./icon/print.jfif'))
        btnPrint.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnPrint)
        btnPrint.clicked.connect(self.print_)

        # add Export btn to toolbar
        btnExport = QToolButton(toolBar)
        btnExport.setText("Export")
        btnExport.setFont(font2)
        btnExport.setIcon(QIcon('./icon/snapshot.jfif'))
        btnExport.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnExport)
        btnExport.clicked.connect(self.exportDocument)

        toolBar.addSeparator()

        # add About btn to toolbar
        btnAbout = QToolButton(toolBar)
        btnAbout.setText("About")
        btnAbout.setFont(font2)
        btnAbout.setIcon(QIcon('./icon/about.png'))
        btnAbout.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnAbout)
        btnAbout.clicked.connect(self.About)

        #self.statusBar().setStyleSheet("QStatusBar::item{border: 5px}")
        self.statusBar().setStyleSheet("color:green")
        #self.statusBar().addPermanentWidget(VLine())
        self.statusBar().addPermanentWidget(QLabel("X = "))
        #self.statusBar().addPermanentWidget(VLine())
        self.statusBar().addPermanentWidget(QLabel("Y = "))

        #self.statusBar().addPermanentWidget(VLine())

        PermanentLabel = QLabel("Version:" + kProgVersion + " Developed by " +
                                kProgramDeveloperName +
                                " Python. Running with " + kPythonVersion)
        font3 = QFont()
        font3.setFamily("Calibri")
        font3.setPointSize(12)
        PermanentLabel.setFont(font3)

        self.statusBar().setFont(font3)
        self.statusBar().addPermanentWidget(PermanentLabel)

        self.showInfo("Show info here ......")

    # get UI settings
    def SetParas(self):
        '''
        y_lower,y_upper,y_interval,x_interval,X-Upper,x_lower
        '''
        self.plot.setPara(int(self.LineEdit_y_Lower.text()),
                          int(self.LineEdit_Y_Upper.text()),
                          int(self.LineEdit_y_interval.text()),
                          int(self.LineEdit_x_interval.text()),
                          int(self.LineEdit_x_upper.text()),
                          int(self.LineEdit_x_lower.text()))

    # get COM settings
    def GetComSettings_Connect(self):
        '''
            com, baud
        '''
        self.showInfo(
            'COM:%s, BaudRate: %d' %
            (self.lineEdit_COM.text(), int(self.lineEdit_baud.text())))
        self.plot.Connect(self.lineEdit_COM.text(),
                          int(self.lineEdit_baud.text()))

    def About(self):
        QMessageBox.about(self, "About", __doc__)

    def print_(self):
        printer = QPrinter(QPrinter.HighResolution)

        printer.setCreator('Bode example')
        printer.setOrientation(QPrinter.Landscape)
        printer.setColorMode(QPrinter.Color)

        docName = str(self.plot.title().text())
        if not docName:
            docName.replace('\n', ' -- ')
            printer.setDocName(docName)

        dialog = QPrintDialog(printer)
        if dialog.exec_():
            renderer = QwtPlotRenderer()
            if (QPrinter.GrayScale == printer.colorMode()):
                renderer.setDiscardFlag(QwtPlotRenderer.DiscardBackground)
                renderer.setDiscardFlag(
                    QwtPlotRenderer.DiscardCanvasBackground)
                renderer.setDiscardFlag(QwtPlotRenderer.DiscardCanvasFrame)
                renderer.setLayoutFlag(QwtPlotRenderer.FrameWithScales)
            renderer.renderTo(self.plot, printer)

    def exportDocument(self):
        renderer = QwtPlotRenderer(self.plot)
        renderer.exportTo(
            self.plot, "./export/export_%s" % (str(datetime.datetime.now())))

    def showInfo(self, text=""):
        self.statusBar().showMessage(text)

    def moved(self, point):
        info = "x =%g, y =%g" % (
            self.plot.invTransform(QwtPlot.xBottom, point.x()),
            self.plot.invTransform(QwtPlot.yLeft, point.y()),
            #self.plot.invTransform(QwtPlot.yRight, point.y())
        )
        self.showInfo(info)

    def selected(self, _):
        self.showInfo()

    # Get QMainWindow Close event , executed just before  the window closes.
    def closeEvent(self, *args, **kwargs):
        if QMessageBox.Yes == QMessageBox.warning(
                self, 'Warning',
                'The default Parameters are stored in conf.ini files!',
                QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes):
            config.write_item_value('COM', 'Port', self.lineEdit_COM.text())
            config.write_item_value('COM', 'BaudRate',
                                    self.lineEdit_baud.text())

            config.write_item_value('X_axis', 'X_lower', str(self.plot.x_ZERO))
            config.write_item_value('X_axis', 'X_upper',
                                    str(self.plot.x_range))
            config.write_item_value('X_axis', 'X_grid_interval',
                                    str(self.plot.x_interval))

            config.write_item_value('Y_axis', 'Y_lower',
                                    str(self.plot.y_range_Lower))
            config.write_item_value('Y_axis', 'Y_upper',
                                    str(self.plot.y_range_Upper))
            config.write_item_value('Y_axis', 'Y_grid_interval',
                                    str(self.plot.y_interval))
Esempio n. 3
0
class CurveDemo(QMainWindow):
 
    def __init__(self, *args):
        QMainWindow.__init__(self, *args)
 
        self.plot = DataPlot(self)
        #self.plot.resize(540,760)
        self.plot.setContentsMargins(5, 5, 5, 0)
        self.setCentralWidget(self.plot)
        print(type(self.plot.signal_showinfo))
        # signal slot connect
        self.plot.signal_showinfo.connect(self.showInfo)
        

        font = QFont()
        font.setFamily("Calibri")   #,Consolas
        font.setPointSize(16)
        
        font2 = QFont()
        font2.setFamily("Calibri")
        font2.setPointSize(14)
        
        self.plot.setFont(font2)
       
        #  add toolbar
        toolBar = QToolBar(self)
        self.addToolBar(toolBar)
        # label COM
        lbl_COM = QLabel("COM:",toolBar)
        lbl_COM.setFont(font)
        lbl_COM.setStyleSheet("")        
        toolBar.addWidget(lbl_COM)
        
        #lineEdit_COM
        self.lineEdit_COM =  QLineEdit('COM37')
        self.lineEdit_COM.setFont(font2)    
        self.lineEdit_COM.setMinimumWidth(50)
        toolBar.addWidget(self.lineEdit_COM)
        
        # label baudrate
        lbl_baud = QLabel("BAUD Rate:",toolBar)
        lbl_baud.setFont(font)
        lbl_baud.setStyleSheet("") 
        toolBar.addWidget(lbl_baud)
        
        #lineEdit_baud 
        self.lineEdit_baud =  QLineEdit('9600')
        self.lineEdit_baud.setMinimumWidth(100)
        self.lineEdit_baud.setFont(font2)
        toolBar.addWidget(self.lineEdit_baud)
        
        # label command
        lbl_command = QLabel("Command:",toolBar)
        lbl_command.setFont(font)
        lbl_command.setStyleSheet("") 
        toolBar.addWidget(lbl_command)
        
        #lineEdit_command 
        self.lineEdit_command =  QLineEdit(r'UPPER_VAL?\r\n')
        self.lineEdit_command.setFont(font2)
        #self.lineEdit_command.resize(200,12)
        
        #self.lineEdit_command.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Preferred)
        self.lineEdit_command.setMinimumWidth(300)
        
        toolBar.addWidget(self.lineEdit_command)
        
        # label response_rex
        lbl_response_rex = QLabel("response_rex:",toolBar)
        lbl_response_rex.setFont(font)
        lbl_response_rex.setStyleSheet("") 
        toolBar.addWidget(lbl_response_rex)
        
        #lineEdit_response_rex 
        self.lineEdit_response_rex =  QLineEdit(r'^[-]?([0-9]{1,}[.]?[0-9]*)')
        self.lineEdit_response_rex.setFont(font2)
        #self.lineEdit_command.resize(200,12)
        
        #self.lineEdit_command.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Preferred)
        self.lineEdit_response_rex.setMinimumWidth(300)
        
        toolBar.addWidget(self.lineEdit_response_rex)
        
        # Connect device,              QIcon(const QString &filename);     // 从图像文件构造图标
        btnConnect = QToolButton(toolBar)
        btnConnect.setText("Connect")
        btnConnect.setFont(font2)
        btnConnect.setIcon(QIcon('./icon/Connect.png'))
        btnConnect.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnConnect)        
        btnConnect.clicked.connect(self.GetComSettings_Connect)

        # disConnect device
        btnDisConnect = QToolButton(toolBar)
        btnDisConnect.setText("DisConnect")
        btnDisConnect.setFont(font2)
        btnDisConnect.setIcon(QIcon('./icon/Disconnect.jfif'))
        btnDisConnect.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnDisConnect)        
        
        btnDisConnect.clicked.connect(self.plot.DisConnect)
        
        toolBar.addSeparator()
        
        # Label sample interval        
        lbl_timer_interval = QLabel("Timer(ms):",toolBar)
        lbl_timer_interval.setFont(font)
        lbl_timer_interval.setStyleSheet("")         
        toolBar.addWidget(lbl_timer_interval)
        
        # lineEdit sample interval        
        self.lineEdit_timer_interval =  QLineEdit('250')     
        self.lineEdit_timer_interval.setFont(font2)
        self.lineEdit_timer_interval.setStyleSheet("")         
        toolBar.addWidget(self.lineEdit_timer_interval)        
        
        # Start timer
        btnStartTimer = QToolButton(toolBar)
        btnStartTimer.setText("Start Timer")
        btnStartTimer.setFont(font2)
        btnStartTimer.setIcon(QIcon('./icon/start.jfif'))
        btnStartTimer.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnStartTimer)
        btnStartTimer.clicked.connect(self.plot.StartTimer)
        
        # Stop timer
        btnStopTimer = QToolButton(toolBar)
        btnStopTimer.setText("Stop Timer")
        btnStopTimer.setFont(font2)
        btnStopTimer.setIcon(QIcon('./icon/stop.jfif'))
        btnStopTimer.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnStopTimer)
        btnStopTimer.clicked.connect(self.plot.StopTimer)
        
        toolBar.addSeparator()
        
        # dampBox = QWidget(toolBar)
        # dampLayout = QHBoxLayout(dampBox)
        # dampLayout.setSpacing(0)
        # dampLayout.addWidget(QWidget(dampBox), 0) # spacer 
        
        #X_interval   
        lbl_x_inteval = QLabel("X-Interval(s):", toolBar)  
        lbl_x_inteval.setFont(font)    
        #dampLayout.addWidget(lbl_x_inteval, 0) 
        toolBar.addWidget(lbl_x_inteval)
        
        self.LineEdit_x_interval= QLineEdit('30',toolBar)
        self.LineEdit_x_interval.setFont(font2)
        #dampLayout.addWidget(self.LineEdit_x_interval,0)
        #dampLayout.addSpacing(10)
        toolBar.addWidget(self.LineEdit_x_interval)
        
        # Y_Lower 
        lbl_y_lower = QLabel("Y-Lower:", toolBar)
        lbl_y_lower.setFont(font)
        #dampLayout.addWidget(lbl_y_lower, 0)  
        toolBar.addWidget(lbl_y_lower)
        
        self.LineEdit_y_Lower = QLineEdit('-90', toolBar)
        self.LineEdit_y_Lower.setFont(font2)
        #dampLayout.addWidget(self.LineEdit_y_Lower, 0)
        #dampLayout.addSpacing(10)
        toolBar.addWidget(self.LineEdit_y_Lower)
        
        # Y_Upper 
        lbl_y_uppwer = QLabel("Y-Upper:", toolBar)
        lbl_y_uppwer.setFont(font)
        #dampLayout.addWidget(lbl_y_uppwer, 0)  
        toolBar.addWidget(lbl_y_uppwer)
        
        self.LineEdit_Y_Upper = QLineEdit('210', toolBar)
        self.LineEdit_Y_Upper.setFont(font2)
        #dampLayout.addWidget(self.LineEdit_Y_Upper, 0)
        #dampLayout.addSpacing(10)
        toolBar.addWidget(self.LineEdit_Y_Upper)
        # Y-Interval
        lbl_Y_Interval = QLabel("Y-Interval:", toolBar)
        lbl_Y_Interval.setFont(font)
        #dampLayout.addWidget(lbl_Y_Interval, 0) 
        toolBar.addWidget(lbl_Y_Interval)
        
        self.LineEdit_y_interval= QLineEdit('50', toolBar)
        self.LineEdit_y_interval.setFont(font2)
        #dampLayout.addWidget(self.LineEdit_y_interval, 0)
        #dampLayout.addSpacing(10)       
        toolBar.addWidget(self.LineEdit_y_interval)
 
        #toolBar.addWidget(dampBox)         
        
        # Set axis para
        btnSet = QToolButton(toolBar)
        btnSet.setText("Set Paras")
        btnSet.setFont(font2)
        btnSet.setIcon(QIcon('./icon/Settings.jfif'))
        btnSet.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnSet)
        btnSet.clicked.connect(self.SetParas) 
                
        toolBar.addSeparator()
        
        # add print btn to toolbar
        btnPrint = QToolButton(toolBar)
        btnPrint.setText("Print")
        btnPrint.setFont(font2)
        btnPrint.setIcon(QIcon('./icon/print.jfif'))
        btnPrint.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnPrint)
        btnPrint.clicked.connect(self.print_)
        
        # add Export btn to toolbar
        btnExport = QToolButton(toolBar)
        btnExport.setText("Export")
        btnExport.setFont(font2)
        btnExport.setIcon(QIcon('./icon/snapshot.jfif'))
        btnExport.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnExport)
        btnExport.clicked.connect(self.exportDocument)
          
          
        toolBar.addSeparator()
      
        self.statusBar()     
        self.showInfo("Show info here ......")
        
        #self.resize(900,500)
    
    # get UI settings
    def SetParas(self):
        '''
        y_lower,y_upper,y_interval,x_interval
        '''       
        self.plot.setPara(int(self.LineEdit_y_Lower.text()),int(self.LineEdit_Y_Upper.text()),int(self.LineEdit_y_interval.text()),int(self.LineEdit_x_interval.text()))

    # get COM settings
    def GetComSettings_Connect(self):
        '''
            com, baud
        '''   
        self.showInfo('COM:%s, BaudRate: %d'%(self.lineEdit_COM.text(),int(self.lineEdit_baud.text())))        
        self.plot.Connect(self.lineEdit_COM.text(),int(self.lineEdit_baud.text()))
        self.plot.getReadingCommand = self.lineEdit_command.text()
        self.plot.getResp_rex = r'' + self.lineEdit_response_rex.text().encode()
        
        self.plot.interval = int(self.lineEdit_timer_interval.text())
        print('Timer interval: %d'%self.plot.interval)
        print('Command: %s'%self.plot.getReadingCommand)
        print('Regular expression: %s'%(self.plot.getResp_rex))
       
    
    def print_(self):
        printer = QPrinter(QPrinter.HighResolution)
 
        printer.setCreator('Bode example')
        printer.setOrientation(QPrinter.Landscape)
        printer.setColorMode(QPrinter.Color)
 
        docName = str(self.plot.title().text())
        if not docName:
            docName.replace('\n', ' -- ')
            printer.setDocName(docName)
 
        dialog = QPrintDialog(printer)
        if dialog.exec_():
            renderer = QwtPlotRenderer()
            if (QPrinter.GrayScale == printer.colorMode()):
                renderer.setDiscardFlag(QwtPlotRenderer.DiscardBackground)
                renderer.setDiscardFlag(QwtPlotRenderer.DiscardCanvasBackground)
                renderer.setDiscardFlag(QwtPlotRenderer.DiscardCanvasFrame)
                renderer.setLayoutFlag(QwtPlotRenderer.FrameWithScales)
            renderer.renderTo(self.plot, printer)
 
    def exportDocument(self):
        renderer = QwtPlotRenderer(self.plot)
        renderer.exportTo(self.plot, "./export/export_%d"%(datetime.datetime.now()))
     
    def showInfo(self, text=""):
        self.statusBar().showMessage(text)
        #self.statusBar().addSeparator()
                 
    def moved(self, point):
        info = "x =%g, y =%g" % (
            self.plot.invTransform(QwtPlot.xBottom, point.x()),
            self.plot.invTransform(QwtPlot.yLeft, point.y()),
            #self.plot.invTransform(QwtPlot.yRight, point.y())
            )
        self.showInfo(info)
 
    def selected(self, _):
        self.showInfo()