Exemplo n.º 1
0
    def __init__(self, host=None):
        self.plotData_withThread = None
        self.MainWindow = QtWidgets.QMainWindow()
        self.laser = Laser(host=host)
        self.worker_get = WorkerCplot(self.getCplot)

        self.timer = QtCore.QTimer()
        self.timer.setInterval(100)
        self.timer.timeout.connect(self.getCplot_withThread)
        self.timer.start()
        self.x = list(range(0, 200))
        self.y = [0] * 200
Exemplo n.º 2
0
 def __init__(self, host: str = "192.168.1.107", channel: float = 2):
     """
     init the main view of the GUI.
     :param str host: IP address of the laser, depending of the choice you made during the selection. by default he
     will initiate Shakdhag
     :param int channel: red Pitaya channel, 1 for shakdhag and 2 for kapaz
     """
     self.host: str = host
     self.channel: int = channel
     self.addr_scope: str = 'TCPIP::192.168.1.137::INSTR'
     self.laser = Laser(host=self.host)
     self.red = MyRedpitaya()
     self.worker = WorkerThread(self.plotAbsSat)
     self.timer = QtCore.QTimer()
     self.timer.setInterval(5000)
     self.timer.timeout.connect(self.get_data_with_thread)
     self.timer.start()
Exemplo n.º 3
0
    def __init__(self, host: str = None):
        """

        Parameters
        ----------
        host depending on the host entered. it will display data from the laser that you entered the IP address.
        """
        self.plotData_withThread = None
        self.MainWindow = QtWidgets.QMainWindow()
        self.laser = Laser(host=host)
        self.worker_get = WorkerCplot(self.getCplot)

        self.timer = QtCore.QTimer()
        self.timer.setInterval(100)
        self.timer.timeout.connect(self.getCplot_withThread)
        self.timer.start()
        self.x = list(range(0, 200))
        self.y = [0] * 200
Exemplo n.º 4
0
class Cplot(object):
    def __init__(self, host=None):
        self.plotData_withThread = None
        self.MainWindow = QtWidgets.QMainWindow()
        self.laser = Laser(host=host)
        self.worker_get = WorkerCplot(self.getCplot)

        self.timer = QtCore.QTimer()
        self.timer.setInterval(100)
        self.timer.timeout.connect(self.getCplot_withThread)
        self.timer.start()
        self.x = list(range(0, 200))
        self.y = [0] * 200

    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(1080, 1293)
        MainWindow.setStyleSheet("QMainWindow{\n"
                                 "    background-color:#333437;\n"
                                 "}")
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout.setObjectName("gridLayout")
        self.frame = QtWidgets.QFrame(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding,
                                           QtWidgets.QSizePolicy.MinimumExpanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.frame.sizePolicy().hasHeightForWidth())
        self.frame.setSizePolicy(sizePolicy)
        self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame.setObjectName("frame")
        self.gridLayout_3 = QtWidgets.QGridLayout(self.frame)
        self.gridLayout_3.setObjectName("gridLayout_3")
        self.lineEdit_5 = QtWidgets.QLineEdit(self.frame)
        self.lineEdit_5.setStyleSheet("QLineEdit{\n"
                                      "    font: 13pt \"Poppins\";\n"
                                      "    background-color:white;\n"
                                      "    border-radius:3px;\n"
                                      "}")
        self.lineEdit_5.setObjectName("lineEdit_5")
        self.gridLayout_3.addWidget(self.lineEdit_5, 4, 1, 1, 1)
        self.Mon_Optical_Power_Laser_Diode = QtWidgets.QLabel(self.frame)
        self.Mon_Optical_Power_Laser_Diode.setStyleSheet("QLabel{\n"
                                                         "    color:#FAF9F9;\n"
                                                         "    font: 75 15pt \"Poppins\";\n"
                                                         "}")
        self.Mon_Optical_Power_Laser_Diode.setObjectName("Mon_Optical_Power_Laser_Diode")
        self.gridLayout_3.addWidget(self.Mon_Optical_Power_Laser_Diode, 5, 0, 1, 1)
        self.Status_Temp_Control_Laser_Diode = QtWidgets.QLabel(self.frame)
        self.Status_Temp_Control_Laser_Diode.setStyleSheet("QLabel{\n"
                                                           "    color:#FAF9F9;\n"
                                                           "    font: 75 15pt \"Poppins\";\n"
                                                           "}")
        self.Status_Temp_Control_Laser_Diode.setObjectName("Status_Temp_Control_Laser_Diode")
        self.gridLayout_3.addWidget(self.Status_Temp_Control_Laser_Diode, 8, 0, 1, 1)
        self.Mon_Temp_NTC_Laser_Diode = QtWidgets.QLabel(self.frame)
        self.Mon_Temp_NTC_Laser_Diode.setStyleSheet("QLabel{\n"
                                                    "    color:#FAF9F9;\n"
                                                    "    font: 75 15pt \"Poppins\";\n"
                                                    "}")
        self.Mon_Temp_NTC_Laser_Diode.setObjectName("Mon_Temp_NTC_Laser_Diode")
        self.gridLayout_3.addWidget(self.Mon_Temp_NTC_Laser_Diode, 1, 0, 1, 1)
        self.Mon_Current_TEC_Laser_Diode = QtWidgets.QLabel(self.frame)
        self.Mon_Current_TEC_Laser_Diode.setStyleSheet("QLabel{\n"
                                                       "    color:#FAF9F9;\n"
                                                       "    font: 75 15pt \"Poppins\";\n"
                                                       "}")
        self.Mon_Current_TEC_Laser_Diode.setObjectName("Mon_Current_TEC_Laser_Diode")
        self.gridLayout_3.addWidget(self.Mon_Current_TEC_Laser_Diode, 0, 0, 1, 1)
        self.Mon_Current_TEC_Case_Laser_Diode = QtWidgets.QLabel(self.frame)
        self.Mon_Current_TEC_Case_Laser_Diode.setStyleSheet("QLabel{\n"
                                                            "    color:#FAF9F9;\n"
                                                            "    font: 75 15pt \"Poppins\";\n"
                                                            "}")
        self.Mon_Current_TEC_Case_Laser_Diode.setObjectName("Mon_Current_TEC_Case_Laser_Diode")
        self.gridLayout_3.addWidget(self.Mon_Current_TEC_Case_Laser_Diode, 2, 0, 1, 1)
        self.Mon_Temp_NTC_Case_Laser_Diode = QtWidgets.QLabel(self.frame)
        self.Mon_Temp_NTC_Case_Laser_Diode.setStyleSheet("QLabel{\n"
                                                         "    color:#FAF9F9;\n"
                                                         "    font: 75 15pt \"Poppins\";\n"
                                                         "}")
        self.Mon_Temp_NTC_Case_Laser_Diode.setObjectName("Mon_Temp_NTC_Case_Laser_Diode")
        self.gridLayout_3.addWidget(self.Mon_Temp_NTC_Case_Laser_Diode, 3, 0, 1, 1)
        self.Enable_Current_Laser_Diode = QtWidgets.QLabel(self.frame)
        self.Enable_Current_Laser_Diode.setStyleSheet("QLabel{\n"
                                                      "    color:#FAF9F9;\n"
                                                      "    font: 75 15pt \"Poppins\";\n"
                                                      "}")
        self.Enable_Current_Laser_Diode.setObjectName("Enable_Current_Laser_Diode")
        self.gridLayout_3.addWidget(self.Enable_Current_Laser_Diode, 7, 0, 1, 1)
        self.Mon_Temp_LM35_Case_Laser_Diode = QtWidgets.QLabel(self.frame)
        self.Mon_Temp_LM35_Case_Laser_Diode.setStyleSheet("QLabel{\n"
                                                          "    color:#FAF9F9;\n"
                                                          "    font: 75 15pt \"Poppins\";\n"
                                                          "}")
        self.Mon_Temp_LM35_Case_Laser_Diode.setObjectName("Mon_Temp_LM35_Case_Laser_Diode")
        self.gridLayout_3.addWidget(self.Mon_Temp_LM35_Case_Laser_Diode, 6, 0, 1, 1)
        self.lineEdit_4 = QtWidgets.QLineEdit(self.frame)
        self.lineEdit_4.setStyleSheet("QLineEdit{\n"
                                      "    font: 13pt \"Poppins\";\n"
                                      "    background-color:white;\n"
                                      "    border-radius:3px;\n"
                                      "}")
        self.lineEdit_4.setObjectName("lineEdit_4")
        self.gridLayout_3.addWidget(self.lineEdit_4, 3, 1, 1, 1)
        self.lineEdit_6 = QtWidgets.QLineEdit(self.frame)
        self.lineEdit_6.setStyleSheet("QLineEdit{\n"
                                      "    font: 13pt \"Poppins\";\n"
                                      "    background-color:white;\n"
                                      "    border-radius:3px;\n"
                                      "}")
        self.lineEdit_6.setObjectName("lineEdit_6")
        self.gridLayout_3.addWidget(self.lineEdit_6, 5, 1, 1, 1)
        self.lineEdit_3 = QtWidgets.QLineEdit(self.frame)
        self.lineEdit_3.setStyleSheet("QLineEdit{\n"
                                      "    font: 13pt \"Poppins\";\n"
                                      "    background-color:white;\n"
                                      "    border-radius:3px;\n"
                                      "}")
        self.lineEdit_3.setObjectName("lineEdit_3")
        self.gridLayout_3.addWidget(self.lineEdit_3, 2, 1, 1, 1)
        self.lineEdit = QtWidgets.QLineEdit(self.frame)
        self.lineEdit.setStyleSheet("QLineEdit{\n"
                                    "    font: 13pt \"Poppins\";\n"
                                    "    background-color:white;\n"
                                    "    border-radius:3px;\n"
                                    "}")
        self.lineEdit.setObjectName("lineEdit")
        self.gridLayout_3.addWidget(self.lineEdit, 0, 1, 1, 1)
        self.lineEdit_7 = QtWidgets.QLineEdit(self.frame)
        self.lineEdit_7.setStyleSheet("QLineEdit{\n"
                                      "    font: 13pt \"Poppins\";\n"
                                      "    background-color:white;\n"
                                      "    border-radius:3px;\n"
                                      "}")
        self.lineEdit_7.setObjectName("lineEdit_7")
        self.gridLayout_3.addWidget(self.lineEdit_7, 6, 1, 1, 1)
        self.lineEdit_8 = QtWidgets.QLineEdit(self.frame)
        self.lineEdit_8.setStyleSheet("QLineEdit{\n"
                                      "    font: 13pt \"Poppins\";\n"
                                      "    background-color:white;\n"
                                      "    border-radius:3px;\n"
                                      "}")
        self.lineEdit_8.setObjectName("lineEdit_8")
        self.gridLayout_3.addWidget(self.lineEdit_8, 7, 1, 1, 1)
        self.Mon_Current_Laser_Diode = QtWidgets.QLabel(self.frame)
        self.Mon_Current_Laser_Diode.setStyleSheet("QLabel{\n"
                                                   "    color:#FAF9F9;\n"
                                                   "    font: 75 15pt \"Poppins\";\n"
                                                   "}")
        self.Mon_Current_Laser_Diode.setObjectName("Mon_Current_Laser_Diode")
        self.gridLayout_3.addWidget(self.Mon_Current_Laser_Diode, 4, 0, 1, 1)
        self.lineEdit_2 = QtWidgets.QLineEdit(self.frame)
        self.lineEdit_2.setStyleSheet("QLineEdit{\n"
                                      "    font: 13pt \"Poppins\";\n"
                                      "    background-color:white;\n"
                                      "    border-radius:3px;\n"
                                      "}")
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.gridLayout_3.addWidget(self.lineEdit_2, 1, 1, 1, 1)
        self.lineEdit_9 = QtWidgets.QLineEdit(self.frame)
        self.lineEdit_9.setStyleSheet("QLineEdit{\n"
                                      "    font: 13pt \"Poppins\";\n"
                                      "    background-color:white;\n"
                                      "    border-radius:3px;\n"
                                      "}")
        self.lineEdit_9.setObjectName("lineEdit_9")
        self.gridLayout_3.addWidget(self.lineEdit_9, 8, 1, 1, 1)
        self.Status_Temp_Control_Case_Laser_Diode = QtWidgets.QLabel(self.frame)
        self.Status_Temp_Control_Case_Laser_Diode.setStyleSheet("QLabel{\n"
                                                                "    color:#FAF9F9;\n"
                                                                "    font: 75 15pt \"Poppins\";\n"
                                                                "}")
        self.Status_Temp_Control_Case_Laser_Diode.setObjectName("Status_Temp_Control_Case_Laser_Diode")
        self.gridLayout_3.addWidget(self.Status_Temp_Control_Case_Laser_Diode, 9, 0, 1, 1)
        self.lineEdit_10 = QtWidgets.QLineEdit(self.frame)
        self.lineEdit_10.setStyleSheet("QLineEdit{\n"
                                       "    font: 13pt \"Poppins\";\n"
                                       "    background-color:white;\n"
                                       "    border-radius:3px;\n"
                                       "}")
        self.lineEdit_10.setObjectName("lineEdit_10")
        self.gridLayout_3.addWidget(self.lineEdit_10, 9, 1, 1, 1)
        self.pushButton = QtWidgets.QPushButton(self.frame)
        self.pushButton.setStyleSheet("QPushButton {\n"
                                      "    background-color:#E5E5DB;\n"
                                      "    color:#303030;\n"
                                      "    border-radius:4px;\n"
                                      "    transition-duration: 0.4s;\n"
                                      "    height:20px;\n"
                                      "    width: 115px\n"
                                      "}\n"
                                      "                      \n"
                                      "QPushButton:hover {\n"
                                      "    background-color: #D4DAFF; \n"
                                      "    color:#FDFAEB;\n"
                                      "}\n"
                                      "\n"
                                      "QPushButton:pressed {\n"
                                      "    background-color: #303030;\n"
                                      "    color:#FAF9F9;\n"
                                      "}\n"
                                      "\n"
                                      "")
        self.pushButton.setObjectName("pushButton")
        self.gridLayout_3.addWidget(self.pushButton, 0, 2, 1, 1)
        self.pushButton_2 = QtWidgets.QPushButton(self.frame)
        self.pushButton_2.setStyleSheet("QPushButton {\n"
                                        "    background-color:#E5E5DB;\n"
                                        "    color:#303030;\n"
                                        "    border-radius:4px;\n"
                                        "    transition-duration: 0.4s;\n"
                                        "    height:20px;\n"
                                        "    width: 115px\n"
                                        "}\n"
                                        "                      \n"
                                        "QPushButton:hover {\n"
                                        "    background-color: #D4DAFF; \n"
                                        "    color:#FDFAEB;\n"
                                        "}\n"
                                        "\n"
                                        "QPushButton:pressed {\n"
                                        "    background-color: #303030;\n"
                                        "    color:#FAF9F9;\n"
                                        "}\n"
                                        "\n"
                                        "")
        self.pushButton_2.setObjectName("pushButton_2")
        self.gridLayout_3.addWidget(self.pushButton_2, 1, 2, 1, 1)
        self.pushButton_3 = QtWidgets.QPushButton(self.frame)
        self.pushButton_3.setStyleSheet("QPushButton {\n"
                                        "    background-color:#E5E5DB;\n"
                                        "    color:#303030;\n"
                                        "    border-radius:4px;\n"
                                        "    transition-duration: 0.4s;\n"
                                        "    height:20px;\n"
                                        "    width: 115px\n"
                                        "}\n"
                                        "                      \n"
                                        "QPushButton:hover {\n"
                                        "    background-color: #D4DAFF; \n"
                                        "    color:#FDFAEB;\n"
                                        "}\n"
                                        "\n"
                                        "QPushButton:pressed {\n"
                                        "    background-color: #303030;\n"
                                        "    color:#FAF9F9;\n"
                                        "}\n"
                                        "\n"
                                        "")
        self.pushButton_3.setObjectName("pushButton_3")
        self.gridLayout_3.addWidget(self.pushButton_3, 2, 2, 1, 1)
        self.pushButton_4 = QtWidgets.QPushButton(self.frame)
        self.pushButton_4.setStyleSheet("QPushButton {\n"
                                        "    background-color:#E5E5DB;\n"
                                        "    color:#303030;\n"
                                        "    border-radius:4px;\n"
                                        "    transition-duration: 0.4s;\n"
                                        "    height:20px;\n"
                                        "    width: 115px\n"
                                        "}\n"
                                        "                      \n"
                                        "QPushButton:hover {\n"
                                        "    background-color: #D4DAFF; \n"
                                        "    color:#FDFAEB;\n"
                                        "}\n"
                                        "\n"
                                        "QPushButton:pressed {\n"
                                        "    background-color: #303030;\n"
                                        "    color:#FAF9F9;\n"
                                        "}\n"
                                        "\n"
                                        "")
        self.pushButton_4.setObjectName("pushButton_4")
        self.gridLayout_3.addWidget(self.pushButton_4, 3, 2, 1, 1)
        self.pushButton_5 = QtWidgets.QPushButton(self.frame)
        self.pushButton_5.setStyleSheet("QPushButton {\n"
                                        "    background-color:#E5E5DB;\n"
                                        "    color:#303030;\n"
                                        "    border-radius:4px;\n"
                                        "    transition-duration: 0.4s;\n"
                                        "    height:20px;\n"
                                        "    width: 115px\n"
                                        "}\n"
                                        "                      \n"
                                        "QPushButton:hover {\n"
                                        "    background-color: #D4DAFF; \n"
                                        "    color:#FDFAEB;\n"
                                        "}\n"
                                        "\n"
                                        "QPushButton:pressed {\n"
                                        "    background-color: #303030;\n"
                                        "    color:#FAF9F9;\n"
                                        "}\n"
                                        "\n"
                                        "")
        self.pushButton_5.setObjectName("pushButton_5")
        self.gridLayout_3.addWidget(self.pushButton_5, 4, 2, 1, 1)
        self.pushButton_6 = QtWidgets.QPushButton(self.frame)
        self.pushButton_6.setStyleSheet("QPushButton {\n"
                                        "    background-color:#E5E5DB;\n"
                                        "    color:#303030;\n"
                                        "    border-radius:4px;\n"
                                        "    transition-duration: 0.4s;\n"
                                        "    height:20px;\n"
                                        "    width: 115px\n"
                                        "}\n"
                                        "                      \n"
                                        "QPushButton:hover {\n"
                                        "    background-color: #D4DAFF; \n"
                                        "    color:#FDFAEB;\n"
                                        "}\n"
                                        "\n"
                                        "QPushButton:pressed {\n"
                                        "    background-color: #303030;\n"
                                        "    color:#FAF9F9;\n"
                                        "}\n"
                                        "\n"
                                        "")
        self.pushButton_6.setObjectName("pushButton_6")
        self.gridLayout_3.addWidget(self.pushButton_6, 5, 2, 1, 1)
        self.pushButton_7 = QtWidgets.QPushButton(self.frame)
        self.pushButton_7.setStyleSheet("QPushButton {\n"
                                        "    background-color:#E5E5DB;\n"
                                        "    color:#303030;\n"
                                        "    border-radius:4px;\n"
                                        "    transition-duration: 0.4s;\n"
                                        "    height:20px;\n"
                                        "    width: 115px\n"
                                        "}\n"
                                        "                      \n"
                                        "QPushButton:hover {\n"
                                        "    background-color: #D4DAFF; \n"
                                        "    color:#FDFAEB;\n"
                                        "}\n"
                                        "\n"
                                        "QPushButton:pressed {\n"
                                        "    background-color: #303030;\n"
                                        "    color:#FAF9F9;\n"
                                        "}\n"
                                        "\n"
                                        "")
        self.pushButton_7.setObjectName("pushButton_7")
        self.gridLayout_3.addWidget(self.pushButton_7, 6, 2, 1, 1)
        self.pushButton_8 = QtWidgets.QPushButton(self.frame)
        self.pushButton_8.setStyleSheet("QPushButton {\n"
                                        "    background-color:#E5E5DB;\n"
                                        "    color:#303030;\n"
                                        "    border-radius:4px;\n"
                                        "    transition-duration: 0.4s;\n"
                                        "    height:20px;\n"
                                        "    width: 115px\n"
                                        "}\n"
                                        "                      \n"
                                        "QPushButton:hover {\n"
                                        "    background-color: #D4DAFF; \n"
                                        "    color:#FDFAEB;\n"
                                        "}\n"
                                        "\n"
                                        "QPushButton:pressed {\n"
                                        "    background-color: #303030;\n"
                                        "    color:#FAF9F9;\n"
                                        "}\n"
                                        "\n"
                                        "")
        self.pushButton_8.setObjectName("pushButton_8")
        self.gridLayout_3.addWidget(self.pushButton_8, 7, 2, 1, 1)
        self.pushButton_9 = QtWidgets.QPushButton(self.frame)
        self.pushButton_9.setStyleSheet("QPushButton {\n"
                                        "    background-color:#E5E5DB;\n"
                                        "    color:#303030;\n"
                                        "    border-radius:4px;\n"
                                        "    transition-duration: 0.4s;\n"
                                        "    height:20px;\n"
                                        "    width: 115px\n"
                                        "}\n"
                                        "                      \n"
                                        "QPushButton:hover {\n"
                                        "    background-color: #D4DAFF; \n"
                                        "    color:#FDFAEB;\n"
                                        "}\n"
                                        "\n"
                                        "QPushButton:pressed {\n"
                                        "    background-color: #303030;\n"
                                        "    color:#FAF9F9;\n"
                                        "}\n"
                                        "\n"
                                        "")
        self.pushButton_9.setObjectName("pushButton_9")
        self.gridLayout_3.addWidget(self.pushButton_9, 8, 2, 1, 1)
        self.pushButton_10 = QtWidgets.QPushButton(self.frame)
        self.pushButton_10.setStyleSheet("QPushButton {\n"
                                         "    background-color:#E5E5DB;\n"
                                         "    color:#303030;\n"
                                         "    border-radius:4px;\n"
                                         "    transition-duration: 0.4s;\n"
                                         "    height:20px;\n"
                                         "    width: 115px\n"
                                         "}\n"
                                         "                      \n"
                                         "QPushButton:hover {\n"
                                         "    background-color: #D4DAFF; \n"
                                         "    color:#FDFAEB;\n"
                                         "}\n"
                                         "\n"
                                         "QPushButton:pressed {\n"
                                         "    background-color: #303030;\n"
                                         "    color:#FAF9F9;\n"
                                         "}\n"
                                         "\n"
                                         "")
        self.pushButton_10.setObjectName("pushButton_10")
        self.gridLayout_3.addWidget(self.pushButton_10, 9, 2, 1, 1)
        self.gridLayout.addWidget(self.frame, 0, 0, 1, 1)
        self.frame_2 = QtWidgets.QFrame(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding,
                                           QtWidgets.QSizePolicy.MinimumExpanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.frame_2.sizePolicy().hasHeightForWidth())
        self.frame_2.setSizePolicy(sizePolicy)
        self.frame_2.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame_2.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame_2.setObjectName("frame_2")
        self.gridLayout_2 = QtWidgets.QGridLayout(self.frame_2)
        self.gridLayout_2.setObjectName("gridLayout_2")
        self.plotwidget_cplot = PlotWidget(parent=self.frame_2)
        self.plotwidget_cplot.setObjectName("plotwidget_cplot")
        self.plotwidget_cplot.setLabel(axis='left', text='Temperature [°C] (f**k you Faraday)')
        self.plotwidget_cplot.setLabel(axis='bottom', text='time [s]')
        self.gridLayout_2.addWidget(self.plotwidget_cplot, 0, 0, 1, 1)
        self.gridLayout.addWidget(self.frame_2, 0, 1, 1, 1)
        MainWindow.setCentralWidget(self.centralwidget)

        # connect buttons with methods.
        self.pushButton.clicked.connect(self.button)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.Mon_Optical_Power_Laser_Diode.setText(
            _translate("MainWindow", "Indicateur de puissance optique (valeur non linéaire). \n"
                                     "Ne sert qu’à savoir si la diode émet et si sa puissance n\'a fluctuée."))
        self.Status_Temp_Control_Laser_Diode.setText(
            _translate("MainWindow", "Signal d’entrée pour savoir si l’asservissement de\n"
                                     "température de la diode fonctionne correctement\n"
                                     "OK : La température de consigne a été atteinte et est\n"
                                     "asservie."))
        self.Mon_Temp_NTC_Laser_Diode.setText(_translate("MainWindow", "Température de la diode "))
        self.Mon_Current_TEC_Laser_Diode.setText(
            _translate("MainWindow", "Courant dans le module peltier de la diode pour l\'asservir en température"))
        self.Mon_Current_TEC_Case_Laser_Diode.setText(
            _translate("MainWindow", "Courant dans le module peltier du boitier enfermant la diode \n"
                                     "pour l’asservir en température"))
        self.Mon_Temp_NTC_Case_Laser_Diode.setText(
            _translate("MainWindow", "Température dans le boitier, mesurée par thermistance) "))
        self.Enable_Current_Laser_Diode.setText(
            _translate("MainWindow", "Signal de sortie pour allumer/éteindre la diode\n"
                                     "ON : Diode allumé / OFF : Diode éteinte"))
        self.Mon_Temp_LM35_Case_Laser_Diode.setText(_translate("MainWindow", "Température dans le boitier\n"
                                                                             "(mesurée par LM35)"))
        self.Mon_Current_Laser_Diode.setText(_translate("MainWindow", "Courant de la diode"))
        self.Status_Temp_Control_Case_Laser_Diode.setText(
            _translate("MainWindow", "Signal d’entrée pour savoir si l’asservissement de\n"
                                     "température du boitier fonctionne correctement\n"
                                     "OK : La température de consigne a été atteinte et est\n"
                                     "asservie."))
        self.pushButton.setText(_translate("MainWindow", "Plot"))
        self.pushButton_2.setText(_translate("MainWindow", "Plot"))
        self.pushButton_3.setText(_translate("MainWindow", "Plot"))
        self.pushButton_4.setText(_translate("MainWindow", "Plot"))
        self.pushButton_5.setText(_translate("MainWindow", "Plot"))
        self.pushButton_6.setText(_translate("MainWindow", "Plot"))
        self.pushButton_7.setText(_translate("MainWindow", "Plot"))
        self.pushButton_8.setText(_translate("MainWindow", "Plot"))
        self.pushButton_9.setText(_translate("MainWindow", "Plot"))
        self.pushButton_10.setText(_translate("MainWindow", "Plot"))

    def getCplot(self):
        """
        Take the return of the laser as a list and cut it for each value. need to run in a sub_thread, independently of
        the main thread of mainWindow.
        :return: all
        """
        # the first part consists in using str to set text in the different lineEdits
        cplot: str = str(self.laser.get_cplot())
        I_peltier_asserv_temp: str = cplot[61:66] + " V"
        self.lineEdit.setText(I_peltier_asserv_temp)
        diode_temp: str = cplot[134:139] + "°C"
        self.lineEdit_2.setText(diode_temp)
        I_peltier_asserv_temp_boitier: str = cplot[174:179] + " V"
        self.lineEdit_3.setText(I_peltier_asserv_temp_boitier)
        boitier_thermistance_temp = None
        self.lineEdit_4.setText(boitier_thermistance_temp)
        I_diode: str = cplot[287:291] + "mA"
        self.lineEdit_5.setText(I_diode)
        power: str = cplot[362:367] + " V"
        self.lineEdit_6.setText(power)
        temp_boitier: str = cplot[460:465] + "°C"
        self.lineEdit_7.setText(temp_boitier)
        diode_state: str = cplot[207:211]
        self.lineEdit_8.setText(diode_state)
        asserv_diode_state: str = cplot[326:329]
        self.lineEdit_9.setText(asserv_diode_state)
        asserv_boitier_state: str = cplot[407:420]
        self.lineEdit_10.setText(asserv_boitier_state)

        # the second part consists in translate str in float and return them to use them
        diode_temp = float(cplot[134:139])
        if type(diode_temp) != float:
            pass
        else:
            self.plotData(diode_temp)

        """(I_peltier_asserv_temp, diode_temp, I_peltier_asserv_temp_boitier, boitier_thermistance_temp, I_diode,
                        power, temp_boitier, diode_state, asserv_diode_state, asserv_boitier_state)"""

        return diode_temp

    def plotData(self, data):
        self.x.append(self.x[-1] + 1)
        self.y.append(data)
        self.x = self.x[1:]
        self.y = self.y[1:]
        self.plotwidget_cplot.plot(self.x, self.y)

    def getCplot_withThread(self):
        """
        method that calls the class Worker for data.
        :return:
        """
        self.worker_get.get_data()

    def button(self):
        data = self.getCplot()[0]
        self.worker_plot = WorkerDataPot(self.plotData(data))
        self.timer2 = QtCore.QTimer()
        self.timer2.setInterval(1000)
        self.timer2.timeout.connect(self.plotData_withThread)
Exemplo n.º 5
0
class Ui_MainWindow(object):
    def __init__(self, host: str = "192.168.1.107", channel: float = 2):
        """
        init the main view of the GUI.
        :param str host: IP address of the laser, depending of the choice you made during the selection. by default he
        will initiate Shakdhag
        :param int channel: red Pitaya channel, 1 for shakdhag and 2 for kapaz
        """
        self.host: str = host
        self.channel: int = channel
        self.addr_scope: str = 'TCPIP::192.168.1.137::INSTR'
        self.laser = Laser(host=self.host)
        self.red = MyRedpitaya()
        self.worker = WorkerThread(self.plotAbsSat)
        self.timer = QtCore.QTimer()
        self.timer.setInterval(5000)
        self.timer.timeout.connect(self.get_data_with_thread)
        self.timer.start()

    def setupUi(self, MainWindow: QtWidgets.QMainWindow):
        """
        initiate all the objects of the GUI and the classes Scope and AFG from ClassLaser. can be initiate in the init
        but this method also works and it is by default generated by pyuic% tool (that translates a ui_ramp file to
        python file)
        How this method works ?
        you have all your widget objects that are instantiated and then parametrized. each widget is contained in a
        layout with a position specified (x, y, "other parameters") like a grid. these layouts are contained in frames
        that are contained in the central widget.
        so : central main window > central widget > frames > layouts > widget objects
        THE MOST IMPORTANT POINT IS  THAT THIS METHOD WORKS ON THE THREAD LIKE A LONG TASK

        all the important widgets and buttons are contained at the end of this method.
        :param MainWindow: Qt object that generates the main view that contains every widgets like buttons or frames.
        :return: None
        """

        # scales, depending of the red Pitaya channel output.
        if self.channel == 2:
            try:
                self.scope = USBScope(addr=self.addr_scope)
                self.scope.set_scales(channel=2,
                                      x=2.51,
                                      offset=1.52,
                                      horizontal_scale=100)
                self.scope.set_scales(channel=4,
                                      x=1,
                                      offset=-1.84,
                                      horizontal_scale=100)
            except:
                self.dialog_browser.setText("couldn't scale axis")
        else:
            try:
                self.scope = USBScope(addr=self.addr_scope)
                self.scope.set_scales(channel=1,
                                      x=0.2,
                                      offset=-1.248,
                                      horizontal_scale=100)
                self.scope.set_scales(channel=3,
                                      x=1,
                                      offset=0.840,
                                      horizontal_scale=100)
            except:
                self.dialog_browser.setText("couldn't scale axis")

        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(1639, 1052)
        font = QtGui.QFont()
        font.setFamily("Poppins")
        MainWindow.setFont(font)
        MainWindow.setStyleSheet("QMainWindow{\n"
                                 "    background-color:#333437;\n"
                                 "}")
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        font = QtGui.QFont()
        font.setFamily("Poppins")
        self.centralwidget.setFont(font)
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout.setObjectName("gridLayout")
        self.left_widget = QtWidgets.QWidget(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(
            QtWidgets.QSizePolicy.MinimumExpanding,
            QtWidgets.QSizePolicy.MinimumExpanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.left_widget.sizePolicy().hasHeightForWidth())
        self.left_widget.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Poppins")
        self.left_widget.setFont(font)
        self.left_widget.setObjectName("left_widget")
        self.gridLayout_2 = QtWidgets.QGridLayout(self.left_widget)
        self.gridLayout_2.setObjectName("gridLayout_2")
        self.dialog_frame = QtWidgets.QFrame(self.left_widget)
        self.dialog_frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.dialog_frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.dialog_frame.setObjectName("dialog_frame")
        self.gridLayout_5 = QtWidgets.QGridLayout(self.dialog_frame)
        self.gridLayout_5.setObjectName("gridLayout_5")

        self.dialog_browser = QtWidgets.QTextBrowser(self.dialog_frame)
        if self.host == "192.168.1.107":
            self.dialog_browser.setText(
                f"connected to the laser on bottom \n"
                f"Laser IP address:{self.host}\n"
                f"channel Red Pitaya:{self.channel}"
                "turn on the diode and set the power to the edfa ;)\n"
                "To get the saturated absorption, set a ramp with 1Hz and low power laser"
            )

        else:
            self.dialog_browser.setText(
                f"connected to laser on top \n"
                f"IP address:{self.host} \n"
                "turn on the diode and set the power to the edfa ;)\n"
                "To get the saturated absorption, set a ramp with 1Hz")

        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
                                           QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.dialog_browser.sizePolicy().hasHeightForWidth())
        self.dialog_browser.setSizePolicy(sizePolicy)
        self.dialog_browser.setObjectName("dialog_browser")
        self.gridLayout_5.addWidget(self.dialog_browser, 1, 0, 1, 1)
        self.exit_button = QtWidgets.QPushButton(self.dialog_frame)
        font = QtGui.QFont()
        font.setFamily("Poppins")
        self.exit_button.setFont(font)
        self.exit_button.setStyleSheet("QPushButton {\n"
                                       "    background-color:#E5E5DB;\n"
                                       "    color:#303030;\n"
                                       "    border-radius:4px;\n"
                                       "    transition-duration: 0.4s;\n"
                                       "    height:20px;\n"
                                       "    width: 115px\n"
                                       "}\n"
                                       "                      \n"
                                       "QPushButton:hover {\n"
                                       "    background-color: #D4DAFF; \n"
                                       "    color:#FDFAEB;\n"
                                       "}\n"
                                       "\n"
                                       "QPushButton:pressed {\n"
                                       "    background-color: #303030;\n"
                                       "    color:#FAF9F9;\n"
                                       "}\n"
                                       "\n"
                                       "")
        self.exit_button.setObjectName("exit_button")
        self.gridLayout_5.addWidget(self.exit_button, 2, 0, 1, 1)
        self.dialog_label = QtWidgets.QLabel(self.dialog_frame)
        self.dialog_label.setStyleSheet("QLabel{\n"
                                        "    color:#FAF9F9;\n"
                                        "    font: 75 15pt \"Poppins\";\n"
                                        "}")
        self.dialog_label.setObjectName("dialog_label")
        self.gridLayout_5.addWidget(self.dialog_label, 0, 0, 1, 1)
        self.gridLayout_2.addWidget(self.dialog_frame, 2, 0, 1, 1)
        self.afg_frame = QtWidgets.QFrame(self.left_widget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
                                           QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.afg_frame.sizePolicy().hasHeightForWidth())
        self.afg_frame.setSizePolicy(sizePolicy)
        self.afg_frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.afg_frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.afg_frame.setObjectName("afg_frame")
        self.gridLayout_4 = QtWidgets.QGridLayout(self.afg_frame)
        self.gridLayout_4.setObjectName("gridLayout_4")
        self.afg_label = QtWidgets.QLabel(self.afg_frame)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                           QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.afg_label.sizePolicy().hasHeightForWidth())
        self.afg_label.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Poppins")
        font.setPointSize(15)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(9)
        self.afg_label.setFont(font)
        self.afg_label.setStyleSheet("QLabel{\n"
                                     "    color:#FAF9F9;\n"
                                     "    font: 75 15pt \"Poppins\";\n"
                                     "}")
        self.afg_label.setObjectName("afg_label")
        self.gridLayout_4.addWidget(self.afg_label, 0, 0, 1, 1)
        self.sine_button = QtWidgets.QPushButton(self.afg_frame)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.sine_button.sizePolicy().hasHeightForWidth())
        self.sine_button.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Poppins")
        self.sine_button.setFont(font)
        self.sine_button.setStyleSheet("QPushButton {\n"
                                       "    background-color:#E5E5DB;\n"
                                       "    color:#303030;\n"
                                       "    border-radius:4px;\n"
                                       "    transition-duration: 0.4s;\n"
                                       "    height:20px;\n"
                                       "    width: 115px\n"
                                       "}\n"
                                       "                      \n"
                                       "QPushButton:hover {\n"
                                       "    background-color: #D4DAFF; \n"
                                       "    color:#FDFAEB;\n"
                                       "}\n"
                                       "\n"
                                       "QPushButton:pressed {\n"
                                       "    background-color: #303030;\n"
                                       "    color:#FAF9F9;\n"
                                       "}\n"
                                       "\n"
                                       "")
        self.sine_button.setObjectName("sine_button")
        self.gridLayout_4.addWidget(self.sine_button, 4, 0, 1, 1)
        self.volt_label = QtWidgets.QLabel(self.afg_frame)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
                                           QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.volt_label.sizePolicy().hasHeightForWidth())
        self.volt_label.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Poppins")
        self.volt_label.setFont(font)
        self.volt_label.setStyleSheet("QLabel{\n"
                                      "    color:#FAF9F9;\n"
                                      "    font: 13pt \"Poppins\";\n"
                                      "}")
        self.volt_label.setObjectName("volt_label")
        self.gridLayout_4.addWidget(self.volt_label, 0, 2, 1, 1)
        self.ramp_button = QtWidgets.QPushButton(self.afg_frame)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.ramp_button.sizePolicy().hasHeightForWidth())
        self.ramp_button.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Poppins")
        self.ramp_button.setFont(font)
        self.ramp_button.setStyleSheet("QPushButton {\n"
                                       "    background-color:#E5E5DB;\n"
                                       "    color:#303030;\n"
                                       "    border-radius:4px;\n"
                                       "    transition-duration: 0.4s;\n"
                                       "    height:20px;\n"
                                       "    width: 115px\n"
                                       "}\n"
                                       "                      \n"
                                       "QPushButton:hover {\n"
                                       "    background-color: #D4DAFF; \n"
                                       "    color:#FDFAEB;\n"
                                       "}\n"
                                       "\n"
                                       "QPushButton:pressed {\n"
                                       "    background-color: #303030;\n"
                                       "    color:#FAF9F9;\n"
                                       "}\n"
                                       "\n"
                                       "")
        self.ramp_button.setObjectName("ramp_button")
        self.gridLayout_4.addWidget(self.ramp_button, 2, 0, 1, 1)
        self.volt_spinbox = QtWidgets.QDoubleSpinBox(self.afg_frame)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.volt_spinbox.sizePolicy().hasHeightForWidth())
        self.volt_spinbox.setSizePolicy(sizePolicy)
        self.volt_spinbox.setStyleSheet("QDoubleSpinBox{\n"
                                        "    width:50px;\n"
                                        "    background-color:#EBEAE5;\n"
                                        "}")
        self.volt_spinbox.setObjectName("volt_spinbox")
        self.volt_spinbox.setMaximum(5)
        self.volt_spinbox.setMinimum(-8)
        self.gridLayout_4.addWidget(self.volt_spinbox, 0, 1, 1, 1)
        self.pulse_button = QtWidgets.QPushButton(self.afg_frame)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.pulse_button.sizePolicy().hasHeightForWidth())
        self.pulse_button.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Poppins")
        self.pulse_button.setFont(font)
        self.pulse_button.setStyleSheet("QPushButton {\n"
                                        "    background-color:#E5E5DB;\n"
                                        "    color:#303030;\n"
                                        "    border-radius:4px;\n"
                                        "    transition-duration: 0.4s;\n"
                                        "    height:20px;\n"
                                        "    width: 115px\n"
                                        "}\n"
                                        "                      \n"
                                        "QPushButton:hover {\n"
                                        "    background-color: #D4DAFF; \n"
                                        "    color:#FDFAEB;\n"
                                        "}\n"
                                        "\n"
                                        "QPushButton:pressed {\n"
                                        "    background-color: #303030;\n"
                                        "    color:#FAF9F9;\n"
                                        "}\n"
                                        "\n"
                                        "")
        self.pulse_button.setObjectName("pulse_button")
        self.gridLayout_4.addWidget(self.pulse_button, 3, 0, 1, 1)
        self.square_button = QtWidgets.QPushButton(self.afg_frame)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.square_button.sizePolicy().hasHeightForWidth())
        self.square_button.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Poppins")
        self.square_button.setFont(font)
        self.square_button.setStyleSheet("QPushButton {\n"
                                         "    background-color:#E5E5DB;\n"
                                         "    color:#303030;\n"
                                         "    border-radius:4px;\n"
                                         "    transition-duration: 0.4s;\n"
                                         "    height:20px;\n"
                                         "    width: 115px\n"
                                         "}\n"
                                         "                      \n"
                                         "QPushButton:hover {\n"
                                         "    background-color: #D4DAFF; \n"
                                         "    color:#FDFAEB;\n"
                                         "}\n"
                                         "\n"
                                         "QPushButton:pressed {\n"
                                         "    background-color: #303030;\n"
                                         "    color:#FAF9F9;\n"
                                         "}\n"
                                         "\n"
                                         "")
        self.square_button.setObjectName("square_button")
        self.gridLayout_4.addWidget(self.square_button, 5, 0, 1, 1)
        spacerItem = QtWidgets.QSpacerItem(40, 20,
                                           QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Minimum)
        self.gridLayout_4.addItem(spacerItem, 0, 3, 1, 1)
        self.gridLayout_2.addWidget(self.afg_frame, 1, 0, 1, 1)
        self.laser_frame = QtWidgets.QFrame(self.left_widget)
        font = QtGui.QFont()
        font.setFamily("Poppins")
        self.laser_frame.setFont(font)
        self.laser_frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.laser_frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.laser_frame.setObjectName("laser_frame")
        self.gridLayout_3 = QtWidgets.QGridLayout(self.laser_frame)
        self.gridLayout_3.setObjectName("gridLayout_3")
        self.diode_button = QtWidgets.QRadioButton(self.laser_frame)
        font = QtGui.QFont()
        font.setFamily("Poppins")
        self.diode_button.setFont(font)
        self.diode_button.setStyleSheet("QRadioButton{\n"
                                        "    color:#FAF9F9;\n"
                                        "}")
        self.diode_button.setObjectName("diode_button")
        self.gridLayout_3.addWidget(self.diode_button, 0, 0, 1, 1)
        self.power_label = QtWidgets.QLabel(self.laser_frame)
        font = QtGui.QFont()
        font.setFamily("Poppins")
        self.power_label.setFont(font)
        self.power_label.setStyleSheet("QLabel{\n"
                                       "    color:#FAF9F9;\n"
                                       "    font: 13pt \"Poppins\";\n"
                                       "}")
        self.power_label.setObjectName("power_label")
        self.gridLayout_3.addWidget(self.power_label, 1, 2, 1, 1)
        self.edfa_label = QtWidgets.QLabel(self.laser_frame)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                           QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.edfa_label.sizePolicy().hasHeightForWidth())
        self.edfa_label.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Poppins")
        font.setPointSize(15)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(9)
        self.edfa_label.setFont(font)
        self.edfa_label.setStyleSheet("QLabel{\n"
                                      "    color:#FAF9F9;\n"
                                      "    font: 75 15pt \"Poppins\";\n"
                                      "}")
        self.edfa_label.setObjectName("edfa_label")
        self.gridLayout_3.addWidget(self.edfa_label, 1, 0, 1, 1)
        self.power_spinbox = QtWidgets.QDoubleSpinBox(self.laser_frame)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.power_spinbox.sizePolicy().hasHeightForWidth())
        self.power_spinbox.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        self.power_spinbox.setFont(font)
        self.power_spinbox.setStyleSheet("QDoubleSpinBox{\n"
                                         "    width:50px;\n"
                                         "    background-color:#EBEAE5;\n"
                                         "}")
        self.power_spinbox.setObjectName("power_spinbox")
        self.power_spinbox.setMaximum(1415)
        self.power_spinbox.setSingleStep(20)
        self.gridLayout_3.addWidget(self.power_spinbox, 1, 1, 1, 1)
        self.shutdown_button = QtWidgets.QPushButton(self.laser_frame)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.shutdown_button.sizePolicy().hasHeightForWidth())
        self.shutdown_button.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Poppins")
        self.shutdown_button.setFont(font)
        self.shutdown_button.setStyleSheet("QPushButton {\n"
                                           "    background-color:#E5E5DB;\n"
                                           "    color:#303030;\n"
                                           "    border-radius:4px;\n"
                                           "    transition-duration: 0.4s;\n"
                                           "    height:20px;\n"
                                           "    width: 115px\n"
                                           "}\n"
                                           "                      \n"
                                           "QPushButton:hover {\n"
                                           "    background-color: #D4DAFF; \n"
                                           "    color:#FDFAEB;\n"
                                           "}\n"
                                           "\n"
                                           "QPushButton:pressed {\n"
                                           "    background-color: #303030;\n"
                                           "    color:#FAF9F9;\n"
                                           "}\n"
                                           "\n"
                                           "")
        self.shutdown_button.setObjectName("shutdown_button")
        self.gridLayout_3.addWidget(self.shutdown_button, 2, 0, 1, 1)
        spacerItem1 = QtWidgets.QSpacerItem(40, 20,
                                            QtWidgets.QSizePolicy.Expanding,
                                            QtWidgets.QSizePolicy.Minimum)
        self.gridLayout_3.addItem(spacerItem1, 1, 3, 1, 1)
        self.gridLayout_2.addWidget(self.laser_frame, 0, 0, 1, 1)
        self.gridLayout.addWidget(self.left_widget, 0, 0, 1, 1)
        self.right_widget = QtWidgets.QWidget(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(
            QtWidgets.QSizePolicy.MinimumExpanding,
            QtWidgets.QSizePolicy.MinimumExpanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.right_widget.sizePolicy().hasHeightForWidth())
        self.right_widget.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Poppins")
        self.right_widget.setFont(font)
        self.right_widget.setObjectName("right_widget")
        self.gridLayout_6 = QtWidgets.QGridLayout(self.right_widget)
        self.gridLayout_6.setObjectName("gridLayout_6")
        self.display_frame = QtWidgets.QFrame(self.right_widget)
        sizePolicy = QtWidgets.QSizePolicy(
            QtWidgets.QSizePolicy.MinimumExpanding,
            QtWidgets.QSizePolicy.MinimumExpanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.display_frame.sizePolicy().hasHeightForWidth())
        self.display_frame.setSizePolicy(sizePolicy)
        self.display_frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.display_frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.display_frame.setObjectName("display_frame")
        self.gridLayout_7 = QtWidgets.QGridLayout(self.display_frame)
        self.gridLayout_7.setObjectName("gridLayout_7")
        self.display_laser_state_button = QtWidgets.QPushButton(
            self.display_frame)
        font = QtGui.QFont()
        font.setFamily("Poppins")
        self.display_laser_state_button.setFont(font)
        self.display_laser_state_button.setStyleSheet(
            "QPushButton {\n"
            "    background-color:#E5E5DB;\n"
            "    color:#303030;\n"
            "    border-radius:4px;\n"
            "    transition-duration: 0.4s;\n"
            "    height:20px;\n"
            "    width: 115px\n"
            "}\n"
            "                      \n"
            "QPushButton:hover {\n"
            "    background-color: #D4DAFF; \n"
            "    color:#FDFAEB;\n"
            "}\n"
            "\n"
            "QPushButton:pressed {\n"
            "    background-color: #303030;\n"
            "    color:#FAF9F9;\n"
            "}\n"
            "\n"
            "")
        self.display_laser_state_button.setObjectName(
            "display_laser_state_button")
        self.gridLayout_7.addWidget(self.display_laser_state_button, 3, 0, 1,
                                    1)

        self.plotwidget_abs_sat = PlotWidget(self.display_frame,
                                             xlabel="Volts [V]",
                                             histogram=None)
        self.plotwidget_abs_sat.setObjectName("plotwidget_abs_sat")
        self.gridLayout_7.addWidget(self.plotwidget_abs_sat, 1, 0, 1, 1)
        self.plotwidget_abs_sat.setLabel(axis='left',
                                         text='Transmission T(V) [wu]')
        self.plotwidget_abs_sat.setLabel(axis='bottom', text='Voltage [V]')
        self.plotwidget_signal = PlotWidget(self.display_frame)
        self.plotwidget_signal.setObjectName("plotwidget_signal")
        self.plotwidget_signal.setLabel(axis='left', text='Voltage [V]')
        self.plotwidget_signal.setLabel(axis='bottom', text='time [s]')
        self.gridLayout_7.addWidget(self.plotwidget_signal, 2, 0, 1, 1)
        self.gridLayout_6.addWidget(self.display_frame, 0, 0, 1, 1)
        self.gridLayout.addWidget(self.right_widget, 0, 1, 1, 1)
        MainWindow.setCentralWidget(self.centralwidget)
        self.sliderOffset = QtWidgets.QSlider(self.afg_frame)
        self.sliderOffset.setStyleSheet("")
        self.sliderOffset.setOrientation(QtCore.Qt.Horizontal)
        self.sliderOffset.setObjectName("sliderOffset")
        self.sliderOffset.setMaximum(28)
        self.sliderOffset.setMinimum(-80)
        self.sliderOffset.setSingleStep(1)
        self.sliderOffset.valueChanged.connect(self.voltageUpdate)
        self.sliderPower = QtWidgets.QSlider(self.laser_frame)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.sliderPower.sizePolicy().hasHeightForWidth())
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.sliderOffset.sizePolicy().hasHeightForWidth())

        self.gridLayout_4.addWidget(self.sliderOffset, 1, 0, 1, 1)
        self.sliderPower.setOrientation(QtCore.Qt.Horizontal)
        self.sliderPower.setObjectName("sliderPower")
        self.sliderPower.setStyleSheet("QSlider{" "height:30px;" "}")
        self.sliderPower.setMaximum(1500)
        self.sliderPower.setMinimum(0)
        self.sliderPower.valueChanged.connect(self.changeLaserPower)
        self.gridLayout_3.addWidget(self.sliderPower, 3, 0, 1, 1)
        self.label = QtWidgets.QLabel(self.display_frame)
        self.label.setStyleSheet("QLabel{\n"
                                 "    color:#FAF9F9;\n"
                                 "    font: 75 15pt \"Poppins\";\n"
                                 "}")
        self.label.setObjectName("label")
        self.gridLayout_7.addWidget(self.label, 0, 0, 1, 1)

        # connect buttons with methods :
        self.exit_button.clicked.connect(self.exitButton)
        self.pulse_button.clicked.connect(self.openPulseView)
        self.ramp_button.clicked.connect(self.openRampView)
        self.sine_button.clicked.connect(self.openSineView)
        self.square_button.clicked.connect(self.openSquareView)
        self.diode_button.clicked.connect(self.whenClicked)
        self.shutdown_button.clicked.connect(self.edfaShutdown)

        self.power_spinbox.valueChanged.connect(self.powerUpdate)
        self.volt_spinbox.valueChanged.connect(self.changeLaserFrequency)

        self.display_laser_state_button.clicked.connect(self.openCplotView)

        # display and param graphs
        self.plotwidget_abs_sat.plotItem.showGrid(True, True, 1)
        self.plotAbsSat()
        self.plotwidget_abs_sat.setXRange(-8, 3)
        self.plotwidget_abs_sat.setYRange(0, 1.1)
        self.plotwidget_signal.setXRange(0, 1)
        self.plotwidget_signal.setYRange(-8, 3)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow: QtWidgets.QMainWindow):
        """
        function that set text on different widget objects, out of the main thread
        :param MainWindow: Qt object that generates the main view that contains every widgets like buttons or frames.
        :return: None
        """
        _translate = QtCore.QCoreApplication.translate
        if self.host == "192.168.1.108":
            MainWindow.setWindowTitle(_translate("MainWindow", "Kapaz"))
        else:
            MainWindow.setWindowTitle(_translate("MainWindow", "Shakdhag"))
        self.exit_button.setText(_translate("MainWindow", "Exit"))
        self.dialog_label.setText(_translate("MainWindow", "TextLabel"))
        self.afg_label.setText(
            _translate("MainWindow", "Red Pitaya Controller"))
        self.sine_button.setText(_translate("MainWindow", "Sine"))
        self.volt_label.setText(
            _translate("MainWindow", "sent to the Laser Diode"))
        self.ramp_button.setText(_translate("MainWindow", "Ramp"))
        self.pulse_button.setText(_translate("MainWindow", "Pulse"))
        self.square_button.setText(_translate("MainWindow", "Square"))
        self.diode_button.setText(_translate("MainWindow", "Diode <ON|OFF>"))
        self.power_label.setText(
            _translate("MainWindow", "sent to the Laser EDFA"))
        self.edfa_label.setText(_translate("MainWindow", "EDFA Controller"))
        self.shutdown_button.setText(_translate("MainWindow", "Shutdown"))
        self.display_laser_state_button.setText(
            _translate("MainWindow", "CPLOT COMMAND"))
        self.menuIP_Configuration.setTitle(
            _translate("MainWindow", "IP Configuration"))
        self.actionLaser_Muquans.setText(
            _translate("MainWindow", "Laser Muquans"))
        self.actionAFG.setText(_translate("MainWindow", "AFG "))
        self.actionScope.setText(_translate("MainWindow", "Scope"))

    def whenClicked(self) -> bool:
        """
        method Tell to the UX if the diode is ON or not. if not, intensity isn't sent to the edfa
        :return:bool
        """
        if self.diode_button.isChecked():
            self.laser.diode_on()
            self.dialog_browser.setText("diode on")
            return True
        else:
            self.laser.shutdown()
            time.sleep(4)
            self.laser.diode_off()
            self.dialog_browser.setText("diode off")
            return False

    def powerToIntensity(self, x: float):
        """
         method that converts the power entered in the spin box or the slider's position in a interpolation function of
         class Laser. The function converts
        :param x: Value taken from position's slider or spin box.
        :return: 0<y<=,2.5,3 where y is the intensity sent to the edfa
        """
        if self.host == "192.168.1.108":
            maximum: float = 3
        else:
            maximum: float = 3
        y = self.laser.f(x)
        if y > maximum:
            y = maximum
        elif y < 0.1:
            y = 0.1
        y = float(y)
        self.dialog_browser.setText(
            f"power sent to the edfa : {np.round(y, 1)} [mA]")
        return y

    def edfaShutdown(self):
        """
        method that shutdown the laser properly.
        :return: None
        """
        if self.whenClicked() is True:
            self.laser.shutdown()
            self.dialog_browser.setText('laser shutdown')
            self.dialog_browser.setText('sleeping during 4 secs')
            time.sleep(4)
            self.laser.diode_off()
            self.dilog_browser.setText('laser diode off')
            self.diode_button.setChecked(False)
            self.power_spinbox.setValue(0)
            self.sliderPower.setValue(0)
        else:
            self.laser.shutdown()
            self.dialog_browser.setText('sleeping during 4 secs')
            time.sleep(4)
            self.laser.diode_off()
            self.dialog_browser.setText('laser shutdown')
            self.dialog_browser.setText('laser diode off')
            self.power_spinbox.setValue(0)
            self.sliderPower.setValue(0)

    def exitButton(self):
        """
        exit the software without danger
        :return: None
        """
        import sys
        self.laser.shutdown()
        self.dialog_browser.setText("sleeping during 4s before exit. Zzzz")
        time.sleep(4)
        self.laser.diode_off()
        self.laser.exit()
        sys.exit()

    def powerUpdate(self):
        """
        take on reel time the value of the dial button, convert it and send it to the edfa (another way)
        :return: None
        """
        if self.whenClicked():
            value = str(self.power_spinbox.value())
            value_txt = str(float(value))
            self.power_label.setText(f"set power: {value_txt} mW")
            value = float(value)
            value = self.powerToIntensity(value)
            self.laser.set_power(value)
        else:
            self.dialog_browser.setText(
                "error, diode off, no power sent. Please turn on the diode")

    def voltageUpdate(self):
        """
        change the offset sent to the diode between -8V and 5V
        :return: None
        """
        try:
            value: str = str(self.sliderOffset.value())
            self.volt_spinbox.setValue(float(value) / 10)
        except:
            self.dialog_browser.setText("error, red not connected")

    def changeLaserPower(self):
        """
        take the power slider value and send it to the edfa after convert it in mA with powerToIntensity.
        :return:None
        """
        if self.whenClicked() is True:
            value: str = str(self.sliderPower.value())
            self.power_spinbox.setValue(float(value))
            power = self.powerToIntensity(float(value))
            self.laser.set_power(power)
        else:
            self.dialog_browser.setText(
                "power no sent to the diode, please turn on the diode.")

    def changeLaserFrequency(self):
        """
        put a tension [V] offset from red Pitaya to the diode slow laser. Allows to keep a frequency.
        Returns : None
        -------
        """
        value = float(str(self.volt_spinbox.value()))
        try:
            self.red.set_dc_offset(output=self.channel, offset=value)
            self.dialog_browser.setText(f"offset {value} V")
        except:
            self.dialog_browser.setText(
                "Error, could not connect to the AFG by this way")

    def openPulseView(self):
        """
        open the window to parameter the pulse signal
        :return: None
        """
        try:
            self.pulse_view = QtWidgets.QMainWindow()
            self.ui_pulse = PulseSignals(output=self.channel)
            self.ui_pulse.setupUi(self.pulse_view)
            self.pulse_view.show()
        except:
            self.dialog_browser.setText(
                "error, could not connect to specified AFG")

    def openRampView(self):
        """
        open the window ramp parameters to set  ramp signal on diode
        :return: None
        """
        try:
            self.ramp_view = QtWidgets.QMainWindow()
            self.ui_ramp = RampSignals(output=self.channel, red=self.red)
            self.ui_ramp.setupUi(self.ramp_view)
            self.ramp_view.show()
        except:
            self.dialog_browser.setText(
                "error, could not connect to specified AFG")

    def openSineView(self):
        try:
            self.sine_view = QtWidgets.QMainWindow()
            self.ui_sine = SineSignals(output=self.channel)
            self.ui_sine.setupUi(self.sine_view)
            self.sine_view.show()
        except:
            self.dialog_browser.setText(
                "error, could not connect to specified AFG")

    def openSquareView(self):
        try:
            self.square_view = QtWidgets.QMainWindow()
            self.ui_square = SquareSignals(output=self.square_view)
            self.ui_square.setupUi(self.square_view)
            self.square_view.show()
        except:
            self.dialog_browser.setText(
                "error, could not connect to specified AFG")

    def plotAbsSat(self):
        """
        get the information of the afg and plot the signal on the UI
        Ch1 from scope is for absorption and ch2 for AFG signal
        :return: None
        """
        # get data from scope, depending of the laser. :
        try:
            if self.host == "192.168.1.107":
                self.Data, self.Time = self.scope.get_waveform(channels=[4],
                                                               plot=False)
                self.volt = self.scope.get_waveform(channels=[2],
                                                    plot=False)[0]
            else:
                self.Data, self.Time = self.scope.get_waveform(channels=[3],
                                                               plot=False)
                self.volt = self.scope.get_waveform(channels=[1],
                                                    plot=False)[0]
            # Normalise Data to have the transmission with the good ax
            # The normalisation allows us to not use two photo-diodes cause.
            # smooth the array
            self.Data = savgol_filter(self.Data / np.amax(self.Data), 11, 3)

            # plot
            self.plotwidget_abs_sat.plot(self.volt, self.Data, clear=True)
            self.plotwidget_signal.plot(self.Time, self.volt, clear=True)
        except:
            self.dialog_browser.setText("couldn't plot data")

    def openCplotView(self):
        """
        open the view with all the laser state.
        Returns None
        -------

        """
        self.cplot_view = QtWidgets.QMainWindow()
        self.ui_ramp = CplotView(host=self.host)
        self.ui_ramp.setupUi(self.cplot_view)
        self.cplot_view.show()

    def get_data_with_thread(self):
        """
        call the method that executes the thread.
        :return: None
        """
        self.worker.get_data()