Answer the question
In order to leave comments, you need to log in
How to pass a variable to another class?
I can't pass the row_numberSU variable from class BaseWindow to AmplyWindow in any way.
The purpose of all this is to keep track of the row number of the double-clicked row.
import sys
import os, os.path
from PyQt5 import QtCore, QtGui, QtWidgets
import gui
from docxtpl import DocxTemplate
import sqlite3
from AmplyWindow import Ui_AmplyWindow
class BaseWindow(QtWidgets.QMainWindow, gui.Ui_MainWindow, DocxTemplate):
def __init__(self):
super().__init__()
self.setupUi(self)
self.loadData()
self.action_interface()
self.liststud.doubleClicked.connect(self.OpenAmpWin)
for idx in self.liststud.selectionModel().selectedIndexes():
row_numberSU = idx.row()
return row_numberSU
def action_interface(self):
self.butupd.clicked.connect(self.loadData)
self.exit.clicked.connect(self.close)
self.save.clicked.connect(self.active)
def OpenAmpWin(self):
self.AmpWinShow = AmplyWindow()
self.AmpWinShow.show()
def loadData(self):
Connection = sqlite3.connect('datam.db')
query = "SELECT * FROM Sbase"
result = Connection.execute(query)
self.liststud.setRowCount(0)
for row_number, row_data in enumerate(result):
self.liststud.insertRow(row_number)
for colum_number, data in enumerate(row_data):
self.liststud.setItem(row_number, colum_number, QtWidgets.QTableWidgetItem(str(data)))
Connection.close()
self.liststud.setHorizontalHeaderLabels(["№","Фамилия","Имя","Отчество","Дата рождения","Специальность"])
def active(self):
AFam = self.AFam.text()
AImy = self.AImy.text()
AOtch = self.AOtch.text()
patternpath = r'.\pattern\1.docx'
savepath = r'.\resdoc\done.docx'
doc = DocxTemplate(patternpath)
context = { 'AFam' : AFam , 'AImy' : AImy, 'AOtch' : AOtch}
doc.render(context)
doc.save(savepath)
class AmplyWindow(BaseWindow, QtWidgets.QWidget, Ui_AmplyWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.AmpWinAct()
def AmpWinAct(self, row_numberSU):
condb = sqlite3.connect('datam.db')
cursor = condb.cursor()
querydb = """SELECT fam, imy, otch, dateb, sts FROM Sbase WHERE row = ?"""
cursor.execute(querydb,(row_numberSU))
data = cursor.fetchall()
for row in data:
a=row[0]
b=row[1]
c=row[2]
d=row[3]
e=row[4]
cursor.close()
self.abfam.setText(a)
self.abimy.setText(b)
self.abotch.setText(c)
self.abdate.setText(d)
self.status.setCurrentText(e)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
window = BaseWindow()
window.show()
app.exec()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question