Added "Add record" dialog

This commit is contained in:
svk 2017-03-21 20:10:38 +03:00
parent f43e23ee6a
commit bf02a7f567
2 changed files with 83 additions and 11 deletions

2
dm.py
View File

@ -186,7 +186,7 @@ def selectData(tbl):
return c.fetchall() return c.fetchall()
# получаем на вход имя таблицы и возвращаем список заголовков полей # получаем на вход имя таблицы и возвращаем список заголовков полей
def getTablesStructure(tbl): def getTableStructure(tbl):
global tbl_descr_list global tbl_descr_list
for item in tbl_descr_list: for item in tbl_descr_list:
if item[0] == tbl: if item[0] == tbl:

92
gui.py
View File

@ -52,20 +52,91 @@ class MyTable(QTableWidget):
print(currentQTableWidgetItem.row(), currentQTableWidgetItem.column(), currentQTableWidgetItem.text()) print(currentQTableWidgetItem.row(), currentQTableWidgetItem.column(), currentQTableWidgetItem.text())
# Форма для добавления и редактирования # Форма для добавления и редактирования
class EditForm(QWidget): class EditForm_(QWidget):
def __init__(self): def __init__(self, tblName, tblDescr):
super().__init__() super().__init__()
#scrollArea = QScrollArea()
l = QVBoxLayout() l = QVBoxLayout()
b = QPushButton('Добавить без параметра!') headBox = QHBoxLayout()
b.clicked.connect(lambda: self.function1()) lblHeader = QLabel('Таблица:' + tblDescr)
b2 = QPushButton('Добавить с параметром!') l.addLayout(headBox)
b2.clicked.connect(lambda: self.function1(args='параметр')) headBox.addWidget(lblHeader)
l.addWidget(b) hboxBtn = QHBoxLayout()
l.addWidget(b2) btnOk = QPushButton('Записать')
btnOk.clicked.connect(lambda: self.function1())
btnCancel = QPushButton('Закрыть')
btnCancel.clicked.connect(lambda: self.close())
i=0
while i < 30:
hboxEdit1 = QHBoxLayout()
lbl1 = QLabel(str(i))
edit1 = QLineEdit()
#edit1.setMaxLength(30)
hboxEdit1.addWidget(lbl1)
hboxEdit1.addWidget(edit1)
l.addLayout(hboxEdit1)
i = i+1
hboxBtn.addWidget(btnOk)
hboxBtn.addWidget(btnCancel)
l.addLayout(hboxBtn)
self.setWindowTitle("Добавление записи")
self.setLayout(l) self.setLayout(l)
self.setFixedSize(640, 480)
#scrollArea.setWidget(self)
#self.setCentralWidget(scrollArea)
self.show() self.show()
class EditForm(QMainWindow):
def __init__(self, tblName, tblDescr):
super().__init__()
scroll_widget = QWidget()
self.general_layout = QVBoxLayout()
scroll_area = QScrollArea()
l = QVBoxLayout()
headBox = QHBoxLayout()
lblHeader = QLabel('Таблица: ' + tblDescr)
l.addLayout(headBox)
headBox.addWidget(lblHeader)
hboxBtn = QHBoxLayout()
btnOk = QPushButton('Записать')
btnOk.clicked.connect(lambda: self.function1())
btnCancel = QPushButton('Закрыть')
btnCancel.clicked.connect(lambda: self.close())
i=0
for item in dm.getTableStructure(tblName):
print(item)
hboxEdit1 = QHBoxLayout()
lbl1 = QLabel(item)
edit1 = QLineEdit()
#edit1.setMaxLength(30)
hboxEdit1.addWidget(lbl1)
hboxEdit1.addWidget(edit1)
l.addLayout(hboxEdit1)
i = i+1
hboxBtn.addWidget(btnOk)
hboxBtn.addWidget(btnCancel)
l.addLayout(hboxBtn)
self.general_layout.addLayout(l)
scroll_widget.setLayout(self.general_layout)
scroll_area.setWidget(scroll_widget)
self.setCentralWidget(scroll_area)
self.setWindowTitle("Добавление записи")
#self.setFixedSize(640, 480)
#scrollArea.setWidget(self)
#self.setCentralWidget(scrollArea)
#self.show()
def addDataIntoTable(tbl_descr, tblDataWidget): def addDataIntoTable(tbl_descr, tblDataWidget):
global tblList global tblList
@ -76,7 +147,7 @@ def addDataIntoTable(tbl_descr, tblDataWidget):
#print(tbl_descr) #print(tbl_descr)
data = dm.selectData(tbl_name) data = dm.selectData(tbl_name)
#print(data) #print(data)
fieldNames = dm.getTablesStructure(tbl_name) fieldNames = dm.getTableStructure(tbl_name)
# проверка на наличие записей в таблице # проверка на наличие записей в таблице
if data: if data:
# количество строк # количество строк
@ -183,7 +254,8 @@ def addNewRecord():
tblName = i[0] tblName = i[0]
print(tblName) print(tblName)
editForm = EditForm() editForm = EditForm(tblName, tblDescr)
editForm.show()
#editForm.setParent(listTables) #editForm.setParent(listTables)
#editForm.show() #editForm.show()
#editForm.setParent(tblRelationsData) #editForm.setParent(tblRelationsData)