Advertisement
Week045

Lab1

Oct 18th, 2023
1,226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 24.62 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import PyQt5
  3. # Form implementation generated from reading ui file 'Lab1.ui'
  4. #
  5. # Created by: PyQt5 UI code generator 5.15.9
  6. #
  7. # WARNING: Any manual changes made to this file will be lost when pyuic5 is
  8. # run again.  Do not edit this file unless you know what you are doing.
  9.  
  10. from PyQt5 import QtCore, QtGui, QtWidgets
  11. from COMPort import COMPort
  12. import threading
  13. import re
  14.  
  15.  
  16. class UiMainWindow(object):
  17.     input_port_name: str
  18.     output_port_name: str
  19.     ports_baudrate: int
  20.     input_port: COMPort
  21.     output_port: COMPort
  22.     accept_flag: bool
  23.     change_port_name_flag: bool
  24.     change_port_speed_flag: bool
  25.     numbers_bytes: int
  26.     total_numbers_bytes: int
  27.  
  28.     def __init__(self, main_window):
  29.         self.input_port_name = "????"
  30.         self.output_port_name = "????"
  31.         self.ports_baudrate = 0
  32.         self.accept_flag = False
  33.         self.change_port_name_flag = False
  34.         self.numbers_bytes = 0
  35.         self.total_numbers_bytes = 0
  36.         # InitComPorts
  37.         self.input_port = COMPort(self.input_port_name, self.ports_baudrate)
  38.         self.output_port = COMPort(self.output_port_name, self.ports_baudrate)
  39.         # InitWidget
  40.         self.centralwidget = QtWidgets.QWidget(main_window)
  41.         self.lbl_input = QtWidgets.QLabel(self.centralwidget)
  42.         self.le_input_entry = QtWidgets.QLineEdit(self.centralwidget)
  43.         self.lbl_input_port = QtWidgets.QLabel(self.centralwidget)
  44.         self.lbl_output = QtWidgets.QLabel(self.centralwidget)
  45.         self.le_output_entry = QtWidgets.QLineEdit(self.centralwidget)
  46.         self.lbl_output_port = QtWidgets.QLabel(self.centralwidget)
  47.         self.lbl_accept_flag = QtWidgets.QLabel(self.centralwidget)
  48.         self.hLine = QtWidgets.QFrame(self.centralwidget)
  49.         self.vLine = QtWidgets.QFrame(self.centralwidget)
  50.         self.gridLayoutWidget = QtWidgets.QWidget(self.centralwidget)
  51.         self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
  52.         self.btn_accept_output = QtWidgets.QPushButton(self.gridLayoutWidget)
  53.         self.btn_noaccept_output = QtWidgets.QPushButton(self.gridLayoutWidget)
  54.         self.btn_clear_output = QtWidgets.QPushButton(self.gridLayoutWidget)
  55.         self.btn_send_input = QtWidgets.QPushButton(self.centralwidget)
  56.         self.btn_clear_input = QtWidgets.QPushButton(self.centralwidget)
  57.         self.combobox_ports = QtWidgets.QComboBox(self.centralwidget)
  58.         self.lbl_com_ports = QtWidgets.QLabel(self.centralwidget)
  59.         self.lbl_debug = QtWidgets.QLabel(self.centralwidget)
  60.         self.txt_debug = QtWidgets.QTextEdit(self.centralwidget)
  61.         self.btn_create_ports = QtWidgets.QPushButton(self.centralwidget)
  62.         self.combobox_speed = QtWidgets.QComboBox(self.centralwidget)
  63.         self.lbl_com_ports_state = QtWidgets.QLabel(self.centralwidget)
  64.         self.lbl_input_state = QtWidgets.QLabel(self.centralwidget)
  65.         self.lbl_input_state_2 = QtWidgets.QLabel(self.centralwidget)
  66.         self.txt_input_state = QtWidgets.QTextBrowser(self.centralwidget)
  67.         self.txt_output_state = QtWidgets.QTextBrowser(self.centralwidget)
  68.         # InitInformationAboutComPortState
  69.         self.update_state_text(self.txt_input_state, self.input_port.port_name)
  70.         self.update_state_text(self.txt_output_state, self.output_port.port_name)
  71.  
  72.     def setupUi(self, mainWindow):
  73.         mainWindow.setObjectName("mainWindow")
  74.         mainWindow.setEnabled(True)
  75.         mainWindow.resize(805, 585)
  76.         mainWindow.setMouseTracking(False)
  77.         mainWindow.setStyleSheet("background-color: rgb(255, 234, 179);")
  78.  
  79.         self.centralwidget.setObjectName("centralwidget")
  80.  
  81.         self.lbl_input.setGeometry(QtCore.QRect(108, 30, 175, 30))
  82.         font = QtGui.QFont()
  83.         font.setPointSize(14)
  84.         font.setBold(True)
  85.         font.setWeight(75)
  86.         self.lbl_input.setFont(font)
  87.         self.lbl_input.setStyleSheet("background-color:  rgb(255, 234, 179);")
  88.         self.lbl_input.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignTop)
  89.         self.lbl_input.setObjectName("lbl_input")
  90.  
  91.         self.le_input_entry.setGeometry(QtCore.QRect(25, 70, 350, 40))
  92.         font = QtGui.QFont()
  93.         font.setPointSize(11)
  94.         self.le_input_entry.setFont(font)
  95.         self.le_input_entry.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
  96.         self.le_input_entry.setStyleSheet("background-color: rgb(255, 250, 188);")
  97.         self.le_input_entry.setMaxLength(30)
  98.         self.le_input_entry.setClearButtonEnabled(True)
  99.         self.le_input_entry.setObjectName("le_input_entry")
  100.  
  101.         self.lbl_input_port.setGeometry(QtCore.QRect(320, 30, 51, 30))
  102.         font = QtGui.QFont()
  103.         font.setPointSize(10)
  104.         font.setBold(False)
  105.         font.setWeight(50)
  106.         self.lbl_input_port.setFont(font)
  107.         self.lbl_input_port.setAlignment(QtCore.Qt.AlignCenter)
  108.         self.lbl_input_port.setObjectName("lbl_input_port")
  109.  
  110.         self.lbl_output.setGeometry(QtCore.QRect(510, 30, 175, 30))
  111.         font = QtGui.QFont()
  112.         font.setPointSize(14)
  113.         font.setBold(True)
  114.         font.setWeight(75)
  115.         self.lbl_output.setFont(font)
  116.         self.lbl_output.setStyleSheet("background-color:  rgb(255, 234, 179);")
  117.         self.lbl_output.setAlignment(QtCore.Qt.AlignCenter)
  118.         self.lbl_output.setObjectName("lbl_output")
  119.  
  120.         self.le_output_entry.setGeometry(QtCore.QRect(425, 70, 350, 40))
  121.         font = QtGui.QFont()
  122.         font.setPointSize(11)
  123.         self.le_output_entry.setFont(font)
  124.         self.le_output_entry.setStyleSheet("background-color: rgb(255, 250, 188);")
  125.         self.le_output_entry.setReadOnly(True)
  126.         self.le_output_entry.setObjectName("le_output_entry")
  127.  
  128.         self.lbl_output_port.setGeometry(QtCore.QRect(720, 30, 51, 30))
  129.         font = QtGui.QFont()
  130.         font.setPointSize(10)
  131.         font.setBold(False)
  132.         font.setWeight(50)
  133.         self.lbl_output_port.setFont(font)
  134.         self.lbl_output_port.setAlignment(QtCore.Qt.AlignCenter)
  135.         self.lbl_output_port.setObjectName("lbl_output_port")
  136.  
  137.         self.lbl_accept_flag.setGeometry(QtCore.QRect(435, 30, 55, 30))
  138.         font = QtGui.QFont()
  139.         font.setPointSize(10)
  140.         self.lbl_accept_flag.setFont(font)
  141.         self.lbl_accept_flag.setObjectName("lbl_accept_flag")
  142.  
  143.         self.hLine.setGeometry(QtCore.QRect(0, 182, 801, 20))
  144.         self.hLine.setFrameShape(QtWidgets.QFrame.HLine)
  145.         self.hLine.setFrameShadow(QtWidgets.QFrame.Sunken)
  146.         self.hLine.setObjectName("hLine")
  147.  
  148.         self.vLine.setGeometry(QtCore.QRect(400, 0, 3, 600))
  149.         self.vLine.setFrameShape(QtWidgets.QFrame.VLine)
  150.         self.vLine.setFrameShadow(QtWidgets.QFrame.Sunken)
  151.         self.vLine.setObjectName("vLine")
  152.  
  153.         self.gridLayoutWidget.setGeometry(QtCore.QRect(430, 120, 341, 61))
  154.         self.gridLayoutWidget.setObjectName("gridLayoutWidget")
  155.  
  156.         self.gridLayout.setContentsMargins(0, 0, 0, 0)
  157.         self.gridLayout.setObjectName("gridLayout")
  158.  
  159.         sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Maximum)
  160.         sizePolicy.setHorizontalStretch(0)
  161.         sizePolicy.setVerticalStretch(0)
  162.         sizePolicy.setHeightForWidth(self.btn_accept_output.sizePolicy().hasHeightForWidth())
  163.         self.btn_accept_output.setSizePolicy(sizePolicy)
  164.         font = QtGui.QFont()
  165.         font.setPointSize(11)
  166.         self.btn_accept_output.setFont(font)
  167.         self.btn_accept_output.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
  168.         self.btn_accept_output.setMouseTracking(False)
  169.         self.btn_accept_output.setStyleSheet("background-color: rgb(79, 198, 0);")
  170.         self.btn_accept_output.setIconSize(QtCore.QSize(20, 20))
  171.         self.btn_accept_output.setObjectName("btn_accept_output")
  172.         self.gridLayout.addWidget(self.btn_accept_output, 0, 0, 1, 1)
  173.  
  174.         sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Maximum)
  175.         sizePolicy.setHorizontalStretch(0)
  176.         sizePolicy.setVerticalStretch(0)
  177.         sizePolicy.setHeightForWidth(self.btn_noaccept_output.sizePolicy().hasHeightForWidth())
  178.         self.btn_noaccept_output.setSizePolicy(sizePolicy)
  179.         font = QtGui.QFont()
  180.         font.setPointSize(11)
  181.         self.btn_noaccept_output.setFont(font)
  182.         self.btn_noaccept_output.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
  183.         self.btn_noaccept_output.setStyleSheet("background-color: rgb(230, 230, 0);")
  184.         self.btn_noaccept_output.setObjectName("btn_noaccept_output")
  185.         self.gridLayout.addWidget(self.btn_noaccept_output, 0, 1, 1, 1)
  186.  
  187.         sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Maximum)
  188.         sizePolicy.setHorizontalStretch(0)
  189.         sizePolicy.setVerticalStretch(0)
  190.         sizePolicy.setHeightForWidth(self.btn_clear_output.sizePolicy().hasHeightForWidth())
  191.         self.btn_clear_output.setSizePolicy(sizePolicy)
  192.         font = QtGui.QFont()
  193.         font.setPointSize(11)
  194.         self.btn_clear_output.setFont(font)
  195.         self.btn_clear_output.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
  196.         self.btn_clear_output.setMouseTracking(False)
  197.         self.btn_clear_output.setStyleSheet("background-color: rgb(239, 0, 0);")
  198.         self.btn_clear_output.setObjectName("btn_clear_output")
  199.         self.gridLayout.addWidget(self.btn_clear_output, 0, 2, 1, 1)
  200.  
  201.         self.btn_send_input.setGeometry(QtCore.QRect(70, 137, 93, 31))
  202.         font = QtGui.QFont()
  203.         font.setPointSize(11)
  204.         self.btn_send_input.setFont(font)
  205.         self.btn_send_input.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
  206.         self.btn_send_input.setMouseTracking(False)
  207.         self.btn_send_input.setStyleSheet("background-color: rgb(79, 198, 0);")
  208.         self.btn_send_input.setObjectName("btn_send_input")
  209.  
  210.         self.btn_clear_input.setGeometry(QtCore.QRect(230, 137, 93, 31))
  211.         font = QtGui.QFont()
  212.         font.setPointSize(11)
  213.         self.btn_clear_input.setFont(font)
  214.         self.btn_clear_input.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
  215.         self.btn_clear_input.setMouseTracking(False)
  216.         self.btn_clear_input.setStyleSheet("background-color: rgb(239, 0, 0);")
  217.         self.btn_clear_input.setObjectName("btn_clear_input")
  218.  
  219.         self.combobox_ports.setGeometry(QtCore.QRect(30, 244, 180, 30))
  220.         font = QtGui.QFont()
  221.         font.setPointSize(11)
  222.         self.combobox_ports.setFont(font)
  223.         self.combobox_ports.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
  224.         self.combobox_ports.setStyleSheet("background-color: rgb(255, 250, 188);")
  225.         self.combobox_ports.setObjectName("combobox_ports")
  226.         self.combobox_ports.addItem("")
  227.         self.combobox_ports.addItem("")
  228.  
  229.         self.lbl_com_ports.setGeometry(QtCore.QRect(30, 210, 320, 20))
  230.         font = QtGui.QFont()
  231.         font.setPointSize(12)
  232.         font.setBold(True)
  233.         font.setWeight(75)
  234.         self.lbl_com_ports.setFont(font)
  235.         self.lbl_com_ports.setAlignment(QtCore.Qt.AlignCenter)
  236.         self.lbl_com_ports.setObjectName("lbl_com_ports")
  237.  
  238.         self.lbl_debug.setGeometry(QtCore.QRect(430, 210, 345, 30))
  239.         font = QtGui.QFont()
  240.         font.setPointSize(12)
  241.         font.setBold(True)
  242.         font.setWeight(75)
  243.         self.lbl_debug.setFont(font)
  244.         self.lbl_debug.setAlignment(QtCore.Qt.AlignCenter)
  245.         self.lbl_debug.setObjectName("lbl_debug")
  246.  
  247.         self.txt_debug.setGeometry(QtCore.QRect(444, 250, 321, 300))
  248.         font = QtGui.QFont()
  249.         font.setPointSize(10)
  250.         self.txt_debug.setFont(font)
  251.         self.txt_debug.setStyleSheet("background-color: rgb(255, 250, 188);")
  252.         self.txt_debug.setReadOnly(True)
  253.         self.txt_debug.setObjectName("txt_debug")
  254.  
  255.         self.btn_create_ports.setGeometry(QtCore.QRect(229, 254, 141, 50))
  256.         font = QtGui.QFont()
  257.         font.setPointSize(11)
  258.         self.btn_create_ports.setFont(font)
  259.         self.btn_create_ports.setStyleSheet("background-color: rgb(79, 198, 0);")
  260.         self.btn_create_ports.setObjectName("btn_create_ports")
  261.  
  262.         self.combobox_speed.setGeometry(QtCore.QRect(30, 290, 180, 30))
  263.         font = QtGui.QFont()
  264.         font.setPointSize(11)
  265.         self.combobox_speed.setFont(font)
  266.         self.combobox_speed.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
  267.         self.combobox_speed.setStyleSheet("background-color: rgb(255, 250, 188);")
  268.         self.combobox_speed.setObjectName("combobox_speed")
  269.         self.combobox_speed.addItem("")
  270.         self.combobox_speed.addItem("")
  271.         self.combobox_speed.addItem("")
  272.         self.combobox_speed.addItem("")
  273.         self.combobox_speed.addItem("")
  274.         self.combobox_speed.addItem("")
  275.         self.combobox_speed.addItem("")
  276.         self.combobox_speed.addItem("")
  277.         self.combobox_speed.addItem("")
  278.         self.combobox_speed.addItem("")
  279.         self.combobox_speed.addItem("")
  280.         self.combobox_speed.addItem("")
  281.         self.combobox_speed.addItem("")
  282.         self.combobox_speed.addItem("")
  283.  
  284.         self.lbl_com_ports_state.setGeometry(QtCore.QRect(30, 340, 320, 20))
  285.         font = QtGui.QFont()
  286.         font.setPointSize(12)
  287.         font.setBold(True)
  288.         font.setWeight(75)
  289.         self.lbl_com_ports_state.setFont(font)
  290.         self.lbl_com_ports_state.setAlignment(QtCore.Qt.AlignCenter)
  291.         self.lbl_com_ports_state.setObjectName("lbl_com_ports_state")
  292.  
  293.         self.lbl_input_state.setGeometry(QtCore.QRect(40, 370, 150, 30))
  294.         font = QtGui.QFont()
  295.         font.setPointSize(12)
  296.         font.setBold(True)
  297.         font.setWeight(75)
  298.         self.lbl_input_state.setFont(font)
  299.         self.lbl_input_state.setAlignment(QtCore.Qt.AlignCenter)
  300.         self.lbl_input_state.setObjectName("lbl_input_state")
  301.  
  302.         self.lbl_input_state_2.setGeometry(QtCore.QRect(210, 370, 150, 30))
  303.         font = QtGui.QFont()
  304.         font.setPointSize(12)
  305.         font.setBold(True)
  306.         font.setWeight(75)
  307.         self.lbl_input_state_2.setFont(font)
  308.         self.lbl_input_state_2.setAlignment(QtCore.Qt.AlignCenter)
  309.         self.lbl_input_state_2.setObjectName("lbl_input_state_2")
  310.  
  311.         self.txt_input_state.setGeometry(QtCore.QRect(40, 410, 150, 140))
  312.         font = QtGui.QFont()
  313.         font.setPointSize(10)
  314.         self.txt_input_state.setFont(font)
  315.         self.txt_input_state.setStyleSheet("background-color: rgb(255, 250, 188);")
  316.         self.txt_input_state.setObjectName("txt_input_state")
  317.  
  318.         self.txt_output_state.setGeometry(QtCore.QRect(210, 410, 150, 140))
  319.         font = QtGui.QFont()
  320.         font.setPointSize(10)
  321.         self.txt_output_state.setFont(font)
  322.         self.txt_output_state.setStyleSheet("background-color: rgb(255, 250, 188);")
  323.         self.txt_output_state.setObjectName("txt_output_state")
  324.         mainWindow.setCentralWidget(self.centralwidget)
  325.  
  326.         self.retranslateUi(mainWindow)
  327.         QtCore.QMetaObject.connectSlotsByName(mainWindow)
  328.  
  329.     def combo_box_ports_changed(self):
  330.         selected_text = self.combobox_ports.currentText()
  331.         if selected_text == "COM2 <=> COM3":
  332.             if self.input_port_name == "COM2" and self.output_port_name == "COM3":
  333.                 self.change_port_name_flag = False
  334.             else:
  335.                 self.logger(f"Changed a new pair of COM-ports: COM2, COM3")
  336.                 self.change_port_name_flag = True
  337.             self.input_port_name = "COM2"
  338.             self.output_port_name = "COM3"
  339.         elif selected_text == "COM1 <=> COM4":
  340.             if self.input_port_name == "COM1" and self.output_port_name == "COM4":
  341.                 self.change_port_name_flag = False
  342.             else:
  343.                 self.logger(f"Changed a new pair of COM-ports: COM1, COM4")
  344.                 self.change_port_name_flag = True
  345.             self.input_port_name = "COM1"
  346.             self.output_port_name = "COM4"
  347.  
  348.     def combo_box_speed_changed(self):
  349.         old_ports_speed: int = self.ports_baudrate
  350.         selected_text = self.combobox_speed.currentText()
  351.         match = re.search(r'(\d+)', selected_text)
  352.  
  353.         if match:
  354.             self.ports_baudrate = int(match.group())
  355.         else:
  356.             print("ComboBoxSpeedError")
  357.  
  358.         if old_ports_speed == self.ports_baudrate:
  359.             self.change_port_speed_flag = False
  360.         else:
  361.             self.logger(f"Baudrate has been changed from {old_ports_speed} to {self.ports_baudrate} baud")
  362.             self.change_port_speed_flag = True
  363.  
  364.     def logger(self, data: str):
  365.         self.txt_debug.append(f"{data}")
  366.         self.txt_debug.append("------------------------------------------------")
  367.  
  368.     def create_pair_ports(self):
  369.         print(self.input_port_name)
  370.         print(self.output_port_name)
  371.  
  372.         if (self.change_port_name_flag or self.change_port_speed_flag) and self.input_port.init_flag:
  373.             self.close_pair_ports()
  374.  
  375.         if (self.input_port_name != "????" and self.ports_baudrate != 0 and
  376.                 (self.change_port_name_flag or self.change_port_speed_flag)):
  377.             self.input_port.port_name = self.input_port_name
  378.             self.input_port.baudrate = self.ports_baudrate
  379.             self.update_state_text(self.txt_input_state, self.input_port.port_name)
  380.             # Create input COM-port
  381.             self.input_port.SetParamCOMPort()
  382.             self.lbl_input_port.setText(self.input_port_name)
  383.             self.logger(f"Create input port {self.input_port_name}")
  384.  
  385.         if (self.output_port_name != "????" and self.ports_baudrate != 0 and
  386.                 (self.change_port_name_flag or self.change_port_speed_flag)):
  387.             self.output_port.port_name = self.output_port_name
  388.             self.output_port.baudrate = self.ports_baudrate
  389.             self.update_state_text(self.txt_output_state, self.output_port.port_name)
  390.             # Create output COM-port
  391.             self.output_port.SetParamCOMPort()
  392.             self.lbl_output_port.setText(self.output_port_name)
  393.             self.logger(f"Create input port {self.output_port_name}")
  394.  
  395.     def close_pair_ports(self):
  396.         if self.accept_flag:
  397.             self.noaccept_data()
  398.         self.input_port.CloseCOMPort()
  399.         self.output_port.CloseCOMPort()
  400.         self.total_numbers_bytes = 0
  401.         self.numbers_bytes = 0
  402.         self.logger(f"Close COM-ports: {self.input_port_name}, {self.output_port_name}")
  403.  
  404.     def send_data(self):
  405.         if self.input_port.init_flag:
  406.             data = self.le_input_entry.text()
  407.             self.input_port.WriteToPort(data)
  408.             self.numbers_bytes = len(data)
  409.             self.total_numbers_bytes += self.numbers_bytes
  410.             self.update_state_text(self.txt_input_state, self.input_port.port_name)
  411.             self.logger(f"The message has been sent")
  412.             self.clear_input_data()
  413.         else:
  414.             self.logger("The input port was not created")
  415.  
  416.     def clear_input_data(self):
  417.         self.logger(f"The input field has been cleared")
  418.         self.le_input_entry.clear()
  419.  
  420.     def thread_read_data(self):
  421.         while True:
  422.             data = self.output_port.ReadFromPort()
  423.             if data != b'':
  424.                 self.upgrade_text(data.decode('utf-8'))
  425.  
  426.             if self.accept_flag is False:
  427.                 break
  428.  
  429.     def upgrade_text(self, data: str):
  430.         self.le_output_entry.setText(self.le_output_entry.text() + data)
  431.         self.txt_output_state.append(
  432.             f"Port: \n{self.output_port.port_name} \nBaudrate: \n{self.output_port.baudrate} бод\n" +
  433.             f"One: {self.numbers_bytes} bytes\nAll: {self.total_numbers_bytes} bytes")
  434.  
  435.     def accept_data(self):
  436.         if self.output_port.init_flag:
  437.             self.accept_flag = True
  438.             self.logger("The read THREAD has been created")
  439.             thread = threading.Thread(target=self.thread_read_data)
  440.             thread.daemon = True
  441.             thread.start()
  442.             self.lbl_accept_flag.setText("TRUE")
  443.         else:
  444.             self.logger("The output port was not created")
  445.  
  446.     def noaccept_data(self):
  447.         self.accept_flag = False
  448.         self.logger("The read THREAD has been delete")
  449.         self.lbl_accept_flag.setText("FALSE")
  450.  
  451.     def clear_output_data(self):
  452.         self.logger(f"The output field has been cleared")
  453.         self.le_output_entry.clear()
  454.  
  455.     def update_state_text(self, widget: QtWidgets.QTextBrowser, port_name: str):
  456.         widget.setText("Port: \n" + port_name + "\n" +
  457.                        "Baudrate: \n" + f"{self.ports_baudrate} бод\n" +
  458.                        f"One: {self.numbers_bytes} bytes\n" +
  459.                        f"All: {self.total_numbers_bytes} bytes")
  460.  
  461.     def add_function(self):
  462.         self.combobox_ports.activated.connect(lambda: self.combo_box_ports_changed())
  463.         self.combobox_speed.activated.connect(lambda: self.combo_box_speed_changed())
  464.         self.btn_send_input.clicked.connect(lambda: self.send_data())
  465.         self.btn_clear_input.clicked.connect(lambda: self.clear_input_data())
  466.         self.le_input_entry.returnPressed.connect(lambda: self.send_data())
  467.         self.btn_accept_output.clicked.connect(lambda: self.accept_data())
  468.         self.btn_noaccept_output.clicked.connect(lambda: self.noaccept_data())
  469.         self.btn_clear_output.clicked.connect(lambda: self.clear_output_data())
  470.         self.btn_create_ports.clicked.connect(lambda: self.create_pair_ports())
  471.  
  472.     def retranslateUi(self, mainWindow):
  473.         _translate = QtCore.QCoreApplication.translate
  474.         mainWindow.setWindowTitle(_translate("mainWindow", "COM ports program"))
  475.         self.lbl_input.setText(_translate("mainWindow", "Input"))
  476.         self.le_input_entry.setPlaceholderText(_translate("mainWindow", "Введите сообщение для отправки:"))
  477.         self.lbl_input_port.setText(_translate("mainWindow", "????"))
  478.         self.lbl_output.setText(_translate("mainWindow", "Output"))
  479.         self.le_output_entry.setPlaceholderText(_translate("mainWindow", "Сообщение:"))
  480.         self.lbl_output_port.setText(_translate("mainWindow", "????"))
  481.         self.lbl_accept_flag.setText(_translate("mainWindow", "FALSE"))
  482.         self.btn_accept_output.setText(_translate("mainWindow", "Accept"))
  483.         self.btn_noaccept_output.setText(_translate("mainWindow", "No accept"))
  484.         self.btn_clear_output.setText(_translate("mainWindow", "Clear"))
  485.         self.btn_send_input.setText(_translate("mainWindow", "Send"))
  486.         self.btn_clear_input.setText(_translate("mainWindow", "Clear"))
  487.         self.combobox_ports.setItemText(0, _translate("mainWindow", "COM1 <=> COM4"))
  488.         self.combobox_ports.setItemText(1, _translate("mainWindow", "COM2 <=> COM3"))
  489.         self.lbl_com_ports.setText(_translate("mainWindow", "Настройка COM-портов:"))
  490.         self.lbl_debug.setText(_translate("mainWindow", "DEBUG"))
  491.         self.txt_debug.setPlaceholderText(_translate("mainWindow", "Ход работы программы:"))
  492.         self.btn_create_ports.setText(_translate("mainWindow", "Create pair"))
  493.         self.combobox_speed.setItemText(0, _translate("mainWindow", "50 бод"))
  494.         self.combobox_speed.setItemText(1, _translate("mainWindow", "75 бод"))
  495.         self.combobox_speed.setItemText(2, _translate("mainWindow", "110 бод"))
  496.         self.combobox_speed.setItemText(3, _translate("mainWindow", "150 бод"))
  497.         self.combobox_speed.setItemText(4, _translate("mainWindow", "300 бод"))
  498.         self.combobox_speed.setItemText(5, _translate("mainWindow", "600 бод"))
  499.         self.combobox_speed.setItemText(6, _translate("mainWindow", "1200 бод"))
  500.         self.combobox_speed.setItemText(7, _translate("mainWindow", "2400 бод"))
  501.         self.combobox_speed.setItemText(8, _translate("mainWindow", "4800 бод"))
  502.         self.combobox_speed.setItemText(9, _translate("mainWindow", "9600 бод"))
  503.         self.combobox_speed.setItemText(10, _translate("mainWindow", "19200 бод"))
  504.         self.combobox_speed.setItemText(11, _translate("mainWindow", "38400 бод"))
  505.         self.combobox_speed.setItemText(12, _translate("mainWindow", "57500 бод"))
  506.         self.combobox_speed.setItemText(13, _translate("mainWindow", "115200 бод"))
  507.         self.lbl_com_ports_state.setText(_translate("mainWindow", "Состояния COM-портов:"))
  508.         self.lbl_input_state.setText(_translate("mainWindow", "Input"))
  509.         self.lbl_input_state_2.setText(_translate("mainWindow", "Output"))
  510.         self.txt_input_state.setPlaceholderText(_translate("mainWindow", "Состояние:"))
  511.         self.txt_output_state.setPlaceholderText(_translate("mainWindow", "Состояние:"))
  512.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement