我有两个文件,我想将一个数组从Bitacora对话框返回到Main。在主代码的某些部分中调用Bitacora。 Bitacora有一个textEdit。我需要返回这些值。
我希望你能帮助我。
文件:Main.py
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtCore import Qt
from dbFuncs import *
from demoUI import *
from PandasModel import *
from dataLogger import *
from bitacorasend import Ui_Dialog
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
super(MainWindow, self).__init__()
#QtWidgets.QMainWindow.__init__(self, *args, **kwargs)
self.setupUi(self)
'''Variables for DB'''
'''Table Config'''
self.dataTable.setColumnCount(1)
self.dataTable.setRowCount(5)
self.dataTable.setHorizontalHeaderLabels(["Medición"])
self.dataTable.horizontalHeaderItem(0).setTextAlignment(Qt.AlignHCenter)
self.dataTable.horizontalHeader().setStretchLastSection(True)
self.dataTable.verticalHeader().setStretchLastSection(True)
'''Buttons signals'''
self.saveButton.clicked.connect(self.savePressed)
def bitacora(self):
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog,["data","data","data","data"])
Dialog.exec_()
def savePressed(self):
self.bitacora()
if __name__ == "__main__":
app = QtWidgets.QApplication([])
window = MainWindow()
window.show()
app.exec_()
文件:Bitacora.py
from PyQt5 import QtCore, QtGui, QtWidgets
#import time
class Ui_Dialog(object):
def setupUi(self, Dialog, datos):
self.data = datos
self.Dialog = Dialog
Dialog.setObjectName("Dialog")
Dialog.resize(617, 405)
self.verticalLayout = QtWidgets.QVBoxLayout(Dialog)
self.verticalLayout.setObjectName("verticalLayout")
self.label = QtWidgets.QLabel(Dialog)
font = QtGui.QFont()
font.setPointSize(10)
self.label.setFont(font)
self.label.setAlignment(QtCore.Qt.AlignBottom|QtCore.Qt.AlignHCenter)
self.label.setObjectName("label")
self.verticalLayout.addWidget(self.label)
self.label_2 = QtWidgets.QLabel(Dialog)
font = QtGui.QFont()
font.setPointSize(16)
font.setBold(True)
font.setWeight(75)
self.label_2.setFont(font)
self.label_2.setAlignment(QtCore.Qt.AlignHCenter|QtCore.Qt.AlignTop)
self.label_2.setObjectName("label_2")
self.verticalLayout.addWidget(self.label_2)
self.label_5 = QtWidgets.QLabel(Dialog)
self.label_5.setAlignment(QtCore.Qt.AlignCenter)
self.label_5.setObjectName("label_5")
self.verticalLayout.addWidget(self.label_5)
self.label_3 = QtWidgets.QLabel(Dialog)
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.label_3.setFont(font)
self.label_3.setAlignment(QtCore.Qt.AlignBottom|QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft)
self.label_3.setObjectName("label_3")
self.verticalLayout.addWidget(self.label_3)
self.textEdit = QtWidgets.QTextEdit(Dialog)
self.textEdit.setMaximumSize(QtCore.QSize(16777215, 100))
self.textEdit.setObjectName("textEdit")
self.verticalLayout.addWidget(self.textEdit)
self.label_4 = QtWidgets.QLabel(Dialog)
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.label_4.setFont(font)
self.label_4.setAlignment(QtCore.Qt.AlignBottom|QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft)
self.label_4.setObjectName("label_4")
self.verticalLayout.addWidget(self.label_4)
self.textEdit_2 = QtWidgets.QTextEdit(Dialog)
self.textEdit_2.setObjectName("textEdit_2")
self.verticalLayout.addWidget(self.textEdit_2)
self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox")
self.verticalLayout.addWidget(self.buttonBox)
self.retranslateUi(Dialog)
self.buttonBox.accepted.connect(self.save)
self.buttonBox.rejected.connect(Dialog.reject)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def save(self):
print("Return here")
self.Dialog.close()
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.label.setText(_translate("Dialog", "Punto Fuera de Control"))
self.label_2.setText(_translate("Dialog", "Bitacora de Proceso"))
self.label_5.setText(_translate("Dialog", "Cualquier cambio en mano de obra, materiales, medio ambiente, métodos o máquinas debe ser anotado"))
self.label_3.setText(_translate("Dialog", "Causa:"))
self.textEdit.setText(_translate("Dialog", ""))
self.label_4.setText(_translate("Dialog", "Correcciones:"))
self.textEdit_2.setHtml(_translate("Dialog", ""))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
答案 0 :(得分:1)
尝试一下:
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtCore import Qt
#from dbFuncs import *
#from demoUI import *
#from PandasModel import *
#from dataLogger import *
#import time
#from bitacorasend import Ui_Dialog
class Ui_Dialog(object):
def setupUi(self, Dialog, datos):
self.data = datos
self.Dialog = Dialog
Dialog.setObjectName("Dialog")
Dialog.resize(617, 405)
self.verticalLayout = QtWidgets.QVBoxLayout(Dialog)
self.verticalLayout.setObjectName("verticalLayout")
self.label = QtWidgets.QLabel(Dialog)
font = QtGui.QFont()
font.setPointSize(10)
self.label.setFont(font)
self.label.setAlignment(QtCore.Qt.AlignBottom|QtCore.Qt.AlignHCenter)
self.label.setObjectName("label")
self.verticalLayout.addWidget(self.label)
self.label_2 = QtWidgets.QLabel(Dialog)
font = QtGui.QFont()
font.setPointSize(16)
font.setBold(True)
font.setWeight(75)
self.label_2.setFont(font)
self.label_2.setAlignment(QtCore.Qt.AlignHCenter|QtCore.Qt.AlignTop)
self.label_2.setObjectName("label_2")
self.verticalLayout.addWidget(self.label_2)
self.label_5 = QtWidgets.QLabel(Dialog)
self.label_5.setAlignment(QtCore.Qt.AlignCenter)
self.label_5.setObjectName("label_5")
self.verticalLayout.addWidget(self.label_5)
self.label_3 = QtWidgets.QLabel(Dialog)
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.label_3.setFont(font)
self.label_3.setAlignment(QtCore.Qt.AlignBottom|QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft)
self.label_3.setObjectName("label_3")
self.verticalLayout.addWidget(self.label_3)
self.textEdit = QtWidgets.QTextEdit(Dialog)
self.textEdit.setMaximumSize(QtCore.QSize(16777215, 100))
self.textEdit.setObjectName("textEdit")
self.verticalLayout.addWidget(self.textEdit)
self.label_4 = QtWidgets.QLabel(Dialog)
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.label_4.setFont(font)
self.label_4.setAlignment(QtCore.Qt.AlignBottom|QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft)
self.label_4.setObjectName("label_4")
self.verticalLayout.addWidget(self.label_4)
self.textEdit_2 = QtWidgets.QTextEdit(Dialog)
self.textEdit_2.setObjectName("textEdit_2")
self.verticalLayout.addWidget(self.textEdit_2)
self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox")
self.verticalLayout.addWidget(self.buttonBox)
self.retranslateUi(Dialog)
self.buttonBox.accepted.connect(self.save)
self.buttonBox.rejected.connect(Dialog.reject)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def save(self):
print("Return here")
self.Dialog.close()
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.label.setText(_translate("Dialog", "Punto Fuera de Control"))
self.label_2.setText(_translate("Dialog", "Bitacora de Proceso"))
self.label_5.setText(_translate("Dialog", "Cualquier cambio en mano de obra, materiales, medio ambiente, métodos o máquinas debe ser anotado"))
self.label_3.setText(_translate("Dialog", "Causa:"))
self.textEdit.setText(_translate("Dialog", ""))
self.label_4.setText(_translate("Dialog", "Correcciones:"))
self.textEdit_2.setHtml(_translate("Dialog", ""))
class MainWindow(QtWidgets.QMainWindow): #, Ui_MainWindow):
def __init__(self):
super(MainWindow, self).__init__()
#QtWidgets.QMainWindow.__init__(self, *args, **kwargs)
# self.setupUi(self)
'''Variables for DB'''
centralWidget = QtWidgets.QWidget(self)
self.setCentralWidget(centralWidget)
self.dataTable = QtWidgets.QTableWidget(self)
self.saveButton = QtWidgets.QPushButton("saveButton", self)
layout = QtWidgets.QGridLayout(centralWidget)
layout.addWidget(self.dataTable)
layout.addWidget(self.saveButton)
'''Table Config'''
self.dataTable.setColumnCount(1)
self.dataTable.setRowCount(5)
self.dataTable.setHorizontalHeaderLabels(["Medición"])
self.dataTable.horizontalHeaderItem(0).setTextAlignment(Qt.AlignHCenter)
self.dataTable.horizontalHeader().setStretchLastSection(True)
self.dataTable.verticalHeader().setStretchLastSection(True)
'''Buttons signals'''
self.saveButton.clicked.connect(self.savePressed)
def bitacora(self):
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog,["data","data","data","data"])
Dialog.exec_()
print(ui.textEdit.toPlainText()) # <---
print(ui.textEdit_2.toPlainText()) # <---
def savePressed(self):
self.bitacora()
if __name__ == "__main__":
app = QtWidgets.QApplication([])
window = MainWindow()
window.show()
app.exec_()