Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- from __future__ import division
- import multiprocessing
- import sys, socket
- import threading
- from PyQt4 import QtCore, QtGui, uic
- qtCreatorFile = "mainwindow.ui"
- Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)
- def handle(myApp, connection, address):
- import logging
- logging.basicConfig(level=logging.DEBUG)
- logger = logging.getLogger("process-%r" % (address,))
- try:
- logger.debug("Connected %r at %r", connection, address)
- while True:
- data = connection.recv(1024)
- if data == "":
- logger.debug("Socket closed remotely")
- break
- logger.debug("Received data %r", data)
- with open("output.log", "a") as myfile:
- myfile.write(data)
- myApp.lblSideVal.setText(data)
- #connection.sendall("Got It")
- logger.debug("Sent data")
- except:
- logger.exception("Problem handling request")
- finally:
- logger.debug("Closing socket")
- connection.close()
- class Server(object):
- def __init__(myApp, hostname, port):
- import logging
- self.logger = logging.getLogger("server")
- self.myApp = myApp
- self.hostname = hostname
- self.port = port
- def start(self):
- self.logger.debug("listening")
- self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- self.socket.bind((self.hostname, self.port))
- self.socket.listen(1)
- while True:
- conn, address = self.socket.accept()
- self.logger.debug("Got connection")
- process = multiprocessing.Process(target=handle, args=(self.myApp, conn, address))
- process.daemon = True
- process.start()
- self.logger.debug("Started process %r", process)
- class MyApp(QtGui.QMainWindow, Ui_MainWindow):
- def __init__(self):
- QtGui.QMainWindow.__init__(self)
- Ui_MainWindow.__init__(self)
- self.setupUi(self)
- #self.calc_tax_button.clicked.connect(self.CalculateTax)
- self.lblMixVal.setText("3770835")
- self.lblSideVal.setText("LA")
- self.lblPLCVal.setText("--D-RRS")
- self.server = Server(self, '0.0.0.0',6666)
- server_thread=threading.Thread(target=self.server.start)
- server_thread.start()
- if __name__ == "__main__":
- app = QtGui.QApplication(sys.argv)
- import logging
- logging.basicConfig(level=logging.DEBUG)
- window = MyApp()
- window.show()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement