Хочу чтобы нажимая на кнопку в
main.py я получил все возможности, которые предоставляет файл
mainApp.py
main.py
from PyQt5 import QtCore, QtGui, QtWidgets
from mainApp import MainApp, editDialog, AddDialog
class Ui_MainWindow(object):
def open_per(self):#открывается только одного окно(в нем не могу наживать другие кнопки)
self.window = QtWidgets.QMainWindow()
self.ui = MainApp()
self.ui.setupUi(self.window)
self.window.show()
def setupUi(self, MainWindow):
[.....]
mainApp.py
from mainWin import Ui_mainWindow
import addDialog
from editDialog import Ui_Dialog
from PyQt5.QtWidgets import QApplication, QDialog, QMainWindow, QMessageBox, QTableWidgetItem
import sqlite3
conn = sqlite3.connect('tableDB1.db')
curs = conn.cursor()
curs.execute('CREATE TABLE IF NOT EXISTS squad (ID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, First TEXT not null, Last TEXT, Father TEXT, Birth TEXT, Pasp_num TEXT, Pasp_series TEXT, Address TEXT, Faculty TEXT, Course TEXT, Specialty TEXT, Phone_num TEXT, Dohana TEXT, Room_num TEXT) ')
class MainApp(QMainWindow, Ui_mainWindow):
def __init__(self, parent=None):
super(MainApp, self).__init__(parent)
# self.setupUi(self)
# self.Load_Database()
self.init_Ui()
def init_Ui(self):
self.setupUi(self)
self.Load_Database()
self.show()
self.pushButton.clicked.connect(self.Show_Add_Dialog)
self.pushButton_3.clicked.connect(self.Delete_Data)
self.pushButton_2.clicked.connect(self.Change_Data)
self.pushButton_4.clicked.connect(self.Search)
self.pushButton_5.clicked.connect(self.Clear_Search)
def Clear_Search(self):
self.Load_Database()
self.lineEdit.clear()
def Show_Add_Dialog(self):
self.adding = AddDialog()
self.adding.pushButton_2.clicked.connect(self.Add_Data)
self.adding.exec_()
def Add_Data(self):
fname = self.adding.lineEdit.text()
lname = self.adding.lineEdit_2.text()
father = self.adding.lineEdit_3.text()
birth = self.adding.lineEdit_4.text()
pasp_num = self.adding.lineEdit_17.text()
pasp_series = self.adding.lineEdit_18.text()
address = self.adding.lineEdit_19.text()
faculty = self.adding.lineEdit_20.text()
course = self.adding.lineEdit_21.text()
specialty = self.adding.lineEdit_23.text()
phone_num = self.adding.lineEdit_26.text()
dohana = self.adding.lineEdit_24.text()
room_num = self.adding.lineEdit_25.text()
try:
curs.execute('INSERT INTO squad (First, Last, Father, Birth, Pasp_num, Pasp_series, Address, Faculty, Course, Specialty, Phone_num, Dohana, Room_num) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)', (fname, lname, father, birth, pasp_num, pasp_series, address, faculty, course, specialty, phone_num, dohana, room_num))
conn.commit()
self.Load_Database()
except Exception as error:
print(error)
def Search(self):
db = sqlite3.connect('tableDB1.db')
cursor = db.cursor()
search = self.lineEdit.text() + '%'
res = cursor.execute('SELECT * FROM squad WHERE Father LIKE ? OR First LIKE ? OR Last LIKE ? OR Birth LIKE ?',(search, search, search, search))
self.tableWidget.setRowCount(0)
for row_index, row_data in enumerate(res):
self.tableWidget.insertRow(row_index)
for colm_index, colm_data in enumerate(row_data):
self.tableWidget.setItem(row_index, colm_index,QTableWidgetItem(str(colm_data)))
def Delete_Data(self):
row = self.tableWidget.currentRow()
row_id = self.tableWidget.item(row,0).text()
curs.execute('DELETE FROM squad WHERE ID = ?', [row_id])
conn.commit()
self.Load_Database()
def Load_Database(self):
while self.tableWidget.rowCount()>0:#so that the information is not displayed again!(while)
self.tableWidget.removeRow(0)
conn = sqlite3.connect('tableDB1.db')
content = 'SELECT * FROM squad'
res = conn.execute(content)
for row_index, row_data in enumerate(res):
self.tableWidget.insertRow(row_index)
for colm_index, colm_data in enumerate(row_data):
self.tableWidget.setItem(row_index, colm_index,QTableWidgetItem(str(colm_data)))
# conn.close()
self.label.setText("Кількість користувачів: "+str(self.tableWidget.rowCount()))
return
def Change_Data(self):
row = self.tableWidget.currentRow()
row_id = self.tableWidget.item(row,0).text()
First = self.tableWidget.item(row,1).text()
Last = self.tableWidget.item(row,2).text()
Father = self.tableWidget.item(row,3).text()
Birth = self.tableWidget.item(row,4).text()
Pasp_num = self.tableWidget.item(row,5).text()
Pasp_series = self.tableWidget.item(row,6).text()
Address = self.tableWidget.item(row,7).text()
Faculty = self.tableWidget.item(row,8).text()
Course = self.tableWidget.item(row,9).text()
Specialty = self.tableWidget.item(row,10).text()
Phone_num = self.tableWidget.item(row,11).text()
Dohana = self.tableWidget.item(row,12).text()
Room_num = self.tableWidget.item(row,13).text()
curs.execute("UPDATE squad SET First = ?, Last = ?, Father = ?, Birth = ?, Pasp_num = ?, Pasp_series = ?, Address = ?, Faculty = ?, Course = ?, Specialty = ?, Phone_num = ?, Dohana = ?, Room_num = ? WHERE ID = ?", (First, Last, Father, Birth, Pasp_num, Pasp_series, Address, Faculty, Course, Specialty, Phone_num, Dohana, Room_num, row_id))
conn.commit()
self.Load_Database()
class editDialog(QDialog, Ui_Dialog):
def __init__(self, parent=None):
super(editDialog, self).__init__(parent)
self.setupUi(self)
class AddDialog(QDialog, addDialog.Ui_Dialog):
def __init__(self, parent=None):
super(AddDialog, self).__init__(parent)
self.setupUi(self)
app = QApplication([])
win = MainApp()
app.exec_()