Exemple #1
0
    def create_rating_ticker(self, i, rating):
        """Creates the rating ticker that is displayed on the Local Storage
        View tab's QTableView. Each QSpinBox is mapped to a row, representing
        the rating of the patch.

        i: The current row the buttons are being created for.
        rating: The current rating associated with the selected patch.
        """

        if rating < 0 or rating > 5:
            raise errors.SortingError(rating, 901)

        rate_tkr = QSpinBox()
        rate_tkr.setValue(rating)
        rate_tkr.setRange(0, 5)
        rate_tkr.setSingleStep(1)
        rate_tkr.valueChanged.connect(self.update_rating)

        rate_tkr.setFont(self.ui.table_PS.horizontalHeader().font())
        self.ui.table_local.setCellWidget(i, 4, rate_tkr)
Exemple #2
0
class Clock_widget(QMainWindow):

    def __init__(self, frameless=False, web=False, debug=0):
        super(Clock_widget, self).__init__()

        self.debug = debug
        self.frameless = frameless
        self.web = web
        self.analog = None
        self.bedtime = QTime(20, 15, 00)
        self.bedtime_grace_period = 10
        self.LEDBall_state = 0
        self.temp_update_interval = 10
        self.n_updates = 0

        self.temp_data = ['i', 0, 0, 0, 'o', 0, 0, 0, 'c', 0, 0]
        self.LCD_brightness = 150

        self.resize(800, 460)
        self.setupUi(self)

        self.timer = QTimer(self)
        self.timer.timeout.connect(self.update)
        self.timer.start(1000)

    def setupUi(self, parent):
        """Setup the interfaces for the clock."""

        if not self.objectName():
            self.setObjectName(u"Clock")

        sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(parent.sizePolicy().hasHeightForWidth())
        parent.setSizePolicy(sizePolicy)
        parent.setAutoFillBackground(True)

        parent.setWindowFlag(Qt.Widget, True)
        if os.uname().sysname == "Linux" or self.frameless:
            parent.setWindowFlag(Qt.FramelessWindowHint, True)
    
        self.tabWidget = QTabWidget(parent)
        self.tabWidget.setObjectName(u"tabWidget")
        self.tabWidget.setGeometry(QRect(0, 0, 800, 460))
        # This works for Mac, but seems to not work with Linux/Arm/RPi
        # tabbar = self.tabWidget.tabBar()
        # tabbar.setMinimumSize(50, 24)
        # tabfont = QFont()
        # tabfont.setBold(True)
        # tabfont.setItalic(True)
        # tabfont.setPointSize(32)
        # tabbar.setFont(tabfont)

        # Setup the TABS
        self.clock = QWidget()
        self.clock.setObjectName(u"clock")
        self.tabWidget.addTab(self.clock, "")
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.clock), "Clock")

        self.weather = QWeather(parent=None, debug=self.debug)
        self.tabWidget.addTab(self.weather, "")
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.weather), "Weather")

        self.settings = QWidget()
        self.settings.setObjectName(u"settings")
        self.tabWidget.addTab(self.settings, "")
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.settings), "Settings")

        self.tabWidget.setCurrentIndex(0)

        #################################################################################################
        # Setup Clock Page
        #################################################################################################

        self.analog = AnalogClock(self.clock)

        # DIGITAL clock in "clock" tab
        self.Digital = QLabel(self.clock)
        self.Digital.setObjectName(u"Digital")
        self.Digital.setGeometry(QRect(0, 5, 765, 71))
        self.Digital.setAutoFillBackground(False)
        self.Digital.setStyleSheet(u"")
        self.Digital.setText(u"Current Time - Date + time")

        # Weather Icon
        self.weathericon = QWeatherIcon((480, 5), self.weather, parent=self.clock)
        self.weather.weather_updated.connect(self.weathericon.update)

        # Weather info on the Clock page.
        self.minipanel = QTempMiniPanel((475, 105), self.weather, parent=self.clock)
        self.weather.temp_updated.connect(self.minipanel.update)

        self.hilo = QHiLoTide((580, 5), parent=self.clock, debug=self.debug)


        # Moon phase
        self.moon = QMoon(pos=(450, 210), parent=self.clock, size=216, web=self.web)

        # Push buttons in "clock tab.
        push_button_width = 111
        push_button_height = 40
        push_button_x = 670
        push_button_y = 220

        self.ledball_off = QPushButton(self.clock)
        self.ledball_off.setObjectName(u"ledball_off")
        self.ledball_off.setText(u"LED off")
        self.ledball_off.setGeometry(QRect(push_button_x, push_button_y, push_button_width, push_button_height))

        self.ledball_on = QPushButton(self.clock)
        self.ledball_on.setObjectName(u"ledball_on")
        self.ledball_on.setText(u"LED on ")
        self.ledball_on.setGeometry(QRect(push_button_x, push_button_y+push_button_height, push_button_width, push_button_height))

        self.ledball_on2 = QPushButton(self.clock)
        self.ledball_on2.setObjectName(u"ledball_on2")
        self.ledball_on2.setText(u"LED on 2")
        self.ledball_on2.setGeometry(QRect(push_button_x, push_button_y+push_button_height*2, push_button_width, push_button_height))

        self.sleep = QPushButton(self.clock)
        self.sleep.setObjectName(u"sleep")
        self.sleep.setText(u"Sleep")
        self.sleep.setGeometry(QRect(push_button_x, push_button_y+push_button_height*3+10, push_button_width, push_button_height))

        #################################################################################################
        # Setup Weather Page
        #################################################################################################

        #################################################################################################
        # Setup Setting Page
        #################################################################################################
        self.timeEdit = QTimeEdit(self.settings)
        self.timeEdit.setObjectName(u"timeEdit")
        self.timeEdit.setDisplayFormat(u"h:mm AP")
        self.timeEdit.setGeometry(QRect(200, 30, 191, 41))
        font8 = QFont()
        font8.setFamily(u"Gill Sans")
        font8.setPointSize(16)
        font8.setBold(False)
        font8.setItalic(False)
        font8.setWeight(50)
        self.timeEdit.setFont(font8)
        self.timeEdit.setAutoFillBackground(True)
        self.timeEdit.setTime(self.bedtime)
        self.bedtime_label = QLabel(self.settings)
        self.bedtime_label.setObjectName(u"bedtime_label")
        self.bedtime_label.setText(u"Set Bedtime:")
        self.bedtime_label.setGeometry(QRect(200, 0, 151, 31))
        self.bedtime_label.setFont(font8)
        self.bedtime_label.setAutoFillBackground(True)
        self.Brightness_Value = QLCDNumber(self.settings)
        self.Brightness_Value.setObjectName(u"Brightness_Value")
        self.Brightness_Value.setGeometry(QRect(20, 120, 61, 31))
        self.Brightness_Value.setStyleSheet(u"color: \"White\";\n"
                                            "margin:0px;\n"
                                            "border:0px;background:\"transparent\";")
        self.Brightness_Value.setDigitCount(3)
        self.Brightness_Value.setProperty("value", 180.000000000000000)
        self.Brightness = QSlider(self.settings)
        self.Brightness.setObjectName(u"Brightness")
        self.Brightness.setGeometry(QRect(30, 160, 51, 261))
        self.Brightness.setAutoFillBackground(False)
        self.Brightness.setMaximum(255)
        self.Brightness.setValue(self.LCD_brightness)
        self.Brightness.setOrientation(Qt.Vertical)
        self.Brightness_label = QLabel(self.settings)
        self.Brightness_label.setObjectName(u"Brightness_label")
        self.Brightness_label.setText(u"Brightness")
        self.Brightness_label.setGeometry(QRect(20, 70, 101, 41))
        font10 = QFont()
        font10.setFamily(u"Arial Black")
        font10.setPointSize(12)
        font10.setBold(True)
        font10.setWeight(75)
        self.Brightness_label.setFont(font10)
        self.temp_test = QLabel(self.settings)
        self.temp_test.setObjectName(u"temp_test")
        self.temp_test.setText(u"T20.5 C")
        self.temp_test.setFont(font8)
        self.temp_test.setGeometry(QRect(630, 60, 141, 51))
        # self.temp_test.setFont(font_bold_20)
        self.temp_test_slide = QSlider(self.settings)
        self.temp_test_slide.setObjectName(u"temp_test_slide")
        self.temp_test_slide.setGeometry(QRect(660, 150, 51, 271))
        self.temp_test_slide.setAutoFillBackground(False)
        self.temp_test_slide.setMinimum(-250)
        self.temp_test_slide.setMaximum(450)
        self.temp_test_slide.setSingleStep(5)
        self.temp_test_slide.setPageStep(25)
        self.temp_test_slide.setValue(38)
        self.temp_test_slide.setOrientation(Qt.Vertical)
        self.temp_check_outside = QCheckBox(self.settings)
        self.temp_check_outside.setObjectName(u"temp_check_outside")
        self.temp_check_outside.setText(u"Outside")
        self.temp_check_outside.setGeometry(QRect(640, 110, 86, 20))
        self.grace_period = QSpinBox(self.settings)
        self.grace_period.setObjectName(u"grace_period")
        self.grace_period.setGeometry(QRect(411, 31, 111, 41))
        self.grace_period.setFont(font8)
        self.grace_period.setMinimum(1)
        self.grace_period.setMaximum(60)
        self.grace_period.setValue(self.bedtime_grace_period)
        self.grace_period.setDisplayIntegerBase(10)
        self.grace_period_label = QLabel(self.settings)
        self.grace_period_label.setObjectName(u"grace_period_label")
        self.grace_period_label.setText(u"Grace period:")
        self.grace_period_label.setGeometry(QRect(410, 10, 111, 16))
        self.grace_period_label.setFont(font8)

        #################################################################################################
        # SET ALL LABEL TEXTS
        #################################################################################################

        # if QT_CONFIG(tooltip)
        self.sleep.setToolTip(u"Put display to sleep")
        self.ledball_on2.setToolTip(u"Turn on the LED Ball, mode 2")
        self.ledball_on.setToolTip(u"Turn on the LED Ball.")
        self.ledball_off.setToolTip(u"Turn off the LED Ball.")
        # endif // QT_CONFIG(tooltip)

        #################################################################################################
        # Make the Connections.
        #################################################################################################

        self.temp_test_slide.valueChanged.connect(self.test_temp_update)
        self.temp_check_outside.clicked.connect(self.test_temp_update)

        self.ledball_off.clicked.connect(self.set_ledball_off)
        self.ledball_on.clicked.connect(self.set_ledball_on)
        self.ledball_on2.clicked.connect(self.set_ledball_on2)
        self.sleep.clicked.connect(self.set_sleep)

        self.timeEdit.timeChanged.connect(self.set_bedtime)
        self.grace_period.valueChanged.connect(self.set_grace_period)
        self.Brightness.valueChanged.connect(self.set_screen_brightness)
        self.Brightness.valueChanged.connect(self.Brightness_Value.display)

    def setup_from_json(self, json):
        """Set settings from the json dictionary passed."""

        if "BedTime" in json:
            new_bedtime = QTime.fromString(json["BedTime"], "hh:mm:ss")
            if not new_bedtime.isValid():
                new_bedtime = QTime.fromString(json["BedTime"], "hh:mm")

            if new_bedtime.isValid():
                self.bedtime = new_bedtime
                self.timeEdit.setTime(self.bedtime)
            else:
                print("Could not set bedtime to {}".format(str(new_bedtime)))

        if "GracePeriod" in json:
            self.bedtime_grace_period = int(json["GracePeriod"])
            self.grace_period.setValue(self.bedtime_grace_period)

        if "Brightness" in json:
            self.LCD_brightness = int(json["Brightness"])
            self.Brightness.setValue(self.LCD_brightness)

    @Slot()
    def update(self):
        """This is called every second to perform the clock functions."""
        AnalogClock.update(self)

        dtime = QDateTime.currentDateTime()
        text = dtime.toString("ddd MMM dd hh:mm:ss")
        self.Digital.setText(text)

        time = dtime.time()
        if self.bedtime < time < self.bedtime.addSecs(self.bedtime_grace_period * 60):
            self.Digital.setStyleSheet("color: rgba(200,100,0,200)")
            self.Digital.setText(text + " Bedtime")

        if self.bedtime < time < self.bedtime.addSecs(1) and self.LEDBall_state > 0:
            self.set_ledball_ready_for_bed()

        if self.bedtime.addSecs(self.bedtime_grace_period*60) < time < \
                self.bedtime.addSecs(self.bedtime_grace_period*60 + 1):
            self.Digital.setStyleSheet("")
            self.set_ledball_off()
            self.turn_off_lcd()


    @Slot()
    def set_ledball_off(self):
        """Turn off the LED ball."""
        if self.debug > 0:
            print("Set LED ball off.")

        os.system("ssh bbb1 \"./LEDBall_off.py\" >/dev/null")
        self.LEDBall_state = 0

    @Slot()
    def set_ledball_ready_for_bed(self):
        """Set LED ball to very red."""
        if self.LEDBall_state != 3:
            if self.debug > 0:
                print("Set LED ball to ready for bed.")
            os.system("ssh bbb1 \"./LEDBall_off.py && ./matrix.py 200 5.\" >/dev/null ")
            self.LEDBall_state = 3

    @Slot()
    def set_ledball_on(self):
        """Turn LED ball to normal on"""
        if self.debug > 0:
            print("Set LED ball on.")

        os.system("(ssh bbb1 \"./LEDBall_off.py && ./matrix.py 200\" >/dev/null)")
        self.LEDBall_state = 1

    @Slot()
    def set_ledball_on2(self):
        """Turn LED ball to alternate on"""
        if self.debug > 0:
            print("Set LED ball alternate on.")

        os.system("(ssh bbb1 \"./LEDBall_off.py && ./matrix.py 300 3. 50\" >/dev/null)");
        self.LEDBall_state = 2

    @Slot()
    def set_sleep(self):
        self.set_ledball_off()
        self.turn_off_lcd()

    def turn_off_lcd(self):
        """Turn the LCD off with the DPMS."""
        if os.uname().sysname == "Linux":
            os.system("/usr/bin/xset dpms force off");

    def set_pressure_color(selfs, obj, press, valid = True):
        """Set the color of obj according to the pressure. """
        pressures = (900., 950., 1000., 1020., 1040.)
        colors = (0, 60, 120, 240, 300)
        if valid:
            if press < pressures[0]:
                press = pressures[0] + 0.0001
            if press > pressures[-1]:
                press = pressures[-1] - 0.0001

            i=0
            while press > pressures[i]:
                i += 1
            hue = int(((press - pressures[i-1])/(pressures[i] - pressures[i-1]))*(colors[i]-colors[i-1]) +
                      colors[i-1])
            color = QColor.fromHsv(hue, 255, 120, 255)
            obj.setStyleSheet("color: rgba({},{},{},255)".format(color.red(), color.green(), color.blue()))


    def set_temp_color(self, obj, temp, inside=True, invalid=False):
        """Set the color of obj depending on the temperature displayed by obj."""
        temps = (-15., 16., 28., 40.)
        colors = (270, 145, 60, 0)

        if inside:
            temps = (12., 20., 25., 32.)

        if invalid:
            obj.setStyleSheet("color: rgba(100,100,100,100)")
        else:
            if temp < temps[0]:
                temp = temps[0] + 0.0001
            if temp > temps[-1]:
                temp = temps[-1] - 0.0001

            i = 0
            while temp > temps[i]:
                i += 1
            hue = int(((temp - temps[i-1])/(temps[i] - temps[i-1]))*(colors[i] - colors[i-1]) + colors[i-1])
            color = QColor.fromHsv(hue, 255, 150, 255)

            obj.setStyleSheet("color: rgba({},{},{},255)".format(color.red(), color.green(), color.blue()))

    @Slot()
    def test_temp_update(self, val=None):
        """Update the temperature on the test slider."""

        if val is None or type(val) is bool:
            val = self.temp_test_slide.value()

        temp = val*0.1
        text = "{:6.2f} C".format(temp)
        self.temp_test.setText(text)
        self.set_temp_color(self.temp_test, temp, not self.temp_check_outside.isChecked(), False)

    @Slot()
    def set_bedtime(self, ntime):
        """Set the bedtime to a new time"""
        self.bedtime = ntime

    @Slot()
    def set_grace_period(self, grace):
        """Set the grace period to a new delta time"""
        self.bedtime_grace_period = grace

    @Slot()
    def set_screen_brightness(self, value):
        """Set the brightness of the screen on Raspberry Pi"""
        self.LCD_brightness = value

        if os.uname().sysname == "Linux":
            try:
                f = open("/sys/class/backlight/rpi_backlight/brightness", "w")
                f.write(str(value))
                f.close()
            except Exception as e:
                print("Issue with opening brightness file \n",e)
Exemple #3
0
class OscGui(QWidget):
    triggerEnable = 0
    ADCEnable = 0

    def __init__(self, device):
        QWidget.__init__(self)
        self.setWindowIcon(QIcon("icon/silabslogo.png"))

        self.device = device
        screen = QDesktopWidget()
        self.m_width = screen.width()
        self.m_height = screen.height()
        self.resize(self.m_width, self.m_height)
        self.showMaximized()

        self.setWindowTitle("Silabs")
        self.setObjectName("mainWindow")
        self.setStyleSheet("#mainWindow{background-color:rgb(54, 56, 60);}")

        self.layout = QtWidgets.QHBoxLayout()
        self.layout.setContentsMargins(self.m_width / 200, self.m_width / 200,
                                       self.m_width / 200, self.m_width / 20)
        self.layout.setSpacing(10)

        self.create_left_frame()
        self.create_right_frame()

        self.layout.setStretch(0, 3)
        self.layout.setStretch(1, 1)

        self.setLayout(self.layout)

        if self.device:
            logging.debug("device name:" + str(self.device))
            self.readThread = USBReadThread(self.device)
            self.readThread.updateWaveForm.connect(self.update_canvas)
            self.readThread.updateFrequency.connect(self.update_frequency)
            self.readThread.singleTrigger.connect(self.single_trigger_event)
            self.readThread.start()

            self.frequencyGet = Protocol.PREAMBLE.value \
                + Protocol.FREQUENCY_GET.value \
                + '\x00'  # '\xAA' + '\x41' + '\x00'
            self.setThread = USBWriteThread(self.device, self.frequencyGet)
            self.setThread.start()

    def create_left_frame(self):
        self.leftlayout = QtWidgets.QVBoxLayout()
        self.leftlayout.setContentsMargins(self.m_width / 200,
                                           self.m_width / 200,
                                           self.m_width / 200,
                                           self.m_width / 200)

        self.canvasFrame = CanvasFrame()
        # self.canvasFrame.setFrameStyle(QtWidgets.QFrame.StyledPanel | QtWidgets.QFrame.Plain)
        self.canvasFrame.setStyleSheet(
            "border-radius:10px;background-color:rgb(40, 38, 39);")
        self.leftlayout.addWidget(self.canvasFrame)

        self.navigationBarFrame = QtWidgets.QFrame()
        self.navigationBarFrame.setObjectName("NBF")
        self.navigationBarFrame.setStyleSheet(
            "#NBF{border-radius:10px;"
            "background-color:rgb(200, 200, 200);}")
        self.navigationBarLayout = QtWidgets.QVBoxLayout(
            self.navigationBarFrame)
        self.playBarLayout = QtWidgets.QHBoxLayout(self.navigationBarFrame)
        self.playBarLayout.setSpacing(self.m_width / 40)

        self.playBarLayout.addStretch(1)

        self.zoomInButton = QtWidgets.QPushButton()
        self.zoomInButton.setObjectName("zoomInButton")
        self.zoomInButton.setMaximumSize(self.m_width / 40, self.m_width / 40)
        self.zoomInButton.setMinimumSize(self.m_width / 40, self.m_width / 40)
        self.zoomInButton.setStyleSheet(
            "QPushButton{border-radius:25px;"
            "border-image:url(icon/ZoomIn.png);}"
            "QPushButton:hover{border-radius:25px;"
            "border-image:url(icon/ZoomIn2.png);"
            "background-colora:rgb(50, 50, 50,0);}")

        self.zoomInButton.clicked.connect(self.zoom_in_event)
        self.playBarLayout.addWidget(self.zoomInButton)

        self.zoomOutButton = QtWidgets.QPushButton()
        self.zoomOutButton.setObjectName("zoomOutButton")
        self.zoomOutButton.setMaximumSize(self.m_width / 40, self.m_width / 40)
        self.zoomOutButton.setMinimumSize(self.m_width / 40, self.m_width / 40)
        self.zoomOutButton.setIcon(QIcon("icon/ZoomOut.png"))
        self.zoomOutButton.setIconSize(
            QSize(self.m_width / 40, self.m_width / 40))
        self.zoomOutButton.setStyleSheet(
            "QPushButton{border-radius:%dpx;}"
            "QPushButton:hover{border:1 solid red;"
            "border-radius:%dpx;"
            "background-color:rgb(250, 100, 100);}" %
            (self.m_width / 80, self.m_width / 80))
        self.zoomOutButton.clicked.connect(self.zoom_out_event)
        self.playBarLayout.addWidget(self.zoomOutButton)

        self.playButton = QtWidgets.QPushButton()
        self.playButton.setObjectName("playButton")
        self.playButton.setFixedSize(self.m_width / 20, self.m_width / 20)
        # self.playButton.setStyleSheet("border-radius:%dpx;" % self.m_width/40)
        self.playButton.setStyleSheet("QPushButton{border:none;"
                                      "border-radius:%dpx;"
                                      "background-color:"
                                      "rgb(200, 100, 100);}"
                                      "QPushButton:hover{border:0;"
                                      "border-radius:%dpx;"
                                      "background-color:rgb(250, 100, 100);}" %
                                      (self.m_width / 40, self.m_width / 40))
        self.playButton.clicked.connect(self.play_button_event)
        self.playBarLayout.addWidget(self.playButton)

        self.triggerLayout = QtWidgets.QHBoxLayout(self.navigationBarFrame)
        self.triggerLayout.setContentsMargins(0, 0, 0, 0)
        self.triggerLayout.setSpacing(1)

        self.triggerEnable = 0
        self.triggerButton = QtWidgets.QPushButton(self.navigationBarFrame)
        # self.triggerButton.setObjectName("triggerButton")
        self.triggerButton.setFixedSize(self.m_width / 12, self.m_height / 20)
        self.triggerButton.setFont(QFont("New Time Roman", 10))
        self.triggerButton.setText("Single Trigger")
        self.triggerButton.setStyleSheet(
            "QPushButton{border-top-left-radius:5px;"
            "border-bottom-left-radius: 5px;"
            "background-color:rgba(100, 100, 100,255);"
            "color:rgb(200, 200, 200);}"
            "QPushButton:hover{color: rgb(100, 200, 100);font-weight:bold}")
        self.triggerButton.clicked.connect(self.trigger_event)
        self.triggerLayout.addWidget(self.triggerButton)

        self.triggerValue = 0
        self.triggerSpinBox = QSpinBox(self.navigationBarFrame)
        self.triggerSpinBox.setFixedSize(self.m_width / 10, self.m_height / 20)
        self.triggerSpinBox.setMaximum(3300)
        self.triggerSpinBox.setMinimum(1)
        self.triggerSpinBox.setFont(QFont("New Time Roman", 10))
        self.triggerSpinBox.setStyleSheet(
            "QSpinBox{border-top-right-radius:5px;"
            "border-bottom-left-right: 5px;"
            "background-color:rgb(100, 100, 100);"
            "color:rgb(200, 200, 200);}"
            "QSpinBox:drop{subcontrol-origin: padding;"
            "subcontrol-position: top right;"
            "width: 50px;border-left-style:solid;"
            "border-top-right-radius: 3px;"
            "border-bottom-right-radius: 3px;"
            "border-left: 2px solid gray;"
            "background-color: rgba(100, 25, 100, 0);}")
        self.triggerSpinBox.setMinimumWidth(30)
        self.triggerLayout.addWidget(self.triggerSpinBox)
        self.playBarLayout.addLayout(self.triggerLayout)

        self.playBarLayout.addStretch(1)
        self.navigationBarLayout.addLayout(self.playBarLayout)

        self.navigationBarLine = QtWidgets.QFrame(self.navigationBarFrame)
        self.navigationBarLine.setAutoFillBackground(True)
        self.navigationBarLine.setFixedHeight(1)
        self.navigationBarLine.setStyleSheet(
            "background-color:rgb(150, 150, 150);")
        self.navigationBarLayout.addWidget(self.navigationBarLine)
        # self.navigationBarLayout.addStretch(1)
        self.leftlayout.addWidget(self.navigationBarFrame)
        self.leftlayout.setStretch(0, 5)
        self.leftlayout.setStretch(1, 1)
        self.leftlayout.setStretch(2, 1)
        self.leftlayout.setSpacing(self.m_width / 40)
        self.layout.addLayout(self.leftlayout)

    def create_right_frame(self):

        self.rightlayout = QtWidgets.QVBoxLayout()
        self.rightlayout.setContentsMargins(self.m_width / 200,
                                            self.m_width / 200,
                                            self.m_width / 200,
                                            self.m_width / 200)

        self.dialogFrame = QtWidgets.QFrame()
        self.dialogFrame.setObjectName("dialogFrame")
        # self.dialogFrame.setAutoFillBackground(True)
        # self.dialogFrame.setStyleSheet("#dialogFrame{border-radius:10px;"
        #                                "background-color:rgb(255, 100, 100);}")
        self.dialogFrame.setStyleSheet("#dialogFrame{border-radius:10px;"
                                       "background-color:rgb(10, 10, 10);}")
        self.dialoglayout = QtWidgets.QVBoxLayout(self.dialogFrame)
        self.dialoglayout.setContentsMargins(0, self.m_width / 40, 0,
                                             self.m_width /
                                             40)  # left, top, right, bottom
        self.dialoglayout.setSpacing(self.m_width / 40)
        self.dialoglayout.addStretch(2)

        self.ledLayout = QtWidgets.QHBoxLayout(self.dialogFrame)

        self.ledLayout.addStretch(1)

        self.redLedState = 0
        self.redLedSwitch = QtWidgets.QPushButton(self.dialogFrame)
        self.redLedSwitch.setObjectName("redLedSwitch")
        self.redLedSwitch.setIcon(QIcon("icon/switchOFF.png"))
        self.redLedSwitch.setIconSize(
            QSize(self.m_width / 40, self.m_width / 40 / 1.75))
        self.redLedSwitch.setFixedSize(self.m_width / 40,
                                       self.m_width / 40 / 1.75)
        self.redLedSwitch.setStyleSheet("#redLedSwitch{border:none;}")
        self.redLedSwitch.clicked.connect(self.red_led_switch_event)
        self.ledLayout.addWidget(self.redLedSwitch)

        self.ledLayout.addStretch(1)

        self.greenLedState = 0
        self.greenLedSwitch = QtWidgets.QPushButton(self.dialogFrame)
        self.greenLedSwitch.setObjectName("greenLedSwitch")
        self.greenLedSwitch.setIcon(QIcon("icon/switchOFF.png"))
        self.greenLedSwitch.setIconSize(
            QSize(self.m_width / 40, self.m_width / 40 / 1.75))
        self.greenLedSwitch.setFixedSize(self.m_width / 40,
                                         self.m_width / 40 / 1.75)
        self.greenLedSwitch.setStyleSheet("#greenLedSwitch{border:none;}")
        self.greenLedSwitch.clicked.connect(self.green_led_switch_event)
        self.ledLayout.addWidget(self.greenLedSwitch)

        self.ledLayout.addStretch(1)

        self.blueLedState = 0
        self.blueLedSwitch = QtWidgets.QPushButton(self.dialogFrame)
        self.blueLedSwitch.setObjectName("blueLedSwitch")
        self.blueLedSwitch.setIcon(QIcon("icon/switchOFF.png"))
        self.blueLedSwitch.setIconSize(
            QSize(self.m_width / 40, self.m_width / 40 / 1.75))
        self.blueLedSwitch.setFixedSize(self.m_width / 40,
                                        self.m_width / 40 / 1.75)
        self.blueLedSwitch.setStyleSheet("#blueLedSwitch{border:none;}")
        self.blueLedSwitch.clicked.connect(self.blue_led_switch_event)
        self.ledLayout.addWidget(self.blueLedSwitch)

        self.ledLayout.addStretch(1)
        self.dialoglayout.addLayout(self.ledLayout)

        self.dialoglayout.addStretch(1)

        self.dialogLine = QtWidgets.QFrame(self.dialogFrame)
        self.dialogLine.setAutoFillBackground(True)
        self.dialogLine.setFixedHeight(1)
        self.dialogLine.setStyleSheet("background-color:rgb(50, 50, 50);")
        self.dialoglayout.addWidget(self.dialogLine)

        self.channelLayout = QtWidgets.QHBoxLayout(self.dialogFrame)
        self.channelLayout.setSpacing(0)
        self.channelLayout.setContentsMargins(self.m_width / 100, 0,
                                              self.m_width / 100, 0)
        # self.channelLayout.addStretch(1)

        self.channel1Enable = 0
        self.channel1Button = QPushButton(self.dialogFrame)
        self.channel1Button.setFixedHeight(self.m_width / 40)
        self.channel1Button.setStyleSheet(
            "QPushButton{border:1px solid rgb(200,200,200);"
            "border-top-left-radius:5px;"
            "border-bottom-left-radius: 5px;"
            "background-color:rgba(100, 100, 100,0);"
            "color:rgb(200, 200, 200);"
            "padding: 1px 20px;}"
            "QPushButton:hover{font-weight:bold;}")
        self.channel1Button.setFont(QFont("New Time Roman", 10))
        self.channel1Button.setText("Channel_1")
        self.channel1Button.clicked.connect(self.channel1_button_event)
        self.channelLayout.addWidget(self.channel1Button)

        self.channel2Enable = 0
        self.channel2Button = QPushButton(self.dialogFrame)
        self.channel2Button.setFixedHeight(self.m_width / 40)
        self.channel2Button.setStyleSheet(
            "QPushButton{border:1px solid rgb(200,200,200);"
            "border-top-right-radius: 5px;"
            "border-bottom-right-radius:5px;"
            "background-color:rgba(100, 100, 100,0);"
            "color:rgb(200, 200, 200);"
            "padding: 1px 20px;}"
            "QPushButton:hover{font-weight:bold;}")
        self.channel2Button.setFont(QFont("New Time Roman", 10))
        self.channel2Button.setText("Channel_2")
        self.channel2Button.clicked.connect(self.channel2_button_event)
        self.channelLayout.addWidget(self.channel2Button)
        # self.channelLayout.addStretch(1)

        self.dialoglayout.addLayout(self.channelLayout)

        self.dialogLine2 = QtWidgets.QFrame(self.dialogFrame)
        self.dialogLine2.setAutoFillBackground(True)
        self.dialogLine2.setFixedHeight(1)
        self.dialogLine2.setStyleSheet("background-color:rgb(50, 50, 50);")
        self.dialoglayout.addWidget(self.dialogLine2)

        self.configutatorLayout = QtWidgets.QVBoxLayout(self.dialogFrame)
        self.configutatorLayout.setContentsMargins(20, 0, 20, 0)
        self.configutatorLayout.setSpacing(self.m_width / 100)

        self.frenquencyComboBox = QtWidgets.QComboBox()
        self.frenquencyComboBox.setObjectName("frenquencyComboBox")
        self.frenquencyComboBox.setFixedHeight(self.m_width / 40)
        self.frenquencyComboBox.setFont(QFont("New Time Roman", 10))
        self.frenquencyComboBox.setStyleSheet(
            "QComboBox{border-radius:5px;"
            "background-color:rgb(200, 200, 200);"
            "color:rgb(0, 0, 0);"
            "padding: 1px 20px;}"
            "QComboBox:drop-down{subcontrol-origin: padding;"
            "subcontrol-position: top right;"
            "width: 50px;border-left-style:solid;"
            "border-top-right-radius: 3px;"
            "border-bottom-right-radius: 3px;"
            "border-left: 2px solid gray;"
            "background-color: rgba(100, 100, 100, 0);}"
            "QComboBox:down-arrow{border-image:url(icon/arrow-1.png);}")
        self.frenquencyComboBox.addItem("4Hz")
        self.frenquencyComboBox.addItem("10Hz")
        self.frenquencyComboBox.addItem("100Hz")
        self.frenquencyComboBox.addItem("1000Hz")
        self.frenquencyComboBox.setCurrentText("1000Hz")
        self.frenquencyComboBox.setFont(QFont("New Time Roman", 10))

        self.configutatorLayout.addWidget(self.frenquencyComboBox)

        self.setButton = QPushButton(self.dialogFrame)
        self.setButton.setObjectName("setButton")
        self.setButton.setFixedHeight(self.m_width / 40)
        self.setButton.setStyleSheet(
            "QPushButton{border-radius:%dpx;"
            "background-color:rgb(150, 255, 150);"
            "color:rgb(0, 0, 0);"
            "text-align: center center;}"
            "QPushButton:hover{background-color:"
            "rgb(100, 255, 100);color:rgb(255, 100, 100);"
            "font-size:20px}" % (self.m_width / 80))
        self.setButton.setFont(QFont("New Time Roman", 12, QFont.Bold))
        self.setButton.setText("set")
        self.setButton.clicked.connect(self.set_button_event)
        self.setButton.setEnabled(True)
        self.configutatorLayout.addWidget(self.setButton)

        self.dialoglayout.addLayout(self.configutatorLayout)
        self.dialoglayout.addStretch(1)

        self.rightlayout.addWidget(self.dialogFrame)

        self.stateFrame = QtWidgets.QFrame()
        self.stateFrame.setObjectName("stateFrame")
        # self.dialogFrame.setAutoFillBackground(True)
        self.stateFrame.setStyleSheet(
            "QFrame{border:2px solid rgb(200, 200, 200);"
            "border-radius:10px;"
            "background-color:rgb(200, 200, 200);}")
        self.statelayout = QtWidgets.QGridLayout(self.stateFrame)
        self.statelayout.setContentsMargins(self.m_width / 40,
                                            self.m_width / 40,
                                            self.m_width / 40,
                                            self.m_width / 40)
        self.enableLabelKey = QLabel(self.stateFrame)
        self.enableLabelKey.setText("state:")
        self.enableLabelKey.setFont(QFont("New Time Roman", 10, QFont.Bold))
        self.statelayout.addWidget(self.enableLabelKey, 0, 0)
        self.enableLabelValue = QLabel(self.stateFrame)
        self.enableLabelValue.setText("Stop")
        self.enableLabelValue.setFont(QFont("New Time Roman", 10, QFont.Bold))
        self.statelayout.addWidget(self.enableLabelValue, 0, 1)

        self.frequencyLabelKey = QLabel(self.stateFrame)
        self.frequencyLabelKey.setText("frequency:")
        self.frequencyLabelKey.setFont(QFont("New Time Roman", 10, QFont.Bold))
        self.statelayout.addWidget(self.frequencyLabelKey, 1, 0)
        self.frequencyLabelValue = QLabel(self.stateFrame)
        self.frequencyLabelValue.setText(
            str(self.canvasFrame.frequency) + "Hz")
        self.frequencyLabelValue.setFont(
            QFont("New Time Roman", 10, QFont.Bold))
        self.statelayout.addWidget(self.frequencyLabelValue, 1, 1)

        self.bitModeLabelKey = QLabel(self.stateFrame)
        self.bitModeLabelKey.setText("BitMode:")
        self.bitModeLabelKey.setFont(QFont("New Time Roman", 10, QFont.Bold))
        self.statelayout.addWidget(self.bitModeLabelKey, 2, 0)
        self.bitModeLabelValue = QLabel(self.stateFrame)
        self.bitModeLabelValue.setText("8 bit")
        self.bitModeLabelValue.setFont(QFont("New Time Roman", 10, QFont.Bold))
        self.statelayout.addWidget(self.bitModeLabelValue, 2, 1)

        self.rightlayout.addWidget(self.stateFrame)

        self.rightlayout.addStretch(1)

        self.layout.addLayout(self.rightlayout)

    def trigger_event(self):
        if self.device is None:
            logging.error("no device!!!")
            return
        if self.triggerEnable:
            self.triggerButton.setStyleSheet(
                "QPushButton{border-top-left-radius:5px;"
                "border-bottom-left-radius: 5px;"
                "background-color:rgba(100, 100, 100,255);}"
                "QPushButton:hover{color: rgb(100, 200, 100);font-weight:bold}"
            )
            self.triggerEnable = 0
            self.triggerValue = 0
            self.readThread.triggerEnable = 0
            self.readThread.triggerValue = 0
            self.triggerSpinBox.setEnabled(True)
            self.triggerSpinBox.setStyleSheet(
                "QSpinBox{border-top-right-radius:5px;"
                "border-bottom-left-right: 5px;"
                "background-color:rgb(100, 100, 100);"
                "color:rgb(200, 200, 200);}")

        else:
            self.triggerButton.setStyleSheet(
                "QPushButton{border:1px solid rgb(200,200,200);"
                "border-top-left-radius:5px;"
                "border-bottom-left-radius: 5px;"
                "background-color:rgba(100, 200, 100);}"
                "QPushButton:hover{color: rgb(100, 100, 100);font-weight:bold}"
            )
            self.triggerEnable = 1
            self.triggerValue = self.triggerSpinBox.value()
            self.readThread.triggerEnable = 1
            self.readThread.triggerValue = self.triggerValue
            self.triggerSpinBox.setEnabled(False)
            self.triggerSpinBox.setStyleSheet(
                "QSpinBox{border-top-right-radius:5px;"
                "border-bottom-left-right: 5px;"
                "background-color:rgb(150, 150, 150);}")
        logging.debug("triggerButtonEvent:" +
                      str(self.readThread.triggerEnable))

    def zoom_in_event(self):
        if self.canvasFrame.scaleRatio == 1:
            self.canvasFrame.scaleRatio = 1
        else:
            self.canvasFrame.scaleRatio = self.canvasFrame.scaleRatio - 1
        self.canvasFrame.update()
        logging.debug("zoom_in_event, scaleRatio= " +
                      str(self.canvasFrame.scaleRatio))

    def zoom_out_event(self):
        if self.canvasFrame.scaleRatio > 5:
            self.canvasFrame.scaleRatio = 6
        else:
            self.canvasFrame.scaleRatio = self.canvasFrame.scaleRatio + 1
        self.canvasFrame.update()
        logging.debug("zoom_out_event, scaleRatio= " +
                      str(self.canvasFrame.scaleRatio))

    def play_button_event(self):
        logging.debug("playButtonEvent")
        if self.device is None:
            logging.error("no device!!!")
            return

        if self.ADCEnable:
            self.channel1Button.setEnabled(True)
            self.channel2Button.setEnabled(True)
            self.playButton.setStyleSheet(
                "QPushButton{border-radius:%dpx;"
                "background-color:rgb(200, 100, 100);}"
                "QPushButton:hover{border:0;"
                "border-radius:%dpx;"
                "background-color:rgb(250, 100, 100);}" %
                (self.m_width / 40, self.m_width / 40))
            self.command = Protocol.PREAMBLE.value \
                + Protocol.ENABLE_ADC.value \
                + '\x01' \
                + Protocol.DISABLE.value  # '\xAA'+'\xF1'+'\x01'+'\x00'
            self.playthread = USBWriteThread(self.device, self.command)
            self.playthread.start()
            self.ADCEnable = 0
            self.enableLabelValue.setText("Stop")
            self.setButton.setStyleSheet(
                "QPushButton{border-radius:%dpx;"
                "background-color:rgb(150, 255, 150);"
                "color:rgb(0, 0, 0);"
                "text-align: center center;}"
                "QPushButton:hover{background-color:rgb(100, 255, 100);"
                "color:rgb(255, 100, 100);"
                "font-size:20px;}" % (self.m_width / 80))
            self.setButton.setEnabled(True)

            self.canvasFrame.dragEnable = True
        else:
            if self.channel1Enable == 0 and self.channel2Enable == 0:
                return

            if self.canvasFrame.frequency == 1000:
                self.freq = Protocol.FREQUENCY_1000HZ.value
            elif self.canvasFrame.frequency == 100:
                self.freq = Protocol.FREQUENCY_100HZ.value
            elif self.canvasFrame.frequency == 10:
                self.freq = Protocol.FREQUENCY_10HZ.value
            elif self.canvasFrame.frequency == 4:
                self.freq = Protocol.FREQUENCY_4HZ.value
            else:
                self.freq = Protocol.FREQUENCY_1000HZ.value

            self.frequencyCommand = Protocol.PREAMBLE.value \
                + Protocol.FREQUENCY_SET.value \
                + '\x01' \
                + self.freq  # '\xAA' + '\x43' + '\x01' + '\x03'
            self.frequencyThread = USBWriteThread(self.device,
                                                  self.frequencyCommand)
            self.frequencyThread.start()

            self.channel1Button.setEnabled(False)
            self.channel2Button.setEnabled(False)
            self.playButton.setStyleSheet(
                "QPushButton{border-radius:%dpx;"
                "background-color:rgb(100, 200, 100);}"
                "QPushButton:hover{border:0;"
                "border-radius:%dpx;"
                "background-color:rgb(100, 250, 100);}" %
                (self.m_width / 40, self.m_width / 40))
            self.command = Protocol.PREAMBLE.value \
                + Protocol.ENABLE_ADC.value \
                + '\x01' \
                + Protocol.ENABLE.value  # '\xAA'+'\xF1'+'\x01'+'\x01'
            self.playthread = USBWriteThread(self.device, self.command)
            self.playthread.start()
            self.ADCEnable = 1
            self.enableLabelValue.setText("Runing")

            self.setButton.setStyleSheet("QPushButton{border-radius:%dpx;"
                                         "background-color:rgb(150, 150, 150);"
                                         "color:rgb(0, 0, 0);"
                                         "text-align: center center;}" %
                                         (self.m_width / 80))
            self.setButton.setEnabled(False)
            self.canvasFrame.dragEnable = False
            self.canvasFrame.dragBias = 0
            self.canvasFrame.dragBias_t = 0

    def red_led_switch_event(self):
        if self.device is None:
            logging.error("no device!!!")
            return
        logging.debug("redled is pressed")
        if self.redLedState:
            self.redLedSwitch.setIcon(QIcon("icon/switchOFF.png"))
            self.redLedState = 0
            self.ledCommand = Protocol.PREAMBLE.value \
                + Protocol.LED_SET.value \
                + '\x02' \
                + Protocol.LED_RED.value \
                + Protocol.LED_OFF.value  # '\xAA' + '\x13' + '\x02' + '\x01' + '\x00'
        else:
            self.redLedSwitch.setIcon(QIcon("icon/switchRedOn.png"))
            self.redLedState = 1
            self.ledCommand = Protocol.PREAMBLE.value \
                + Protocol.LED_SET.value \
                + '\x02' + Protocol.LED_RED.value \
                + Protocol.LED_ON.value  # '\xAA' + '\x13' + '\x02' + '\x01' + '\x01'

        self.ledThread = USBWriteThread(self.device, self.ledCommand)
        self.ledThread.start()

    def green_led_switch_event(self):
        if self.device is None:
            logging.error("no device!!!")
            return
        logging.debug("greenled is pressed")
        if self.greenLedState:
            self.greenLedSwitch.setIcon(QIcon("icon/switchOFF.png"))
            self.greenLedState = 0
            self.ledCommand = Protocol.PREAMBLE.value \
                + Protocol.LED_SET.value \
                + '\x02' \
                + Protocol.LED_GREEN.value \
                + Protocol.LED_OFF.value  # '\xAA' + '\x13' + '\x02' + '\x02' + '\x00'

        else:
            self.greenLedSwitch.setIcon(QIcon("icon/switchGreenOn.png"))
            self.greenLedState = 1
            self.ledCommand = Protocol.PREAMBLE.value \
                + Protocol.LED_SET.value \
                + '\x02' \
                + Protocol.LED_GREEN.value \
                + Protocol.LED_ON.value  # '\xAA' + '\x13' + '\x02' + '\x02' + '\x01'
        self.ledThread = USBWriteThread(self.device, self.ledCommand)
        self.ledThread.start()

    def blue_led_switch_event(self):
        if self.device is None:
            logging.error("no device!!!")
            return
        logging.debug("blueled is pressed")
        if self.blueLedState:
            self.blueLedSwitch.setIcon(QIcon("icon/switchOFF.png"))
            self.blueLedState = 0
            self.ledCommand = Protocol.PREAMBLE.value \
                + Protocol.LED_SET.value \
                + '\x02' \
                + Protocol.LED_BLUE.value \
                + Protocol.LED_OFF.value  # '\xAA' + '\x13' + '\x02' + '\x03' + '\x00'
        else:
            self.blueLedSwitch.setIcon(QIcon("icon/switchBlueOn.png"))
            self.blueLedState = 1
            self.ledCommand = Protocol.PREAMBLE.value \
                + Protocol.LED_SET.value \
                + '\x02' \
                + Protocol.LED_BLUE.value \
                + Protocol.LED_ON.value  # '\xAA' + '\x13' + '\x02' + '\x03' + '\x01'
        self.ledThread = USBWriteThread(self.device, self.ledCommand)
        self.ledThread.start()

    def channel1_button_event(self):
        if self.device is None:
            logging.error("no device!!!")
            return
        if self.channel1Enable:
            del self.canvasFrame.Channel1List[:]
            self.command = Protocol.PREAMBLE.value \
                + Protocol.ENABLE_CHANNEL.value \
                + '\x02' \
                + Protocol.CHANNEL1.value \
                + Protocol.DISABLE.value  # '\xAA'+'\xF1'+'\x01'+'\x00'
            self.channel1thread = USBWriteThread(self.device, self.command)
            self.channel1thread.start()
            self.channel1Enable = 0
            self.canvasFrame.channel1Enable = 0

            self.channel1Button.setStyleSheet(
                "QPushButton{border:1px solid rgb(200,200,200);"
                "border-top-left-radius:5px;"
                "border-bottom-left-radius: 5px;"
                "background-color:rgba(100, 100, 100,0);"
                "color:rgb(200, 200, 200);"
                "padding: 1px 20px;}"
                "QPushButton:hover{font-weight:bold;}")

            logging.debug("channel1 disable")

        else:
            self.command = Protocol.PREAMBLE.value \
                           + Protocol.ENABLE_CHANNEL.value \
                           + '\x02' \
                           + Protocol.CHANNEL1.value \
                           + Protocol.ENABLE.value  # '\xAA'+'\xF1'+'\x01'+'\x00'
            self.channel1thread = USBWriteThread(self.device, self.command)
            self.channel1thread.start()
            self.channel1Enable = 1
            self.canvasFrame.channel1Enable = 1
            self.channel1Button.setStyleSheet(
                "QPushButton{border:1px solid rgb(200,200,200);"
                "border-top-left-radius:5px;"
                "border-bottom-left-radius: 5px;"
                "background-color:rgba(200, 100, 100,255);"
                "color:rgb(200, 200, 200);"
                "padding: 1px 20px;}"
                "QPushButton:hover{font-weight:bold;}")

            logging.debug("channel1 enable")

    def channel2_button_event(self):
        if self.device is None:
            logging.error("no device!!!")
            return
        if self.channel2Enable:
            del self.canvasFrame.Channel2List[:]
            self.command2 = Protocol.PREAMBLE.value \
                + Protocol.ENABLE_CHANNEL.value \
                + '\x02' \
                + Protocol.CHANNEL2.value \
                + Protocol.DISABLE.value  # '\xAA'+'\xF1'+'\x01'+'\x00'
            self.channel2thread = USBWriteThread(self.device, self.command2)
            self.channel2thread.start()
            self.channel2Enable = 0
            self.canvasFrame.channel2Enable = 0
            self.channel2Button.setStyleSheet(
                "QPushButton{border:1px solid rgb(200,200,200);"
                "border-top-right-radius:5px;"
                "border-bottom-right-radius: 5px;"
                "background-color:rgba(100, 100, 100,0);"
                "color:rgb(200, 200, 200);"
                "padding: 1px 20px;}"
                "QPushButton:hover{font-weight:bold;}")
            logging.debug("channel2 disable")

        else:
            self.command2 = Protocol.PREAMBLE.value \
                           + Protocol.ENABLE_CHANNEL.value \
                           + '\x02' \
                           + Protocol.CHANNEL2.value \
                           + Protocol.ENABLE.value  # '\xAA'+'\xF1'+'\x01'+'\x00'
            self.channel2thread = USBWriteThread(self.device, self.command2)
            self.channel2thread.start()
            self.channel2Enable = 1
            self.canvasFrame.channel2Enable = 1
            self.channel2Button.setStyleSheet(
                "QPushButton{border:1px solid rgb(200,200,200);"
                "border-top-right-radius:5px;"
                "border-bottom-right-radius: 5px;"
                "background-color:rgba(0, 200, 255,255);"
                "color:rgb(200, 200, 200);"
                "padding: 1px 20px;}"
                "QPushButton:hover{font-weight:bold;}")

            logging.debug("channel2 enable")

    def set_button_event(self):
        if self.device is None:
            logging.error("no device!!!")
            return
        logging.debug("setButton is pressed" +
                      str(self.frenquencyComboBox.currentIndex()) + '+' +
                      self.frenquencyComboBox.currentText())

        if self.frenquencyComboBox.currentText() == '1000Hz':
            self.canvasFrame.frequency = 1000
            self.readThread.frequency = 1000
        elif self.frenquencyComboBox.currentText() == '100Hz':
            self.canvasFrame.frequency = 100
            self.readThread.frequency = 100

        elif self.frenquencyComboBox.currentText() == '10Hz':
            self.canvasFrame.frequency = 10
            self.readThread.frequency = 10

        elif self.frenquencyComboBox.currentText() == '4Hz':
            self.canvasFrame.frequency = 4
            self.readThread.frequency = 4

        else:
            logging.warning("error frequency value:" +
                            self.frenquencyComboBox.currentText())

        self.frequencyLabelValue.setText(self.frenquencyComboBox.currentText())

    def update_canvas(self, state):
        logging.debug("update_canvas:" + state)
        self.canvasFrame.update()

    def update_frequency(self, frequency):
        logging.debug("update_frequency")
        if self.readThread:
            self.frequencyLabelValue.setText(str(frequency) + "(HZ)")
            if frequency == 0:
                logging.warning("receive wrong frequency:0")
            else:
                self.canvasFrame.frequency = frequency

    def single_trigger_event(self, state):
        logging.debug("single_trigger_event:" + state)
        if self.ADCEnable == 0:
            return
        self.command = Protocol.PREAMBLE.value \
            + Protocol.ENABLE_ADC.value \
            + '\x01' \
            + Protocol.DISABLE.value  # '\xAA' + '\xF2' + '\x01' + '\x00'
        self.playThread = USBWriteThread(self.device, self.command)
        self.playThread.start()
        self.ADCEnable = 0
        self.enableLabelValue.setText("Stop")
        self.playButton.setStyleSheet("QPushButton{border:none;"
                                      "border-radius:%dpx;"
                                      "background-color:rgb(200, 100, 100);}"
                                      "QPushButton:hover{border:0;"
                                      "border-radius:%dpx;"
                                      "background-color:rgb(250, 100, 100);}" %
                                      (self.m_width / 40, self.m_width / 40))
        self.setButton.setStyleSheet(
            "QPushButton{border-radius:%dpx;"
            "background-color:rgb(150, 255, 150);"
            "color:rgb(0, 0, 0);"
            "text-align: center center;}"
            "QPushButton:hover{background-color:rgb(100, 255, 100);"
            "color:rgb(255, 100, 100);"
            "font-size:20px}" % (self.m_width / 80))
        self.setButton.setEnabled(True)
        self.channel1Button.setEnabled(True)
        self.channel2Button.setEnabled(True)
        logging.debug("trigger!!! sample stop")

    def closeEvent(self, *args, **kwargs):
        logging.debug("this closeEvent -------------")
        if self.device:
            self.device.close()
            self.readThread.terminate()
            self.readThread.wait()

    def __del__(self):
        logging.debug("this del -------------")