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()
# получаем на вход имя таблицы и возвращаем список заголовков полей
def getTablesStructure(tbl):
def getTableStructure(tbl):
global tbl_descr_list
for item in tbl_descr_list:
if item[0] == tbl:

92
gui.py
View File

@ -52,20 +52,91 @@ class MyTable(QTableWidget):
print(currentQTableWidgetItem.row(), currentQTableWidgetItem.column(), currentQTableWidgetItem.text())
# Форма для добавления и редактирования
class EditForm(QWidget):
def __init__(self):
class EditForm_(QWidget):
def __init__(self, tblName, tblDescr):
super().__init__()
#scrollArea = QScrollArea()
l = QVBoxLayout()
b = QPushButton('Добавить без параметра!')
b.clicked.connect(lambda: self.function1())
b2 = QPushButton('Добавить с параметром!')
b2.clicked.connect(lambda: self.function1(args='параметр'))
l.addWidget(b)
l.addWidget(b2)
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
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.setFixedSize(640, 480)
#scrollArea.setWidget(self)
#self.setCentralWidget(scrollArea)
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):
global tblList
@ -76,7 +147,7 @@ def addDataIntoTable(tbl_descr, tblDataWidget):
#print(tbl_descr)
data = dm.selectData(tbl_name)
#print(data)
fieldNames = dm.getTablesStructure(tbl_name)
fieldNames = dm.getTableStructure(tbl_name)
# проверка на наличие записей в таблице
if data:
# количество строк
@ -183,7 +254,8 @@ def addNewRecord():
tblName = i[0]
print(tblName)
editForm = EditForm()
editForm = EditForm(tblName, tblDescr)
editForm.show()
#editForm.setParent(listTables)
#editForm.show()
#editForm.setParent(tblRelationsData)