text: # -*- coding: utf-8 -*-
  
  # Form implementation generated from reading ui file 'gui1.ui'
  #
  # Created by: PyQt5 UI code generator 5.15.1
  #
  # WARNING: Any manual changes made to this file will be lost when pyuic5 is
  # run again.  Do not edit this file unless you know what you are doing.
  
  
  from PyQt5 import QtCore, QtGui, QtWidgets
  from PyQt5.QtCore import QRunnable, pyqtSlot, QThreadPool
  
  import time
  import socket
  
  HEADER = 64
  PORT = 65432
  SERVER = socket.gethostbyname(socket.gethostname())
  ADDR=(SERVER,PORT)
  FORMAT = 'utf-8'
  DISCONNECT_MESSAGE = '!DISCONNECT'
  
  class Worker(QRunnable):
  
      @pyqtSlot()
      def run(self):
  
          print('Thread start')
          # i =1
          # while True:
          #     print(i)
          #     i+=1
          #     time.sleep(.5)
          #     if i==20:
          #         break
          #function to run through this thread
  
          #live feed from server loop
          ##### SERVER ---> CLIENT (LIVE)
  
          Ui_MainWindow.send(f'[{ADDR}] Sent from live feed',Ui_MainWindow.client)
  
          # connected = True
          # while connected:
          #     msg_length = self.window.client.recv(HEADER).decode(FORMAT)  # from client
          #     if msg_length:  # if msg_length has something
          #         msg_length = int(msg_length)
          #         msg = self.window.client.recv(msg_length).decode(FORMAT)
          #
          #         if msg == DISCONNECT_MESSAGE:
          #             connected = False
          #         print(f'[SERVER] {msg}')  # prints what server sent to client
          #         time.sleep(2)
          #
          #         self.window.client.send(f"[{ADDR}] Client received from live feed".encode(FORMAT))
          #
          # print("Live feed ended (Thread end)")
  
  class Ui_MainWindow(object):
      def __init__(self,client=None):
          self.voltage = 0
          self.client = client
          self.received_message = ''
          # self.threadpool = QThreadPool()
          # print(f'Multithreading with maximum {self.threadpool.maxThreadCount()} threads')
  
      def setupUi(self, MainWindow):
          MainWindow.setObjectName("MainWindow")
          MainWindow.resize(829, 694)
          self.centralwidget = QtWidgets.QWidget(MainWindow)
          self.centralwidget.setObjectName("centralwidget")
          self.button = QtWidgets.QPushButton(self.centralwidget)
          self.button.setGeometry(QtCore.QRect(190, 450, 451, 101))
          font = QtGui.QFont()
          font.setPointSize(36)
          self.button.setFont(font)
          self.button.setAutoFillBackground(False)
          self.button.setObjectName("button")
          self.label = QtWidgets.QLabel(self.centralwidget)
          self.label.setGeometry(QtCore.QRect(200, 140, 441, 61))
          self.label.setMaximumSize(QtCore.QSize(441, 16777215))
          font = QtGui.QFont()
          font.setPointSize(24)
          self.label.setFont(font)
          self.label.setLayoutDirection(QtCore.Qt.LeftToRight)
          self.label.setObjectName("label")
          MainWindow.setCentralWidget(self.centralwidget)
          self.menubar = QtWidgets.QMenuBar(MainWindow)
          self.menubar.setGeometry(QtCore.QRect(0, 0, 829, 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", "MainWindow"))
          self.button.setText(_translate("MainWindow", "Start Live Feed"))
          self.label.setText(_translate("MainWindow", "Battery Voltage : 10 V"))
  
          # adding action to a button
          self.button.clicked.connect(lambda: self.button_pressed())
  
      def button_pressed(self): #update voltage
          # worker = Worker()
          # self.threadpool.start(worker)
  
          self.label.setText(f"Battery Voltage : {self.voltage} V")
          self.label.adjustSize()
          self.send(str(self.voltage),self.client)
          self.voltage = int(self.received_message[-1])
  
  
      def send(self, msg, client):
          message = msg.encode(FORMAT)
          msg_length = len(message)
          send_length = str(msg_length).encode(FORMAT)
          send_length += b' ' * (HEADER - len(send_length))
          client.send(send_length) #sends header length
          client.send(message) #sends actual message
  
          self.received_message = client.recv(HEADER).decode(FORMAT)
          print(self.received_message)
  
  
  
  
  
  
  if __name__ == "__main__":
      import sys
      app = QtWidgets.QApplication(sys.argv)
      MainWindow = QtWidgets.QMainWindow()
      ui = Ui_MainWindow()
      ui.setupUi(MainWindow)
      MainWindow.show()
      sys.exit(app.exec_())
  