class Plotter(QtGui.QWidget): update_plot_xy_signal = pyqtSignal(object, object) def __init__(self, title='PLOTTER', x_label='X', y_label='Y'): QtGui.QWidget.__init__(self) self.gridLayout = QtGui.QGridLayout(self) self.setWindowTitle(title) #graph graphSetOptions(antialias=True) self.graph = PlotWidget() self.graph.setTitle(title) self.graph.setLabel('left', y_label) self.graph.setLabel('bottom', x_label) self.graph.showGrid(x=True, y=True) self.graph.setBackground((235, 236, 237)) self.pen = mkPen(color=(46, 142, 226), width=3, style=QtCore.Qt.DashLine) self.gridLayout.addWidget(self.graph, 0, 1, 10, 10) self.update_plot_xy_signal.connect(self.update_graph_with_value) self.x_vect = [] self.y_vect = [] self.__x_range_was_set = False def set_max_x(self, value): self.graph.setXRange(0, value) self.__x_range_was_set = True def get_max(self): max_y = max(self.y_vect) x = self.x_vect[self.y_vect.index(max_y)] return x, max_y def get_min(self): min_y = min(self.y_vect) x = self.x_vect[self.y_vect.index(min_y)] return x, min_y def update_graph_with_value(self, x, y): self.x_vect.append(x) self.y_vect.append(y) y_max = 0 y_min = 0 x_max = 0 for x_val in self.x_vect: y_val = self.y_vect[self.x_vect.index(x_val)] if y_val > y_max: y_max = y_val if y_val < y_min: y_min = y_val if x_val > x_max: x_max = x_val self.graph.clear() self.graph.setYRange(y_min - float(y_min) / 10, y_max + float(y_max) / 10) if self.__x_range_was_set is False: self.graph.setXRange(0, x_max + float(x_max) / 10) self.graph.plot(self.x_vect, self.y_vect, symbol='o', pen=self.pen)
class ExampleApp(QtGui.QMainWindow): def __init__(self): super().__init__() pyqtgraph.setConfigOption('background', 'w') self.setupUi(self) def setupUi(self, MainWindow): MainWindow.setObjectName('MainWindow') MainWindow.resize(900, 900) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.graphicsView = PlotWidget(self.centralwidget) self.graphicsView.setGeometry(QtCore.QRect(200, 200, 500, 500)) self.graphicsView.setObjectName("graphicsView") MainWindow.setCentralWidget(self.centralwidget) def update(self): points = 100 X = np.arange(points) n = 0 dataLst = [] while n < 100: dataPoint = ser.readline() dataPoint = float(dataPoint) dataLst.append(dataPoint) n += 1 Y = dataLst penn = pyqtgraph.mkPen('k', width=3, style=QtCore.Qt.SolidLine) self.graphicsView.setYRange(0, 1200, padding=0) labelStyle = {'color': '#000', 'font-size': '20px'} self.graphicsView.setLabel('bottom', 'Number of Points', '', **labelStyle) self.graphicsView.setLabel('left', 'Voltage', '', **labelStyle) self.graphicsView.plot(X, Y, pen=penn, clear=True) QtCore.QTimer.singleShot(1, self.update)
class Ui_MainWindow_Company_Scatter_Plot(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(800, 650) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.label = QtWidgets.QLabel(self.centralwidget) self.label.setGeometry(QtCore.QRect(10, 600, 850, 31)) font = QtGui.QFont() font.setPointSize(10) self.label.setFont(font) self.label.setObjectName("label") read_company_records() read_altered_company_records() alphabet_value = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26] unaltered_employee_names = company_name_value_array altered_employee_names = altered_company_name_value_array self.graphWidget = PlotWidget(self.centralwidget) self.graphWidget.setGeometry(QtCore.QRect(0, 0, 785, 580)) self.graphWidget.setObjectName("graphWidget") MainWindow.setCentralWidget(self.centralwidget) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.graphWidget.setLabel('left', 'Number of occurrences of company names first letter values', color='red', size=30) self.graphWidget.setLabel('bottom', 'Company Names sorted by first letter in a companies name', color='red', size=30) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) self.graphWidget.addLegend() self.graphWidget.showGrid(x=True, y=True) self.graphWidget.setXRange(0, 26.5, padding=0) self.graphWidget.setYRange(0, 300, padding=0) try: self.plot(alphabet_value, unaltered_employee_names, "Original Company Names", 'r') self.plot(alphabet_value, altered_employee_names, "Altered Company Names", 'b') except Exception: msg = QMessageBox() msg.setIcon(QMessageBox.Critical) msg.setText("Error! Please close existing window.") msg.setInformativeText('You can only have one window open at a time. Please close the existing window to continue!') msg.setWindowTitle("Error") msg.exec_() pass def plot(self, x, y, plotname, color): pen = pg.mkPen(color=color) self.graphWidget.plot(x, y, name=plotname, pen=pen, symbol='+', symbolSize=10, symbolBrush=(color)) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "Differential Privacy Engine")) self.label.setText(_translate("MainWindow", "NOTE: This graph displays the difference between company names if the Differential Privacy Engine includes the company name values."))
def getVoltsFromChannel(self, CH: str, dataCurve, graph: pG.PlotWidget): data_from_channel, time_array, time_unit = self.Osciloscope.get_data_points_from_channel( CH) print("time unit", time_unit) graph.setLabel('bottom', 'Time', units=time_unit) graph.setLabel('left', 'Voltage', units='V') dataCurve.setData(time_array, data_from_channel) self.DebugMessage("Working on it ...", 1000) pass
class LookupTableWithGraph(QtGui.QWidget): def __init__(self, name='LOOKPUP TABLE', init_table={}): QtGui.QWidget.__init__(self) self.gridLayout = QtGui.QGridLayout(self) self.name = name #table self.table = LookupTable(init_table) #self.table.add_row() self.table.values_updated_signal.connect(self.values_updated_slot) #graph graphSetOptions(antialias=True) self.graph = PlotWidget() self.graph.setTitle(self.name) self.graph.setLabel('left', 'OUTPUT') self.graph.setLabel('bottom', 'INPUT') self.graph.showGrid(x=True, y=True) self.graph.setBackground((235, 236, 237)) self.pen = mkPen(color=(46, 142, 226), width=3, style=QtCore.Qt.DashLine) self.gridLayout.addWidget(self.table, 0, 0) self.gridLayout.addWidget(self.graph, 0, 1) self.values_updated_slot() def values_updated_slot(self): x_vect = [] y_vect = [] y_max = 0 y_min = 0 x_max = 0 for x_val in self.table.lookup_table: y_val = self.table.lookup_table[x_val] x_vect.append(x_val) y_vect.append(y_val) if y_val > y_max: y_max = y_val if y_val < y_min: y_min = y_val if x_val > x_max: x_max = x_val self.graph.clear() self.graph.setYRange(y_min - float(y_min) / 10, y_max + float(y_max) / 10) self.graph.setXRange(0, x_max + float(x_max) / 10) self.graph.plot(x_vect, y_vect, symbol='o', pen=self.pen) def get_table(self): return self.table.get_table()
class SimpleTestResultsDialog(QMainWindow): def __init__(self, parent=None, methods=None): super(SimpleTestResultsDialog, self).__init__(parent) self.setWindowTitle("Grismo - Wyniki dla prostego testu") self.setMinimumWidth(500) self.results_count = 0 self.all_results = [] self.methods = methods central = QWidget() self.setCentralWidget(central) result_dialog_layout = QVBoxLayout() central.setLayout(result_dialog_layout) self.results_table = QTableWidget() result_dialog_layout.addWidget(self.results_table) self.results_table.setRowCount(len(methods)) self.results_table.setColumnCount(3) self.results_table.setColumnWidth(2, 200) self.results_table.setHorizontalHeaderLabels(["Metoda", "Wynik", "Czas [s]"]) for i in range(len(methods)): self.results_table.setItem(i, 0, QTableWidgetItem(methods[i])) # plot box x_axis_dict = dict(enumerate(methods)) x_axis = AxisItem(orientation='bottom') x_axis.setTicks([x_axis_dict.items()]) self.results_plot = PlotWidget(axisItems={'bottom': x_axis}) self.results_plot.setBackground('w') self.results_plot.setTitle("Porównanie metod dla wskazanych grafów") self.results_plot.setLabel('left', 'Czas obliczeń [s]', color='k', size=10) self.results_plot.setLabel('bottom', 'Metody ', color='k', size=10) self.results_plot.setMaximumWidth(600) self.results_plot.showGrid(y=True) result_dialog_layout.addWidget(self.results_plot) # prepare plot data pen = mkPen(color='k', width=2) self.plot_data = self.results_plot.plot([], [], pen=pen, symbol='+', symbolSize=10, symbolBrush='k') def add_result(self, result): for i in range(len(result)): self.results_table.setItem(self.results_count, i, QTableWidgetItem(str(result[i]))) self.results_count = self.results_count + 1 self.all_results.append(result[-1]) self.plot_data.setData(range(len(self.all_results)), self.all_results)
class ExampleApp(QtGui.QMainWindow): def __init__(self): super().__init__() pyqtgraph.setConfigOption('background', 'w') # self.setupUi(self) def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(350, 300) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") # the plot widget self.graphicsView = PlotWidget( self.centralwidget) # assign this PlotWidget to the graphicsView. self.graphicsView.setGeometry(QtCore.QRect(20, 20, 300, 300)) self.graphicsView.setObjectName("graphicsView") # MainWindow.setCentralWidget(self.centralwidget) def analogInput(self, channel): spi.max_speed_hz = 1350000 adc = spi.xfer2([1, (8 + channel) << 4, 0]) data = ((adc[1] & 3) << 8) + adc[2] return data def update(self): points = 100 #number of data points X = np.arange(points) n = 0 dataLst = [] while n < 100: dataPoint = self.analogInput(0) # Reading from CH0 #dataPoint=int(dataPoint) dataLst.append(dataPoint) n += 1 Y = dataLst penn = pyqtgraph.mkPen('k', width=3, style=QtCore.Qt.SolidLine) self.graphicsView.setYRange(0, 1200, padding=0) labelStyle = {'color': '#000', 'font-size': '20px'} self.graphicsView.setLabel('bottom', 'Number of Points', '', **labelStyle) self.graphicsView.setLabel('left', 'Voltage', '', **labelStyle) self.graphicsView.plot(X, Y, pen=penn, clear=True) QtCore.QTimer.singleShot( 1, self.update ) # 1 ms, QUICKLY repeat, recursively. Use this timer to invoke the 'update()' function recursively.
class UiVisualConsumos(GraphicsLayoutWidget): def __init__(self): super().__init__() self.threadpool = QThreadPool() self.cpuUsage = [] self.countTime = [] self.start_time = time() self.timer = QTimer() # --------------------------------------------------------------------------- self.plot_view = PlotWidget() self.plot_view.plotItem.setTitle("Processor percent usage") setConfigOptions(antialias=False) # --------------------------------------------------------------------------- self.hour = [] self.temperature = [] # --------------------------------------------------------------------------- self.plot_view.plot(self.hour, self.temperature, pen=mkPen(cosmetic=True, width=40.0, color='r')) self.plot_view.setLabel('left', "Processor usage", units='%') # --------------------------------------------------------------------------- self.main_layout = QVBoxLayout() self.main_layout.addWidget(self.plot_view) self.setLayout(self.main_layout) @Slot() def refresh(self, n): self.hour.append(n[0]) self.temperature.append(n[1]) self.plot_view.plot(self.hour, self.temperature, pen='r') @Slot() def init_logica(self, cpu_usage_callback): cpu_usage_callback.emit( [float(time() - self.start_time), float(psutil.cpu_percent())])
def update_graph(self, graph: pg.PlotWidget, x, y, y_name, x_Unit, y_Unit='V', color=(255, 255, 102)): """ Updates a graph :param graph: plotWidget :param x: x dataset :param y: y dataset :param y_name: name (MUST) :param color: default: 255, 255, 102 :return: """ sizex = len(x) sizey = len(y) np_x = np.asarray(x) np_y = np.asarray(y) if sizex == sizey: dataItems = graph.listDataItems() for i in dataItems: # console(i.name(), " ", y_name) if i is not None: if i.name() == y_name: graph.removeItem(i) cpen = mkPen(color=color, width=3) # npx, npy = get_mod_array(np_x, np_y, self.ui.corZeroBox.isChecked(), self.ui.formulaEdit.text()) graph.plot(np_x, np_y, pen=cpen, name=y_name) self.replot_saved_graphs() graph.setLabel('bottom', "Time scale", units=str(x_Unit)) graph.setLabel('left', "CH scale", units=str(y_Unit)) else: console("Inequality", y_name, " ; ", sizex, " ; ", sizey) self.append_html_paragraph( "Inequality: " + str(y_name) + " ; " + str(sizex) + " ; " + str(sizey), -1, True)
class ExampleApp(QtGui.QMainWindow): def __init__(self): super().__init__() pyqtgraph.setConfigOption('background', 'w') self.setupUi(self) def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(900, 900) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName('centralwidget') # plot widget self.graphicsView = PlotWidget( self.centralwidget) # assign this plotwidget to the graphicsView self.graphicsView.setObjectName("graphicsView") MainWindow.setCentralWidget(self.centralwidget) def update(self): points = 100 x = np.array(points) n = 0 dataLst = [] while n < 200: dataPoint = ser.readline() dataPoint = int(dataPoint) dataLst.append(dataPoint) n += 1 y = dataLst penn = pyqtgraph.mkPen('k', width=3, style=QtCore.Qt.SolidLine) self.graphicsView.setYRange(0, 1200, padding=0) labelStyle = {'color': '#000', 'font-size': '20px'} self.graphicsView.setLabel('bottom', 'Number of Points', '', **labelStyle) self.graphicsView.plot(x, y, pen=penn, clear=True) QtCore.QTimer.singleShot(1, self.update)
def __init__(self, atri_plot: PlotWidget, vent_plot: PlotWidget, data_size: int): print("Graphs handler init") # noinspection PyArgumentList atri_plot.setRange(xRange=[-1, data_size], yRange=[-0.5, 5.5], padding=0) atri_plot.setLimits(xMin=-1, xMax=data_size, maxXRange=data_size + 1, yMin=-0.5, yMax=5.5) atri_plot.setMouseEnabled(x=True, y=False) atri_plot.enableAutoRange(x=False, y=True) atri_plot.setAutoVisible(x=False, y=True) atri_plot.showGrid(x=True, y=True) atri_plot.hideButtons() atri_plot.setMenuEnabled(False) atri_plot.setLabel('left', "Amplitude", units='V', **{'color': '#FFF', 'font-size': '10pt'}) atri_plot.setLabel('bottom', "Time", units='s', **{'color': '#FFF', 'font-size': '10pt'}) atri_plot.getAxis('bottom').setHeight(30) # noinspection PyArgumentList vent_plot.setRange(xRange=[-1, data_size], yRange=[-0.5, 5.5], padding=0) vent_plot.setLimits(xMin=-1, xMax=data_size, maxXRange=data_size + 1, yMin=-0.5, yMax=5.5) vent_plot.setMouseEnabled(x=True, y=False) vent_plot.enableAutoRange(x=False, y=True) vent_plot.setAutoVisible(x=False, y=True) vent_plot.showGrid(x=True, y=True) vent_plot.hideButtons() vent_plot.setMenuEnabled(False) vent_plot.setLabel('left', "Amplitude", units='V', **{'color': '#FFF', 'font-size': '10pt'}) vent_plot.setLabel('bottom', "Time", units='s', **{'color': '#FFF', 'font-size': '10pt'}) vent_plot.getAxis('bottom').setHeight(30) # Initialize graphs to 0 self._atri_data = np.zeros(data_size) self._vent_data = np.zeros(data_size) # Create new sense plots for the atrial and ventricular graphs, in blue self._atri_plot = atri_plot.plot(pen=(0, 229, 255)) self._vent_plot = vent_plot.plot(pen=(0, 229, 255)) self._plot_data()
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)
class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(671, 600) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.lab_gen = QtWidgets.QLabel(self.centralwidget) self.lab_gen.setGeometry(QtCore.QRect(20, 10, 81, 51)) font = QtGui.QFont() font.setPointSize(11) self.lab_gen.setFont(font) self.lab_gen.setObjectName("lab_gen") self.lab_pop = QtWidgets.QLabel(self.centralwidget) self.lab_pop.setGeometry(QtCore.QRect(130, 10, 101, 51)) font = QtGui.QFont() font.setPointSize(11) self.lab_pop.setFont(font) self.lab_pop.setObjectName("lab_pop") self.lab_route = QtWidgets.QLabel(self.centralwidget) self.lab_route.setGeometry(QtCore.QRect(260, 10, 111, 51)) font = QtGui.QFont() font.setPointSize(11) self.lab_route.setFont(font) self.lab_route.setObjectName("lab_route") self.lab_mut = QtWidgets.QLabel(self.centralwidget) self.lab_mut.setGeometry(QtCore.QRect(400, 10, 131, 51)) font = QtGui.QFont() font.setPointSize(11) self.lab_mut.setFont(font) self.lab_mut.setObjectName("lab_mut") self.lab_copy = QtWidgets.QLabel(self.centralwidget) self.lab_copy.setGeometry(QtCore.QRect(560, 10, 81, 51)) font = QtGui.QFont() font.setPointSize(11) self.lab_copy.setFont(font) self.lab_copy.setObjectName("lab_copy") self.line_gen = QtWidgets.QLineEdit(self.centralwidget) self.line_gen.setGeometry(QtCore.QRect(20, 50, 81, 20)) self.line_gen.setObjectName("line_gen") self.line_gen.setToolTip("Number of generations. Must be an integer.") input_validator = QRegExpValidator(reg_ex, self.line_gen) self.line_gen.setValidator(input_validator) self.line_gen.editingFinished.connect(self.gen_equ) self.line_pop = QtWidgets.QLineEdit(self.centralwidget) self.line_pop.setGeometry(QtCore.QRect(140, 50, 81, 20)) self.line_pop.setObjectName("line_pop") self.line_pop.setToolTip( "Maximum population size. Must be an integer.") input_validator = QRegExpValidator(reg_ex, self.line_pop) self.line_pop.setValidator(input_validator) self.line_pop.editingFinished.connect(self.pop_equ) self.line_route = QtWidgets.QLineEdit(self.centralwidget) self.line_route.setGeometry(QtCore.QRect(270, 50, 81, 20)) self.line_route.setObjectName("line_route") self.line_route.setToolTip("Maximum route size. Must be an integer.") input_validator = QRegExpValidator(reg_ex, self.line_route) self.line_route.setValidator(input_validator) self.line_route.editingFinished.connect(self.route_equ) self.line_mut = QtWidgets.QLineEdit(self.centralwidget) self.line_mut.setGeometry(QtCore.QRect(420, 50, 81, 20)) self.line_mut.setObjectName("line_mut") self.line_mut.setToolTip( "Probability of mutation in percentage. Must be an integer.") input_validator = QRegExpValidator(reg_ex, self.line_mut) self.line_mut.setValidator(input_validator) self.line_mut.editingFinished.connect(self.mut_equ) self.line_copy = QtWidgets.QLineEdit(self.centralwidget) self.line_copy.setGeometry(QtCore.QRect(560, 50, 81, 20)) self.line_copy.setObjectName("line_copy") self.line_copy.setToolTip( "Copies made of each string for reproduction. Must be an integer.") input_validator = QRegExpValidator(reg_ex, self.line_copy) self.line_copy.setValidator(input_validator) self.line_copy.editingFinished.connect(self.copy_equ) self.pushButton = QtWidgets.QPushButton(self.centralwidget) self.pushButton.setGeometry(QtCore.QRect(260, 80, 111, 51)) font = QtGui.QFont() font.setPointSize(14) self.pushButton.setFont(font) self.pushButton.setObjectName("pushButton") self.pushButton.setToolTip( "Start the genetic algorithm with these parameters.") self.pushButton.clicked.connect(self.model_start) self.graphWidget = PlotWidget(self.centralwidget) self.graphWidget.setGeometry(QtCore.QRect(19, 159, 631, 351)) self.graphWidget.setObjectName("graphWidget") self.graphWidget.setTitle( "<span style=\"color:white;font-size:20px\">Fitness vs Generations</span>" ) self.graphWidget.setLabel('left', 'Fitness', color='white', size=15) self.graphWidget.setLabel('bottom', 'Generations', color='white', size=15) self.lab_demand = QtWidgets.QLabel(self.centralwidget) self.lab_demand.setGeometry(QtCore.QRect(10, 550, 261, 21)) font = QtGui.QFont() font.setPointSize(11) self.lab_demand.setFont(font) self.lab_demand.setObjectName("lab_demand") self.lab_timefit = QtWidgets.QLabel(self.centralwidget) self.lab_timefit.setGeometry(QtCore.QRect(390, 550, 221, 21)) font = QtGui.QFont() font.setPointSize(11) self.lab_timefit.setFont(font) self.lab_timefit.setObjectName("lab_timefit") MainWindow.setCentralWidget(self.centralwidget) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle( _translate("MainWindow", "Genetic Algorithm Simulator")) self.lab_gen.setText(_translate("MainWindow", "Generations")) self.lab_pop.setText(_translate("MainWindow", "Population Size")) self.lab_route.setText(_translate("MainWindow", "Max Route Size")) self.lab_mut.setText(_translate("MainWindow", "Mutation Probability")) self.lab_copy.setText(_translate("MainWindow", "Copy Count")) self.pushButton.setText(_translate("MainWindow", "Start")) def gen_equ(self): if self.line_gen.text() == '': pass else: data[0] = int(self.line_gen.text()) def pop_equ(self): if self.line_pop.text() == '': pass else: data[1] = int(self.line_pop.text()) def mut_equ(self): if self.line_mut.text() == '': pass else: data[2] = int(self.line_mut.text()) def route_equ(self): if self.line_route.text() == '': pass else: data[3] = int(self.line_route.text()) def copy_equ(self): if self.line_copy.text() == '': pass else: data[4] = int(self.line_copy.text()) def model_start(self): _translate = QtCore.QCoreApplication.translate final_population, max_fit, avg_fit, demand_fit, time_fit = GAM.model_run( data) pen2 = pg.mkPen(color=(0, 255, 0)) self.graphWidget.plot([x for x in range(data[0])], avg_fit, name="Avg Fit", pen=pen2, clear=True) self.lab_demand.setText( _translate("MainWindow", "Percentage of Demand Fulifilled " + f"{demand_fit}")) self.lab_timefit.setText( _translate("MainWindow", "Time Fitness " + f"{time_fit}"))
class Ui_Dialog(object): def __init__(self) : self.c = 1 self.dx = 0.1 self.n = 1 def setupUi(self, Dialog): Dialog.setObjectName("Equation de transport") Dialog.resize(996, 388) Dialog.setWindowIcon(QtGui.QIcon(r'D:\Cours\Aero2\GP\Transport\Numerix.jpg')) Dialog.setFixedSize(996,388) font = QtGui.QFont() font.setFamily("CMU Bright") font.setPointSize(10) Dialog.setFont(font) self.frame = QtWidgets.QFrame(Dialog) self.frame.setGeometry(QtCore.QRect(20, 10, 361, 81)) self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel) self.frame.setFrameShadow(QtWidgets.QFrame.Raised) self.frame.setObjectName("frame") self.label = QtWidgets.QLabel(self.frame) self.label.setGeometry(QtCore.QRect(10, 10, 181, 16)) self.label.setObjectName("label") self.label_2 = QtWidgets.QLabel(self.frame) self.label_2.setGeometry(QtCore.QRect(200, 10, 161, 16)) self.label_2.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor)) self.label_2.setMouseTracking(False) self.label_2.setObjectName("label_2") self.L = QtWidgets.QLineEdit(self.frame) self.L.setGeometry(QtCore.QRect(10, 40, 113, 22)) self.L.setObjectName("L") self.tmax = QtWidgets.QLineEdit(self.frame) self.tmax.setGeometry(QtCore.QRect(200, 40, 113, 22)) self.tmax.setObjectName("tmax") self.frame_2 = QtWidgets.QFrame(Dialog) self.frame_2.setGeometry(QtCore.QRect(20, 110, 361, 221)) font = QtGui.QFont() font.setFamily("CMU Serif") font.setPointSize(10) self.frame_2.setFont(font) self.frame_2.setFrameShape(QtWidgets.QFrame.StyledPanel) self.frame_2.setFrameShadow(QtWidgets.QFrame.Raised) self.frame_2.setObjectName("frame_2") self.label_3 = QtWidgets.QLabel(self.frame_2) self.label_3.setGeometry(QtCore.QRect(10, 10, 171, 16)) self.label_3.setObjectName("label_3") self.CI = QtWidgets.QComboBox(self.frame_2) self.CI.setGeometry(QtCore.QRect(10, 50, 91, 22)) font = QtGui.QFont() font.setFamily("CMU Serif") font.setPointSize(10) font.setBold(False) font.setItalic(False) font.setWeight(50) self.CI.setFont(font) self.CI.setStyleSheet("") self.CI.setObjectName("CI") self.CI.addItem("sin(x)") self.CI.addItem("exp(-x^2)") self.CI.addItem("0") self.label_4 = QtWidgets.QLabel(self.frame_2) self.label_4.setGeometry(QtCore.QRect(180, 10, 201, 16)) self.label_4.setObjectName("label_4") self.frame_3 = QtWidgets.QFrame(self.frame_2) self.frame_3.setGeometry(QtCore.QRect(170, 0, 191, 181)) self.frame_3.setFrameShape(QtWidgets.QFrame.StyledPanel) self.frame_3.setFrameShadow(QtWidgets.QFrame.Raised) self.frame_3.setObjectName("frame_3") self.label_5 = QtWidgets.QLabel(self.frame_3) self.label_5.setGeometry(QtCore.QRect(20, 40, 71, 16)) self.label_5.setObjectName("label_5") self.Cl_0 = QtWidgets.QComboBox(self.frame_3) self.Cl_0.setGeometry(QtCore.QRect(20, 70, 90, 22)) self.Cl_0.setObjectName("Cl_0") self.Cl_0.addItem("0") self.Cl_0.addItem("sin(t)") self.label_6 = QtWidgets.QLabel(self.frame_3) self.label_6.setGeometry(QtCore.QRect(20, 110, 71, 16)) self.label_6.setObjectName("label_6") self.Cl_L = QtWidgets.QComboBox(self.frame_3) self.Cl_L.setGeometry(QtCore.QRect(20, 140, 90, 22)) self.Cl_L.setObjectName("Cl_L") self.Cl_L.addItem("0") self.Cl_L.addItem("sin(t)") self.Cl_L.addItem("Aucune") self.label_7 = QtWidgets.QLabel(self.frame_2) self.label_7.setGeometry(QtCore.QRect(10, 100, 151, 16)) self.label_7.setObjectName("label_7") self.Vitesse = QtWidgets.QLineEdit(self.frame_2) self.Vitesse.setGeometry(QtCore.QRect(10, 140, 113, 22)) self.Vitesse.setObjectName("Vitesse") self.Animation = QtWidgets.QCheckBox(Dialog) self.Animation.setGeometry(QtCore.QRect(30, 340, 101, 20)) self.Animation.setObjectName("Animation") self.Plot_btn = QtWidgets.QPushButton(Dialog) self.Plot_btn.setGeometry(QtCore.QRect(220, 340, 93, 28)) self.Plot_btn.setObjectName("Plot_btn") self.Graph = PlotWidget(Dialog) self.Graph.setGeometry(QtCore.QRect(389, 9, 591, 361)) self.Graph.setObjectName("Graph") self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) Dialog.setTabOrder(self.CI, self.Vitesse) Dialog.setTabOrder(self.Vitesse,self.Cl_0) Dialog.setTabOrder(self.Cl_0, self.Cl_L) Dialog.setTabOrder(self.Cl_L, self.Animation) Dialog.setTabOrder(self.Animation, self.Plot_btn) setConfigOptions(antialias=True) self.Plot_btn.clicked.connect(self.plotter) self.Graph.setBackground('w') self.Graph.setLabel('left','y(x,tmax)') self.Graph.setLabel('bottom','x') self.timer = QtCore.QTimer() self.timer.timeout.connect(self.animplotter) def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "Equation de transport")) self.label.setText(_translate("Dialog", "Longueur de l\'espace :")) self.label_2.setText(_translate("Dialog", "Temps maximum :")) self.label_3.setText(_translate("Dialog", "Conditions initiales :")) self.CI.setItemText(0, _translate("Dialog", "sin(x)")) self.CI.setItemText(1, _translate("Dialog", "exp(-x^2)")) self.CI.setItemText(2, _translate("Dialog", "0")) self.label_4.setText(_translate("Dialog", "Conditions aux limites :")) self.label_5.setText(_translate("Dialog", "En x = 0 :")) self.Cl_0.setItemText(0, _translate("Dialog", "0")) self.Cl_0.setItemText(1, _translate("Dialog", "sin(t)")) self.label_6.setText(_translate("Dialog", "En x = L :")) self.Cl_L.setItemText(0, _translate("Dialog", "0")) self.Cl_L.setItemText(1, _translate("Dialog", "sin(t)")) self.Animation.setText(_translate("Dialog", "Animation")) self.Plot_btn.setText(_translate("Dialog", "Plot !")) self.label_6.setText(_translate("Dialog", "En x = L :")) self.Cl_L.setItemText(0, _translate("Dialog", "0")) self.Cl_L.setItemText(1, _translate("Dialog", "sin(t)")) self.Cl_L.setItemText(2, _translate("Dialog", "Aucune")) self.Animation.setText(_translate("Dialog", "Animation")) self.Plot_btn.setText(_translate("Dialog", "Plot !")) self.label_7.setText(_translate("Dialog", "Vitesse de l\'onde :")) def solve(self) : self.C = self.c*self.dt/self.dx self.Fi = init = self.Finit() self.sol = [] self.solutions = [0 for t in self.T] for t in range(len(self.T)) : for x in range(len(self.Fi)) : self.sol.append( init[x] - self.C*(init[x] - init[x-1]) ) if self.Cl_0.currentText() == 'sin(t)' : self.sol[0] = np.sin(self.T[t]*self.c) elif self.Cl_0.currentText() == '0' : self.sol[0] = 0 if self.Cl_L.currentText() == 'sin(t)' : self.sol[-1] = np.sin(self.T[t]) elif self.Cl_L.currentText() == '0' : self.sol[-1] = 0 init = self.sol self.sol = [] self.solutions[t] = init self.sol = init return self.sol def plotter(self) : self.c = float(self.Vitesse.text()) self.tmaxv = float(self.tmax.text()) self.dt = self.dx/self.c self.Graph.clear() self.X = np.arange(0,float(self.L.text()),self.dx).tolist() self.T = np.arange(0,self.tmaxv,self.dt).tolist() Solution = self.solve() self.Graph.setXRange(0,float(self.L.text())) self.Graph.setYRange(min(Solution)-self.dx,1.1) self.timer.setInterval(self.tmaxv/len(self.T)*10**3) #self.timer.setInterval(50) if self.Animation.isChecked() : self.n = 1 self.my_line = self.Graph.plot(self.X,self.Finit(),name ='t=0', pen = mkPen(color = 'k') ) self.timer.start() else : self.Graph.plot(self.X,self.Finit(),name ='t=0', pen = mkPen(color = 'b') ) self.Graph.plot(self.X,Solution,name ='t=tmax', pen = mkPen(color = 'k') ) def Finit(self) : X = np.arange(0,float(self.L.text()),self.dx) if self.CI.currentText() == 'exp(-x^2)' : return np.exp(-(X-float(self.L.text())/2)**2) elif self.CI.currentText() == 'sin(x)' : return np.sin(X) elif self.CI.currentText() == '0' : return [0 for x in X] def animplotter(self) : try : self.my_line.setData(self.X,self.solutions[self.n]) self.n += 1 except : self.timer.stop()
class ControllerWindow(QtWidgets.QWidget): app_name = "Controller" def __init__(self): # Simple reason why we use it here is that it allows us to # access variables, methods etc in the design.py file super(self.__class__, self).__init__() # self.setupUi(self) # This is defined in design.py file automatically # It sets up layout and widgets that are defined self.setWindowTitle(self.app_name) self.resize(1280, 720) # self.setCentralWidget(self.pushButton) self.quit_shortcut = QtWidgets.QShortcut(QtGui.QKeySequence("Ctrl+Q"), self) self.quit_shortcut.activated.connect(self.close_application) self.new_layout = QtWidgets.QGridLayout() self.setLayout(self.new_layout) # self.layout.addWidget(pushButton) self.hbox = QtWidgets.QHBoxLayout() self.new_layout.addLayout(self.hbox, 0, 0, 1, 1) self.ct = {} self.ct["axis0"] = {} self.ct["axis1"] = {} # self.ct["axis0"]velocity_label = QtWidgets.QLabel() # self.ct["axis0"]velocity_label.setText("Velocity (Turns/s)") # self.ct["axis0"]control_buttons_layout.addWidget(self.ct["axis0"]velocity_label, 1, 0, 1, 1) self.setup_control_axis("axis0") self.setup_control_axis("axis1") # self.ct["axis0"]control_box.addLayout # self.ct["axis0"]control_box.setObjectName("test") # self.ct["axis0"]control_box.setMaximumWidth(300) # self.axis1_control_box = QtWidgets.QGroupBox() # self.axis1_control_box.setTitle("Axis1") # self.ct["axis0"]control_box.setObjectName("test") # self.axis1_control_box.setMaximumWidth(300) self.control_vertical_layout = QtWidgets.QVBoxLayout() self.control_vertical_layout.addWidget(self.ct["axis0"]["control_box"]) self.control_vertical_layout.addWidget(self.ct["axis1"]["control_box"]) self.hbox.addLayout(self.control_vertical_layout) # self.hbox.addWidget(groupbox) self.verticalLayout = QtWidgets.QVBoxLayout() self.horizontalLayout_3 = QtWidgets.QHBoxLayout() self.verticalLayout.addLayout(self.horizontalLayout_3) self.hbox.addLayout(self.verticalLayout) self.plotWidget_velocity = PlotWidget() self.plotWidget_velocity.setStyleSheet("") self.plotWidget_velocity.setObjectName("plotWidget_velocity") self.verticalLayout.addWidget(self.plotWidget_velocity) self.plotWidget_current = PlotWidget() self.plotWidget_current.setMinimumSize(QtCore.QSize(900, 0)) self.plotWidget_current.setObjectName("plotWidget_current") self.verticalLayout.addWidget(self.plotWidget_current) self.plotWidget_position = PlotWidget() self.plotWidget_position.setObjectName("plotWidget_position") self.verticalLayout.addWidget(self.plotWidget_position) self.control_statusBar = QtWidgets.QLabel() self.verticalLayout.addWidget(self.control_statusBar) # self.showAxis1_checkBox = QtWidgets.QCheckBox() # self.showAxis1_checkBox.setEnabled(True) # self.showAxis1_checkBox.setChecked(True) # self.showAxis1_checkBox.setObjectName("showAxis1_checkBox") # self.verticalLayout.addWidget(self.showAxis1_checkBox) self.showAxis0_checkBox = QtWidgets.QCheckBox() self.showAxis0_checkBox.setText("Axis0") self.showAxis0_checkBox.setChecked(True) self.showAxis0_checkBox.setObjectName("showAxis0_checkBox") self.horizontalLayout_3.addWidget(self.showAxis0_checkBox) self.label_2 = QtWidgets.QLabel("Estimate") self.label_2.setObjectName("label_2") self.horizontalLayout_3.addWidget(self.label_2) self.label_6 = QtWidgets.QLabel() self.label_6 = QtWidgets.QLabel() self.label_6.setText("") self.label_6.setPixmap( QtGui.QPixmap("Icons/legendLines/legendLines_Blue.png")) self.label_6.setObjectName("label_6") self.horizontalLayout_3.addWidget(self.label_6) self.label = QtWidgets.QLabel("Estimate") self.label.setObjectName("label") self.horizontalLayout_3.addWidget(self.label) self.label_7 = QtWidgets.QLabel() self.label_7.setText("") self.label_7.setPixmap( QtGui.QPixmap("Icons/legendLines/legendLines_Purple.png")) self.label_7.setObjectName("label_7") self.horizontalLayout_3.addWidget(self.label_7) # self.horizontalLayout_3.setContentsMargins(11, 11, 11, 11) # self.horizontalLayout_3.setSpacing(6) self.horizontalLayout_3.setObjectName("horizontalLayout_3") self.showAxis1_checkBox = QtWidgets.QCheckBox() self.showAxis1_checkBox.setEnabled(True) self.showAxis1_checkBox.setChecked(True) self.showAxis1_checkBox.setText("Axis1") # self.showAxis1_checkBox.setLayoutDirection(QtCore.Qt.RightToLeft) self.showAxis1_checkBox.setObjectName("showAxis1_checkBox") self.horizontalLayout_3.addWidget(self.showAxis1_checkBox) self.label_13 = QtWidgets.QLabel() self.label_13.setObjectName("label_13") self.horizontalLayout_3.addWidget(self.label_13) self.label_14 = QtWidgets.QLabel() self.label_14.setText("") self.label_14.setPixmap( QtGui.QPixmap("Icons/legendLines/legendLines_Orange.png")) self.label_14.setObjectName("label_14") self.horizontalLayout_3.addWidget(self.label_14) self.label_8 = QtWidgets.QLabel() self.label_8.setObjectName("label_8") self.horizontalLayout_3.addWidget(self.label_8) self.label_9 = QtWidgets.QLabel() self.label_9.setText("") self.label_9.setPixmap( QtGui.QPixmap("Icons/legendLines/legendLines_Yellow.png")) self.label_9.setObjectName("label_9") self.label_13.setText("Setpoint") self.label_8.setText("Estimate") self.horizontalLayout_3.addWidget(self.label_9) self.label_graph_time = QtWidgets.QLabel() self.label_graph_time.setText("Time Window (sec)") self.horizontalLayout_3.addWidget(self.label_graph_time) self.spinBox_graphTime = QtWidgets.QSpinBox() # self.spinBox_graphTime.setT self.spinBox_graphTime.setMinimum(1) self.spinBox_graphTime.setMaximum(600) self.spinBox_graphTime.setProperty("value", 20) self.spinBox_graphTime.setObjectName("spinBox_graphTime") self.horizontalLayout_3.addWidget(self.spinBox_graphTime) self.clearGraph_pushButton = QtWidgets.QPushButton() self.clearGraph_pushButton.setText("Clear Graph") self.clearGraph_pushButton.setObjectName("clearGraph_pushButton") self.horizontalLayout_3.addWidget(self.clearGraph_pushButton) self.showAxis0_checkBox.stateChanged.connect( self.axis0_graph_state_changed) self.showAxis1_checkBox.stateChanged.connect( self.axis1_graph_state_changed) self.clearGraph_pushButton.clicked.connect(self.clearGraph_clicked) self.plotWidget_velocity.setLabel('bottom', 'Time', 's') self.plotWidget_velocity.setLabel('left', 'Velocity', 'rpm') self.plotWidget_velocity.setTitle("Velocity") self.plotWidget_position.setLabel('bottom', 'Time', 's') self.plotWidget_position.setLabel('left', 'Position', 'counts') self.plotWidget_position.setTitle("Position") self.plotWidget_current.setLabel('bottom', 'Time', 's') self.plotWidget_current.setLabel('left', 'Current', 'Iq') self.plotWidget_current.setTitle("Current") self.ad = {} #axis_dcit pen_sp_axis0 = pg.mkPen(color=(0, 128, 255), width=1) # Blue: 0 128 255 pen_est_axis0 = pg.mkPen(color=(135, 0, 191), width=1) # Purple: 135 0 191 pen_sp_axis1 = pg.mkPen(color=(255, 78, 0), width=1) # Red: 255 78 0 pen_est_axis1 = pg.mkPen(color=(255, 212, 0), width=1) #Yellow 255 212 0 # Poop yellow)Orange: 155 170 0 # old orange (color=(255, 192, 0) self.ad["axis0"] = {} self.ad["axis0"]["time_array"] = [] self.ad["axis0"]["position"] = {} self.ad["axis0"]["position"]["estimate"] = [] self.ad["axis0"]["position"]["set_point"] = [] self.ad["axis0"]["velocity"] = {} self.ad["axis0"]["velocity"]["estimate"] = [] self.ad["axis0"]["velocity"]["set_point"] = [] self.ad["axis0"]["current"] = {} self.ad["axis0"]["current"]["estimate"] = [] self.ad["axis0"]["current"]["set_point"] = [] self.ad["axis0"]["vel_sp_curve"] = self.plotWidget_velocity.plot( name="Setpoint", pen=pen_sp_axis0) self.ad["axis0"]["vel_est_curve"] = self.plotWidget_velocity.plot( name="Estimate", pen=pen_est_axis0) self.ad["axis0"]["pos_sp_curve"] = self.plotWidget_position.plot( name="Setpoint", pen=pen_sp_axis0) self.ad["axis0"]["pos_est_curve"] = self.plotWidget_position.plot( name="Estimate", pen=pen_est_axis0) self.ad["axis0"]["current_sp_curve"] = self.plotWidget_current.plot( name="Setpoint", pen=pen_sp_axis0) self.ad["axis0"]["current_est_curve"] = self.plotWidget_current.plot( name="Estimate", pen=pen_est_axis0) self.ad["axis1"] = {} self.ad["axis1"]["time_array"] = [] self.ad["axis1"]["position"] = {} self.ad["axis1"]["position"]["estimate"] = [] self.ad["axis1"]["position"]["set_point"] = [] self.ad["axis1"]["velocity"] = {} self.ad["axis1"]["velocity"]["estimate"] = [] self.ad["axis1"]["velocity"]["set_point"] = [] self.ad["axis1"]["current"] = {} self.ad["axis1"]["current"]["estimate"] = [] self.ad["axis1"]["current"]["set_point"] = [] self.ad["axis1"]["vel_sp_curve"] = self.plotWidget_velocity.plot( name="Setpoint", pen=pen_sp_axis1) self.ad["axis1"]["vel_est_curve"] = self.plotWidget_velocity.plot( name="Estimate", pen=pen_est_axis1) self.ad["axis1"]["pos_sp_curve"] = self.plotWidget_position.plot( name="Setpoint", pen=pen_sp_axis1) self.ad["axis1"]["pos_est_curve"] = self.plotWidget_position.plot( name="Estimate", pen=pen_est_axis1) self.ad["axis1"]["current_sp_curve"] = self.plotWidget_current.plot( name="Setpoint", pen=pen_sp_axis1) self.ad["axis1"]["current_est_curve"] = self.plotWidget_current.plot( name="Estimate", pen=pen_est_axis1) self.axis0_state = None self.axis1_state = None def close_application(self): self.close() # print("Closing!!!") # try: # self.odrive_worker.stop() # except Exception as e: # print("exception stopping, closing: {}".format(e)) # sys.exit() def setup_control_axis(self, axis): size_width = 50 size_height = 70 self.ct[axis]["control_box"] = QtWidgets.QGroupBox() self.ct[axis]["control_box"].setTitle(axis) self.ct[axis]["control_box_layout"] = QtWidgets.QVBoxLayout( self.ct[axis]["control_box"]) self.ct[axis]["state_buttons_layout"] = QtWidgets.QGridLayout() self.ct[axis]["control_box_layout"].addLayout( self.ct[axis]["state_buttons_layout"]) self.ct[axis]["state_idle_pb"] = QtWidgets.QPushButton() self.ct[axis]["state_idle_pb"].clicked.connect( self.machine_state_clicked) self.ct[axis]["state_idle_pb"].setObjectName( "state_idle_pb_{}".format(axis)) self.ct[axis]["state_idle_pb"].setMinimumSize(size_width, size_height) self.ct[axis]["state_idle_pb"].setText("Idle") self.ct[axis]["state_buttons_layout"].addWidget( self.ct[axis]["state_idle_pb"], 0, 0, 1, 1) self.ct[axis]["state_start_up_sequece_pb"] = QtWidgets.QPushButton() self.ct[axis]["state_start_up_sequece_pb"].clicked.connect( self.machine_state_clicked) self.ct[axis]["state_start_up_sequece_pb"].setObjectName( "state_start_up_sequece_pb_{}".format(axis)) self.ct[axis]["state_start_up_sequece_pb"].setMinimumSize( size_width, size_height) #setMinimumSize(50,50) self.ct[axis]["state_start_up_sequece_pb"].setText("Startup\nSequence") self.ct[axis]["state_buttons_layout"].addWidget( self.ct[axis]["state_start_up_sequece_pb"], 0, 1, 1, 1) self.ct[axis][ "state_full_calibration_sequence_pb"] = QtWidgets.QPushButton() self.ct[axis]["state_full_calibration_sequence_pb"].clicked.connect( self.machine_state_clicked) self.ct[axis]["state_full_calibration_sequence_pb"].setObjectName( "state_full_calibration_sequence_pb_{}".format(axis)) self.ct[axis]["state_full_calibration_sequence_pb"].setMinimumSize( size_width, size_height) self.ct[axis]["state_full_calibration_sequence_pb"].setText( "Full\nCalibration\nSeqience") self.ct[axis]["state_buttons_layout"].addWidget( self.ct[axis]["state_full_calibration_sequence_pb"], 0, 2, 1, 1) self.ct[axis]["state_motor_calibration_pb"] = QtWidgets.QPushButton() self.ct[axis]["state_motor_calibration_pb"].clicked.connect( self.machine_state_clicked) self.ct[axis]["state_motor_calibration_pb"].setObjectName( "state_motor_calibration_pb_{}".format(axis)) self.ct[axis]["state_motor_calibration_pb"].setMinimumSize( size_width, size_height) self.ct[axis]["state_motor_calibration_pb"].setText( "Motor\nCalibration") self.ct[axis]["state_buttons_layout"].addWidget( self.ct[axis]["state_motor_calibration_pb"], 0, 3, 1, 1) self.ct[axis]["state_sensorless_control_pb"] = QtWidgets.QPushButton() self.ct[axis]["state_sensorless_control_pb"].clicked.connect( self.machine_state_clicked) self.ct[axis]["state_sensorless_control_pb"].setObjectName( "state_sensorless_control_pb_{}".format(axis)) self.ct[axis]["state_sensorless_control_pb"].setMinimumSize( size_width, size_height) self.ct[axis]["state_sensorless_control_pb"].setText( "Sensorless\nControl") self.ct[axis]["state_buttons_layout"].addWidget( self.ct[axis]["state_sensorless_control_pb"], 1, 0, 1, 1) self.ct[axis]["state_encoder_index_search_pb"] = QtWidgets.QPushButton( ) self.ct[axis]["state_encoder_index_search_pb"].clicked.connect( self.machine_state_clicked) self.ct[axis]["state_encoder_index_search_pb"].setObjectName( "state_encoder_index_search_pb_{}".format(axis)) self.ct[axis]["state_encoder_index_search_pb"].setMinimumSize( size_width, size_height) self.ct[axis]["state_encoder_index_search_pb"].setText( "Encoder\nIndex\nSearch") self.ct[axis]["state_buttons_layout"].addWidget( self.ct[axis]["state_encoder_index_search_pb"], 1, 1, 1, 1) self.ct[axis][ "state_encoder_offset_calibration_pb"] = QtWidgets.QPushButton() self.ct[axis]["state_encoder_offset_calibration_pb"].clicked.connect( self.machine_state_clicked) self.ct[axis]["state_encoder_offset_calibration_pb"].setObjectName( "state_encoder_offset_calibration_pb_{}".format(axis)) self.ct[axis]["state_encoder_offset_calibration_pb"].setMinimumSize( size_width, size_height) self.ct[axis]["state_encoder_offset_calibration_pb"].setText( "Encoder\nOffset\nCalibration") self.ct[axis]["state_buttons_layout"].addWidget( self.ct[axis]["state_encoder_offset_calibration_pb"], 1, 2, 1, 1) self.ct[axis]["state_closed_loop_control_pb"] = QtWidgets.QPushButton() self.ct[axis]["state_closed_loop_control_pb"].clicked.connect( self.machine_state_clicked) self.ct[axis]["state_closed_loop_control_pb"].setObjectName( "state_closed_loop_control_pb_{}".format(axis)) self.ct[axis]["state_closed_loop_control_pb"].setMinimumSize( size_width, size_height) self.ct[axis]["state_closed_loop_control_pb"].setText( "Closed\nLoop\nControl") self.ct[axis]["state_buttons_layout"].addWidget( self.ct[axis]["state_closed_loop_control_pb"], 1, 3, 1, 1) self.PIXMAP_FORWARD = QtGui.QPixmap("Icons/Right.png") self.PIXMAP_BACKWARD = QtGui.QPixmap("Icons/Left.png") self.PIXMAP_STOP = QtGui.QPixmap("Icons/odrive_icons_stop4.png") icon_forward = QtGui.QIcon() icon_forward.addPixmap(self.PIXMAP_FORWARD, QtGui.QIcon.Normal, QtGui.QIcon.Off) icon_backward = QtGui.QIcon() icon_backward.addPixmap(self.PIXMAP_BACKWARD, QtGui.QIcon.Normal, QtGui.QIcon.Off) icon_stop = QtGui.QIcon() icon_stop.addPixmap(self.PIXMAP_STOP, QtGui.QIcon.Normal, QtGui.QIcon.Off) self.ct[axis]["control_buttons_layout"] = QtWidgets.QGridLayout() self.ct[axis]["control_box_layout"].addLayout( self.ct[axis]["control_buttons_layout"]) self.ct[axis]["torque_label"] = QtWidgets.QRadioButton() self.ct[axis]["torque_label"].setText("Torque (Nm)") self.ct[axis]["control_buttons_layout"].addWidget( self.ct[axis]["torque_label"], 0, 0, 1, 1) self.ct[axis]["torque_sb"] = QtWidgets.QSpinBox() self.ct[axis]["torque_sb"].setMaximum(100) self.ct[axis]["control_buttons_layout"].addWidget( self.ct[axis]["torque_sb"], 0, 1, 1, 1) self.ct[axis]["torque_cw_pb"] = QtWidgets.QPushButton() self.ct[axis]["torque_ccw_pb"] = QtWidgets.QPushButton() self.ct[axis]["torque_stop_pb"] = QtWidgets.QPushButton() self.ct[axis]["torque_cw_pb"].setIcon(icon_forward) self.ct[axis]["torque_ccw_pb"].setIcon(icon_backward) self.ct[axis]["torque_stop_pb"].setIcon(icon_stop) self.ct[axis]["torque_cw_pb"].setObjectName( "torque_cw_pb_{}".format(axis)) self.ct[axis]["torque_ccw_pb"].setObjectName( "torque_ccw_pb{}".format(axis)) self.ct[axis]["torque_stop_pb"].setObjectName( "torque_stop_pb{}".format(axis)) self.ct[axis]["torque_cw_pb"].pressed.connect( self.torque_button_pressed) self.ct[axis]["torque_ccw_pb"].pressed.connect( self.torque_button_pressed) self.ct[axis]["torque_stop_pb"].pressed.connect( self.torque_button_pressed) self.ct[axis]["control_buttons_layout"].addWidget( self.ct[axis]["torque_cw_pb"], 0, 4, 1, 1) self.ct[axis]["control_buttons_layout"].addWidget( self.ct[axis]["torque_ccw_pb"], 0, 2, 1, 1) self.ct[axis]["control_buttons_layout"].addWidget( self.ct[axis]["torque_stop_pb"], 0, 3, 1, 1) self.ct[axis]["velocity_label"] = QtWidgets.QRadioButton() self.ct[axis]["velocity_label"].setText("Velocity (Turns/s)") self.ct[axis]["control_buttons_layout"].addWidget( self.ct[axis]["velocity_label"], 1, 0, 1, 1) self.ct[axis]["velocity_sb"] = QtWidgets.QSpinBox() self.ct[axis]["velocity_sb"].setMaximum(1000) self.ct[axis]["control_buttons_layout"].addWidget( self.ct[axis]["velocity_sb"], 1, 1, 1, 1) self.ct[axis]["velocity_cw_pb"] = QtWidgets.QPushButton() self.ct[axis]["velocity_ccw_pb"] = QtWidgets.QPushButton() self.ct[axis]["velocity_stop_pb"] = QtWidgets.QPushButton() self.ct[axis]["velocity_cw_pb"].setIcon(icon_forward) self.ct[axis]["velocity_ccw_pb"].setIcon(icon_backward) self.ct[axis]["velocity_stop_pb"].setIcon(icon_stop) self.ct[axis]["velocity_cw_pb"].setObjectName( "velocity_cw_pb{}".format(axis)) self.ct[axis]["velocity_ccw_pb"].setObjectName( "velocity_ccw_pb{}".format(axis)) self.ct[axis]["velocity_stop_pb"].setObjectName( "velocity_stop_pb{}".format(axis)) self.ct[axis]["velocity_cw_pb"].pressed.connect( self.velocity_button_pressed) self.ct[axis]["velocity_ccw_pb"].pressed.connect( self.velocity_button_pressed) self.ct[axis]["velocity_stop_pb"].pressed.connect( self.velocity_button_pressed) self.ct[axis]["control_buttons_layout"].addWidget( self.ct[axis]["velocity_cw_pb"], 1, 4, 1, 1) self.ct[axis]["control_buttons_layout"].addWidget( self.ct[axis]["velocity_ccw_pb"], 1, 2, 1, 1) self.ct[axis]["control_buttons_layout"].addWidget( self.ct[axis]["velocity_stop_pb"], 1, 3, 1, 1) self.ct[axis]["position_label"] = QtWidgets.QRadioButton() self.ct[axis]["position_label"].setText("Position (Turns)") self.ct[axis]["control_buttons_layout"].addWidget( self.ct[axis]["position_label"], 2, 0, 1, 1) self.ct[axis]["position_sb"] = QtWidgets.QSpinBox() self.ct[axis]["position_sb"].setMaximum(10000) self.ct[axis]["position_sb"].setMinimum(-10000) self.ct[axis]["position_sb"].setValue(0) self.ct[axis]["control_buttons_layout"].addWidget( self.ct[axis]["position_sb"], 2, 1, 1, 1) self.ct[axis]["position_go_pb"] = QtWidgets.QPushButton("GO") self.ct[axis]["position_go_pb"].setObjectName( "position_go_pb{}".format(axis)) self.ct[axis]["position_go_pb"].pressed.connect( self.position_button_pressed) # self.ct[axis]position_go_zero_pb = QtWidgets.QPushButton("Go to Zero") # self.ct[axis]position_stop_pb = QtWidgets.QPushButton() # self.ct[axis]control_buttons_layout.addWidget(self.ct[axis]position_go_zero_pb, 2, 2, 1, 1) self.ct[axis]["control_buttons_layout"].addWidget( self.ct[axis]["position_go_pb"], 2, 2, 1, 3) # self.ct[axis]control_buttons_layout.addWidget(self.ct[axis]position_stop_pb, 1, 3, 1, 1) self.ct[axis]["rb_group"] = QtWidgets.QButtonGroup( self.ct[axis]["control_buttons_layout"]) # self.ct[axis]["rb_group"].setObjectName(axis) self.ct[axis]["rb_group"].buttonClicked.connect( self.axis_controller_mode_changed) # self.ct[axis]rb_group.setObjectName(item["name"]) # bgroup.buttonClicked.connect(self.radio_button_changed) self.ct[axis]["rb_group"].addButton(self.ct[axis]["torque_label"]) self.ct[axis]["rb_group"].addButton(self.ct[axis]["velocity_label"]) self.ct[axis]["rb_group"].addButton(self.ct[axis]["position_label"]) # print(self.my_drive) def give_odrive(self, my_drive): self.my_drive = my_drive self.timer = pg.QtCore.QTimer() self.timer.timeout.connect(self.update_statuses) self.timer.start(250) self.ad["start_time"] = pg.ptime.time() self.timer_graphUpdate = pg.QtCore.QTimer() self.timer_graphUpdate.timeout.connect(self.update_graphs) self.timer_graphUpdate.start(20) def odrive_stopped(self): self.timer.stop() self.timer_graphUpdate.stop() def clearGraph_clicked(self): self.clear_axis_graph_lists("axis0") self.clear_axis_graph_lists("axis1") self.ad["start_time"] = pg.ptime.time() def axis0_graph_state_changed(self, state): if state != QtCore.Qt.Checked: self.clear_axis_graph_lists("axis0") self.axis_graph_state_changed() def axis1_graph_state_changed(self, state): if state != QtCore.Qt.Checked: self.clear_axis_graph_lists("axis1") self.axis_graph_state_changed() def axis_graph_state_changed(self): axis0_state = self.showAxis0_checkBox.isChecked() axis1_state = self.showAxis1_checkBox.isChecked() if axis0_state == False and axis1_state == False: self.timer_graphUpdate.stop() # add something to clear graphs else: if self.timer_graphUpdate.isActive() == False: self.timer_graphUpdate.start(20) self.ad["start_time"] = pg.ptime.time() def clear_axis_graph_lists(self, axis_key): self.ad[axis_key]["time_array"] = [] self.ad[axis_key]["velocity"]["set_point"] = [] self.ad[axis_key]["velocity"]["estimate"] = [] self.ad[axis_key]["current"]["set_point"] = [] self.ad[axis_key]["current"]["estimate"] = [] self.ad[axis_key]["position"]["set_point"] = [] self.ad[axis_key]["position"]["estimate"] = [] self.ad[axis_key]["vel_sp_curve"].setData([], []) self.ad[axis_key]["vel_est_curve"].setData([], []) self.ad[axis_key]["current_sp_curve"].setData([], []) self.ad[axis_key]["current_est_curve"].setData([], []) self.ad[axis_key]["pos_sp_curve"].setData([], []) self.ad[axis_key]["pos_est_curve"].setData([], []) def update_velocity_graph(self, axis_key, odrv_axis): self.ad[axis_key]["velocity"]["estimate"].append( odrv_axis.encoder.vel_estimate) self.ad[axis_key]["velocity"]["set_point"].append( odrv_axis.controller.vel_setpoint) self.ad[axis_key]["vel_sp_curve"].setData( self.ad[axis_key]["time_array"], self.ad[axis_key]["velocity"]["set_point"]) self.ad[axis_key]["vel_est_curve"].setData( self.ad[axis_key]["time_array"], self.ad[axis_key]["velocity"]["estimate"]) def update_current_graph(self, axis_key, odrv_axis): self.ad[axis_key]["current"]["estimate"].append( odrv_axis.motor.current_control.Iq_measured) self.ad[axis_key]["current"]["set_point"].append( odrv_axis.motor.current_control.Iq_setpoint) self.ad[axis_key]["current_sp_curve"].setData( self.ad[axis_key]["time_array"], self.ad[axis_key]["current"]["set_point"]) self.ad[axis_key]["current_est_curve"].setData( self.ad[axis_key]["time_array"], self.ad[axis_key]["current"]["estimate"]) def update_position_graph(self, axis_key, odrv_axis): self.ad[axis_key]["position"]["estimate"].append( odrv_axis.encoder.pos_estimate) self.ad[axis_key]["position"]["set_point"].append( odrv_axis.controller.pos_setpoint) self.ad[axis_key]["pos_sp_curve"].setData( self.ad[axis_key]["time_array"], self.ad[axis_key]["position"]["set_point"]) self.ad[axis_key]["pos_est_curve"].setData( self.ad[axis_key]["time_array"], self.ad[axis_key]["position"]["estimate"]) def update_X_range(self, axis): upper_limit = self.ad[axis]["time_array"][-1] lower_limit = self.ad[axis]["time_array"][0] delta = self.spinBox_graphTime.value() if (upper_limit - lower_limit) > delta: while ((upper_limit - lower_limit) > delta): self.ad[axis]["time_array"].pop(0) self.ad[axis]["velocity"]["estimate"].pop(0) self.ad[axis]["velocity"]["set_point"].pop(0) self.ad[axis]["current"]["estimate"].pop(0) self.ad[axis]["current"]["set_point"].pop(0) self.ad[axis]["position"]["estimate"].pop(0) self.ad[axis]["position"]["set_point"].pop(0) upper_limit = self.ad[axis]["time_array"][-1] lower_limit = self.ad[axis]["time_array"][0] def axis_controller_mode_changed(self, id): button_name = id.text() group_name = id.sender().objectName() # print("button name {}".format(button_name)) # print("group name {}".format(group_name)) if group_name == "axis0": if button_name == "Position (Turns)": self.axis_control_mode_changed(CONTROL_MODE_POSITION_CONTROL, 0) elif button_name == "Torque (Nm)": self.axis_control_mode_changed(CONTROL_MODE_TORQUE_CONTROL, 0) elif button_name == "Velocity (Turns/s)": self.axis_control_mode_changed(CONTROL_MODE_VELOCITY_CONTROL, 0) elif group_name == "axis1": if button_name == "Position (Turns)": self.axis_control_mode_changed(CONTROL_MODE_POSITION_CONTROL, 1) elif button_name == "Torque (Nm)": self.axis_control_mode_changed(CONTROL_MODE_TORQUE_CONTROL, 1) elif button_name == "Velocity (Turns/s)": self.axis_control_mode_changed(CONTROL_MODE_VELOCITY_CONTROL, 1) def axis_control_mode_changed(self, control_mode, axis): # print("changin stuff") if control_mode == CONTROL_MODE_POSITION_CONTROL: self.axis_controller_fields_position_enabled( CONTROL_MODE_POSITION_CONTROL, axis) elif control_mode == CONTROL_MODE_TORQUE_CONTROL: self.axis_controller_fields_position_enabled( CONTROL_MODE_TORQUE_CONTROL, axis) elif control_mode == CONTROL_MODE_VELOCITY_CONTROL: self.axis_controller_fields_position_enabled( CONTROL_MODE_VELOCITY_CONTROL, axis) # Updated mode inside odrive board if axis == 0: self.my_drive.axis0.controller.config.control_mode = control_mode elif axis == 1: self.my_drive.axis1.controller.config.control_mode = control_mode def axis_controller_fields_position_enabled(self, control_mode, axis_num): if axis_num == 0: axis = "axis0" else: axis = "axis1" # self.ct[axis]["torque_sb"].setDisabled(True) self.ct[axis]["torque_cw_pb"].setDisabled(True) self.ct[axis]["torque_ccw_pb"].setDisabled(True) self.ct[axis]["torque_stop_pb"].setDisabled(True) # self.ct[axis]["velocity_sb"].setDisabled(True) self.ct[axis]["velocity_cw_pb"].setDisabled(True) self.ct[axis]["velocity_ccw_pb"].setDisabled(True) self.ct[axis]["velocity_stop_pb"].setDisabled(True) # self.ct[axis]["position_sb"].setDisabled(True) self.ct[axis]["position_go_pb"].setDisabled(True) if control_mode == CONTROL_MODE_POSITION_CONTROL: # self.ct[axis]["position_sb"].setDisabled(False) self.ct[axis]["position_go_pb"].setDisabled(False) elif control_mode == CONTROL_MODE_VELOCITY_CONTROL: # self.ct[axis]["velocity_sb"].setDisabled(False) self.ct[axis]["velocity_cw_pb"].setDisabled(False) self.ct[axis]["velocity_ccw_pb"].setDisabled(False) self.ct[axis]["velocity_stop_pb"].setDisabled(False) elif control_mode == CONTROL_MODE_TORQUE_CONTROL: # self.ct[axis]["torque_sb"].setDisabled(False) self.ct[axis]["torque_cw_pb"].setDisabled(False) self.ct[axis]["torque_ccw_pb"].setDisabled(False) self.ct[axis]["torque_stop_pb"].setDisabled(False) def torque_button_pressed(self): button_name = self.sender().objectName() axis = button_name[-5:] value = self.ct[axis]["torque_sb"].value() if button_name[:-5] == "torque_ccw_pb": value = value * -1 elif button_name[:-5] == "torque_stop_pb": value = 0 # print("Button {}, Axis {}".format(button_name, axis)) exec_string = "self.my_drive.{}.controller.input_torque = {}".format( axis, value) # print(exec_string) exec(exec_string) def velocity_button_pressed(self): button_name = self.sender().objectName() axis = button_name[-5:] value = self.ct[axis]["velocity_sb"].value() if button_name[:-5] == "velocity_ccw_pb": value = value * -1 elif button_name[:-5] == "velocity_stop_pb": value = 0 # print("Button {}, Axis {}".format(button_name, axis)) exec_string = "self.my_drive.{}.controller.input_vel = {}".format( axis, value) # print(exec_string) exec(exec_string) def position_button_pressed(self): button_name = self.sender().objectName() axis = button_name[-5:] # print("Button {}, Axis {}".format(button_name, axis)) exec_string = "self.my_drive.{}.controller.input_pos = {}".format( axis, self.ct[axis]["position_sb"].value()) exec(exec_string) # print(exec_string) def update_controller_mode(self): # print("Controller mode {}".format(self.my_drive.axis0.controller.config.control_mode)) axis0_control_mode = self.my_drive.axis0.controller.config.control_mode if axis0_control_mode == CONTROL_MODE_POSITION_CONTROL: # self.axis0Position_radioButton.setChecked(True) self.ct["axis0"]["position_label"].setChecked(True) self.axis_controller_fields_position_enabled( CONTROL_MODE_POSITION_CONTROL, 0) elif axis0_control_mode == CONTROL_MODE_VELOCITY_CONTROL: self.ct["axis0"]["velocity_label"].setChecked(True) # self.axis0Current_radioButton.setChecked(True) self.axis_controller_fields_position_enabled( CONTROL_MODE_VELOCITY_CONTROL, 0) elif axis0_control_mode == CONTROL_MODE_TORQUE_CONTROL: # self.axis0Velocity_radioButton.setChecked(True) self.ct["axis0"]["torque_label"].setChecked(True) self.axis_controller_fields_position_enabled( CONTROL_MODE_TORQUE_CONTROL, 0) axis1_control_mode = self.my_drive.axis1.controller.config.control_mode if axis1_control_mode == CONTROL_MODE_POSITION_CONTROL: # self.axis1Position_radioButton.setChecked(True) self.ct["axis1"]["position_label"].setChecked(True) self.axis_controller_fields_position_enabled( CONTROL_MODE_POSITION_CONTROL, 1) elif axis1_control_mode == CONTROL_MODE_VELOCITY_CONTROL: self.ct["axis1"]["velocity_label"].setChecked(True) # self.axis1Current_radioButton.setChecked(True) self.axis_controller_fields_position_enabled( CONTROL_MODE_VELOCITY_CONTROL, 1) elif axis1_control_mode == CONTROL_MODE_TORQUE_CONTROL: # self.axis1Velocity_radioButton.setChecked(True) self.ct["axis1"]["torque_label"].setChecked(True) self.axis_controller_fields_position_enabled( CONTROL_MODE_TORQUE_CONTROL, 1) def error_checks(self): # axis0_error = hex(self.my_drive.axis0.error)[2:] # axis1_error = hex(self.my_drive.axis1.error)[2:] axis0_message = "A0: " axis1_message = "A1: " axis0_error = self.check_axis_errors( hex(self.my_drive.axis0.error)[2:]) axis1_error = self.check_axis_errors( hex(self.my_drive.axis1.error)[2:]) axis0_encoder_error = self.check_axis_encoder_errors( hex(self.my_drive.axis0.encoder.error)[2:]) axis1_encoder_error = self.check_axis_encoder_errors( hex(self.my_drive.axis1.encoder.error)[2:]) axis0_motor_error = self.check_axis_motor_errors( hex(self.my_drive.axis0.motor.error)[2:]) axis1_motor_error = self.check_axis_motor_errors( hex(self.my_drive.axis1.motor.error)[2:]) axis0_error += ", E: " axis1_error += ", E: " axis0_error += axis0_encoder_error axis1_error += axis1_encoder_error axis0_error += ", M: " axis1_error += ", M: " axis0_error += axis0_motor_error axis1_error += axis1_motor_error axis0_message += axis0_error axis1_message += axis1_error self.control_statusBar.setText(axis0_message + " " + axis1_message) def check_axis_motor_errors(self, motor_error): error_string = "" if len(motor_error) == 1: first_bit = motor_error error_string = self.check_motor_error_b1(first_bit) elif len(motor_error) == 2: first_bit = motor_error[1] second_bit = motor_error[0] error_string = self.check_motor_error_b1(first_bit) error_string += " - " error_string += self.check_motor_error_b2(second_bit) elif len(motor_error) == 3: first_bit = motor_error[2] second_bit = motor_error[1] third_bit = motor_error[0] error_string = self.check_motor_error_b1(first_bit) error_string += " - " error_string += self.check_motor_error_b2(second_bit) error_string += " - " error_string += self.check_motor_error_b3(third_bit) return error_string def check_motor_error_b1(self, bit): error_string = "NULL" if bit == "0": #ERROR_NONE = 0x00, error_string = "No errors" elif bit == "1": #ERROR_PHASE_RESISTANCE_OUT_OF_RANGE = 0x0001, error_string = "ERROR_PHASE_RESISTANCE_OUT_OF_RANGE" elif bit == "2": #ERROR_PHASE_INDUCTANCE_OUT_OF_RANGE = 0x0002, error_string = "ERROR_PHASE_INDUCTANCE_OUT_OF_RANGE" elif bit == "4": #ERROR_ADC_FAILED = 0x0004, error_string = "ERROR_ADC_FAILED" elif bit == "8": #ERROR_DRV_FAULT = 0x0008, error_string = "ERROR_DRV_FAULT" return error_string def check_motor_error_b2(self, bit): error_string = " " if bit == "1": #ERROR_CONTROL_DEADLINE_MISSED = 0x0010, error_string = "ERROR_CONTROL_DEADLINE_MISSED" elif bit == "2": #ERROR_NOT_IMPLEMENTED_MOTOR_TYPE = 0x0020, error_string = "ERROR_NOT_IMPLEMENTED_MOTOR_TYPE" elif bit == "4": #ERROR_BRAKE_CURRENT_OUT_OF_RANGE = 0x0040, error_string = "ERROR_BRAKE_CURRENT_OUT_OF_RANGE" elif bit == "8": #ERROR_MODULATION_MAGNITUDE = 0x0080, error_string = "ERROR_MODULATION_MAGNITUDE" return error_string def check_motor_error_b3(self, bit): error_string = " " if bit == "1": #ERROR_BRAKE_DEADTIME_VIOLATION = 0x0100, error_string = "ERROR_BRAKE_DEADTIME_VIOLATION" elif bit == "2": #ERROR_UNEXPECTED_TIMER_CALLBACK = 0x0200, error_string = "ERROR_UNEXPECTED_TIMER_CALLBACK" elif bit == "4": #ERROR_CURRENT_SENSE_SATURATION = 0x0400 error_string = "ERROR_CURRENT_SENSE_SATURATION" return error_string def check_axis_encoder_errors(self, encoder_error): error_string = "" if len(encoder_error) == 1: first_bit = encoder_error error_string = self.check_encoder_error_b1(first_bit) elif len(encoder_error) == 2: first_bit = encoder_error[1] second_bit = encoder_error[0] error_string = self.check_encoder_error_b1(first_bit) error_string += " - " error_string += self.check_encoder_error_b2(second_bit) return error_string def check_encoder_error_b1(self, bit): error_string = "NULL" if bit == "0": #ERROR_NONE = 0x00, error_string = "No errors" elif bit == "1": #ERROR_UNSTABLE_GAIN = 0x01, error_string = "ERROR_UNSTABLE_GAIN" elif bit == "2": #ERROR_CPR_OUT_OF_RANGE = 0x02, error_string = "ERROR_CPR_OUT_OF_RANGE" elif bit == "4": #ERROR_NO_RESPONSE = 0x04, error_string = "ERROR_NO_RESPONSE" elif bit == "8": #ERROR_UNSUPPORTED_ENCODER_MODE = 0x08, error_string = "ERROR_UNSUPPORTED_ENCODER_MODE" return error_string def check_encoder_error_b2(self, bit): error_string = " " if bit == "1": #ERROR_ILLEGAL_HALL_STATE = 0x10, error_string = "ERROR_ILLEGAL_HALL_STATE" elif bit == "2": #ERROR_INDEX_NOT_FOUND_YET = 0x20, error_string = "ERROR_INDEX_NOT_FOUND_YET" return error_string def check_axis_errors(self, axis_error): error_string = "" if len(axis_error) == 1: first_bit = axis_error error_string = self.check_axis_error_b1(first_bit) elif len(axis_error) == 2: first_bit = axis_error[1] second_bit = axis_error[0] error_string = self.check_axis_error_b1(first_bit) error_string += " - " error_string += self.check_axis_error_b2(second_bit) elif len(axis_error) == 3: first_bit = axis_error[2] second_bit = axis_error[1] third_bit = axis_error[0] error_string = self.check_axis_error_b1(first_bit) error_string += " - " error_string += self.check_axis_error_b2(second_bit) error_string += " - " error_string += self.check_axis_error_b3(third_bit) return error_string def check_axis_error_b1(self, bit): error_string = "NULL" if bit == "0": #ERROR_NONE = 0x00, error_string = "No errors" elif bit == "1": #ERROR_INVALID_STATE = 0x01, //<! an invalid state was requested error_string = "ERROR_INVALID_STATE" elif bit == "2": #ERROR_DC_BUS_UNDER_VOLTAGE = 0x02, error_string = "ERROR_DC_BUS_UNDER_VOLTAGE" elif bit == "4": #ERROR_DC_BUS_OVER_VOLTAGE = 0x04, error_string = "ERROR_DC_BUS_OVER_VOLTAGE" elif bit == "8": #ERROR_CURRENT_MEASUREMENT_TIMEOUT = 0x08, error_string = "ERROR_CURRENT_MEASUREMENT_TIMEOUT" return error_string def check_axis_error_b2(self, bit): error_string = " " if bit == "1": #ERROR_BRAKE_RESISTOR_DISARMED = 0x10, //<! the brake resistor was unexpectedly disarmed error_string = "ERROR_BRAKE_RESISTOR_DISARMED" elif bit == "2": #ERROR_MOTOR_DISARMED = 0x20, //<! the motor was unexpectedly disarmed error_string = "ERROR_MOTOR_DISARMED" elif bit == "4": #ERROR_MOTOR_FAILED = 0x40, // Go to motor.hpp for information, check odrvX.axisX.motor.error for error value error_string = "ERROR_MOTOR_FAILED" elif bit == "8": #ERROR_SENSORLESS_ESTIMATOR_FAILED = 0x80, error_string = "ERROR_SENSORLESS_ESTIMATOR_FAILED" return error_string def check_axis_error_b3(self, bit): error_string = " " if bit == "1": #ERROR_ENCODER_FAILED = 0x100, // Go to encoder.hpp for information, check odrvX.axisX.encoder.error for error value error_string = "ERROR_ENCODER_FAILED" elif bit == "2": #ERROR_CONTROLLER_FAILED = 0x200, error_string = "ERROR_CONTROLLER_FAILED" elif bit == "4": #ERROR_POS_CTRL_DURING_SENSORLESS = 0x400, error_string = "ERROR_POS_CTRL_DURING_SENSORLESS" return error_string def update_statuses(self): # pass # self.update_voltage() try: self.update_machine_state() self.update_controller_mode() self.error_checks() except Exception as e: print(e) # self.odrive_disconnected_exception() def machine_state_clicked(self): button_name = self.sender().objectName() axis_name = button_name[-5:] m_state_name = button_name[:-6] # print(axis_name) # print(m_state_name) if axis_name == "axis0": axis = self.my_drive.axis0 elif axis_name == "axis1": axis = self.my_drive.axis1 if m_state_name == "state_idle_pb": axis.requested_state = AXIS_STATE_IDLE elif m_state_name == "state_start_up_sequece_pb": axis.requested_state = AXIS_STATE_STARTUP_SEQUENCE elif m_state_name == "state_full_calibration_sequence_pb": axis.requested_state = AXIS_STATE_FULL_CALIBRATION_SEQUENCE elif m_state_name == "state_motor_calibration_pb": axis.requested_state = AXIS_STATE_MOTOR_CALIBRATION elif m_state_name == "state_sensorless_control_pb": axis.requested_state = AXIS_STATE_SENSORLESS_CONTROL elif m_state_name == "state_encoder_index_search_pb": axis.requested_state = AXIS_STATE_ENCODER_INDEX_SEARCH elif m_state_name == "state_encoder_offset_calibration_pb": axis.requested_state = AXIS_STATE_ENCODER_OFFSET_CALIBRATION elif m_state_name == "state_closed_loop_control_pb": axis.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL def update_machine_state(self): current_state = self.my_drive.axis0.current_state if self.axis0_state != current_state: self.axis0_state = current_state # print("New state axis0: {}".format(self.axis0_state)) self.update_machine_state_color(current_state, 0) current_state = self.my_drive.axis1.current_state if self.axis1_state != current_state: self.axis1_state = current_state # print("New state axis1: {}".format(self.axis1_state)) self.update_machine_state_color(current_state, 1) def update_machine_state_color(self, current_state, axis): self.clear_state_buttons(axis) if current_state == AXIS_STATE_IDLE: self.set_state_button_color(axis, "state_idle_pb") elif current_state == AXIS_STATE_STARTUP_SEQUENCE: self.set_state_button_color(axis, "state_start_up_sequece_pb") elif current_state == AXIS_STATE_FULL_CALIBRATION_SEQUENCE: self.set_state_button_color(axis, "state_full_calibration_sequence_pb") elif current_state == AXIS_STATE_MOTOR_CALIBRATION: self.set_state_button_color(axis, "state_motor_calibration_pb") elif current_state == AXIS_STATE_SENSORLESS_CONTROL: self.set_state_button_color(axis, "state_sensorless_control_pb") elif current_state == AXIS_STATE_ENCODER_INDEX_SEARCH: self.set_state_button_color(axis, "state_encoder_index_search_pb") elif current_state == AXIS_STATE_ENCODER_OFFSET_CALIBRATION: self.set_state_button_color(axis, "state_encoder_offset_calibration_pb") elif current_state == AXIS_STATE_CLOSED_LOOP_CONTROL: self.set_state_button_color(axis, "state_closed_loop_control_pb") def clear_state_buttons(self, axis_num): if axis_num == 0: axis = "axis0" else: axis = "axis1" self.ct[axis]["state_idle_pb"].setStyleSheet("") self.ct[axis]["state_start_up_sequece_pb"].setStyleSheet("") self.ct[axis]["state_full_calibration_sequence_pb"].setStyleSheet("") self.ct[axis]["state_motor_calibration_pb"].setStyleSheet("") self.ct[axis]["state_sensorless_control_pb"].setStyleSheet("") self.ct[axis]["state_encoder_index_search_pb"].setStyleSheet("") self.ct[axis]["state_encoder_offset_calibration_pb"].setStyleSheet("") self.ct[axis]["state_closed_loop_control_pb"].setStyleSheet("") def set_state_button_color(self, axis_num, button): if axis_num == 0: axis = "axis0" else: axis = "axis1" self.ct[axis][button].setStyleSheet( "background-color: rgb(246, 224, 143);") # print(self.my_drive.vbus_voltage) def update_graphs(self): delta = pg.ptime.time() - self.ad["start_time"] try: if self.showAxis0_checkBox.isChecked(): self.ad["axis0"]["time_array"].append(delta) self.update_velocity_graph("axis0", self.my_drive.axis0) self.update_position_graph("axis0", self.my_drive.axis0) self.update_current_graph("axis0", self.my_drive.axis0) self.update_X_range("axis0") if self.showAxis1_checkBox.isChecked(): self.ad["axis1"]["time_array"].append(delta) self.update_velocity_graph("axis1", self.my_drive.axis1) self.update_position_graph("axis1", self.my_drive.axis1) self.update_current_graph("axis1", self.my_drive.axis1) self.update_X_range("axis1") except Exception as e: print(e) # self.odrive_disconnected_exception() # self.centralWidget = QtWidgets.QWidget(MainWindow) # self.centralWidget.setObjectName("centralWidget") # gridLayout = QtWidgets.QGridLayout(self) # treeView = QtWidgets.QTreeView() # # self.treeView.setMinimumSize(QtCore.QSize(250, 0)) # treeView.setMaximumSize(QtCore.QSize(200,1000)) # treeView.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers) # # self.treeView.setObjectName("treeView") # self.layout.addWidget(treeView, 0, 0, 2, 1)
class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(1127, 882) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.Tabs = QtWidgets.QTabWidget(self.centralwidget) self.Tabs.setGeometry(QtCore.QRect(0, 0, 1121, 881)) self.Tabs.setObjectName("Tabs") self.tab = QtWidgets.QWidget() self.tab.setObjectName("tab") self.Culture_Dropdown = QtWidgets.QComboBox(self.tab) self.Culture_Dropdown.setGeometry(QtCore.QRect(20, 350, 69, 20)) self.Culture_Dropdown.setObjectName("Culture_Dropdown") self.Culture_Dropdown.addItem("") self.Culture_Dropdown.addItem("") self.Culture_Dropdown.addItem("") self.Culture_Dropdown.addItem("") self.Culture_Dropdown.addItem("") self.Culture_Dropdown.addItem("") self.Data_Table1 = QtWidgets.QTableWidget(self.tab) self.Data_Table1.setColumnCount(2) self.Data_Table1.setRowCount(1) #self.Data_Table1.setHorizontalHeaderLabels(["PPM" , "Time"]) self.Data_Table1.setUpdatesEnabled(True) self.Data_Table1.setGeometry(QtCore.QRect(100, 80, 431, 631)) self.Data_Table1.setObjectName("Data_Table1") #self.Data_Table1.setModel(QtGui.QStandardModel(0,2,self.tab)) #self.Data_Table1.setWordWrap(True) self.Data_Table1.resizeColumnsToContents() self.Data_Table1.setHorizontalHeaderLabels(('Time', 'CO2 (ppm)')) self.Nutrient_Levels_Textbox = QtWidgets.QLabel(self.tab) self.Nutrient_Levels_Textbox.setGeometry(QtCore.QRect(270, 60, 81, 20)) self.Nutrient_Levels_Textbox.setObjectName("Nutrient_Levels_Textbox") date_axis = DateAxisItem(orientation='bottom') self.Data_Graph = PlotWidget(self.tab, axisItems={'bottom': date_axis}) self.Data_Graph.setGeometry(QtCore.QRect(580, 180, 491, 481)) self.Data_Graph.setObjectName("Data_Graph") self.Data_Graph.setLabel('left', 'CO2 Concentration (ppm)', color='white', size=40) self.Data_Graph.setLabel('bottom', 'Seconds', color='white', size=40) #starts thread for updating the plot at same time as taking in data. thread = threading.Thread(target=self.update_plot_timer(), daemon=True) thread.start() self.Exit_Button1 = QtWidgets.QPushButton(self.tab) self.Exit_Button1.setGeometry(QtCore.QRect(1030, 0, 75, 23)) self.Exit_Button1.setObjectName("Exit_Button1") self.Tabs.addTab(self.tab, "") self.tab_2 = QtWidgets.QWidget() self.tab_2.setObjectName("tab_2") self.Nitrite_Levels_Textbox_2 = QtWidgets.QLabel(self.tab_2) self.Nitrite_Levels_Textbox_2.setGeometry( QtCore.QRect(540, 710, 61, 21)) self.Nitrite_Levels_Textbox_2.setObjectName("Nitrite_Levels_Textbox_2") self.Culture2_Checkbox2_2 = QtWidgets.QCheckBox(self.tab_2) self.Culture2_Checkbox2_2.setGeometry(QtCore.QRect(240, 610, 70, 17)) self.Culture2_Checkbox2_2.setObjectName("Culture2_Checkbox2_2") self.Culture4_Checkbox2_2 = QtWidgets.QCheckBox(self.tab_2) self.Culture4_Checkbox2_2.setGeometry(QtCore.QRect(340, 580, 70, 17)) self.Culture4_Checkbox2_2.setObjectName("Culture4_Checkbox2_2") self.Text_box1_2 = QtWidgets.QTextEdit(self.tab_2) self.Text_box1_2.setGeometry(QtCore.QRect(520, 130, 111, 31)) self.Text_box1_2.setObjectName("Text_box1_2") self.Culture1_Checkbox2_2 = QtWidgets.QCheckBox(self.tab_2) self.Culture1_Checkbox2_2.setGeometry(QtCore.QRect(240, 580, 70, 17)) self.Culture1_Checkbox2_2.setObjectName("Culture1_Checkbox2_2") self.Glucose_Textbox_2 = QtWidgets.QLabel(self.tab_2) self.Glucose_Textbox_2.setGeometry(QtCore.QRect(300, 90, 51, 21)) self.Glucose_Textbox_2.setObjectName("Glucose_Textbox_2") self.Culture6_Checkbox2_2 = QtWidgets.QCheckBox(self.tab_2) self.Culture6_Checkbox2_2.setGeometry(QtCore.QRect(340, 640, 70, 17)) self.Culture6_Checkbox2_2.setObjectName("Culture6_Checkbox2_2") self.Culture4_Checkbox1_2 = QtWidgets.QCheckBox(self.tab_2) self.Culture4_Checkbox1_2.setGeometry(QtCore.QRect(340, 170, 70, 17)) self.Culture4_Checkbox1_2.setObjectName("Culture4_Checkbox1_2") self.Data_table1_2 = QtWidgets.QTableWidget(self.tab_2) self.Data_table1_2.setGeometry(QtCore.QRect(500, 170, 151, 141)) self.Data_table1_2.setObjectName("Data_table1_2") self.Data_table1_2.setColumnCount(2) self.Data_table1_2.setRowCount(1) self.Text_box2_2 = QtWidgets.QTextEdit(self.tab_2) self.Text_box2_2.setGeometry(QtCore.QRect(520, 520, 111, 31)) self.Text_box2_2.setObjectName("Text_box2_2") self.Culture5_Checkbox1_2 = QtWidgets.QCheckBox(self.tab_2) self.Culture5_Checkbox1_2.setGeometry(QtCore.QRect(340, 200, 70, 17)) self.Culture5_Checkbox1_2.setObjectName("Culture5_Checkbox1_2") self.Culture3_Checkbox1_2 = QtWidgets.QCheckBox(self.tab_2) self.Culture3_Checkbox1_2.setGeometry(QtCore.QRect(240, 230, 70, 17)) self.Culture3_Checkbox1_2.setObjectName("Culture3_Checkbox1_2") self.Culture6_Checkbox1_2 = QtWidgets.QCheckBox(self.tab_2) self.Culture6_Checkbox1_2.setGeometry(QtCore.QRect(340, 230, 70, 17)) self.Culture6_Checkbox1_2.setObjectName("Culture6_Checkbox1_2") self.Deposit_Button1_2 = QtWidgets.QPushButton(self.tab_2) self.Deposit_Button1_2.setGeometry(QtCore.QRect(640, 130, 75, 23)) self.Deposit_Button1_2.setObjectName("Deposit_Button1_2") self.Culture2_Checkbox1_2 = QtWidgets.QCheckBox(self.tab_2) self.Culture2_Checkbox1_2.setGeometry(QtCore.QRect(240, 200, 70, 17)) self.Culture2_Checkbox1_2.setObjectName("Culture2_Checkbox1_2") self.Nitrite_Textbox_2 = QtWidgets.QLabel(self.tab_2) self.Nitrite_Textbox_2.setGeometry(QtCore.QRect(300, 500, 51, 21)) self.Nitrite_Textbox_2.setObjectName("Nitrite_Textbox_2") self.Culture5_Checkbox2_2 = QtWidgets.QCheckBox(self.tab_2) self.Culture5_Checkbox2_2.setGeometry(QtCore.QRect(340, 610, 70, 17)) self.Culture5_Checkbox2_2.setObjectName("Culture5_Checkbox2_2") self.Culture3_Checkbox2_2 = QtWidgets.QCheckBox(self.tab_2) self.Culture3_Checkbox2_2.setGeometry(QtCore.QRect(240, 640, 70, 17)) self.Culture3_Checkbox2_2.setObjectName("Culture3_Checkbox2_2") self.Deposit_Button2_2 = QtWidgets.QPushButton(self.tab_2) self.Deposit_Button2_2.setGeometry(QtCore.QRect(640, 520, 75, 23)) self.Deposit_Button2_2.setObjectName("Deposit_Button2_2") self.Glucose_Levels_Textbox_2 = QtWidgets.QLabel(self.tab_2) self.Glucose_Levels_Textbox_2.setGeometry( QtCore.QRect(540, 320, 71, 21)) self.Glucose_Levels_Textbox_2.setObjectName("Glucose_Levels_Textbox_2") self.Culture1_Checkbox1_2 = QtWidgets.QCheckBox(self.tab_2) self.Culture1_Checkbox1_2.setGeometry(QtCore.QRect(240, 170, 70, 17)) self.Culture1_Checkbox1_2.setObjectName("Culture1_Checkbox1_2") self.Data_table2_2 = QtWidgets.QTableWidget(self.tab_2) self.Data_table2_2.setGeometry(QtCore.QRect(500, 560, 151, 131)) self.Data_table2_2.setObjectName("Data_table2_2") self.Data_table2_2.setColumnCount(2) self.Data_table2_2.setRowCount(1) self.Exit_Button2 = QtWidgets.QPushButton(self.tab_2) self.Exit_Button2.setGeometry(QtCore.QRect(1030, 0, 75, 23)) self.Exit_Button2.setObjectName("Exit_Button2") self.Open_button1 = QtWidgets.QPushButton(self.tab_2) self.Open_button1.setGeometry(QtCore.QRect(230, 300, 75, 23)) self.Open_button1.setObjectName("Open_button1") self.Close_button1 = QtWidgets.QPushButton(self.tab_2) self.Close_button1.setGeometry(QtCore.QRect(340, 300, 75, 23)) self.Close_button1.setObjectName("Close_button1") self.Open_button2 = QtWidgets.QPushButton(self.tab_2) self.Open_button2.setGeometry(QtCore.QRect(230, 710, 75, 23)) self.Open_button2.setObjectName("Open_button2") self.Close_button2 = QtWidgets.QPushButton(self.tab_2) self.Close_button2.setGeometry(QtCore.QRect(340, 710, 75, 23)) self.Close_button2.setObjectName("Close_button2") self.Culture7_Checkbox1_2 = QtWidgets.QCheckBox(self.tab_2) self.Culture7_Checkbox1_2.setGeometry(QtCore.QRect(240, 260, 70, 17)) self.Culture7_Checkbox1_2.setObjectName("Culture7_Checkbox1_2") self.Culture8_Checkbox1_2 = QtWidgets.QCheckBox(self.tab_2) self.Culture8_Checkbox1_2.setGeometry(QtCore.QRect(340, 260, 70, 17)) self.Culture8_Checkbox1_2.setObjectName("Culture8_Checkbox1_2") self.Culture7_Checkbox2_2 = QtWidgets.QCheckBox(self.tab_2) self.Culture7_Checkbox2_2.setGeometry(QtCore.QRect(240, 670, 70, 17)) self.Culture7_Checkbox2_2.setObjectName("Culture7_Checkbox2_2") self.Culture8_Checkbox2_2 = QtWidgets.QCheckBox(self.tab_2) self.Culture8_Checkbox2_2.setGeometry(QtCore.QRect(340, 670, 70, 17)) self.Culture8_Checkbox2_2.setObjectName("Culture8_Checkbox2_2") self.Tabs.addTab(self.tab_2, "") MainWindow.setCentralWidget(self.centralwidget) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 1127, 21)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.actionNew_File = QtWidgets.QAction(MainWindow) self.actionNew_File.setObjectName("actionNew_File") self.actionOpen_File = QtWidgets.QAction(MainWindow) self.actionOpen_File.setObjectName("actionOpen_File") self.actionSave_File = QtWidgets.QAction(MainWindow) self.actionSave_File.setObjectName("actionSave_File") self.actionExit = QtWidgets.QAction(MainWindow) self.actionExit.setObjectName("actionExit") #gives buttons functionality self.Exit_Button1.clicked.connect(self.exitButton) self.Exit_Button2.clicked.connect(self.exitButton) self.Deposit_Button1_2.clicked.connect(self.update_relay) self.Deposit_Button2_2.clicked.connect(self.update_relay_1) self.Close_button1.clicked.connect(self.close_relays) self.Close_button2.clicked.connect(self.close_relays) self.Open_button1.clicked.connect(self.open_relays) self.Open_button2.clicked.connect(self.open_relays) self.retranslateUi(MainWindow) self.Tabs.setCurrentIndex(0) QtCore.QMetaObject.connectSlotsByName(MainWindow) #updates both the graph and the table with data from the database. def update(self): updateXList = [] updateYList = [] updateTList = [] time_init = 0 timebetweenreads = 6 #Grabs data from current experiment from a specific vessel #Replace 'Vessel 1'with user input from dropdown menu you can use an array query = { '$and': [{ 'Vessel': 'Vessel 1' }, { 'Experiment': paramDict.get('Experiment') }] } #Grabs data from current experiment from all vessels queryAllVes = {'Experiment': paramDict.get('Experiment')} db_vesData = collection1.find(query) db_allData = collection1.find(queryAllVes) #model = QtGui.QStandardItemModel(self.Data_Table1) # analyte = USERINPUT FROM TAB for x in db_data: tableData = [] row = 0 updateXList.append(x[analyte]) updateYList.append(x['ComputerTime']) updateTList.append(x['Time']) # print(updateYList) #col = 0 if self.Data_Table1.rowCount() < len(updateXList): self.Data_Table1.insertRow(row) for a, b in zip(updateXList, updateTList): col = 0 cellData = QTableWidgetItem(str(b)) cellData2 = QTableWidgetItem(str(a)) self.Data_Table1.setItem(row, col, cellData) col += 1 self.Data_Table1.setItem(row, col, cellData2) row += 1 self.Data_Table1.insertRow(row) row += 1 #updateYList.append(x['Time']) #timeList.append(time_init) #time_init = time_init + timebetweenreads #updateYList = np.arange(0, 6*len(updateXList), 6) self.Data_Graph.plot(updateYList, updateXList, title="Nutrient Level Data") #controls the relay through first set of checkboxes def update_relay(self): ser = serial.Serial(relayCOM) boxes = [ self.Culture1_Checkbox1_2, self.Culture2_Checkbox1_2, self.Culture3_Checkbox1_2, self.Culture4_Checkbox1_2, self.Culture5_Checkbox1_2, self.Culture6_Checkbox1_2, self.Culture7_Checkbox1_2, self.Culture8_Checkbox1_2 ] checkedBoxes = [] x = 0 for i in boxes: if i.isChecked(): checkedBoxes.append(x) x = x + 1 for i in checkedBoxes: #ser.close() #ser = serial.Serial(relayCOM) ser.write(("relay on " + str(i) + "\r").encode("ascii")) #turns off all relays def close_relays(self): ser = serial.Serial(relayCOM) ser.write(("relay writeall" + " " + "00" + "\r").encode("ascii")) #turns on all relays def open_relays(self): ser = serial.Serial(relayCOM) ser.write(("relay writeall" + " " + "ff" + "\r").encode("ascii")) #controls relay through second set of checkboxes. def update_relay_1(self): ser = serial.Serial(relayCOM) boxes = [ self.Culture1_Checkbox2_2, self.Culture2_Checkbox2_2, self.Culture3_Checkbox2_2, self.Culture4_Checkbox2_2, self.Culture5_Checkbox2_2, self.Culture6_Checkbox2_2, self.Culture7_Checkbox2_2, self.Culture8_Checkbox2_2 ] checkedBoxes = [] x = 0 for i in boxes: if i.isChecked(): checkedBoxes.append(x) else: x = x + 1 for i in checkedBoxes: ser.close() ser = serial.Serial(relayCOM) ser.write(("relay on " + str(i) + "\r").encode("ascii")) #timer that updates plot def update_plot_timer(self): timer1 = QTimer() timer1.timeout.connect(self.update) timer1.setInterval(6000) timer1.start() timers1.append(timer1) #gives exit button functionality def exitButton(self): sys.exit() def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) self.Culture_Dropdown.setItemText(0, _translate("MainWindow", "Culture1")) self.Culture_Dropdown.setItemText(1, _translate("MainWindow", "Culture2")) self.Culture_Dropdown.setItemText(2, _translate("MainWindow", "Culture3")) self.Culture_Dropdown.setItemText(3, _translate("MainWindow", "Culture4")) self.Culture_Dropdown.setItemText(4, _translate("MainWindow", "Culture5")) self.Culture_Dropdown.setItemText(5, _translate("MainWindow", "Culture6")) self.Nutrient_Levels_Textbox.setText( _translate("MainWindow", "Nutrient Levels")) self.Exit_Button1.setText(_translate("MainWindow", "Exit")) self.Tabs.setTabText(self.Tabs.indexOf(self.tab), _translate("MainWindow", "Nutrient Sensor Data")) self.Nitrite_Levels_Textbox_2.setText( _translate("MainWindow", "Nitrite Levels")) self.Culture2_Checkbox2_2.setText(_translate("MainWindow", "Culture 2")) self.Culture4_Checkbox2_2.setText(_translate("MainWindow", "Culture 4")) self.Text_box1_2.setHtml( _translate( "MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n" "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:\'MS Shell Dlg 2\';\"><br /></p></body></html>" )) self.Culture1_Checkbox2_2.setText(_translate("MainWindow", "Culture 1")) self.Glucose_Textbox_2.setText(_translate("MainWindow", "Glucose")) self.Culture6_Checkbox2_2.setText(_translate("MainWindow", "Culture 6")) self.Culture4_Checkbox1_2.setText(_translate("MainWindow", "Culture 4")) self.Culture5_Checkbox1_2.setText(_translate("MainWindow", "Culture 5")) self.Culture3_Checkbox1_2.setText(_translate("MainWindow", "Culture 3")) self.Culture6_Checkbox1_2.setText(_translate("MainWindow", "Culture 6")) self.Deposit_Button1_2.setText(_translate("MainWindow", "Deposit")) self.Culture2_Checkbox1_2.setText(_translate("MainWindow", "Culture 2")) self.Nitrite_Textbox_2.setText(_translate("MainWindow", "Nitrite")) self.Culture5_Checkbox2_2.setText(_translate("MainWindow", "Culture 5")) self.Culture3_Checkbox2_2.setText(_translate("MainWindow", "Culture 3")) self.Deposit_Button2_2.setText(_translate("MainWindow", "Deposit")) self.Glucose_Levels_Textbox_2.setText( _translate("MainWindow", "Glucose Levels")) self.Culture1_Checkbox1_2.setText(_translate("MainWindow", "Culture 1")) self.Exit_Button2.setText(_translate("MainWindow", "Exit")) self.Open_button1.setText(_translate("MainWindow", "Open All")) self.Close_button1.setText(_translate("MainWindow", "Close All")) self.Open_button2.setText(_translate("MainWindow", "Open All")) self.Close_button2.setText(_translate("MainWindow", "Close All")) self.Culture7_Checkbox1_2.setText(_translate("MainWindow", "Culture 7")) self.Culture8_Checkbox1_2.setText(_translate("MainWindow", "Culture 8")) self.Culture7_Checkbox2_2.setText(_translate("MainWindow", "Culture 7")) self.Culture8_Checkbox2_2.setText(_translate("MainWindow", "Culture 8")) self.Tabs.setTabText(self.Tabs.indexOf(self.tab_2), _translate("MainWindow", "Nutrient Depositing")) self.actionNew_File.setText(_translate("MainWindow", "New File")) self.actionOpen_File.setText(_translate("MainWindow", "Open File")) self.actionSave_File.setText(_translate("MainWindow", "Save File")) self.actionExit.setText(_translate("MainWindow", "Exit"))
class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(1069, 868) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.label_9 = QtWidgets.QLabel(self.centralwidget) self.label_9.setGeometry(QtCore.QRect(170, 20, 61, 51)) self.label_9.setStyleSheet("image: url(:/Arrow/symbols/arrow_up.png);") self.label_9.setText("") self.label_10 = QtWidgets.QLabel(self.centralwidget) self.label_10.setGeometry(QtCore.QRect(160, 500, 81, 51)) self.label_10.setStyleSheet("image: url(:/Arrow/symbols/arrow.png);") self.label_10.setText("") self.label_11 = QtWidgets.QLabel(self.centralwidget) self.label_11.setGeometry(QtCore.QRect(-4, 380, 51, 101)) self.label_11.setStyleSheet("image: url(:/Arrow/symbols/arrow_left.png);") self.label_11.setText("") self.label_12 = QtWidgets.QLabel(self.centralwidget) self.label_12.setGeometry(QtCore.QRect(130, 40, 141, 271)) self.label_12.setStyleSheet("image: url(:/Lines/symbols/vertical.png);") self.label_12.setText("") self.label_14 = QtWidgets.QLabel(self.centralwidget) self.label_14.setGeometry(QtCore.QRect(130, 260, 141, 271)) self.label_14.setStyleSheet("image: url(:/Lines/symbols/vertical.png);") self.label_14.setText("") self.label_2 = QtWidgets.QLabel(self.centralwidget) self.label_2.setGeometry(QtCore.QRect(180, 310, 121, 191)) self.label_2.setStyleSheet("image: url(:/Lines/symbols/horizontalbetter.png);") self.label_2.setText("") self.label_16 = QtWidgets.QLabel(self.centralwidget) self.label_16.setGeometry(QtCore.QRect(180, 190, 121, 191)) self.label_16.setStyleSheet("image: url(:/Lines/symbols/horizontalbetter.png);") self.label_16.setText("") self.label_17 = QtWidgets.QLabel(self.centralwidget) self.label_17.setGeometry(QtCore.QRect(30, 260, 171, 341)) self.label_17.setStyleSheet("image: url(:/Lines/symbols/horizontalnew.png);") self.label_17.setText("") self.label_18 = QtWidgets.QLabel(self.centralwidget) self.label_18.setGeometry(QtCore.QRect(120, 60, 171, 331)) self.label_18.setStyleSheet("image: url(:/Lines/symbols/horizontalnew.png);") self.label_18.setText("") self.label_19 = QtWidgets.QLabel(self.centralwidget) self.label_19.setGeometry(QtCore.QRect(110, -40, 171, 331)) self.label_19.setStyleSheet("image: url(:/Lines/symbols/horizontalnew.png);") self.label_19.setText("") self.label = QtWidgets.QLabel(self.centralwidget) self.label.setGeometry(QtCore.QRect(280, 230, 61, 111)) self.label.setStyleSheet("image: url(:/Sensors/symbols/thermocouple.png);") self.label.setText("") self.label_3 = QtWidgets.QLabel(self.centralwidget) self.label_3.setGeometry(QtCore.QRect(280, 350, 61, 111)) self.label_3.setStyleSheet("image: url(:/Sensors/symbols/thermocouple.png);") self.label_3.setText("") self.label_4 = QtWidgets.QLabel(self.centralwidget) self.label_4.setGeometry(QtCore.QRect(270, 200, 71, 51)) self.label_4.setStyleSheet("image: url(:/Valve/symbols/open valve.png);") self.label_4.setText("") self.label_5 = QtWidgets.QLabel(self.centralwidget) self.label_5.setGeometry(QtCore.QRect(70, 190, 71, 61)) self.label_5.setStyleSheet("image: url(:/Valve/symbols/relief valve.png);") self.label_5.setText("") self.label_6 = QtWidgets.QLabel(self.centralwidget) self.label_6.setGeometry(QtCore.QRect(70, 70, 71, 101)) self.label_6.setStyleSheet("image: url(:/Gauge/symbols/gauge.png);") self.label_6.setText("") self.label_7 = QtWidgets.QLabel(self.centralwidget) self.label_7.setGeometry(QtCore.QRect(260, 60, 81, 121)) self.label_7.setStyleSheet("image: url(:/Sensors/symbols/pressure transmitter.png);") self.label_7.setText("") self.label_8 = QtWidgets.QLabel(self.centralwidget) self.label_8.setGeometry(QtCore.QRect(150, 260, 101, 171)) self.label_8.setStyleSheet("image: url(:/Tank/symbols/vessel.png);") self.label_8.setText("") self.label_13 = QtWidgets.QLabel(self.centralwidget) self.label_13.setGeometry(QtCore.QRect(-10, 430, 241, 101)) self.label_13.setStyleSheet("image: url(:/Lines/symbols/verticalbetter1.png);") self.label_13.setText("") self.label_15 = QtWidgets.QLabel(self.centralwidget) self.label_15.setGeometry(QtCore.QRect(70, 440, 81, 121)) self.label_15.setStyleSheet("image: url(:/Sensors/symbols/pressure transmitter.png);") self.label_15.setText("") self.label_20 = QtWidgets.QLabel(self.centralwidget) self.label_20.setGeometry(QtCore.QRect(270, 170, 91, 21)) self.label_20.setStyleSheet("color: rgb(0, 0, 0);") self.label_21 = QtWidgets.QLabel(self.centralwidget) self.label_21.setGeometry(QtCore.QRect(80, 170, 81, 21)) self.label_21.setStyleSheet("color: rgb(0, 0, 0);") self.label_22 = QtWidgets.QLabel(self.centralwidget) self.label_22.setGeometry(QtCore.QRect(90, 60, 91, 21)) self.label_22.setStyleSheet("color: rgb(0, 0, 0);") self.label_23 = QtWidgets.QLabel(self.centralwidget) self.label_23.setGeometry(QtCore.QRect(260, 60, 91, 21)) self.label_23.setStyleSheet("color: rgb(0, 0, 0);") self.label_24 = QtWidgets.QLabel(self.centralwidget) self.label_24.setGeometry(QtCore.QRect(270, 310, 101, 21)) self.label_24.setStyleSheet("color: rgb(0, 0, 0);") self.label_25 = QtWidgets.QLabel(self.centralwidget) self.label_25.setGeometry(QtCore.QRect(270, 430, 101, 21)) self.label_25.setStyleSheet("color: rgb(0, 0, 0);") self.label_26 = QtWidgets.QLabel(self.centralwidget) self.label_26.setGeometry(QtCore.QRect(70, 540, 91, 21)) self.label_26.setStyleSheet("color: rgb(0, 0, 0);") self.label_27 = QtWidgets.QLabel(self.centralwidget) self.label_27.setGeometry(QtCore.QRect(190, 330, 31, 21)) self.label_27.setStyleSheet("color: rgb(0, 0, 0);") self.lineEdit = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit.setGeometry(QtCore.QRect(340, 110, 51, 21)) self.label_28 = QtWidgets.QLabel(self.centralwidget) self.label_28.setGeometry(QtCore.QRect(396, 100, 61, 41)) self.label_28.setStyleSheet("color: rgb(0, 0, 0);") self.label_29 = QtWidgets.QLabel(self.centralwidget) self.label_29.setGeometry(QtCore.QRect(140, 550, 51, 41)) self.label_29.setStyleSheet("color: rgb(0, 0, 0);") self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit_2.setGeometry(QtCore.QRect(80, 560, 51, 21)) self.lineEdit_3 = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit_3.setGeometry(QtCore.QRect(290, 330, 51, 21)) self.lineEdit_4 = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit_4.setGeometry(QtCore.QRect(290, 450, 51, 21)) self.label_30 = QtWidgets.QLabel(self.centralwidget) self.label_30.setGeometry(QtCore.QRect(350, 320, 61, 41)) self.label_30.setStyleSheet("color: rgb(0, 0, 0);") self.label_31 = QtWidgets.QLabel(self.centralwidget) self.label_31.setGeometry(QtCore.QRect(350, 440, 61, 41)) self.label_31.setStyleSheet("color: rgb(0, 0, 0);") self.label_32 = QtWidgets.QLabel(self.centralwidget) self.label_32.setGeometry(QtCore.QRect(100, 550, 41, 41)) self.label_32.setStyleSheet("color: rgb(0, 0, 0);") self.label_33 = QtWidgets.QLabel(self.centralwidget) self.label_33.setGeometry(QtCore.QRect(300, 320, 41, 41)) self.label_33.setStyleSheet("color: rgb(0, 0, 0);") self.label_34 = QtWidgets.QLabel(self.centralwidget) self.label_34.setGeometry(QtCore.QRect(300, 440, 41, 41)) self.label_34.setStyleSheet("color: rgb(0, 0, 0);") self.label_35 = QtWidgets.QLabel(self.centralwidget) self.label_35.setGeometry(QtCore.QRect(360, 100, 41, 41)) self.label_35.setStyleSheet("color: rgb(0, 0, 0);") self.progressBar = QtWidgets.QProgressBar(self.centralwidget) self.progressBar.setGeometry(QtCore.QRect(120, 280, 31, 131)) self.progressBar.setProperty("value", 70) self.progressBar.setOrientation(QtCore.Qt.Vertical) self.lineEdit_5 = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit_5.setGeometry(QtCore.QRect(40, 330, 51, 21)) self.label_36 = QtWidgets.QLabel(self.centralwidget) self.label_36.setGeometry(QtCore.QRect(100, 320, 51, 41)) self.label_36.setStyleSheet("color: rgb(0, 0, 0);") self.label_37 = QtWidgets.QLabel(self.centralwidget) self.label_37.setGeometry(QtCore.QRect(60, 320, 41, 41)) self.label_37.setStyleSheet("color: rgb(0, 0, 0);") self.widget = PlotWidget(self.centralwidget) self.widget.setLabel('left', 'Pressure [psi]') self.widget.setTitle('PT-OX-VENT') self.widget.setLabel('bottom', 'Time [psi]') self.widget.setXRange(0,100) self.widget.setYRange(0,500) self.widget.setGeometry(QtCore.QRect(490, 30, 491, 151)) self.widget_2 = PlotWidget(self.centralwidget) self.widget_2.setLabel('bottom', 'Time [sec]') self.widget_2.setLabel('left', 'Pressure [psi]') self.widget_2.setTitle('PT-OX-TANK') self.widget_2.setXRange(0,100) self.widget_2.setYRange(0,500) self.widget_2.setGeometry(QtCore.QRect(490, 190, 491, 151)) self.widget_3 = PlotWidget(self.centralwidget) self.widget_3.setLabel('bottom', 'Time [s]') self.widget_3.setLabel('left', 'Temp [K]') self.widget_3.setTitle('TC-OX-TANK-1') self.widget_3.setXRange(0,100) self.widget_3.setYRange(0,4000) self.widget_3.setGeometry(QtCore.QRect(490, 350, 491, 151)) self.widget_4 = PlotWidget(self.centralwidget) self.widget_4.setLabel('bottom', 'Time [s]') self.widget_4.setLabel('left', 'Temp [K]') self.widget_4.setTitle('TC-OX-TANK-2') self.widget_4.setXRange(0,100) self.widget_4.setYRange(0,4000) self.widget_4.setGeometry(QtCore.QRect(490, 510, 491, 151)) self.widget_5 = PlotWidget(self.centralwidget) self.widget_5.setLabel('bottom', 'Time [s]') self.widget_5.setLabel('left', 'Mass [lb]') self.widget_5.setTitle('LOX Fuel Mass') self.widget_5.setXRange(0,100) self.widget_5.setYRange(0,500) self.widget_5.setGeometry(QtCore.QRect(490, 670, 491, 151)) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 1069, 22)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle("Liquid Oxygen Tank Monitor") self.label_20.setText(_translate("MainWindow", "BLEED-OX")) self.label_21.setText(_translate("MainWindow", "VENT-OX")) self.label_22.setText(_translate("MainWindow", "G-OX")) self.label_23.setText(_translate("MainWindow", "PT-OX-VENT")) self.label_24.setText(_translate("MainWindow", "TC-OX-TANK-1")) self.label_25.setText(_translate("MainWindow", "TC-OX-TANK-2")) self.label_26.setText(_translate("MainWindow", "PT-OX-TANK")) self.label_27.setText(_translate("MainWindow", "LOX")) self.label_28.setText(_translate("MainWindow", "psi")) self.label_29.setText(_translate("MainWindow", "psi")) self.label_30.setText(_translate("MainWindow", "K°")) self.label_31.setText(_translate("MainWindow", "K°")) self.label_32.setText(_translate("MainWindow", "491")) self.label_33.setText(_translate("MainWindow", "2672")) self.label_34.setText(_translate("MainWindow", "2193")) self.label_35.setText(_translate("MainWindow", "283")) self.label_36.setText(_translate("MainWindow", "lb")) self.label_37.setText(_translate("MainWindow", "384"))
class ComplicatedTestResultsDialog(QMainWindow): def __init__(self, parent=None, methods=None, vertices_amounts=None, samples_amount=None, name_1=None, name_2=None): super(ComplicatedTestResultsDialog, self).__init__(parent) self.parent_window = parent self.setWindowTitle("Grismo - Wyniki dla testu wpływu liczby " + name_1) self.setMinimumWidth(630) self.setMinimumHeight(800) self.setMaximumHeight(900) self.methods = methods self.results_count = 0 self.start_vertices = vertices_amounts[0] self.all_vertices_amount = len(vertices_amounts) self.samples_amount = samples_amount # store all results to calculate means self.all_results = [] central = QWidget() self.setCentralWidget(central) central_layout = QVBoxLayout() central.setLayout(central_layout) # plot box plot_label = QLabel("Wykres dla wszystkich testów:") central_layout.addWidget(plot_label) self.plot_log_mode = False self.results_plot = PlotWidget() self.results_plot.setLogMode(False, self.plot_log_mode) self.results_plot.setBackground('w') self.results_plot.setTitle("Badanie wpływu liczby " + name_1 + " na czas testu") self.results_plot.setLabel('left', 'Czas obliczeń [s]', color='k', size=10) self.results_plot.setLabel('bottom', 'Liczba ' + name_1, color='k', size=10) self.results_plot.setXRange(self.start_vertices, vertices_amounts[-1]) self.results_plot.setMaximumWidth(600) self.results_plot.showGrid(y=True) central_layout.addWidget(self.results_plot) switch_plot_log_button = QPushButton("Zmień skalę osi Y (logarytmiczna/liniowa)") switch_plot_log_button.setCheckable(False) switch_plot_log_button.clicked.connect(self.switch_plot_log) central_layout.addWidget(switch_plot_log_button) # prepare plot lines self.plot_data = [] method_colors = ['k', 'b', 'g', 'r', 'y'] self.results_plot.plot([], [], name="") self.results_plot.addLegend() for method_index in range(len(self.methods)): method_name = self.methods[method_index] method_color = method_colors[method_index] pen = mkPen(color=method_color, width=2) self.plot_data.append(self.results_plot.plot([], [], name=method_name, pen=pen, symbol='+', symbolSize=10, symbolBrush=method_color)) self.results_plot.addLegend() # tables box tables_box = QScrollArea(self) tables_box.setWidgetResizable(True) tables_box_content = QWidget(tables_box) tables_box_layout = QVBoxLayout(tables_box_content) tables_box_content.setLayout(tables_box_layout) tables_box.setWidget(tables_box_content) central_layout.addWidget(tables_box) # for each vertices_amount prepare table: label -> table -> label -> progress_bar self.results_tables = [] self.results_progress_bars = [] bold_font = QFont() bold_font.setBold(True) for i in vertices_amounts: vertices_label = QLabel("Wyniki dla grafów o " + str(i) + " " + name_2 + ":") vertices_label.setFont(bold_font) results_table = QTableWidget() results_table.setRowCount(len(methods)) results_table.setColumnCount(4) results_table.setColumnWidth(1, 150) results_table.setColumnWidth(2, 150) results_table.setMinimumHeight((len(methods) + 1) * 30) results_table.setHorizontalHeaderLabels(["Metoda", "Wyniki pozytywne", "Wyniki negatywne", "Średni czas [s]"]) progress_label = QLabel("Postęp:") results_progress_bar = QProgressBar() results_progress_bar.setValue(0) self.results_tables.append(results_table) self.results_progress_bars.append(results_progress_bar) tables_box_layout.addWidget(vertices_label) tables_box_layout.addWidget(results_table) tables_box_layout.addWidget(progress_label) tables_box_layout.addWidget(results_progress_bar) self.all_results.append([]) for method_index in range(len(methods)): method_title = methods[method_index] results_table.setItem(method_index, 0, QTableWidgetItem(method_title)) self.all_results[-1].append([]) def add_result(self, result, vertices_amount, sample_number): # result: [method, decision, time] # vertices table index table_index = vertices_amount - self.start_vertices # method index method_index = self.methods.index(result[0]) # add result to all stored results self.all_results[table_index][method_index].append(result) # positive and negatives # firstly extract 2nd column from results matrix new_positives = sum([row[1] for row in self.all_results[table_index][method_index]]) new_negatives = len(self.all_results[table_index][method_index]) - new_positives self.results_tables[table_index].setItem(method_index, 1, QTableWidgetItem(str(new_positives))) self.results_tables[table_index].setItem(method_index, 2, QTableWidgetItem(str(new_negatives))) # mean new_mean = mean([row[2] for row in self.all_results[table_index][method_index]]) self.results_tables[table_index].setItem(method_index, 3, QTableWidgetItem(str(new_mean))) # progress_bar self.results_progress_bars[table_index].setValue(sample_number / self.samples_amount * 100) self.results_count = self.results_count + 1 # update plot self.update_plot() def update_plot(self): for method_index in range(len(self.methods)): # for this method find all mean values x = [] y = [] for vertices_index in range(self.all_vertices_amount): vertices_amount = vertices_index + self.start_vertices if len(self.all_results[vertices_index][method_index]): x.append(vertices_amount) y.append(mean([row[2] for row in self.all_results[vertices_index][method_index]])) self.plot_data[method_index].setData(x, y) def switch_plot_log(self): self.plot_log_mode = not self.plot_log_mode self.results_plot.setLogMode(False, self.plot_log_mode) def closeEvent(self, event): self.parent_window.stop_test = True
class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName(_fromUtf8("MainWindow")) MainWindow.resize(900, 600) MainWindow.setMinimumSize(QtCore.QSize(900, 0)) self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName(_fromUtf8("centralwidget")) self.realtimeData = QtGui.QGroupBox(self.centralwidget) self.realtimeData.setGeometry(QtCore.QRect(10, 10, 611, 551)) font = QtGui.QFont() font.setFamily(_fromUtf8("Arial")) font.setPointSize(8) font.setBold(True) font.setWeight(65) self.realtimeData.setFont(font) self.realtimeData.setObjectName(_fromUtf8("realtimeData")) self.audioPCM = PlotWidget(self.realtimeData) self.audioPCM.setGeometry(QtCore.QRect(10, 30, 591, 201)) self.audioPCM.setObjectName(_fromUtf8("audioPCM")) self.audioPCM.setLabel('left', 'Amplitud (mV)') self.audioPCM.setLabel('bottom', 'Tiempo', 's') self.audioPCM.setTitle( 'Audio Microfono - PCM 16Bit - Entero con Signo (Little Endian)') self.audioFFT = PlotWidget(self.realtimeData) self.audioFFT.setGeometry(QtCore.QRect(10, 240, 591, 301)) self.audioFFT.setObjectName(_fromUtf8("audioFFT")) self.audioFFT.setLabel('left', 'Amplitud', 'dB') self.audioFFT.setLabel('bottom', 'Frecuencua (4096 puntos)', 'Hz') self.audioFFT.setTitle('Fourier Discreta (Log10)') self.controlData = QtGui.QGroupBox(self.centralwidget) self.controlData.setGeometry(QtCore.QRect(630, 160, 261, 401)) font = QtGui.QFont() font.setFamily(_fromUtf8("Arial")) font.setPointSize(10) font.setBold(True) font.setWeight(65) self.controlData.setFont(font) self.controlData.setObjectName(_fromUtf8("controlData")) self.cancelData = PlotWidget(self.controlData) self.cancelData.setGeometry(QtCore.QRect(10, 230, 241, 161)) self.cancelData.setObjectName(_fromUtf8("cancelData")) self.cancelData.setLabel('left', 'Amplitud', 'dB') self.cancelData.setLabel('bottom', 'Tiempo') self.cancelData.setTitle('Anti-Tono') self.btnDetectar = QtGui.QPushButton(self.controlData) self.btnDetectar.setGeometry(QtCore.QRect(40, 30, 171, 23)) font = QtGui.QFont() font.setPointSize(7) font.setBold(False) font.setWeight(50) self.btnDetectar.setFont(font) self.btnDetectar.setObjectName(_fromUtf8("btnDetectar")) self.btnCancelar = QtGui.QPushButton(self.controlData) self.btnCancelar.setGeometry(QtCore.QRect(40, 200, 171, 23)) font = QtGui.QFont() font.setPointSize(7) font.setBold(False) self.btnCancelar.setFont(font) self.btnCancelar.setObjectName(_fromUtf8("btnCancelar")) self.dataLog = QtGui.QTextBrowser(self.controlData) self.dataLog.setFont(font) self.dataLog.setGeometry(QtCore.QRect(10, 60, 241, 131)) self.dataLog.setObjectName(_fromUtf8("dataLog")) self.tprincipal = QtGui.QLabel(self.centralwidget) self.tprincipal.setGeometry(QtCore.QRect(630, 10, 251, 21)) font = QtGui.QFont() font.setFamily(_fromUtf8("Arial")) font.setPointSize(12) self.tprincipal.setFont(font) self.tprincipal.setObjectName(_fromUtf8("tprincipal")) font = QtGui.QFont() font.setFamily(_fromUtf8("Arial")) font.setPointSize(10) self.tproyecto = QtGui.QLabel(self.centralwidget) self.tproyecto.setGeometry(QtCore.QRect(630, 30, 151, 16)) self.tproyecto.setObjectName(_fromUtf8("tproyecto")) self.tproyecto.setFont(font) self.tproyecto2 = QtGui.QLabel(self.centralwidget) self.tproyecto2.setFont(font) self.tproyecto2.setGeometry(QtCore.QRect(630, 40, 181, 16)) self.tproyecto2.setObjectName(_fromUtf8("tproyecto2")) self.pedro = QtGui.QLabel(self.centralwidget) self.pedro.setGeometry(QtCore.QRect(630, 70, 161, 16)) self.pedro.setObjectName(_fromUtf8("pedro")) self.pedro.setFont(font) self.luisa = QtGui.QLabel(self.centralwidget) self.luisa.setGeometry(QtCore.QRect(630, 80, 161, 16)) self.luisa.setObjectName(_fromUtf8("luisa")) self.luisa.setFont(font) self.diana = QtGui.QLabel(self.centralwidget) self.diana.setGeometry(QtCore.QRect(630, 90, 161, 16)) self.diana.setObjectName(_fromUtf8("diana")) self.diana.setFont(font) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtGui.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 900, 18)) self.menubar.setObjectName(_fromUtf8("menubar")) MainWindow.setMenuBar(self.menubar) self.statusbar = QtGui.QStatusBar(MainWindow) self.statusbar.setObjectName(_fromUtf8("statusbar")) MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): MainWindow.setWindowTitle( _translate("MainWindow", "Proyecto Integrado - Cancelador Tonos Puros v0.1", None)) self.realtimeData.setTitle( _translate("MainWindow", "ANÁLISIS EN TIEMPO REAL", None)) self.controlData.setTitle(_translate("MainWindow", "CONTROL", None)) self.btnDetectar.setToolTip( _translate( "MainWindow", "<html><head/><body><p>Iniciar Deteccion de Tonos Puros</p></body></html>", None)) self.btnDetectar.setText( _translate("MainWindow", "INICIAR DETECCIÓN", None)) self.btnCancelar.setToolTip( _translate( "MainWindow", "<html><head/><body><p>Activar/Desactivar Cancelador de Tonos</p></body></html>", None)) self.btnCancelar.setText( _translate("MainWindow", "ACTIVAR CANCELADOR", None)) self.tprincipal.setText( _translate("MainWindow", "Universidad el Bosque", None)) self.tproyecto.setText( _translate("MainWindow", "Proyecto Integrado", None)) self.tproyecto2.setText( _translate("MainWindow", "Transformadas / Transductores", None)) self.pedro.setText(_translate("MainWindow", "PEDRO GUILLEM", None)) self.luisa.setText(_translate("MainWindow", "LUISA ECHEVERRY", None)) self.diana.setText(_translate("MainWindow", "DIANA NUÑEZ", None))
class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(1071, 633) MainWindow.setLayoutDirection(QtCore.Qt.RightToLeft) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget) self.pushButton_3.setGeometry(QtCore.QRect(470, 420, 121, 28)) self.pushButton_3.setObjectName("pushButton_3") self.pushButton_5 = QtWidgets.QPushButton(self.centralwidget) self.pushButton_5.setGeometry(QtCore.QRect(720, 420, 111, 28)) self.pushButton_5.setObjectName("pushButton_5") self.lineEdit = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit.setGeometry(QtCore.QRect(180, 110, 113, 22)) self.lineEdit.setObjectName("lineEdit") self.lineEdit.setText('0') self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit_2.setGeometry(QtCore.QRect(180, 190, 113, 22)) self.lineEdit_2.setObjectName("lineEdit_2") self.lineEdit_2.setText('0') self.lineEdit_3 = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit_3.setGeometry(QtCore.QRect(180, 150, 113, 22)) self.lineEdit_3.setObjectName("lineEdit_3") self.lineEdit_3.setText('0') self.lineEdit_4 = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit_4.setGeometry(QtCore.QRect(180, 230, 113, 22)) self.lineEdit_4.setObjectName("lineEdit_4") self.lineEdit_4.setText('0') self.label = QtWidgets.QLabel(self.centralwidget) self.label.setGeometry(QtCore.QRect(100, 110, 81, 21)) self.label.setObjectName("label") self.label_2 = QtWidgets.QLabel(self.centralwidget) self.label_2.setGeometry(QtCore.QRect(100, 150, 81, 21)) self.label_2.setObjectName("label_2") self.label_3 = QtWidgets.QLabel(self.centralwidget) self.label_3.setGeometry(QtCore.QRect(100, 230, 71, 21)) self.label_3.setObjectName("label_3") self.label_4 = QtWidgets.QLabel(self.centralwidget) self.label_4.setGeometry(QtCore.QRect(100, 190, 71, 21)) self.label_4.setObjectName("label_4") self.widget = PlotWidget(self.centralwidget) self.widget.setGeometry(QtCore.QRect(320, 70, 671, 341)) self.widget.setObjectName("widget") self.widget.setTitle("Lab_8") self.widget.setLabel("left", "coordinate Y") self.widget.setLabel("bottom", "coordinate X") self.label_7 = QtWidgets.QLabel(self.centralwidget) self.label_7.setGeometry(QtCore.QRect(70, 370, 101, 21)) self.label_7.setObjectName("label_7") self.lineEdit_7 = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit_7.setGeometry(QtCore.QRect(180, 370, 113, 22)) self.lineEdit_7.setObjectName("lineEdit_7") self.lineEdit_7.setText('0') MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 1071, 26)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "Lab_7")) self.pushButton_3.setText(_translate("MainWindow", "Bulid")) self.pushButton_5.setText(_translate("MainWindow", "Exit")) self.lineEdit.setText(_translate("MainWindow", "0")) self.lineEdit_2.setText(_translate("MainWindow", "0")) self.lineEdit_3.setText(_translate("MainWindow", "0")) self.lineEdit_4.setText(_translate("MainWindow", "0")) self.label.setText( _translate( "MainWindow", "<html><head/><body><p><span style=\" font-size:12pt;\">X max:</span></p></body></html>" )) self.label_2.setText( _translate( "MainWindow", "<html><head/><body><p><span style=\" font-size:12pt;\">X min:</span></p></body></html>" )) self.label_3.setText( _translate( "MainWindow", "<html><head/><body><p><span style=\" font-size:12pt;\">Y min:</span></p></body></html>" )) self.label_4.setText( _translate( "MainWindow", "<html><head/><body><p><span style=\" font-size:12pt;\">Y max:</span></p></body></html>" )) self.label_7.setText( _translate( "MainWindow", "<html><head/><body><p><span style=\" font-size:12pt;\">Main Step :</span></p></body></html>" )) self.lineEdit_7.setText(_translate("MainWindow", "0"))
class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName(_fromUtf8("MainWindow")) self.resize(1920, 1080) self.status = False self.setAutoFillBackground(False) self.setDocumentMode(False) self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName(_fromUtf8("centralwidget")) self.exitAct = QAction(QIcon('exit.png'), '&Exit', self) self.exitAct.setShortcut('Ctrl+Q') self.exitAct.setStatusTip('Exit application') self.exitAct.triggered.connect(qApp.quit) self.loadAct = QAction(QIcon('exit.png'), '&Import Unfolding', self) self.loadAct.setShortcut('Ctrl+L') self.loadAct.setStatusTip('Import Unfolding') self.loadAct.triggered.connect(self.openFileNameDialog) self.exportAct = QAction(QIcon('exit.png'), '&Export Unfolding', self) self.exportAct.setShortcut('Ctrl+E') self.exportAct.setStatusTip('Export Unfolding') self.exportAct.triggered.connect(self.exportUnfolding) self.writeNPAct = QAction(QIcon('exit.png'), '&Write coordinates as np file', self) self.writeNPAct.setShortcut('Ctrl+W') self.writeNPAct.setStatusTip('Write coordinates') self.writeNPAct.triggered.connect(self.writeNP_file) self.loadGeometryAct = QAction(QIcon('exit.png'), '&Load geometry from .log file', self) #self.loadGeometry.setShortcut('Ctrl+W') self.loadGeometryAct.setStatusTip('Load geometry') self.loadGeometryAct.triggered.connect(self.loadGeometry) self.select_directoryAct = QAction( QIcon('exit.png'), '&Select a directory to generate hdf5 files from', self) self.select_directoryAct.setStatusTip('Select directory') self.select_directoryAct.triggered.connect(self.select_directory) self.load_HDF5Act = QAction(QIcon('exit.png'), '&Select a hdf5 files for the DFT data', self) self.load_HDF5Act.setStatusTip('Select HDF5') self.load_HDF5Act.triggered.connect(self.load_hdf5_scan) self.statusBar() self.menubar = self.menuBar() self.fileMenu = self.menubar.addMenu('&File') self.fileMenu.addAction(self.exitAct) self.fileMenu.addAction(self.loadAct) self.fileMenu.addAction(self.exportAct) self.fileMenu.addAction(self.writeNPAct) self.fileMenu.addAction(self.loadGeometryAct) self.fileMenu.addAction(self.select_directoryAct) self.fileMenu.addAction(self.load_HDF5Act) self.horizontalLayout = QHBoxLayout(self.centralwidget) self.horizontalLayout.setSpacing(10) self.verticalLayout = QVBoxLayout() ### Containing the integration buttons self.horizontalLayout_2 = QHBoxLayout() ### Containing the inital/final position show self.finalPositionLayout = QHBoxLayout() self.gl_widget = gl.GLViewWidget() self.gl_widget.setCameraPosition(distance=20, elevation=40) self.gl_widget.setGeometry(0, 110, 1920, 1080) self.energy_Plot = PlotWidget() self.energy_Plot.setObjectName(_fromUtf8("energyPlot")) self.energy_Plot.setBackground('k') # set properties of the label for y axis self.energy_Plot.setLabel('left', 'E(B3LYP)', units='H') # set properties of the label for x axis self.energy_Plot.setLabel('bottom', 'CC-distance', units='A') # adding legend self.energy_Plot.addLegend() self.horizontalLayout.addWidget(self.gl_widget, 4) ### Push button for sinle integration self.btnUp = QPushButton() self.btnUp.setObjectName(_fromUtf8("btnUp")) ### Check box for continous integration self.chkIntegrate = QCheckBox() self.chkIntegrate.setObjectName(_fromUtf8("chkIntegrate")) ### SpinBox to set the size of the integration step self.spinStep = QSpinBox() self.spinStep.setMinimum(0) self.spinStep.setMaximum(10000) self.spinStep.setObjectName(_fromUtf8("spinStep")) ### final position button self.btnFin = QPushButton() self.btnFin.setObjectName(_fromUtf8("btnFin")) ### initial position button self.btnInit = QPushButton() self.btnInit.setObjectName(_fromUtf8("btnPos")) ### select hinges button self.btnSelHinge = QPushButton() self.btnSelHinge.setObjectName(_fromUtf8("btnSelHinge")) ### close unfolding button self.btnClose = QPushButton() self.btnClose.setObjectName(_fromUtf8("btnClose")) ### add the buttons to the integration layout self.horizontalLayout_2.addWidget(self.spinStep) self.horizontalLayout_2.addWidget(self.btnUp) self.horizontalLayout_2.addWidget(self.chkIntegrate) ## add final position button to layout self.finalPositionLayout.addWidget(self.btnInit) self.finalPositionLayout.addWidget(self.btnFin) self.finalPositionLayout.addWidget(self.btnSelHinge) self.finalPositionLayout.addWidget(self.btnClose) ### add integration and final position layout and plot widget to right side layout self.verticalLayout.addLayout(self.horizontalLayout_2, 1) self.verticalLayout.addLayout(self.finalPositionLayout, 1) self.verticalLayout.addWidget(self.energy_Plot, 6) self.horizontalLayout.addLayout(self.verticalLayout, 1) self.widget = QWidget() self.widget.setLayout(self.horizontalLayout) self.setCentralWidget(self.widget) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) self.setWindowTitle('Fullerene Unfolding') def retranslateUi(self, MainWindow): MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None)) self.btnUp.setText("Integrate") self.chkIntegrate.setText("Keep integrating") self.btnFin.setText("Final position") self.btnInit.setText("Initial position") self.btnClose.setText("Close unfolding") self.btnSelHinge.setText("Select Hinges")
class Ui_MainWindow(object): def setupUi(self, QMainWindow): MainWindow.setObjectName("MainWindow") MainWindow.setFixedSize(800, 600) MainWindow.resize(800, 600) MainWindow.setStyleSheet("QMainWindow{\n" " color: white;\n" " background-color: #fb5d5d;\n" "}\n" "") self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setStyleSheet("background-color: #22222e;\n" "") self.centralwidget.setObjectName("centralwidget") self.graphWidget = PlotWidget(self.centralwidget) self.graphWidget.setGeometry(QtCore.QRect(20, 20, 761, 241)) self.graphWidget.setObjectName("graphWidget") self.dataSerial1 = 0 self.dataSerial2 = 0 #Graph style self.x = [] # 100 time points self.y = [] # 100 data points self.graphWidget.setBackground('w') self.graphWidget.setLabel('left', "<span style=\"color:red;font-size:20px\">Нагрузка, Н</span>") self.graphWidget.setLabel('bottom', "<span style=\"color:red;font-size:20px\">Деформация, мм</span>") self.pen = pg.mkPen(color=(255, 0, 0), width=3) self.graphWidget.showGrid(x=True, y=True) #self.graphWidget.setXRange(0, 155, padding=0) #Установка пределов оси X # plot data: x, y values #self.data_line = self.plot(self.x, self.y, pen) #update graph # self.data_line = self.plot(self.x, self.y, self.pen) # self.timer = QtCore.QTimer() # self.timer.setInterval(50) # self.timer.timeout.connect(self.update_plot_data) # self.timer.start() self.connectBox = QtWidgets.QGroupBox(self.centralwidget) self.connectBox.setGeometry(QtCore.QRect(20, 310, 191, 171)) font = QtGui.QFont() font.setFamily("Arial") font.setPointSize(14) font.setBold(True) font.setItalic(False) font.setUnderline(False) font.setWeight(75) font.setStrikeOut(False) self.connectBox.setFont(font) self.connectBox.setStyleSheet("color: white;\n" "") self.connectBox.setObjectName("connectBox") self.updateComButton = QtWidgets.QPushButton(self.connectBox) self.updateComButton.setGeometry(QtCore.QRect(20, 30, 151, 71)) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.updateComButton.sizePolicy().hasHeightForWidth()) self.updateComButton.setSizePolicy(sizePolicy) self.updateComButton.setMaximumSize(QtCore.QSize(15555, 16777215)) font = QtGui.QFont() font.setFamily("MS Shell Dlg 2") font.setPointSize(12) font.setBold(False) font.setItalic(False) font.setUnderline(False) font.setWeight(50) font.setStrikeOut(False) self.updateComButton.setFont(font) self.updateComButton.setAcceptDrops(False) self.updateComButton.setStyleSheet("QPushButton{\n" " color: white;\n" " background-color: #fb5d5d;\n" " border-radius: 30;\n" "}\n" "\n" "QPushButton:pressed{\n" " background-color: #fa4244\n" "}") self.updateComButton.setCheckable(False) self.updateComButton.setAutoRepeat(False) self.updateComButton.setAutoExclusive(False) self.updateComButton.setAutoDefault(False) self.updateComButton.setDefault(False) self.updateComButton.setFlat(False) self.updateComButton.setObjectName("updateComButton") self.connectComButton = QtWidgets.QPushButton(self.connectBox) self.connectComButton.setGeometry(QtCore.QRect(20, 110, 151, 41)) font = QtGui.QFont() font.setFamily("Arial") font.setPointSize(12) font.setBold(False) font.setItalic(False) font.setUnderline(False) font.setWeight(50) font.setStrikeOut(False) self.connectComButton.setFont(font) self.connectComButton.setStyleSheet("QPushButton{\n" " color: white;\n" " background-color: #fb5d5d;\n" " border-radius: 30;\n" "}\n" "\n" "QPushButton:pressed{\n" " background-color: #fa4244\n" "}") self.connectComButton.setObjectName("connectComButton") self.portBox = QtWidgets.QGroupBox(self.centralwidget) self.portBox.setGeometry(QtCore.QRect(20, 480, 191, 71)) font = QtGui.QFont() font.setFamily("Arial") font.setPointSize(12) font.setBold(True) font.setUnderline(False) font.setWeight(75) self.portBox.setFont(font) self.portBox.setStyleSheet("color: white;") self.portBox.setObjectName("portBox") self.portComboBox = QtWidgets.QComboBox(self.portBox) self.portComboBox.setGeometry(QtCore.QRect(10, 30, 171, 31)) font = QtGui.QFont() font.setFamily("Arial") font.setPointSize(12) self.portComboBox.setFont(font) self.portComboBox.setStyleSheet("QComboBox{\n" " color: white;\n" " background-color: #fb5d5d;\n" "}\n" "") self.portComboBox.setObjectName("portComboBox") self.portComboBox.addItem("") self.portComboBox.addItem("") self.readingInstrumentBox = QtWidgets.QGroupBox(self.centralwidget) self.readingInstrumentBox.setGeometry(QtCore.QRect(220, 330, 571, 221)) font = QtGui.QFont() font.setFamily("Arial") font.setPointSize(14) font.setBold(True) font.setWeight(75) self.readingInstrumentBox.setFont(font) self.readingInstrumentBox.setStyleSheet("color: white;\n" "") self.readingInstrumentBox.setObjectName("readingInstrumentBox") self.tensoBox = QtWidgets.QGroupBox(self.readingInstrumentBox) self.tensoBox.setGeometry(QtCore.QRect(20, 40, 261, 171)) font = QtGui.QFont() font.setFamily("Arial") font.setPointSize(14) font.setBold(False) font.setWeight(50) self.tensoBox.setFont(font) self.tensoBox.setStyleSheet("color: white;") self.tensoBox.setObjectName("tensoBox") self.valueTensoLcd = QtWidgets.QLCDNumber(self.tensoBox) self.valueTensoLcd.setGeometry(QtCore.QRect(20, 40, 221, 101)) self.valueTensoLcd.setObjectName("valueTensoLcd") self.distanceBox = QtWidgets.QGroupBox(self.readingInstrumentBox) self.distanceBox.setGeometry(QtCore.QRect(290, 40, 261, 171)) font = QtGui.QFont() font.setFamily("Arial") font.setPointSize(14) font.setBold(False) font.setWeight(50) self.distanceBox.setFont(font) self.distanceBox.setStyleSheet("color: white;") self.distanceBox.setObjectName("distanceBox") self.valueDistanceLcd = QtWidgets.QLCDNumber(self.distanceBox) self.valueDistanceLcd.setGeometry(QtCore.QRect(20, 40, 221, 101)) self.valueDistanceLcd.setObjectName("valueDistanceLcd") self.startGraph = QtWidgets.QPushButton(self.centralwidget) self.startGraph.setGeometry(QtCore.QRect(430, 280, 191, 41)) font = QtGui.QFont() font.setFamily("Arial") font.setPointSize(14) font.setBold(True) font.setWeight(75) self.startGraph.setFont(font) self.startGraph.setStyleSheet("QPushButton{\n" " color: white;\n" " background-color: #fb5d5d;\n" " border-radius: 30;\n" "}\n" "\n" "QPushButton:pressed{\n" " background-color: #fa4244\n" "}") self.startGraph.setObjectName("startGraph") self.clearGraph = QtWidgets.QPushButton(self.centralwidget) self.clearGraph.setGeometry(QtCore.QRect(630, 280, 161, 41)) font = QtGui.QFont() font.setFamily("Arial") font.setPointSize(14) font.setBold(True) font.setWeight(75) self.clearGraph.setFont(font) self.clearGraph.setStyleSheet("QPushButton{\n" " color: white;\n" " background-color: #fb5d5d;\n" " border-radius: 30;\n" "}\n" "\n" "QPushButton:pressed{\n" " background-color: #fa4244\n" "}") self.clearGraph.setObjectName("clearGraph") #Кнопка сохранения self.saveData = QtWidgets.QPushButton(self.centralwidget) self.saveData.setGeometry(QtCore.QRect(230, 280, 191, 41)) font = QtGui.QFont() font.setFamily("Arial") font.setPointSize(14) font.setBold(True) font.setWeight(75) self.saveData.setFont(font) self.saveData.setStyleSheet("QPushButton{\n" " color: white;\n" " background-color: #fb5d5d;\n" " border-radius: 30;\n" "}\n" "\n" "QPushButton:pressed{\n" " background-color: #fa4244\n" "}") self.saveData.setObjectName("saveData") #Сброс self.dischargeButton = QtWidgets.QPushButton(self.centralwidget) self.dischargeButton.setGeometry(QtCore.QRect(680, 350, 90, 26)) font = QtGui.QFont() font.setFamily("Arial") font.setPointSize(12) font.setBold(True) font.setWeight(75) self.dischargeButton.setFont(font) self.dischargeButton.setStyleSheet("QPushButton{\n" " color: white;\n" " background-color: #fb5d5d;\n" " border-radius: 30;\n" "}\n" "\n" "QPushButton:pressed{\n" " background-color: #fa4244\n" "}") self.dischargeButton.setObjectName("dischargeButton") MainWindow.setCentralWidget(self.centralwidget) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) #Ожидание нажатия кнопки старт измерения self.startGraph.clicked.connect(self.startGraphButton) #Очистить график self.clearGraph.clicked.connect(self.clearGraphButton) #Нажатие на Обновить конфигурацию self.updateComButton.clicked.connect(self.updateComPort) #Подлючиться к ком порту self.connectComButton.clicked.connect(self.connectComPort) #Сохранить данные self.saveData.clicked.connect(self.data_save) #Сбросить(установка нуля) self.dischargeButton.clicked.connect(self.send) QtCore.QMetaObject.connectSlotsByName(MainWindow) def startGraphButton(self): if (self.startGraph.text() == "Начать измерения" or self.startGraph.text() == "Продолжить измерения") and self.connectComButton.text() == "Отключиться" : try: self.data_line = self.plot(self.x, self.y, self.pen) self.timer = QtCore.QTimer() self.timer.setInterval(50) self.timer.timeout.connect(self.update_plot_data) self.timer.start() font = QtGui.QFont() font.setFamily("Arial") font.setPointSize(12) font.setBold(True) font.setWeight(75) self.startGraph.setFont(font) self.startGraph.setText("Остановить измерения") except: print("Ошибка при нажатии на Начать измерение") elif self.portComboBox.currentText() != '' and self.connectComButton.text() != "Подключиться": try: self.timer.stop() font = QtGui.QFont() font.setFamily("Arial") font.setPointSize(11) font.setBold(True) font.setWeight(75) self.startGraph.setFont(font) self.startGraph.setText("Продолжить измерения") except: print("Start graph fail") def plot(self, dateX, dateY, pen): return self.graphWidget.plot(dateX, dateY, pen=pen) def update_plot_data(self): if len(self.x) >= 4328000: self.x = self.x[1:] # Remove the first y element. # self.x.append(self.x[-1] + 10) # Add a new value 1 higher than the last. self.x.append(self.dataSerial2) else: if len(self.x) != 0: self.x.append(self.dataSerial2) else: self.x.append(self.dataSerial2) if len(self.y) >= 4328000: self.y = self.y[1:] # Remove the first element self.y.append(self.dataSerial1) # Add a new random value. else: if len(self.y) == 0: self.y.append(self.dataSerial1) else: self.y.append(self.dataSerial1) self.data_line.setData(self.x, self.y) #Update the datac def clearGraphButton(self): try: if (self.startGraph.text() == "Остановить измерения" or self.startGraph.text() == "Продолжить измерения"): self.x = [] self.y = [] self.graphWidget.clear() font = QtGui.QFont() font.setFamily("Arial") font.setPointSize(14) font.setBold(True) font.setWeight(75) self.startGraph.setFont(font) self.startGraph.setText("Начать измерения") except: print("Ошибка в очистке") #Функция для обновления ком портов def updateComPort(self): try: self.portComboBox.clear() for info in QtSerialPort.QSerialPortInfo.availablePorts(): self.portComboBox.addItem(info.portName()) except: print("Чёт не так") #@QtCore.pyqtSlot() def connectComPort(self): if self.connectComButton.text() == "Подключиться": if self.portComboBox.currentText() != '': self.connectComButton.setText("Отключиться") print("Проверили не пустой ли комбо бокс") try: print("Читаем сериал") self.serial = QtSerialPort.QSerialPort(self.portComboBox.currentText(), baudRate=QtSerialPort.QSerialPort.Baud115200, readyRead=self.receive) self.serial.open(QtCore.QIODevice.ReadWrite) except: print("Подключение к ком порту провалилось") self.disconnectFromPort() elif self.connectComButton.text() == "Отключиться": try: self.disconnectFromPort() self.connectComButton.setText("Подключиться") self.clearGraphButton() except: print("Не отключились от ком-порта") #@QtCore.pyqtSlot() def receive(self): while self.serial.canReadLine(): text = self.serial.readLine().data().decode() text = text.rstrip('\r\n').split('%') print(text) self.dataSerial2 = float(text[0]) self.dataSerial1 = round(float(text[1])) self.valueDistanceLcd.display(self.dataSerial2) self.valueTensoLcd.display(self.dataSerial1) print(self.dataSerial1, self.dataSerial2) def send(self): try: self.serial.write('t') except: print("No connect") #@QtCore.pyqtSlot(bool) def disconnectFromPort(self): self.serial.close() #Save def data_save(self): try: option = QFileDialog.Options() file=QFileDialog.getSaveFileName(QWidget(), "Сохранить измерения", "Эксперимент.txt", "All Files (*),", options=option) th = ["Номер измерения", "Тензодатчик, Н", "Перемещение, мм"] if file: print(file[0]) file = open(file[0], "w") text = th[0] + "\t" + th[1] + "\t" + th[2] + "\n" for number in range(len(self.x)): text += str(number + 1) + "\t" + "\t" + str(self.y[number]) + "\t" + "\t" + str(self.x[number]) + "\n" #text = " ".join(str(elem) for elem in self.x) + "\n" + " ".join(str(elem) for elem in self.y) print(text) file.write(text) file.close() except: print("No save ") def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "Разрывная машина")) self.connectBox.setTitle(_translate("MainWindow", "Подключение")) self.updateComButton.setText(_translate("MainWindow", "Обновить\n" "конфигурацию\n" "оборудования")) self.connectComButton.setText(_translate("MainWindow", "Подключиться")) self.portBox.setTitle(_translate("MainWindow", "Порт")) self.readingInstrumentBox.setTitle(_translate("MainWindow", "Показания приборов")) self.tensoBox.setTitle(_translate("MainWindow", "Тензодатчик, Н")) self.distanceBox.setTitle(_translate("MainWindow", "Расстояние, мм")) self.startGraph.setText(_translate("MainWindow", "Начать измерения")) self.clearGraph.setText(_translate("MainWindow", "Очистить")) self.saveData.setText(_translate("MainWindow", "Сохранить")) self.dischargeButton.setText(_translate("MainWindow", "Сбросить"))
class Ui_MainWindow(object): def __init__(self, state): super().__init__() self.state = state self.timer = QtCore.QTimer() self.timer.timeout.connect(self.update_graph) self.timer.start(1000) def update_graph(self): self.state.update_graph(self.graphicsView, self.lcdNumber) def clear_values(self): self.state.clear_values(self.graphicsView, self.lcdNumber, self.pushButton) def toggle_start(self): self.state.toggle_start(self.pushButton) def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(962, 535) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.graphicsView = PlotWidget(self.centralwidget) self.graphicsView.setGeometry(QtCore.QRect(10, 10, 941, 411)) self.graphicsView.setObjectName("graphicsView") self.splitter = QtWidgets.QSplitter(self.centralwidget) self.splitter.setGeometry(QtCore.QRect(440, 430, 511, 61)) self.splitter.setOrientation(QtCore.Qt.Horizontal) self.splitter.setObjectName("splitter") self.pushButton = QtWidgets.QPushButton(self.splitter) font = QtGui.QFont() font.setPointSize(12) font.setBold(True) font.setWeight(75) self.pushButton.setFont(font) self.pushButton.setObjectName("pushButton") self.pushButton_2 = QtWidgets.QPushButton(self.splitter) font = QtGui.QFont() font.setPointSize(12) font.setBold(True) font.setWeight(75) self.pushButton_2.setFont(font) self.pushButton_2.setObjectName("pushButton_2") self.lcdNumber = QtWidgets.QLCDNumber(self.centralwidget) self.lcdNumber.setGeometry(QtCore.QRect(220, 430, 201, 61)) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Light, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Midlight, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Dark, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Mid, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Light, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Midlight, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Dark, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Mid, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Light, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Midlight, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Dark, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Mid, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush) self.lcdNumber.setPalette(palette) self.lcdNumber.setAutoFillBackground(True) self.lcdNumber.setSmallDecimalPoint(True) self.lcdNumber.setDigitCount(5) self.lcdNumber.setMode(QtWidgets.QLCDNumber.Dec) self.lcdNumber.setSegmentStyle(QtWidgets.QLCDNumber.Flat) self.lcdNumber.setProperty("value", 36.565) self.lcdNumber.setObjectName("lcdNumber") self.label = QtWidgets.QLabel(self.centralwidget) self.label.setGeometry(QtCore.QRect(230, 430, 21, 21)) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.BrightText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.BrightText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(120, 120, 120)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(120, 120, 120)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.BrightText, brush) brush = QtGui.QBrush(QtGui.QColor(120, 120, 120)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText, brush) self.label.setPalette(palette) font = QtGui.QFont() font.setFamily("Georgia") font.setPointSize(14) font.setBold(False) font.setWeight(50) self.label.setFont(font) self.label.setObjectName("label") self.comboBox = QtWidgets.QComboBox(self.centralwidget) self.comboBox.setGeometry(QtCore.QRect(10, 440, 191, 41)) font = QtGui.QFont() font.setPointSize(10) font.setBold(True) font.setWeight(75) self.comboBox.setFont(font) self.comboBox.setObjectName("comboBox") MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 962, 21)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) self.pushButton_2.clicked.connect(self.clear_values) self.pushButton.clicked.connect(self.toggle_start) self.graphicsView.setLabel('left', "Temperatura (°C)") self.graphicsView.setLabel('bottom', "Tiempo (s)") self.comboBox.clear() self.comboBox.addItems(['Temperatura', 'Electrocardiograma', 'Otro']) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) self.pushButton.setText(_translate("MainWindow", "Resumir")) self.pushButton_2.setText(_translate("MainWindow", "Limpiar")) self.label.setText(_translate("MainWindow", "°C"))
class Ui_Op2(object): def setupUi(self, Op2): listChem = Equilibrium() Op2.setObjectName("Op2") Op2.resize(950, 640) Op2.setMinimumSize(QtCore.QSize(950, 640)) Op2.setMaximumSize(QtCore.QSize(950, 640)) Op2.setWindowIcon(QtGui.QIcon('images\Icone.jpg')) Op2.setFocusPolicy(QtCore.Qt.NoFocus) Op2.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly) self.centralwidget = QtWidgets.QWidget(Op2) self.centralwidget.setObjectName("centralwidget") self.line = QtWidgets.QFrame(self.centralwidget) self.line.setGeometry(QtCore.QRect(0, -1, 951, 16)) self.line.setFrameShape(QtWidgets.QFrame.HLine) self.line.setFrameShadow(QtWidgets.QFrame.Sunken) self.line.setObjectName("line") self.line_2 = QtWidgets.QFrame(self.centralwidget) self.line_2.setGeometry(QtCore.QRect(0, 470, 961, 20)) self.line_2.setFrameShape(QtWidgets.QFrame.HLine) self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken) self.line_2.setObjectName("line_2") self.graphicPlot = QtWidgets.QPushButton(self.centralwidget) self.graphicPlot.setGeometry(QtCore.QRect(480, 520, 161, 51)) font = QtGui.QFont() font.setPointSize(11) font.setBold(True) font.setWeight(75) self.graphicPlot.setFont(font) self.graphicPlot.setObjectName("graphicPlot") self.graphics1 = PlotWidget(self.centralwidget) self.graphics1.setGeometry(QtCore.QRect(10, 10, 461, 401)) self.graphics1.setBackground('w') self.graphics1.showGrid(x=True, y=True) self.graphics1.setObjectName("graphics1") self.graphics2 = PlotWidget(self.centralwidget) self.graphics2.setGeometry(QtCore.QRect(480, 10, 461, 401)) self.graphics2.setBackground('w') self.graphics2.showGrid(x=True, y=True) self.graphics2.setObjectName("graphics2") self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget) self.verticalLayoutWidget.setGeometry(QtCore.QRect(310, 520, 171, 51)) self.verticalLayoutWidget.setObjectName("verticalLayoutWidget") self.verticalLayout_2 = QtWidgets.QVBoxLayout( self.verticalLayoutWidget) self.verticalLayout_2.setContentsMargins(0, 0, 0, 0) self.verticalLayout_2.setObjectName("verticalLayout_2") self.pconst = QtWidgets.QRadioButton(self.verticalLayoutWidget) self.pconst.setEnabled(True) self.pconst.setCheckable(True) self.pconst.setChecked(False) self.pconst.setObjectName("pconst") self.verticalLayout_2.addWidget(self.pconst) self.tconst = QtWidgets.QRadioButton(self.verticalLayoutWidget) self.tconst.setChecked(True) self.tconst.setObjectName("tconst") self.verticalLayout_2.addWidget(self.tconst) self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget) self.horizontalLayoutWidget.setGeometry(QtCore.QRect( 310, 490, 331, 31)) self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget") self.horizontalLayout = QtWidgets.QHBoxLayout( self.horizontalLayoutWidget) self.horizontalLayout.setContentsMargins(0, 0, 0, 0) self.horizontalLayout.setObjectName("horizontalLayout") spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem) self.changeTextVar = QtWidgets.QLabel(self.horizontalLayoutWidget) font = QtGui.QFont() font.setPointSize(11) font.setBold(True) font.setWeight(75) self.changeTextVar.setFont(font) self.changeTextVar.setObjectName("changeTextVar") self.horizontalLayout.addWidget(self.changeTextVar) self.databox = QtWidgets.QLineEdit(self.horizontalLayoutWidget) font = QtGui.QFont() font.setPointSize(10) self.databox.setFont(font) self.databox.setValidator(QtGui.QDoubleValidator()) self.databox.setCursor(QtGui.QCursor(QtCore.Qt.IBeamCursor)) self.databox.setToolTipDuration(1) self.databox.setObjectName("databox") self.horizontalLayout.addWidget(self.databox) self.changeTextUni = QtWidgets.QLabel(self.horizontalLayoutWidget) font = QtGui.QFont() font.setPointSize(11) font.setBold(True) font.setWeight(75) self.changeTextUni.setFont(font) self.changeTextUni.setObjectName("changeTextUni") self.horizontalLayout.addWidget(self.changeTextUni) spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem1) self.gridLayoutWidget = QtWidgets.QWidget(self.centralwidget) self.gridLayoutWidget.setGeometry(QtCore.QRect(260, 420, 431, 53)) self.gridLayoutWidget.setObjectName("gridLayoutWidget") self.gridLayout_2 = QtWidgets.QGridLayout(self.gridLayoutWidget) self.gridLayout_2.setContentsMargins(0, 0, 0, 0) self.gridLayout_2.setObjectName("gridLayout_2") self.label_2 = QtWidgets.QLabel(self.gridLayoutWidget) font = QtGui.QFont() font.setPointSize(10) font.setBold(True) font.setWeight(75) self.label_2.setFont(font) self.label_2.setAlignment(QtCore.Qt.AlignCenter) self.label_2.setObjectName("label_2") self.gridLayout_2.addWidget(self.label_2, 0, 1, 1, 1) self.label = QtWidgets.QLabel(self.gridLayoutWidget) font = QtGui.QFont() font.setPointSize(10) font.setBold(True) font.setWeight(75) self.label.setFont(font) self.label.setAlignment(QtCore.Qt.AlignCenter) self.label.setObjectName("label") self.gridLayout_2.addWidget(self.label, 0, 0, 1, 1) self.comp2 = QtWidgets.QComboBox(self.gridLayoutWidget) font = QtGui.QFont() self.comp2.addItems(listChem.chemComp()) font.setPointSize(9) self.comp2.setFont(font) self.comp2.setObjectName("comp2") self.gridLayout_2.addWidget(self.comp2, 1, 1, 1, 1) self.comp1 = QtWidgets.QComboBox(self.gridLayoutWidget) font = QtGui.QFont() self.comp1.addItems(listChem.chemComp()) font.setPointSize(9) self.comp1.setFont(font) self.comp1.setObjectName("comp1") self.gridLayout_2.addWidget(self.comp1, 1, 0, 1, 1) Op2.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(Op2) self.menubar.setGeometry(QtCore.QRect(0, 0, 950, 21)) self.menubar.setObjectName("menubar") self.menuTools = QtWidgets.QMenu(self.menubar) self.menuTools.setObjectName("menuTools") self.menuAbout = QtWidgets.QMenu(self.menubar) self.menuAbout.setObjectName("menuAbout") Op2.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(Op2) self.statusbar.setObjectName("statusbar") Op2.setStatusBar(self.statusbar) self.actionsave2Excel = QtWidgets.QAction(Op2) self.actionsave2Excel.setObjectName("actionsave2Excel") #self.actionsavePlot = QtWidgets.QAction(Op2) #self.actionsavePlot.setObjectName("actionsavePlot") #self.addElement = QtWidgets.QAction(Op2) #self.addElement.setObjectName("addElement") self.about = QtWidgets.QAction(Op2) self.about.setObjectName("about") #self.removeElement = QtWidgets.QAction(Op2) #self.removeElement.setObjectName("removeElement") self.menuTools.addAction(self.actionsave2Excel) #self.menuTools.addAction(self.actionsavePlot) self.menuTools.addSeparator() #self.menuTools.addAction(self.addElement) #self.menuTools.addAction(self.removeElement) self.menuAbout.addAction(self.about) self.menubar.addAction(self.menuTools.menuAction()) self.menubar.addAction(self.menuAbout.menuAction()) self.retranslateUi(Op2) QtCore.QMetaObject.connectSlotsByName(Op2) self.pconst.toggled.connect(lambda: self.selected(self.pconst) ) #Selection RadioButton Pressão Constante self.tconst.toggled.connect(lambda: self.selected( self.tconst)) #Selection RadioButton Temperatura Constante self.graphicPlot.clicked.connect( lambda: self.call(float(self.databox.text( )), self.changeTextUni.text())) #Call the plot function self.actionsave2Excel.triggered.connect(lambda: self.saveData()) self.about.triggered.connect(lambda: self.aboutMsg()) def retranslateUi(self, Op2): _translate = QtCore.QCoreApplication.translate Op2.setWindowTitle(_translate("Op2", "Op_2 App")) self.graphicPlot.setText(_translate("Op2", "Plot")) self.pconst.setText(_translate("Op2", "Constant pressure ")) self.tconst.setText(_translate("Op2", "Constant temperature ")) self.changeTextVar.setText(_translate("Op2", "Temperature")) self.changeTextUni.setText(_translate("Op2", "K")) self.label_2.setText(_translate("Op2", "Substance 2")) self.label.setText(_translate("Op2", "Substance 1")) self.menuTools.setTitle(_translate("Op2", "Tools")) self.menuAbout.setTitle(_translate("Op2", "About")) self.actionsave2Excel.setText(_translate("Op2", "Save data to Excel")) #self.actionsavePlot.setText(_translate("Op2", "Salvar gráficos")) #self.addElement.setText(_translate("Op2", "Adicionar Elemento")) self.about.setText(_translate("Op2", "about")) #self.removeElement.setText(_translate("Op2", "Remover Elemento")) def selected(self, b): if b.text() == "Constant pressure ": if b.isChecked() == True: self.changeTextVar.setText('Pressure') self.changeTextUni.setText("bar") elif b.text() == "Constant temperature ": if b.isChecked() == True: self.changeTextVar.setText('Temperature') self.changeTextUni.setText("K") def call(self, data, signal, n=1000): self.graphics1.clear(), self.graphics2.clear() x = np.arange(0, 1.0 + (1 / n), (1 / n)) y, P, T = np.zeros(np.size(x)), np.zeros(np.size(x)), np.zeros( np.size(x)) if signal == "bar": #Erase float_files if os.path.exists('float_files\\pconstdata.txt'): os.remove('float_files\\pconstdata.txt') try: data = open('float_files\\pconstdata.txt', 'a') newData = Equilibrium( lchem=[self.comp1.currentText(), self.comp2.currentText()], p=float(self.databox.text())) self.A, self.B, self.C, self.Tmax, self.Tmin, self.DG = newData.compData( ) Tsat = ( self.B / (self.A - np.log10(float(self.databox.text())))) - self.C data.write('Temperature [K], x, y\n') for i in range(np.size(x)): T0 = np.sum(np.asarray([x[i], 1 - x[i]]) * Tsat) while (True): a12 = 10**(self.A[0] - self.A[1] - (self.B[0] / (T0 + self.C[0])) + (self.B[1] / (T0 + self.C[1]))) coef = UNIFAC(T=T0, xs=[x[i], 1 - x[i]], chemgroups=self.DG) P2sat = (float(self.databox.text()) / (x[i] * coef[0] * a12 + (1 - x[i]) * coef[1])) Tn = (self.B[1] / (self.A[1] - np.log10(P2sat))) - self.C[1] if (abs(Tn - T0) < 0.001): break T0 = Tn T[i] = T0 y[i] = 1 - ((1 - x[i]) * coef[1] * P2sat) / (float( self.databox.text())) data.write( str(round(T[i], 4)) + ', ' + str(round(x[i], 4)) + ', ' + str(round(y[i], 4))) data.write('\n') self.graphics1.plot(x, y, pen='r') self.graphics1.plot(x, x, pen='r') self.graphics1.setLabel('left', 'Gas composition of ' + self.comp1.currentText(), color='r', size=20) self.graphics1.setLabel('bottom', 'Liquid composition of ' + self.comp1.currentText(), color='b', size=20) self.graphics2.plot(x, T, pen='g') self.graphics2.plot(y, T, pen='k') self.graphics2.setLabel('left', 'Temperature of ' + self.comp1.currentText() + ' [K]', color='r', size=20) self.graphics2.setLabel('bottom', 'Composition of ' + self.comp1.currentText(), color='b', size=20) data.close() except: print('error') elif signal == "K": #Erase float_files if os.path.exists('float_files\\tconstdata.txt'): os.remove('float_files\\tconstdata.txt') try: data = open('float_files\\tconstdata.txt', 'a') newData = Equilibrium( lchem=[self.comp1.currentText(), self.comp2.currentText()], t=float(self.databox.text())) self.A, self.B, self.C, self.Tmax, self.Tmin, self.DG = newData.compData( ) Pvap = 10**(self.A - (self.B / (float(self.databox.text()) + self.C))) data.write('Pressure [bar], x, y\n') for i in range(np.size(x)): actCoef = UNIFAC(T=float(self.databox.text()), xs=[x[i], 1 - x[i]], chemgroups=self.DG) P[i] = np.sum(Pvap * np.asarray(actCoef) * np.asarray([x[i], 1 - x[i]])) y[i] = ((x[i] * actCoef[0] * Pvap[0])) / P[i] data.write( str(round(P[i], 4)) + ', ' + str(round(x[i], 4)) + ', ' + str(round(y[i], 4))) data.write('\n') self.graphics1.plot(x, y, pen='r') self.graphics1.plot(x, x, pen='r') self.graphics1.setLabel('left', 'Gas composition of ' + self.comp1.currentText(), color='r', size=20) self.graphics1.setLabel('bottom', 'Liquid composition of ' + self.comp1.currentText(), color='b', size=20) self.graphics2.plot(x, P, pen='b') self.graphics2.plot(y, P, pen='r') self.graphics2.setLabel('left', 'Pressure of ' + self.comp1.currentText() + ' [bar]', color='r', size=20) self.graphics2.setLabel('bottom', 'Composition of ' + self.comp1.currentText(), color='b', size=20) data.close() except: print('Error!') def saveData(self): if self.changeTextUni.text() == 'bar': try: filename = QtWidgets.QFileDialog.getSaveFileName( caption='Salvar arquivo', directory='c:\\', filter='(*.xlsx)', initialFilter='') data = pd.read_csv('float_files\\pconstdata.txt', sep=', ') data.to_excel(excel_writer=filename[0]) os.remove('float_files\\pconstdata.txt') except: pass elif self.changeTextUni.text() == 'K': try: filename = QtWidgets.QFileDialog.getSaveFileName( caption='Salvar arquivo', directory='c:\\', filter='(*.xlsx)', initialFilter='') data = pd.read_csv('float_files\\tconstdata.txt', sep=', ') data.to_excel(excel_writer=filename[0]) os.remove('float_files\\tconstdata.txt') except: pass def aboutMsg(self): msg = QtWidgets.QMessageBox() msg.setWindowTitle('Sobre') msg.setWindowIcon(QtGui.QIcon('images\Icone.jpg')) msg.setText( 'Programa desenvolvido para calcular o equilíbrio de fase líquido-vapor de um sistema binário com fase vapor ideal e fase liquída não ideal cujo' + ' coeficiente de atividade é obtido por meio do método UNIFAC') x = msg.exec_()
class Ui_MainWindow(object): def __init__(self, state): super().__init__() self.state = state self.timer = QtCore.QTimer() self.timer.timeout.connect(self.update_graph) self.timer.start(1000) def update_graph(self): pen = mkPen(color=(255, 255, 0)) pen_2 = mkPen(color=(0, 150, 255)) self.state.update_graph(self.graphicsView, self.lcdNumber_2, pen) self.state.update_graph_2(self.graphicsView_2, self.lcdNumber, pen_2) def clear_values(self): self.state.clear_values(self.graphicsView, self.lcdNumber_2, self.pushButton) self.state.clear_values_2(self.graphicsView_2, self.lcdNumber, self.pushButton) def toggle_start(self): self.state.toggle_start(self.pushButton) def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(962, 761) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.graphicsView = PlotWidget(self.centralwidget) self.graphicsView.setGeometry(QtCore.QRect(10, 10, 941, 311)) self.graphicsView.setObjectName("graphicsView") self.splitter = QtWidgets.QSplitter(self.centralwidget) self.splitter.setGeometry(QtCore.QRect(440, 650, 511, 61)) self.splitter.setOrientation(QtCore.Qt.Horizontal) self.splitter.setObjectName("splitter") self.pushButton = QtWidgets.QPushButton(self.splitter) font = QtGui.QFont() font.setPointSize(12) font.setBold(True) font.setWeight(75) self.pushButton.setFont(font) self.pushButton.setObjectName("pushButton") self.pushButton_2 = QtWidgets.QPushButton(self.splitter) font = QtGui.QFont() font.setPointSize(12) font.setBold(True) font.setWeight(75) self.pushButton_2.setFont(font) self.pushButton_2.setObjectName("pushButton_2") self.lcdNumber = QtWidgets.QLCDNumber(self.centralwidget) self.lcdNumber.setGeometry(QtCore.QRect(220, 650, 201, 61)) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(0, 170, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Light, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Midlight, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Dark, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Mid, brush) brush = QtGui.QBrush(QtGui.QColor(0, 170, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush) brush = QtGui.QBrush(QtGui.QColor(0, 170, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Light, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Midlight, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Dark, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Mid, brush) brush = QtGui.QBrush(QtGui.QColor(0, 170, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Light, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Midlight, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Dark, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Mid, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush) self.lcdNumber.setPalette(palette) self.lcdNumber.setAutoFillBackground(True) self.lcdNumber.setSmallDecimalPoint(True) self.lcdNumber.setDigitCount(5) self.lcdNumber.setMode(QtWidgets.QLCDNumber.Dec) self.lcdNumber.setSegmentStyle(QtWidgets.QLCDNumber.Flat) self.lcdNumber.setProperty("value", 0.0) self.lcdNumber.setObjectName("lcdNumber") self.label = QtWidgets.QLabel(self.centralwidget) self.label.setGeometry(QtCore.QRect(240, 650, 21, 21)) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(0, 170, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 170, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.BrightText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 170, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 170, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.BrightText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(120, 120, 120)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(120, 120, 120)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.BrightText, brush) brush = QtGui.QBrush(QtGui.QColor(120, 120, 120)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText, brush) self.label.setPalette(palette) font = QtGui.QFont() font.setFamily("Georgia") font.setPointSize(14) font.setBold(False) font.setWeight(50) self.label.setFont(font) self.label.setObjectName("label") self.graphicsView_2 = PlotWidget(self.centralwidget) self.graphicsView_2.setGeometry(QtCore.QRect(10, 340, 941, 291)) self.graphicsView_2.setObjectName("graphicsView_2") self.lcdNumber_2 = QtWidgets.QLCDNumber(self.centralwidget) self.lcdNumber_2.setGeometry(QtCore.QRect(10, 650, 201, 61)) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(255, 255, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Light, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Midlight, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Dark, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Mid, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Light, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Midlight, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Dark, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Mid, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Light, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Midlight, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Dark, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Mid, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush) self.lcdNumber_2.setPalette(palette) self.lcdNumber_2.setAutoFillBackground(True) self.lcdNumber_2.setSmallDecimalPoint(True) self.lcdNumber_2.setDigitCount(5) self.lcdNumber_2.setMode(QtWidgets.QLCDNumber.Dec) self.lcdNumber_2.setSegmentStyle(QtWidgets.QLCDNumber.Flat) self.lcdNumber_2.setProperty("value", 0.0) self.lcdNumber_2.setObjectName("lcdNumber_2") self.label_2 = QtWidgets.QLabel(self.centralwidget) self.label_2.setGeometry(QtCore.QRect(20, 650, 41, 21)) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(255, 255, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.BrightText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.BrightText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(120, 120, 120)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(120, 120, 120)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(255, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.BrightText, brush) brush = QtGui.QBrush(QtGui.QColor(120, 120, 120)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText, brush) self.label_2.setPalette(palette) font = QtGui.QFont() font.setFamily("Georgia") font.setPointSize(12) font.setBold(False) font.setWeight(50) self.label_2.setFont(font) self.label_2.setObjectName("label_2") MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 962, 21)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) self.pushButton_2.clicked.connect(self.clear_values) self.pushButton.clicked.connect(self.toggle_start) self.graphicsView.setLabel('left', "Ritmo Cardiaco (BPM)") self.graphicsView.setLabel('bottom', "Tiempo (s)") self.graphicsView_2.setLabel('left', "SPO2 (%)") self.graphicsView_2.setLabel('bottom', "Tiempo (s)") def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "Ritmo Cardiaco y SPO2")) self.pushButton.setText(_translate("MainWindow", "Pausar")) self.pushButton_2.setText(_translate("MainWindow", "Limpiar")) self.label.setText(_translate("MainWindow", "%")) self.label_2.setText(_translate("MainWindow", "BPM"))
class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(700, 1000) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.CB_Euler = QtWidgets.QCheckBox(self.centralwidget) self.CB_Euler.setGeometry(QtCore.QRect(20, 270, 200, 17)) font = QtGui.QFont() font.setPointSize(10) self.CB_Euler.setFont(font) self.CB_Euler.setObjectName("CB_Euler") self.CB_I_Euler = QtWidgets.QCheckBox(self.centralwidget) self.CB_I_Euler.setGeometry(QtCore.QRect(20, 310, 200, 17)) font = QtGui.QFont() font.setPointSize(10) self.CB_I_Euler.setFont(font) self.CB_I_Euler.setObjectName("CB_I_Euler") self.CB_Runge_Kutta = QtWidgets.QCheckBox(self.centralwidget) self.CB_Runge_Kutta.setGeometry(QtCore.QRect(20, 330, 200, 17)) font = QtGui.QFont() font.setPointSize(10) self.CB_Runge_Kutta.setFont(font) self.CB_Runge_Kutta.setObjectName("CB_Runge_Kutta") self.CB_Exact = QtWidgets.QCheckBox(self.centralwidget) self.CB_Exact.setGeometry(QtCore.QRect(20, 290, 200, 17)) font = QtGui.QFont() font.setPointSize(10) self.CB_Exact.setFont(font) self.CB_Exact.setObjectName("CB_Exact") self.X_0 = QtWidgets.QLabel(self.centralwidget) self.X_0.setGeometry(QtCore.QRect(20, 50, 21, 16)) font = QtGui.QFont() font.setPointSize(10) self.X_0.setFont(font) self.X_0.setObjectName("X_0") self.Y_0 = QtWidgets.QLabel(self.centralwidget) self.Y_0.setGeometry(QtCore.QRect(20, 80, 21, 16)) font = QtGui.QFont() font.setPointSize(10) self.Y_0.setFont(font) self.Y_0.setObjectName("Y_0") self.X = QtWidgets.QLabel(self.centralwidget) self.X.setGeometry(QtCore.QRect(20, 110, 21, 16)) font = QtGui.QFont() font.setPointSize(10) self.X.setFont(font) self.X.setObjectName("X") self.N = QtWidgets.QLabel(self.centralwidget) self.N.setGeometry(QtCore.QRect(20, 140, 16, 16)) font = QtGui.QFont() font.setPointSize(10) self.N.setFont(font) self.N.setObjectName("N") self.lE_X_0 = QtWidgets.QLineEdit(self.centralwidget) self.lE_X_0.setGeometry(QtCore.QRect(40, 50, 131, 20)) self.lE_X_0.setObjectName("lE_X_0") self.lE_Y_0 = QtWidgets.QLineEdit(self.centralwidget) self.lE_Y_0.setGeometry(QtCore.QRect(40, 80, 131, 20)) self.lE_Y_0.setObjectName("lE_Y_0") self.lE_X = QtWidgets.QLineEdit(self.centralwidget) self.lE_X.setGeometry(QtCore.QRect(40, 110, 131, 20)) self.lE_X.setObjectName("lE_X") self.lE_N = QtWidgets.QLineEdit(self.centralwidget) self.lE_N.setGeometry(QtCore.QRect(40, 140, 131, 20)) self.lE_N.setObjectName("lE_N") self.N_i = QtWidgets.QLabel(self.centralwidget) self.N_i.setGeometry(QtCore.QRect(20, 170, 16, 16)) font = QtGui.QFont() font.setPointSize(10) self.N_i.setFont(font) self.N_i.setObjectName("N_i") self.X_4 = QtWidgets.QLabel(self.centralwidget) self.X_4.setGeometry(QtCore.QRect(20, 200, 16, 16)) font = QtGui.QFont() font.setPointSize(10) self.X_4.setFont(font) self.X_4.setObjectName("X_4") self.lE_N_i = QtWidgets.QLineEdit(self.centralwidget) self.lE_N_i.setGeometry(QtCore.QRect(40, 170, 131, 20)) self.lE_N_i.setObjectName("lE_N_i") self.lE_N_f = QtWidgets.QLineEdit(self.centralwidget) self.lE_N_f.setGeometry(QtCore.QRect(40, 200, 131, 20)) self.lE_N_f.setObjectName("lE_N_f") self.Solutions = QtWidgets.QLabel(self.centralwidget) self.Solutions.setGeometry(QtCore.QRect(20, 240, 141, 16)) font = QtGui.QFont() font.setPointSize(11) self.Solutions.setFont(font) self.Solutions.setObjectName("Solutions") self.Parameters = QtWidgets.QLabel(self.centralwidget) self.Parameters.setGeometry(QtCore.QRect(20, 20, 141, 16)) font = QtGui.QFont() font.setPointSize(11) self.Parameters.setFont(font) self.Parameters.setObjectName("Parameters") self.calculate = QtWidgets.QPushButton(self.centralwidget) self.calculate.setGeometry(QtCore.QRect(110, 360, 75, 23)) self.calculate.setObjectName("calculate") self.widget = PlotWidget(self.centralwidget) self.widget.setGeometry(QtCore.QRect(220, 20, 421, 300)) self.widget.setObjectName("widget") self.widget.setBackground('w') self.widget.setTitle("Function & its approximations") self.widget1 = PlotWidget(self.centralwidget) self.widget1.setGeometry(QtCore.QRect(220, 340, 421, 300)) self.widget1.setObjectName("widget1") self.widget1.setBackground('w') self.widget1.setTitle("Local Errors") self.widget2 = PlotWidget(self.centralwidget) self.widget2.setGeometry(QtCore.QRect(220, 660, 421, 300)) self.widget2.setObjectName("widget2") self.widget2.setBackground('w') self.widget2.setTitle("Total Errors") MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 1181, 21)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.calculate.clicked.connect(lambda: self.draw()) self.widget.setBackground('w') self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) self.CB_Euler.setText(_translate("MainWindow", "Euler(green)")) self.CB_I_Euler.setText(_translate("MainWindow", "Imp_Euler(glue)")) self.CB_Runge_Kutta.setText( _translate("MainWindow", "Runge-Kutta(~black)")) self.CB_Exact.setText(_translate("MainWindow", "Exact(red)")) self.X_0.setText(_translate("MainWindow", "X<sub>0</sub>")) self.Y_0.setText(_translate("MainWindow", "Y<sub>0</sub>")) self.X.setText( _translate("MainWindow", "<html><head/><body><p>X</p></body></html>")) self.N.setText( _translate("MainWindow", "<html><head/><body><p>N</p></body></html>")) self.N_i.setText(_translate("MainWindow", "N<sub>i</sub>")) self.X_4.setText(_translate("MainWindow", "N<sub>f</sub>")) self.Solutions.setText(_translate("MainWindow", "Solutions")) self.Parameters.setText(_translate("MainWindow", "Parameters")) self.calculate.setText(_translate("MainWindow", "Calculate")) def Solution_calc(self): try: x0 = float(self.lE_X_0.text()) y0 = float(self.lE_Y_0.text()) x = float(self.lE_X.text()) N = int(self.lE_N.text()) except ValueError: print("Wrong input") de = DE("1/x + (2*y)/(x*math.log(x))", x0, y0, x, N) exact = Exact_Solution() euler = Euler_Solution() ieuler = Improved_Euler_Solution() runge = Runge_Kutta_Solution() self.ex_xs, self.ex_ys = exact.solve(de) self.eu_xs, self.eu_ys = euler.solve(de) self.ieu_xs, self.ieu_ys = ieuler.solve(de) self.rk_xs, self.rk_ys = runge.solve(de) return de def Error_calc(self, de: DE): err = Error() self.eerx, self.eery = err.local_calc(self.ex_ys, self.eu_xs, self.eu_ys) self.ieerx, self.ieery = err.local_calc(self.ex_ys, self.ieu_xs, self.ieu_ys) self.rkerx, self.rkery = err.local_calc(self.ex_ys, self.rk_xs, self.rk_ys) try: N_i = int(self.lE_N_i.text()) N_f = int(self.lE_N_f.text()) if (N_i < N_f): e_g = [] i_g = [] r_g = [] h = [] for N in range(N_i, N_f + 1): de = DE("1/x + (2*y)/(x*math.log(x))", de.x0, de.y0, de.x, N) h.append(N) exact = Exact_Solution() euler = Euler_Solution() improved = Improved_Euler_Solution() runge = Runge_Kutta_Solution() real_xs, real_ys = exact.solve(de) euler_xs, euler_ys = euler.solve(de) improved_xs, improved_ys = improved.solve(de) runge_xs, runge_ys = runge.solve(de) e_g.append( max(err.global_calc(real_ys, euler_xs, euler_ys)[1])) i_g.append( max( err.global_calc(real_ys, improved_xs, improved_ys)[1])) r_g.append( max(err.global_calc(real_ys, runge_xs, runge_ys)[1])) return e_g, i_g, r_g, h except ValueError: print("Wrong input") return [], [], [], [] def draw(self): self.widget.clear() self.widget1.clear() self.widget2.clear() de = self.Solution_calc() pen1 = pg.mkPen(color=(255, 0, 0)) pen2 = pg.mkPen(color=(0, 255, 0)) pen3 = pg.mkPen(color=(0, 0, 255)) pen4 = pg.mkPen(color=(64, 0, 64)) if (self.CB_Exact.isChecked()): self.widget.plot(self.ex_xs, self.ex_ys, name="Exact", pen=pen1) if (self.CB_Euler.isChecked()): self.widget.plot(self.eu_xs, self.eu_ys, name="Euler", pen=pen2) if (self.CB_I_Euler.isChecked()): self.widget.plot(self.ieu_xs, self.ieu_ys, name="Improved Euler", pen=pen3) if (self.CB_Runge_Kutta.isChecked()): self.widget.plot(self.rk_xs, self.rk_ys, name="Runge Kutta", pen=pen4) self.widget.setLabel('left', 'y') self.widget.setLabel('bottom', 'x') e_g, i_g, r_g, h = self.Error_calc(de) if (self.CB_Euler.isChecked()): self.widget1.plot(self.eerx, self.eery, name="Euler", pen=pen2) if (self.CB_I_Euler.isChecked()): self.widget1.plot(self.ieerx, self.ieery, name="Improved Euler", pen=pen3) if (self.CB_Runge_Kutta.isChecked()): self.widget1.plot(self.rkerx, self.rkery, name="Runge Kutta", pen=pen4) self.widget1.setLabel('left', 'Local error') self.widget1.setLabel('bottom', 'x') if (self.CB_Euler.isChecked()): self.widget2.plot(h, e_g, name="Euler", pen=pen2) if (self.CB_I_Euler.isChecked()): self.widget2.plot(h, i_g, name="Improved Euler", pen=pen3) if (self.CB_Runge_Kutta.isChecked()): self.widget2.plot(h, r_g, name="Runge Kutta", pen=pen4) self.widget2.setLabel('left', ' Total approximation error ') self.widget2.setLabel('bottom', 'Interval')
class Window(QWidget): def __init__(self, *args, **kwargs): super(Window, self).__init__(*args, **kwargs) self.title = "Motor Control" self.setWindowTitle(self.title) #Application Size self.left = 100 self.top = 100 self.width = 1000 self.height = 700 self.setGeometry(self.left, self.top, self.width, self.height) self.initUI() def initUI(self): self.setStyleSheet(qdarkstyle.load_stylesheet()) self.horizontalLayout = QHBoxLayout() self.verticalLayout = QVBoxLayout() self.verticalLayout.setSizeConstraint(QLayout.SetDefaultConstraint) self.verticalLayout.setSpacing(6) self.gridLayout = QGridLayout() self.imageLabel = QLabel() sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.imageLabel.sizePolicy().hasHeightForWidth()) self.imageLabel.setSizePolicy(sizePolicy) self.imageLabel.setMinimumSize(QSize(200, 130)) self.imageLabel.setMaximumSize(QSize(200, 130)) self.imageLabel.setPixmap( QPixmap("./Arduino/logo/CUAtHomeLogo-Horz.png").scaled( 200, 130, Qt.KeepAspectRatio, Qt.FastTransformation)) self.verticalLayout.addWidget(self.imageLabel) self.startbutton = QPushButton("Start", self) self.startbutton.setCheckable(False) self.startbutton.clicked.connect(self.startbutton_pushed) self.startbutton.setMaximumSize(QSize(100, 20)) self.gridLayout.addWidget(self.startbutton, 0, 0, 1, 1) self.stopbutton = QPushButton("Stop", self) self.stopbutton.setCheckable(False) self.stopbutton.clicked.connect(self.stopbutton_pushed) sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.stopbutton.sizePolicy().hasHeightForWidth()) self.stopbutton.setSizePolicy(sizePolicy) self.stopbutton.setMaximumSize(QSize(100, 20)) self.gridLayout.addWidget(self.stopbutton, 0, 1, 1, 1) self.clearbutton = QPushButton("Clear", self) self.clearbutton.setCheckable(False) self.clearbutton.clicked.connect(self.clearbutton_pushed) self.clearbutton.setMaximumSize(QSize(100, 20)) self.gridLayout.addWidget(self.clearbutton, 1, 0, 1, 1) self.savebutton = QPushButton("Save", self) self.savebutton.setCheckable(False) self.savebutton.clicked.connect(self.savebutton_pushed) sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.savebutton.sizePolicy().hasHeightForWidth()) self.savebutton.setSizePolicy(sizePolicy) self.savebutton.setMaximumSize(QSize(100, 20)) self.gridLayout.addWidget(self.savebutton, 1, 1, 1, 1) self.settings = QPushButton("Settings", self) self.settings.clicked.connect(self.settingsMenu) self.settings.setMaximumSize(QSize(300, 20)) self.gridLayout.addWidget(self.settings, 2, 0, 1, 2) self.checkBoxShowAll = QCheckBox("Show All Plots", self) self.checkBoxShowAll.setMaximumSize(QSize(100, 20)) self.checkBoxShowAll.setChecked(True) self.checkBoxShowAll.toggled.connect(self.visibilityAll) self.gridLayout.addWidget(self.checkBoxShowAll, 3, 0, 1, 1) self.checkBoxHideAll = QCheckBox("Hide All Plots", self) self.checkBoxHideAll.setChecked(False) self.checkBoxHideAll.toggled.connect(self.hideAll) sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.checkBoxHideAll.sizePolicy().hasHeightForWidth()) self.checkBoxHideAll.setSizePolicy(sizePolicy) self.checkBoxHideAll.setMaximumSize(QSize(100, 20)) self.gridLayout.addWidget(self.checkBoxHideAll, 3, 1, 1, 1) self.checkBoxPlot1 = QCheckBox("Plot 1", self) self.checkBoxPlot1.toggled.connect(self.visibility1) self.checkBoxPlot1.setMaximumSize(QSize(100, 20)) self.gridLayout.addWidget(self.checkBoxPlot1, 4, 0, 1, 1) self.checkBoxPlot2 = QCheckBox("Plot 2", self) self.checkBoxPlot2.toggled.connect(self.visibility2) sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.checkBoxPlot2.sizePolicy().hasHeightForWidth()) self.checkBoxPlot2.setSizePolicy(sizePolicy) self.checkBoxPlot2.setMaximumSize(QSize(100, 20)) self.gridLayout.addWidget(self.checkBoxPlot2, 4, 1, 1, 1) self.checkBoxShowAll.stateChanged.connect(self.checkbox_logic) self.checkBoxHideAll.stateChanged.connect(self.checkbox_logic) self.checkBoxPlot1.stateChanged.connect(self.checkbox_logic) self.checkBoxPlot2.stateChanged.connect(self.checkbox_logic) self.PowerScalingLabel = QLabel("Power Scaling (%)", self) self.PowerScalingLabel.setMinimumSize(QSize(100, 20)) self.PowerScalingLabel.setMaximumSize(QSize(100, 20)) self.gridLayout.addWidget(self.PowerScalingLabel, 7, 0, 1, 1) self.PowerScalingInput = QLineEdit("", self) sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.PowerScalingInput.sizePolicy().hasHeightForWidth()) self.PowerScalingInput.setSizePolicy(sizePolicy) self.PowerScalingInput.setMaximumSize(QSize(100, 20)) #self.PowerScalingInput.setValidator(QRegExpValidator(QRegExp("^[0-9][0-9]?$|^100$"))) #0-1 as a float FIX THIS self.gridLayout.addWidget(self.PowerScalingInput, 7, 1, 1, 1) self.FrequencyLabel = QLabel("Frequency (Hz)", self) self.FrequencyLabel.setMinimumSize(QSize(100, 20)) self.FrequencyLabel.setMaximumSize(QSize(100, 20)) self.gridLayout.addWidget(self.FrequencyLabel, 8, 0, 1, 1) self.FrequencyInput = QLineEdit("", self) sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.FrequencyInput.sizePolicy().hasHeightForWidth()) self.FrequencyInput.setSizePolicy(sizePolicy) self.FrequencyInput.setMaximumSize(QSize(100, 20)) self.FrequencyInput.setValidator(QDoubleValidator()) self.gridLayout.addWidget(self.FrequencyInput, 8, 1, 1, 1) PID_validator = QDoubleValidator( 0.0000, 50.000, 4, notation=QDoubleValidator.StandardNotation) self.PCheckBox = QCheckBox("P", self) self.PCheckBox.setMaximumSize(QSize(100, 20)) self.PCheckBox.setChecked(True) self.PCheckBox.toggled.connect(self.PCheckBoxLogic) self.gridLayout.addWidget(self.PCheckBox, 9, 0, 1, 1) self.PInput = QLineEdit("", self) sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.PInput.sizePolicy().hasHeightForWidth()) self.PInput.setSizePolicy(sizePolicy) self.PInput.setMaximumSize(QSize(100, 20)) self.PInput.setValidator(PID_validator) self.gridLayout.addWidget(self.PInput, 9, 1, 1, 1) self.ICheckBox = QCheckBox("I", self) self.ICheckBox.setMaximumSize(QSize(100, 20)) self.ICheckBox.setChecked(True) self.ICheckBox.toggled.connect(self.ICheckBoxLogic) self.gridLayout.addWidget(self.ICheckBox, 10, 0, 1, 1) self.IInput = QLineEdit("", self) sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.IInput.sizePolicy().hasHeightForWidth()) self.IInput.setSizePolicy(sizePolicy) self.IInput.setMaximumSize(QSize(100, 20)) self.IInput.setValidator(PID_validator) self.gridLayout.addWidget(self.IInput, 10, 1, 1, 1) self.DCheckBox = QCheckBox("D", self) self.DCheckBox.setMaximumSize(QSize(100, 20)) self.DCheckBox.setChecked(True) self.DCheckBox.toggled.connect(self.DCheckBoxLogic) self.gridLayout.addWidget(self.DCheckBox, 11, 0, 1, 1) self.DInput = QLineEdit("", self) sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.DInput.sizePolicy().hasHeightForWidth()) self.DInput.setSizePolicy(sizePolicy) self.DInput.setMaximumSize(QSize(100, 20)) self.DInput.setValidator(PID_validator) self.gridLayout.addWidget(self.DInput, 11, 1, 1, 1) self.LabType = QComboBox() self.LabType.addItems(["Position", "Speed"]) #self.LabType.activated.connect(self.getLabType) sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.LabType.sizePolicy().hasHeightForWidth()) self.LabType.setSizePolicy(sizePolicy) self.LabType.setMaximumSize(QSize(100, 20)) self.gridLayout.addWidget(self.LabType, 5, 1, 1, 1) self.LabLabel = QLabel("Lab Type") self.LabLabel.setMaximumSize(QSize(100, 20)) self.gridLayout.addWidget(self.LabLabel, 5, 0, 1, 1) self.inputForms = QComboBox() self.inputForms.addItems(["Sine", "Step"]) self.inputForms.activated.connect(self.getInput) sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.inputForms.sizePolicy().hasHeightForWidth()) self.inputForms.setSizePolicy(sizePolicy) self.inputForms.setMaximumSize(QSize(100, 20)) self.gridLayout.addWidget(self.inputForms, 6, 1, 1, 1) self.inputType = QLabel("Input Type") self.inputType.setMaximumSize(QSize(100, 20)) self.gridLayout.addWidget(self.inputType, 6, 0, 1, 1) self.verticalLayout.addLayout(self.gridLayout) spacerItem = QSpacerItem(20, 80, QSizePolicy.Minimum, QSizePolicy.Fixed) self.verticalLayout.addItem(spacerItem) #What is this? self.label = QLabel() self.label.setMaximumSize(QSize(200, 130)) self.label.setText("") self.verticalLayout.addWidget(self.label) self.horizontalLayout.addLayout(self.verticalLayout) self.rightVerticalLayout = QVBoxLayout() self.graphWidgetOutput = PlotWidget() self.graphWidgetInput = PlotWidget() #Adds grid lines self.graphWidgetOutput.showGrid(x=True, y=True, alpha=None) self.graphWidgetInput.showGrid(x=True, y=True, alpha=None) #self.graphWidget.setXRange(0, 100, padding=0) #Doesn't move with the plot. Can drag around #self.graphWidget.setLimits(xMin=0, xMax=100)#, yMin=c, yMax=d) #Doesn't move with the plot. Cannot drag around #self.graphWidget.setYRange(0, 4, padding=0) self.graphWidgetOutput.setYRange(-11, 11, padding=0) self.graphWidgetOutput.enableAutoRange() self.graphWidgetInput.setYRange(-11, 11, padding=0) self.graphWidgetInput.enableAutoRange() #Changes background color of graph self.graphWidgetOutput.setBackground((0, 0, 0)) self.graphWidgetInput.setBackground((0, 0, 0)) #Adds a legend after data starts to plot NOT before self.graphWidgetOutput.addLegend() #Adds title to graphs self.graphWidgetOutput.setTitle("Response", color="w", size="12pt") self.graphWidgetInput.setTitle("PWM Actuation Signal", color="w", size="12pt") self.rightVerticalLayout.addWidget(self.graphWidgetOutput) self.rightVerticalLayout.addWidget(self.graphWidgetInput) self.horizontalLayout.addLayout(self.rightVerticalLayout) self.setLayout(self.horizontalLayout) #Plot time update settings self.timer = QTimer() self.timer.setInterval( 50 ) #Changes the plot speed. Defaulted to 50. Can be placed in startbutton_pushed() method self.initialState() time.sleep(2) try: self.timer.timeout.connect(self.update) except: raise Exception("Not Connected") #self.show() #Checkbox logic def checkbox_logic(self, state): # checking if state is checked if state == Qt.Checked: if self.sender() == self.checkBoxShowAll: self.checkBoxHideAll.setChecked(False) self.checkBoxPlot1.setChecked(False) self.checkBoxPlot2.setChecked(False) #self.checkBoxShow.stateChanged.disconnect(self.uncheck) elif self.sender() == self.checkBoxHideAll: #self.checkBoxShow.stateChanged.connect(self.uncheck) self.checkBoxShowAll.setChecked(False) self.checkBoxPlot1.setChecked(False) self.checkBoxPlot2.setChecked(False) elif self.sender() == self.checkBoxPlot1: self.checkBoxShowAll.setChecked(False) self.checkBoxHideAll.setChecked(False) self.checkBoxPlot2.setChecked(False) elif self.sender() == self.checkBoxPlot2: self.checkBoxShowAll.setChecked(False) self.checkBoxHideAll.setChecked(False) self.checkBoxPlot1.setChecked(False) #Resets data arrays and establishes serial communcation. Disables itself after clicking def startbutton_pushed(self): self.initialState( ) #Reinitializes arrays in case you have to retake data self.size = self.serial_values[3] #Value from settings. Windows data #self.buffersize = self.serial_values[4] #Value from settings. Restricts buffer data ''' self.ser = serial.Serial(port = self.serial_values[0], baudrate = self.serial_values[1], timeout = self.serial_values[2]) self.ser.flushInput() self.ser.write(b'A') time.sleep(2) print("Recording Data") self.timer.start() #self.timer.setInterval(50) self.curve() self.startbutton.clicked.disconnect(self.startbutton_pushed) ''' self.serialInstance = SerialComm(self.serial_values[0], self.serial_values[1], self.serial_values[2]) self.serialInstance.serialOpen() time.sleep(2) print("Recording Data") self.timer.start() self.curve() self.startbutton.clicked.disconnect(self.startbutton_pushed) #Stops timer and ends serial communication def stopbutton_pushed(self): self.timer.stop() #self.ser.close() self.serialInstance.serialClose() ''' print("y1 zeros:", self.y1_zeros) print("y2 zeros:", self.y2_zeros) print("y1 full:", self.y1) print("y2 full:", self.y2) ''' #Resets both plotting windows and reenables Start Button def clearbutton_pushed(self): self.graphWidgetOutput.clear() self.graphWidgetInput.clear() self.graphWidgetOutput.enableAutoRange(axis=None, enable=True, x=None, y=None) self.startbutton.clicked.connect(self.startbutton_pushed) #Dumps data into a csv file to a selected path def savebutton_pushed(self): self.createCSV() path = QFileDialog.getSaveFileName(self, 'Save CSV', os.getenv('HOME'), 'CSV(*.csv)') if path[0] != '': with open(path[0], 'w', newline='') as csvfile: csvwriter = csv.writer(csvfile) csvwriter.writerow(self.header) csvwriter.writerows(self.data_set) #Creates csv data def createCSV(self): self.header = ['time', 'y1', 'y2'] self.data_set = zip(self.time, self.y1, self.y2) #Initilizes lists/arrays def initialState(self): self.buffersize = 500 #np array size that is used to plot data self.step = 0 #Used for repositioning data in plot window to the left #Data buffers. What is being plotted in the 2 windows self.time_zeros = np.zeros(self.buffersize + 1, float) self.y1_zeros = np.zeros(self.buffersize + 1, float) self.y2_zeros = np.zeros(self.buffersize + 1, float) self.y3_zeros = np.zeros(self.buffersize + 1, float) #Complete data. What will be written to the csv file self.time = list() self.y1 = list() self.y2 = list() self.y3 = list() self.getLabType() ''' def readValues(self): arduinoData = self.ser.readline().decode().replace('\r\n','').split(",") return arduinoData ''' #Initializes data# to have specific attributes def curve(self): pen1 = pg.mkPen(color=(255, 0, 0), width=1) pen2 = pg.mkPen(color=(0, 255, 0), width=1) pen3 = pg.mkPen(color=(0, 0, 255), width=1) self.data1 = self.graphWidgetOutput.plot(pen=pen1, name="Data 1") #Response self.data2 = self.graphWidgetOutput.plot(pen=pen2, name="Data 2") #Setpoint self.data3 = self.graphWidgetInput.plot( pen=pen3, name="Data 3") #PWM Actuation Signal #Connected to timer to update plot. Incoming data is in the form of timestamp,data1,data2... def update(self): #fulldata = self.readValues() #print(fulldata) fulldata = self.serialInstance.readValues() self.step = self.step + 1 time_index = int(self.time_zeros[self.buffersize]) self.time_zeros[time_index] = self.time_zeros[time_index + self.size] = float( fulldata[0]) self.time_zeros[self.buffersize] = time_index = (time_index + 1) % self.size self.time.append(fulldata[0]) i = int(self.y1_zeros[self.buffersize]) self.y1_zeros[i] = self.y1_zeros[i + self.size] = float(fulldata[1]) self.y1_zeros[self.buffersize] = i = (i + 1) % self.size self.y1.append(fulldata[1]) j = int(self.y2_zeros[self.buffersize]) self.y2_zeros[j] = self.y2_zeros[j + self.size] = float(fulldata[2]) self.y2_zeros[self.buffersize] = j = (j + 1) % self.size self.y2.append(fulldata[2]) k = int(self.y3_zeros[self.buffersize]) self.y3_zeros[k] = self.y3_zeros[k + self.size] = float(fulldata[3]) self.y3_zeros[self.buffersize] = k = (k + 1) % self.size self.y3.append(fulldata[3]) self.data1.setData(self.time_zeros[time_index:time_index + self.size], self.y1_zeros[i:i + self.size]) self.data1.setPos(self.step, 0) self.data2.setData(self.time_zeros[time_index:time_index + self.size], self.y2_zeros[j:j + self.size]) self.data2.setPos(self.step, 0) self.data3.setData(self.time_zeros[time_index:time_index + self.size], self.y3_zeros[k:k + self.size]) self.data3.setPos(self.step, 0) #Below 4 change visibility of data# in the curves() method def visibilityAll(self): showall = self.sender() if showall.isChecked() == True: self.data1.setVisible(True) self.data2.setVisible(True) def hideAll(self): disappearall = self.sender() if disappearall.isChecked() == True: self.data1.setVisible(False) self.data2.setVisible(False) def visibility1(self): test1 = self.sender() if test1.isChecked() == True: self.data1.setVisible(True) self.data2.setVisible(False) def visibility2(self): test2 = self.sender() if test2.isChecked() == True: self.data2.setVisible(True) self.data1.setVisible(False) #Class instance of settings menu. Creates a dialog (popup) def settingsMenu(self): self.settingsPopUp = Dialog1() self.settingsPopUp.show() #self.settingsPopUp.exec() self.serial_values = self.settingsPopUp.getDialogValues() def PCheckBoxLogic(self): test1 = self.sender() if test1.isChecked() == True: self.PInput.setEnabled(True) elif test1.isChecked() == False: self.PInput.setEnabled(False) def ICheckBoxLogic(self): test1 = self.sender() if test1.isChecked() == True: self.IInput.setEnabled(True) elif test1.isChecked() == False: self.IInput.setEnabled(False) def DCheckBoxLogic(self): test1 = self.sender() if test1.isChecked() == True: self.DInput.setEnabled(True) elif test1.isChecked() == False: self.DInput.setEnabled(False) def PIDInput(self): if self.PInput.text() == "" or self.PCheckBox.checkState() == False: self.Pvalue = 0 else: self.Pvalue = self.PInput.text() if self.IInput.text() == "" or self.ICheckBox.checkState() == False: self.Ivalue = 0 else: self.Ivalue = self.IInput.text() if self.DInput.text() == "" or self.DCheckBox.checkState() == False: self.Dvalue = 0 else: self.Dvalue = self.DInput.text() return ([self.Pvalue, self.Ivalue, self.Dvalue]) #Function that connects output pyqtgraph widget, and the combobox def getInput(self): self.inputType = str(self.inputForms.currentText()) pen_input = pg.mkPen(color=(255, 0, 0), width=1) if self.inputType == "Sine": print("Sine") self.graphWidgetInput.clear() self.x_input = np.arange(0, 10, 0.1) self.y_input = np.sin(self.x_input) self.data_input = self.graphWidgetInput.plot(self.x_input, self.y_input, pen=pen_input) self.data_input.setData(self.x_input, self.y_input) self.graphWidgetInput.setYRange(-2, 2, padding=0) elif self.inputType == "Step": print("Step") self.graphWidgetInput.clear() self.x_input = np.arange(0, 10, 0.1) self.y_input = np.heaviside(self.x_input, 1) self.data_input = self.graphWidgetInput.plot(self.x_input, self.y_input, pen=pen_input) self.data_input.setData(self.x_input, self.y_input) self.graphWidgetInput.setYRange(-2, 2, padding=0) def getLabType(self): self.inputType = str(self.LabType.currentText()) if self.inputType == "Position": print("Lab: Position") return ( self.graphWidgetOutput.setLabel( 'left', "<span style=\"color:white;font-size:16px\">θ (°)</span>" ), self.graphWidgetInput.setLabel( 'left', "<span style=\"color:white;font-size:16px\">Voltage</span>" ), self.graphWidgetOutput.setLabel( 'bottom', "<span style=\"color:white;font-size:16px\">Time (s)</span>" ), self.graphWidgetInput.setLabel( 'bottom', "<span style=\"color:white;font-size:16px\">Time (s)</span>" )) elif self.inputType == "Speed": print("Lab: Speed") return ( self.graphWidgetOutput.setLabel( 'left', "<span style=\"color:white;font-size:16px\">ω (°/s)</span>" ), self.graphWidgetInput.setLabel( 'left', "<span style=\"color:white;font-size:16px\">Voltage</span>" ), self.graphWidgetOutput.setLabel( 'bottom', "<span style=\"color:white;font-size:16px\">Time (s)</span>" ), self.graphWidgetInput.setLabel( 'bottom', "<span style=\"color:white;font-size:16px\">Time (s)</span>" ), )
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()
class MoldynMainWindow(QMainWindow): updated_signal = pyqtSignal(int, float) movie_progress_signal = pyqtSignal(int) displayed_properties = dict() def __init__(self): super().__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) # Panneau modèle self.ui.newModelBtn.clicked.connect(self.create_model) self.ui.loadModelBtn.clicked.connect(self.load_model) self.ui.saveModelBtn.clicked.connect(self.save_model) self.ui.loadSimuBtn.clicked.connect(self.load_simulation) self.ui.gotoSimuBtn.clicked.connect(self.goto_simu) self.ui.newSimuBtn.clicked.connect(self.reset_model) self.ui.editModelBtn.clicked.connect(self.edit_model) self.displayed_properties_list = { "display_name" : ["Name"], "T" : ["Temperature", "K"], "Lennard-Jones and mass" : { "First species" : { "sigma_a" : ["Sigma", "m"], "epsilon_a" : ["Epsilon", "J"], "m_a" : ["Atomic mass", "kg"], "rcut_a" : ["rcut_a", "m"], }, "Second species" : { "sigma_b" : ["Sigma", "m"], "epsilon_b" : ["Epsilon", "J"], "m_b" : ["Atomic mass", "kg"], "rcut_b" : ["rcut_b", "m"], }, "Inter-species" : { "sigma_ab" : ["Sigma", "m"], "epsilon_ab" : ["Epsilon", "J"], "rcut_ab" : ["rcut_ab", "m"], }, }, "npart" : ["Atom number"], "x_a" : ["First species mole fraction"], "dt" : ["Timestep", "s"], "Spatial configuration" : { "length_x" : ["Width", "m"], "length_y" : ["Height", "m"], "x_periodic" : ["Periodic condition on x"], "y_periodic" : ["Periodic condition on y"], }, } def sub_items(item, parent): for k in item: if type(item[k]) == list: if len(item[k])>1: item[k][1:] = ["", item[k][1]] current_item = QTreeWidgetItem(item[k]) self.displayed_properties[k] = current_item else: current_item = QTreeWidgetItem([k]) sub_items(item[k], current_item) parent.addChild(current_item) current_item.setExpanded(True) self.ui.paramsTreeWidget.addChild = self.ui.paramsTreeWidget.addTopLevelItem self.ui.paramsTreeWidget.header().setResizeMode(QHeaderView.ResizeToContents) sub_items(self.displayed_properties_list, self.ui.paramsTreeWidget) # Panneau simu self.ui.iterationsSpinBox.valueChanged.connect(self.update_simu_time) self.ui.simulationTimeLineEdit.editingFinished.connect(self.update_iters) self.ui.simuBtn.clicked.connect(self.simulate) self.updated_signal.connect(self.update_progress) self.ui.designTemperatureBtn.clicked.connect(self.design_temperature_profile) self.progress_plt = PlotWidget(self.ui.progress_groupBox) self.ui.progress_groupBox.layout().addWidget(self.progress_plt, 2, 0, 1, 3) self.progress_plt.setXRange(0,1) self.progress_plt.setLabel('bottom',text='Iteration') self.progress_plt.setLabel('left',text='Speed', units='Iteration/s') self.progress_gr = self.progress_plt.plot(pen='y') self.t_deque = deque() self.ui.gotoProcessBtn.clicked.connect(self.goto_process) self.ui.RTViewBtn.clicked.connect(self.show_model) # Panneau processing self.ui.saveRModelBtn.clicked.connect(self.save_final_model) self.ui.saveSimuBtn.clicked.connect(self.save_simu_history) self.ui.reuseModelBtn.clicked.connect(self.reuse_model) self.ui.exportBtn.clicked.connect(self.export_to_csv) self.ui.PDFButton.clicked.connect(self.PDF) self.temporal_variables = { "Time":["time","s"], "Temperature":["T","K"], "Temperature control":["T_ctrl","K"], "Microscopic kinetic energy":["EC","J"], "Inter-atomic potential energy":["EP","J"], "Total energy":["ET","J"], "Number of bonds per atom":["bonds"], "Iteration":["iters"], } self.temp_variables_w = [] for v in self.temporal_variables: self.ui.lineComboW.addItem(v) i = QListWidgetItem(v) i.setCheckState(False) self.temp_variables_w.append(i) self.ui.lineListW.addItem(i) self._1d_options = { "log x":None, "log y":None, "grid":None, } for i_n in self._1d_options: i = QListWidgetItem(i_n) i.setCheckState(False) self.ui.list1DOptions.addItem(i) self._1d_options[i_n] = i self.ui.plotB.clicked.connect(self.line_graph) self._2d_options = { "density map": None, "deformation (compression)":None, "deformation (shear)":None, "particles": None, } for i_n in self._2d_options: i = QListWidgetItem(i_n) i.setCheckState(False) self.ui.surfListW.addItem(i) self._2d_options[i_n] = i self.ui.drawSurfButton.clicked.connect(self.draw_surf) self.ui.makeMovieBtn.clicked.connect(self.make_movie) self.movie_progress_signal.connect(self.ui.movieProgressBar.setValue) # Misc try: self._load_model(tmp_path) except: self.ui.statusbar.showMessage("Please choose a model.") else: self.ui.statusbar.showMessage("Using cached model.") self.show() # Panneau modèle def set_model(self, model): self.model = model self.ui.saveAllAtomsPositionCheckBox.setEnabled(True) self.ui.saveModelBtn.setEnabled(True) self.ui.gotoSimuBtn.setEnabled(True) self.ui.tab_simu.setEnabled(True) self.simulation = Simulation(self.model, prefer_gpu=self.ui.tryToUseGPUCheckBox.checkState()) self.model_view = ModelView(self.simulation.model) for dp in self.displayed_properties: self.displayed_properties[dp].setText(1, str(self.model.__getattr__(dp))) self.update_simu_time() self.model_to_cache() self.ui.tab_processing.setEnabled(False) self.ui.currentTime.setText("0") self.ui.currentIteration.setText("0") self.ui.editModelBtn.setEnabled(True) self.ui.newSimuBtn.setEnabled(True) self.ui.statusbar.showMessage("Model loaded, simulation can begin.") def reset_model(self): self.set_model(self.model) def edit_model(self): self.emd = EditModelDialog(self) self.emd.show() def load_simulation(self): path, filter = QFileDialog.getOpenFileName(caption="Load model", filter=SIMULATION_FILE_FILTER_) if path: ds = self._load_model(path) with ds.open(ds.STATE_FCT, 'r') as IO: for key, item in IO.items(): self.simulation.state_fct[key] = item c_i = len(self.simulation.state_fct["T"]) self.simulation.current_iter = c_i self.ui.currentIteration.setText(str(c_i)) self.ui.currentTime.setText(str((c_i)*self.model.dt)) self.enable_process_tab(True) t, T = self.simulation.state_fct["T_ramps"] if len(t)>1: self.simulation.set_T_ramps(t, T) t, Fx = self.simulation.state_fct["Fx_ramps"] if len(t)>1: self.simulation.set_Fx_ramps(t, Fx) t, Fy = self.simulation.state_fct["Fy_ramps"] if len(t)>1: self.simulation.set_Fy_ramps(t, Fy) sp = self.simulation.model.params["save_pos_history"] self.ui.groupBoxMovie.setEnabled(sp) self.ui.saveAllAtomsPositionCheckBox.setCheckState(sp) self.ui.saveAllAtomsPositionCheckBox.setEnabled(False) self.ui.statusbar.showMessage("Simulation history loaded.") def show_model(self): self.model_view.show() # bidon mais nécessaire pour que ça marche : on risque de redéfinir model donc model_view def create_model(self): self.cmd = CreateModelDialog(self) self.cmd.show() def load_model(self): path, filter = QFileDialog.getOpenFileName(caption="Load model", filter=MODEL_FILE_FILTER) if path: self._load_model(path) def _load_model(self, path): ds = DynState(path) model = Model() # position of particles with ds.open(ds.POS, 'r') as IO: model.pos = IO.load() # parameters with ds.open(ds.PAR) as IO: for key, item in IO.items(): model.params[key] = item # velocity with ds.open(ds.VEL, 'r') as IO: model.v = IO.load() model._m() self.set_model(model) return ds def _save_model(self, m): path, filter = QFileDialog.getSaveFileName(caption="Save model", filter=MODEL_FILE_FILTER) print(filter) if path: path = self._correct_path(path, filter, [".zip", ".mdl"]) try: shutil.rmtree(tmp1_path) except FileNotFoundError: pass ds = DynState(tmp1_path) ds.save_model(m) ds.to_zip(path) def _correct_path(self, path, filter, expected): for ext in expected: if not path.endswith(ext) and ext in filter: path += ext return path return path def save_model(self): self._save_model(self.model) def save_final_model(self): self._save_model(self.simulation.model) # Panneau simu def _model_to_cache(self, index): if (self.ui.tabWidget.currentWidget() is self.ui.tab_simu): self.model_to_cache() def model_to_cache(self): if self.model: self.ds = DynState(tmp_path) self.ds.save_model(self.model) def update_iters(self): try: t = _float(self.ui.simulationTimeLineEdit) except: self.update_simu_time() else: self.ui.iterationsSpinBox.setValue(int(t/self.simulation.model.dt)) def update_simu_time(self, v=None): self.ui.simulationTimeLineEdit.setText(str(self.model.dt*self.ui.iterationsSpinBox.value())) self.ui.simuProgressBar.setMaximum(self.ui.iterationsSpinBox.value()) self.progress_plt.setXRange(0, self.ui.iterationsSpinBox.value()) def goto_simu(self): self.ui.tabWidget.setCurrentWidget(self.ui.tab_simu) def design_temperature_profile(self): queue = Queue(1) axis = (0, (self.ui.iterationsSpinBox.value()+self.simulation.current_iter)*self.model.dt, 0, 100) queue.put((axis, *self.simulation.T_ramps, "Time (s)", "Temperature (K)", 0)) design_thread = Process(target=draggableLine.main, args=(queue,)) design_thread.start() design_thread.join() x_data, y_data = queue.get() queue.close() if len(x_data)<2: qmb = QMessageBox() qmb.setText("This only works with at least two points.") qmb.exec() return self.simulation.set_T_ramps(x_data, y_data) def update_progress(self, v, new_t): c_i = v+1 - self.c_i self.t_deque.append(1/(new_t - self.last_t)) self.last_t = new_t self.ui.simuProgressBar.setValue(c_i) if c_i==self.ui.iterationsSpinBox.value() or not c_i%10: self.progress_gr.setData(self.t_deque) self.ui.currentIteration.setText(str(v+1)) self.ui.currentTime.setText(str((v+1)*self.model.dt)) self.ui.ETA.setText(str(timedelta(seconds=int( (self.ui.iterationsSpinBox.value()/c_i - 1)*(new_t-self.simu_starttime))))) if self.save_pos: self.pos_IO.save(self.simulation.model.pos) def simulate(self): self.ui.simuBtn.setEnabled(False) self.ui.iterationsSpinBox.setEnabled(False) self.ui.simulationTimeLineEdit.setEnabled(False) self.ui.tryToUseGPUCheckBox.setEnabled(False) self.ui.temperature_groupBox.setEnabled(False) self.ui.saveAllAtomsPositionCheckBox.setEnabled(False) self.enable_process_tab(False) self.ui.simuProgressBar.setValue(0) self.last_t = time.perf_counter() self.t_deque.clear() self.t_deque.append(0) self.ui.statusbar.showMessage("Simulation is running...") self.save_pos = self.ui.saveAllAtomsPositionCheckBox.checkState() self.simulation.model.params["save_pos_history"] = self.save_pos if self.save_pos: mode = "a" if self.simulation.current_iter else "w" self.pos_IO = DynState(tmp_path).open(DynState.POS_H, mode=mode) self.pos_IO.__enter__() if len(self.simulation.T_ramps[0]): final_t = (self.simulation.current_iter + self.ui.iterationsSpinBox.value())*self.model.dt t, T = map(list,self.simulation.T_ramps) t.append(final_t) T.append(self.simulation.T_f(final_t)) self.simulation.set_T_ramps(t, T) def run(): # Pour continuer la simu précedente. On est obligés d'en créer une nouvelle pour des questions de scope. # On pourrait créer et conserver le thread une bonne fois pour toutes, pour que ce bricolage cesse. self.c_i = self.simulation.current_iter self.simulation = Simulation(simulation=self.simulation, prefer_gpu=self.ui.tryToUseGPUCheckBox.checkState()) self.model_view = ModelView(self.simulation.model) self.simu_starttime = time.perf_counter() def up(s): self.updated_signal.emit(s.current_iter, time.perf_counter()) self.simulation.iter(self.ui.iterationsSpinBox.value(), up) self.simu_thr.exit() def end(): if self.save_pos: self.pos_IO.file.close() with DynState(tmp_path).open(DynState.STATE_FCT, mode="w") as ds: ds.from_dict(self.simulation.state_fct) self.enable_process_tab(True) self.ui.simuBtn.setEnabled(True) self.ui.iterationsSpinBox.setEnabled(True) self.ui.tryToUseGPUCheckBox.setEnabled(True) self.ui.simulationTimeLineEdit.setEnabled(True) self.ui.temperature_groupBox.setEnabled(True) self.ui.groupBoxMovie.setEnabled(self.save_pos) self.ui.statusbar.showMessage("Simulation complete. (Iterations : " + str(self.simulation.current_iter) + ")") self.simu_thr = QThread() self.simu_thr.run = run self.simu_thr.finished.connect(end) self.simu_thr.start() def enable_process_tab(self, b): self.ui.tab_processing.setEnabled(b) self.ui.gotoProcessBtn.setEnabled(b) def goto_process(self): self.ui.tabWidget.setCurrentWidget(self.ui.tab_processing) # Panneau process def reuse_model(self): self.set_model(self.simulation.model) self.ui.tabWidget.setCurrentWidget(self.ui.tab_model) def save_simu_history(self): path, filter = QFileDialog.getSaveFileName(caption="Save simulation history", filter=SIMULATION_FILE_FILTER_) if path: path = self._correct_path(path, filter, [".zip", ".mds"]) #shutil.rmtree('./data/tmp1') ds = DynState(tmp_path) if not self.ui.saveAllAtomsPositionCheckBox.checkState(): try: os.remove(tmp_path+'/'+DynState.POS_H) except: pass ds.save_model(self.simulation.model) ds.to_zip(path) def export_to_csv(self): path, filter = QFileDialog.getSaveFileName(caption="Export to CSV", filter="CSV file (*.csv)") if path: path = self._correct_path(path, filter, [".csv"]) with open(path, "w", newline='') as csvfile: csvwriter = csv.writer(csvfile) csvwriter.writerow(self.temporal_variables.keys()) csvwriter.writerows(zip(*(self.simulation.state_fct[s[0]] for s in self.temporal_variables.values()))) def line_graph(self): ords = [i.text() for i in self.temp_variables_w if i.checkState()] if not len(ords): return absc = self.ui.lineComboW.currentText() def values(s): return self.simulation.state_fct[self.temporal_variables[s][0]] def label(s): if len(self.temporal_variables[s])>1: return s + " (" + self.temporal_variables[s][1] + ")" return s def dimension(s): if "energy" in s: return "Energy (J)" elif "Temperature" in s: return "Temperature (K)" else: return label(s) dimensions = list(set(dimension(s) for s in ords)) axis = dict() visu.plt.ioff() fig = visu.plt.figure() gr_opts = dict() for o in self._1d_options: gr_opts[o] = self._1d_options[o].checkState() host = HostAxes(fig, [0.15, 0.1, 0.75-(0.04*len(dimensions)), 0.8]) host.set_xlabel(label(absc)) host.set_ylabel(dimensions[0]) if gr_opts["log x"]: host.semilogx() if gr_opts["log y"]: host.semilogy() if gr_opts["grid"]: host.grid(True, which="minor", linestyle="--") host.grid(True, which="major") if len(dimensions)>1: host.axis["right"].set_visible(False) axis[dimensions[0]] = host for i, dim in enumerate(dimensions[1:]): par = ParasiteAxes(host, sharex=host) host.parasites.append(par) par.axis["right"] = par.get_grid_helper().new_fixed_axis(loc="right", axes=par, offset=(55*i, 0)) par.axis["right"].set_visible(True) par.set_ylabel(dim) par.axis["right"].major_ticklabels.set_visible(True) par.axis["right"].label.set_visible(True) axis[dim] = par if gr_opts["log x"]: par.semilogx() if gr_opts["log y"]: par.semilogy() for i in ords: axis[dimension(i)].plot(values(absc), values(i), label=label(i)) fig.add_axes(host) host.legend() visu.plt.show() def PDF(self): """Pair Distribution Function""" self.old_status = self.ui.statusbar.currentMessage() self.ui.statusbar.showMessage("Computing Pair Distribution Function...") visu.plt.ioff() d = PDF(self.simulation.model.pos, self.ui.PDFNSpinBox.value(), self.ui.PDFDistSpinBox.value()*max(self.model.rcut_a, self.model.rcut_b, self.model.rcut_ab), 100) visu.plt.figure() visu.plt.plot(*d) visu.plt.xlabel("Distance (m)") visu.plt.show() self.ui.statusbar.showMessage(self.old_status) def draw_surf(self): self.old_status = self.ui.statusbar.currentMessage() gr_opts = dict() for o in self._2d_options: gr_opts[o] = self._2d_options[o].checkState() visu.plt.figure() if gr_opts["density map"]: self.ui.statusbar.showMessage("Computing density map...") visu.plot_densityf(self.simulation.model, 50) if gr_opts["deformation (compression)"]: self.ui.statusbar.showMessage("Computing deformation...") visu.deformation_volume(self.model, self.simulation.model, self.ui.deformationDistSpinBox.value()*max(self.model.rcut_a, self.model.rcut_b, self.model.rcut_ab)) if gr_opts["deformation (shear)"]: self.ui.statusbar.showMessage("Computing deformation...") visu.deformation_dev(self.model, self.simulation.model, self.ui.deformationDistSpinBox.value()*max(self.model.rcut_a, self.model.rcut_b, self.model.rcut_ab)) if gr_opts["particles"]: visu.plot_particles(self.simulation.model) visu.plt.ylim(self.model.y_lim_inf, self.model.y_lim_sup) visu.plt.xlim(self.model.x_lim_inf, self.model.x_lim_sup) visu.plt.show() self.ui.statusbar.showMessage(self.old_status) def make_movie(self): path, filter = QFileDialog.getSaveFileName(caption="Make movie", filter="Video file (*.mp4)") if path: path = self._correct_path(path, filter, [".mp4"]) self.ui.tab_model.setEnabled(False) self.ui.tab_simu.setEnabled(False) self.ui.groupBoxMovie.setEnabled(False) self.ui.movieProgressBar.setMaximum(self.simulation.current_iter) def run(): def up(k): self.movie_progress_signal.emit(k) visu.make_movie(self.simulation, DynState(tmp_path), path, self.ui.stepsByFrameSpinBox.value(), self.ui.FPSSpinBox.value(), callback=up) def end(): self.ui.tab_model.setEnabled(True) self.ui.tab_simu.setEnabled(True) self.ui.groupBoxMovie.setEnabled(True) self.ui.movieProgressBar.setValue(self.simulation.current_iter) self.render_thr = QThread() self.render_thr.run = run self.render_thr.finished.connect(end) self.render_thr.start()
def initUI(self): global SuhuDahi global SuhuDahia global SuhuHidung global SuhuHidunga global SuhuPipiKanan global SuhuKanana global SuhuPipiKiri global SuhuKiria global JenEmosi self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) self.resize(1920, 1080) self.setStyleSheet("background-color: black;") # Label Kamera self.label = QtGui.QLabel(self) self.label.move(50, 140) self.label.resize(720, 511) th = Thread(self) th.changePixmap.connect(self.setImage) th.start() # Judul self.Judul = QtGui.QLabel(self) self.Judul.move(30, 30) self.Judul.setText('Thermography Camera Interface - TCI') font = QtGui.QFont() font.setFamily("Cantarell") font.setPointSize(32) font.setItalic(True) font.setBold(True) font.setWeight(75) self.Judul.setFont(font) self.Judul.setStyleSheet("color: white;") # Dahi SuhuDahi = PlotWidget(self) SuhuDahi.setGeometry(QtCore.QRect(870, 170, 781, 221)) SuhuDahi.setLabel('left', "Temperature (C)") SuhuDahi.setLabel('bottom', "Time (s)") SuhuDahi.showGrid(x=True, y=True) axisSuhuDahi = SuhuDahi.getAxis('bottom') axisSuhuDahi.setTickSpacing(20, 5) self.TDahi = QtGui.QLabel(self) self.TDahi.move(870, 130) self.TDahi.setText('Suhu Dahi') font = QtGui.QFont() font.setFamily("Cantarell") font.setPointSize(14) self.TDahi.setFont(font) self.TDahi.setStyleSheet("color: white;") self.SuhuDahit = QtGui.QLabel(self) self.SuhuDahit.move(1670, 180) self.SuhuDahit.setText("Suhu Dahi : ") font = QtGui.QFont() font.setFamily("Cantarell") font.setPointSize(14) font.setBold(True) self.SuhuDahit.setFont(font) self.SuhuDahit.setStyleSheet("color: white;") SuhuDahia = QtGui.QLabel(self) SuhuDahia.move(1820, 180) SuhuDahia.resize(101, 71) font = QtGui.QFont() font.setFamily("Cantarell") font.setPointSize(10) font.setBold(True) SuhuDahia.setFont(font) SuhuDahia.setStyleSheet("color: white;") # Hidung SuhuHidung = PlotWidget(self) SuhuHidung.setGeometry(QtCore.QRect(870, 440, 781, 221)) self.THidung = QtGui.QLabel(self) SuhuHidung.setLabel('left', "Temperature (C)") SuhuHidung.setLabel('bottom', "Time (s)") SuhuHidung.showGrid(x=True, y=True) axisSuhuHidung = SuhuHidung.getAxis('bottom') axisSuhuHidung.setTickSpacing(20, 5) self.THidung.move(870, 400) self.THidung.setText('Suhu Hidung') font = QtGui.QFont() font.setPointSize(14) font.setFamily("Cantarell") self.THidung.setFont(font) self.THidung.setStyleSheet("color: white;") self.SuhuHidungt = QtGui.QLabel(self) self.SuhuHidungt.move(1670, 240) self.SuhuHidungt.setText("Suhu Hidung : ") font = QtGui.QFont() font.setFamily("Cantarell") font.setPointSize(14) font.setBold(True) self.SuhuHidungt.setFont(font) self.SuhuHidungt.setStyleSheet("color: white;") SuhuHidunga = QtGui.QLabel(self) SuhuHidunga.move(1820, 250) SuhuHidunga.resize(101, 71) font = QtGui.QFont() font.setFamily("Cantarell") font.setPointSize(10) font.setBold(True) SuhuHidunga.setFont(font) SuhuHidunga.setStyleSheet("color: white;") # Pipi Kanan SuhuPipiKanan = PlotWidget(self) SuhuPipiKanan.setGeometry(QtCore.QRect(870, 730, 781, 221)) SuhuPipiKanan.setLabel('left', "Temperature (C)") SuhuPipiKanan.setLabel('bottom', "Time (s)") SuhuPipiKanan.showGrid(x=True, y=True) axisSuhuPipiKanan = SuhuPipiKanan.getAxis('bottom') axisSuhuPipiKanan.setTickSpacing(20, 5) self.TKanan = QtGui.QLabel(self) self.TKanan.move(870, 680) self.TKanan.setText('Suhu Pipi Kanan') font = QtGui.QFont() font.setPointSize(14) font.setFamily("Cantarell") self.TKanan.setFont(font) self.TKanan.setStyleSheet("color: white;") self.SuhuKanant = QtGui.QLabel(self) self.SuhuKanant.move(1670, 440) self.SuhuKanant.setText("Suhu Pipi Kanan : ") font = QtGui.QFont() font.setFamily("Cantarell") font.setPointSize(10) font.setBold(True) self.SuhuKanant.setFont(font) self.SuhuKanant.setStyleSheet("color: white;") SuhuKanana = QtGui.QLabel(self) SuhuKanana.move(1820, 450) SuhuKanana.resize(101, 71) font = QtGui.QFont() font.setFamily("Cantarell") font.setPointSize(10) font.setBold(True) SuhuKanana.setFont(font) SuhuKanana.setStyleSheet("color: white;") # Pipi Kiri SuhuPipiKiri = PlotWidget(self) SuhuPipiKiri.setGeometry(QtCore.QRect(50, 730, 781, 221)) SuhuPipiKiri.setLabel('left', "Temperature (C)") SuhuPipiKiri.setLabel('bottom', "Time (s)") SuhuPipiKiri.showGrid(x=True, y=True) axisSuhuPipiKiri = SuhuPipiKiri.getAxis('bottom') axisSuhuPipiKiri.setTickSpacing(20, 5) self.TKiri = QtGui.QLabel(self) self.TKiri.move(50, 685) self.TKiri.setText('Suhu Pipi Kiri') font = QtGui.QFont() font.setPointSize(14) font.setFamily("Cantarell") self.TKiri.setFont(font) self.TKiri.setStyleSheet("color: white;") self.SuhuKirit = QtGui.QLabel(self) self.SuhuKirit.move(1670, 540) self.SuhuKirit.setText("Suhu Pipi Kiri : ") font = QtGui.QFont() font.setFamily("Cantarell") font.setPointSize(10) font.setBold(True) self.SuhuKirit.setFont(font) self.SuhuKirit.setStyleSheet("color: white;") SuhuKiria = QtGui.QLabel(self) SuhuKiria.move(1820, 550) SuhuKiria.resize(101, 71) font = QtGui.QFont() font.setFamily("Cantarell") font.setPointSize(10) font.setBold(True) SuhuKiria.setFont(font) SuhuKiria.setStyleSheet("color: white;") # Jenis Emosi self.Emosi = QtGui.QLabel(self) self.Emosi.move(1280, 40) self.Emosi.setText('Jenis Emosi : ') font = QtGui.QFont() font.setPointSize(16) font.setBold(True) self.Emosi.setFont(font) self.Emosi.setStyleSheet("color: white;") # Emosi JenEmosi = QtGui.QLabel(self) JenEmosi.move(1500, 40) JenEmosi.resize(100, 20) font = QtGui.QFont() font.setPointSize(16) font.setBold(True) JenEmosi.setFont(font) JenEmosi.setStyleSheet("color: white;") # Menubar self.menubar = QtGui.QMenuBar(self) self.menubar.setStyleSheet("background-color: white;") self.actionFile = self.menubar.addMenu("File") self.start = self.actionFile.addAction("Start") self.save = self.actionFile.addAction("Save") self.save.triggered.connect(self.simpan) self.start.triggered.connect(self.mulai2) self.actionFile.addSeparator() self.quit = self.actionFile.addAction("Quit") self.quit.triggered.connect(self.keluar) self.actionHelp = self.menubar.addMenu("Help") # Init List self.dialogs = list()