Multiprocesses, Threads / threads in pyqt4?

0

I am trying to enter data in a QListWidget in pyqt4, by means of the keyboard entry raw_input I am entering 5 data but I only want that in the table I get 3, that I already have it, but When I enter the first data round, the GUI is just opened with the 3 data that I want to appear, but it does not allow me to enter more data. As I have investigated it must be done by means of THREADS OR MULTIPROCESSES , so that it executes the GUI and the entry of data at the same time, but the truth I have not been able to understand very well as it is that the threads are programmed or multiprocess, that is why if someone can help me with how to apply the threads or multiprocesses in this program I will be very grateful.

Next I leave the code of the program "code_called" that translates the graphic interface of qtdesigner:

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'llamado.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!


from PyQt4 import QtCore, QtGui

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName(_fromUtf8("Dialog"))
        Dialog.resize(745, 487)
        self.etiqueta_modulo_n = QtGui.QLabel(Dialog)
        self.etiqueta_modulo_n.setGeometry(QtCore.QRect(70, 20, 271, 51))
        font = QtGui.QFont()
        font.setPointSize(22)
        self.etiqueta_modulo_n.setFont(font)
        self.etiqueta_modulo_n.setObjectName(_fromUtf8("etiqueta_modulo_n"))
        self.etiqueta_turno = QtGui.QLabel(Dialog)
        self.etiqueta_turno.setGeometry(QtCore.QRect(50, 120, 81, 21))
        self.etiqueta_turno.setObjectName(_fromUtf8("etiqueta_turno"))
        self.btn_llamado = QtGui.QPushButton(Dialog)
        self.btn_llamado.setGeometry(QtCore.QRect(410, 20, 291, 281))
        self.btn_llamado.setStyleSheet(_fromUtf8("border-image: url(:/imagen_llamado.png);"))
        self.btn_llamado.setText(_fromUtf8(""))
        self.btn_llamado.setObjectName(_fromUtf8("btn_llamado"))
        self.btn_salir = QtGui.QPushButton(Dialog)
        self.btn_salir.setGeometry(QtCore.QRect(590, 400, 141, 71))
        font = QtGui.QFont()
        font.setPointSize(14)
        self.btn_salir.setFont(font)
        self.btn_salir.setObjectName(_fromUtf8("btn_salir"))
        self.etiqueta_turno_actual = QtGui.QLabel(Dialog)
        self.etiqueta_turno_actual.setGeometry(QtCore.QRect(140, 110, 121, 41))
        self.etiqueta_turno_actual.setObjectName(_fromUtf8("etiqueta_turno_actual"))
        self.lista_turnos = QtGui.QListWidget(Dialog)
        self.lista_turnos.setGeometry(QtCore.QRect(30, 210, 351, 251))
        self.lista_turnos.setObjectName(_fromUtf8("lista_turnos"))
        self.etiqueta_turno_lista = QtGui.QLabel(Dialog)
        self.etiqueta_turno_lista.setGeometry(QtCore.QRect(30, 190, 61, 21))
        self.etiqueta_turno_lista.setObjectName(_fromUtf8("etiqueta_turno_lista"))
        self.etiqueta_cedula_lista = QtGui.QLabel(Dialog)
        self.etiqueta_cedula_lista.setGeometry(QtCore.QRect(120, 190, 61, 21))
        self.etiqueta_cedula_lista.setObjectName(_fromUtf8("etiqueta_cedula_lista"))
        self.btn_reporte_excel = QtGui.QPushButton(Dialog)
        self.btn_reporte_excel.setGeometry(QtCore.QRect(424, 380, 81, 71))
        self.btn_reporte_excel.setStyleSheet(_fromUtf8("border-image: url(:/icono_excel.png);"))
        self.btn_reporte_excel.setText(_fromUtf8(""))
        self.btn_reporte_excel.setObjectName(_fromUtf8("btn_reporte_excel"))
        self.etiqueta_generar_reporte = QtGui.QLabel(Dialog)
        self.etiqueta_generar_reporte.setGeometry(QtCore.QRect(410, 450, 111, 21))
        self.etiqueta_generar_reporte.setObjectName(_fromUtf8("etiqueta_generar_reporte"))
        self.etiqueta_servicio_lista = QtGui.QLabel(Dialog)
        self.etiqueta_servicio_lista.setGeometry(QtCore.QRect(240, 190, 71, 21))
        self.etiqueta_servicio_lista.setObjectName(_fromUtf8("etiqueta_servicio_lista"))

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

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
        self.etiqueta_modulo_n.setText(_translate("Dialog", "<html><head/><body><p align=\"center\"><br/></p><p align=\"center\"><br/></p></body></html>", None))
        self.etiqueta_turno.setText(_translate("Dialog", "<html><head/><body><p align=\"center\"><span style=\" font-size:16pt; font-weight:600;\">TURNO:</span></p></body></html>", None))
        self.btn_salir.setText(_translate("Dialog", "SALIR", None))
        self.etiqueta_turno_actual.setText(_translate("Dialog", "<html><head/><body><p align=\"center\"><br/></p></body></html>", None))
        self.etiqueta_turno_lista.setText(_translate("Dialog", "<html><head/><body><p align=\"center\"><span style=\" font-size:12pt;\">TURNO</span></p></body></html>", None))
        self.etiqueta_cedula_lista.setText(_translate("Dialog", "<html><head/><body><p align=\"center\"><span style=\" font-size:12pt;\">CEDULA</span></p></body></html>", None))
        self.etiqueta_generar_reporte.setText(_translate("Dialog", "<html><head/><body><p align=\"center\"><span style=\" font-size:10pt;\">GENERAR REPORTE</span></p></body></html>", None))
        self.etiqueta_servicio_lista.setText(_translate("Dialog", "<html><head/><body><p align=\"center\"><span style=\" font-size:12pt;\">SERVICIO</span></p></body></html>", None))

import recursos

And here I leave the code of the program that runs the GUI:

import sys
from codigo_llamado import *
import threading

class Llamado(QtGui.QDialog):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        datos = True
        while datos:

            turno = raw_input("ingrese turno : ")                             
            cedula = raw_input("ingrese cedula : ")                             
            fecha = raw_input("ingrese fecha : ")              
            hora = raw_input("ingrese hora : ")                               
            servicio = raw_input("ingrese servicio : ")               

            self.ui.lista_turnos.addItem("      "+turno+"                   "+cedula+"                  "+servicio)
            datos = False

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    myapp = Llamado()
    myapp.show()
    sys.exit(app.exec_())

Here's how I get the data from the server:

import sys
from codigo_llamado import *
import socket    #para crear el socket y recibir los datos
import threading

# Se establece la conexion
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("192.168.1.6", 8000))

class Llamado(QtGui.QDialog):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)

        while 1:
            # Se envia turno
            turno = s.recv(1000)              
            print "Turno : ", turno
            cedula = s.recv(1000)                
            print "Cedula : ", cedula
            fecha = s.recv(1000)                
            print "Fecha : ", fecha
            hora = s.recv(1000)                
            print "Hora : ", hora
            servicio = s.recv(1000)
            print "Servicio : ", servicio

            self.ui.lista_turnos.addItem("      "+turno+"                   "+cedula+"                  "+servicio)


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    myapp = Llamado()
    myapp.show()
    sys.exit(app.exec_())
    
asked by andresuarez_95 03.02.2018 в 19:41
source

0 answers