Added title for tables
This commit is contained in:
parent
5c26c1b898
commit
dc40c35424
32
dm.py
32
dm.py
|
@ -2,20 +2,26 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
def createTables(tbl_list):
|
def createTables(tbl_list):
|
||||||
|
global tbl_descr_list
|
||||||
i = 0
|
i = 0
|
||||||
tbl_names_list = []
|
tbl_names_list = []
|
||||||
|
tbl_descr_list = []
|
||||||
|
|
||||||
while i < len(tbl_list):
|
while i < len(tbl_list):
|
||||||
|
one_Table_descr = []
|
||||||
tbl_descr = tbl_list[i]["tableDescription"]
|
tbl_descr = tbl_list[i]["tableDescription"]
|
||||||
tbl_name = tbl_list[i]["tableName"]
|
tbl_name = tbl_list[i]["tableName"]
|
||||||
field_list = tbl_list[i]["fieldList"][i].keys()
|
field_list = tbl_list[i]["fieldList"][i].keys()
|
||||||
|
tbl_names_list.append([tbl_name, tbl_descr])
|
||||||
tbl_names_list.append(tbl_name)
|
one_Table_descr.append(tbl_name)
|
||||||
|
|
||||||
x = 0
|
x = 0
|
||||||
# список всех полей таблицы
|
# список всех полей таблицы
|
||||||
qwery_create = "CREATE TABLE " + tbl_name + " ("
|
qwery_create = "CREATE TABLE " + tbl_name + " ("
|
||||||
qwery_select = "SELECT * FROM "
|
#qwery_select = "SELECT * FROM "
|
||||||
index = ""
|
index = ""
|
||||||
|
field_names_list = []
|
||||||
|
|
||||||
while x < len(tbl_list[i]["fieldList"]):
|
while x < len(tbl_list[i]["fieldList"]):
|
||||||
if tbl_list[i]["fieldList"][x]["autoIncrement"] == "yes":
|
if tbl_list[i]["fieldList"][x]["autoIncrement"] == "yes":
|
||||||
auto_increment = " AUTO_INCREMENT, "
|
auto_increment = " AUTO_INCREMENT, "
|
||||||
|
@ -23,21 +29,26 @@ def createTables(tbl_list):
|
||||||
auto_increment = ", "
|
auto_increment = ", "
|
||||||
qwery_create = qwery_create + tbl_list[i]["fieldList"][x]["fName"] + " " + \
|
qwery_create = qwery_create + tbl_list[i]["fieldList"][x]["fName"] + " " + \
|
||||||
tbl_list[i]["fieldList"][x]["fType"] + auto_increment
|
tbl_list[i]["fieldList"][x]["fType"] + auto_increment
|
||||||
|
|
||||||
if tbl_list[i]["fieldList"][x]["index"] == "PRIMARY KEY":
|
if tbl_list[i]["fieldList"][x]["index"] == "PRIMARY KEY":
|
||||||
index = "PRIMARY KEY(" + tbl_list[i]["fieldList"][x]["fName"] + ")"
|
index = "PRIMARY KEY(" + tbl_list[i]["fieldList"][x]["fName"] + ")"
|
||||||
|
field_names_list.append(tbl_list[i]["fieldList"][x]["fDescription"])
|
||||||
x = x + 1
|
x = x + 1
|
||||||
qwery_create = qwery_create + index + ");"
|
qwery_create = qwery_create + index + ");"
|
||||||
|
|
||||||
print(qwery_create)
|
one_Table_descr.append(field_names_list)
|
||||||
|
#print(qwery_create)
|
||||||
i = i + 1
|
i = i + 1
|
||||||
|
tbl_descr_list.append(one_Table_descr)
|
||||||
|
#print(tbl_descr_list)
|
||||||
return tbl_names_list
|
return tbl_names_list
|
||||||
|
|
||||||
def initDBstructure():
|
def initDBstructure():
|
||||||
|
global tbl_descr_list
|
||||||
table_list = open("tables.json", "r", encoding="utf-8")
|
table_list = open("tables.json", "r", encoding="utf-8")
|
||||||
data = json.load(table_list, encoding="utf-8")
|
data = json.load(table_list, encoding="utf-8")
|
||||||
tbl_list = data["tables"]
|
tbl_list = data["tables"]
|
||||||
tbl_names_list = createTables(tbl_list)
|
tbl_names_list = createTables(tbl_list)
|
||||||
|
|
||||||
return tbl_names_list
|
return tbl_names_list
|
||||||
|
|
||||||
def selectData(table_name):
|
def selectData(table_name):
|
||||||
|
@ -45,4 +56,13 @@ def selectData(table_name):
|
||||||
data_list = ("1","2","3","4","5")
|
data_list = ("1","2","3","4","5")
|
||||||
return table_name
|
return table_name
|
||||||
|
|
||||||
initDBstructure()
|
# получаем на вход имя таблицы и возвращаем список заголовков полей
|
||||||
|
def getTablesStructure(tbl):
|
||||||
|
global tbl_descr_list
|
||||||
|
for item in tbl_descr_list:
|
||||||
|
if item[0] == tbl:
|
||||||
|
return item[1]
|
||||||
|
#print(tbl_descr_list)
|
||||||
|
#return tbl_descr_list
|
||||||
|
|
||||||
|
#initDBstructure()
|
32
gui.py
32
gui.py
|
@ -111,19 +111,26 @@ class MainWin(QMainWindow):
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
class MyTable(QTableWidget):
|
class MyTable(QTableWidget):
|
||||||
def __init__(self, thestruct, *args):
|
def __init__(self, tbl, thestruct, *args):
|
||||||
QTableWidget.__init__(self, *args)
|
QTableWidget.__init__(self, *args)
|
||||||
self.data = thestruct
|
self.data = thestruct
|
||||||
self.setmydata()
|
self.setmydata()
|
||||||
|
self.tbl = tbl
|
||||||
|
|
||||||
|
#print(self.tbl)
|
||||||
|
n = 0
|
||||||
|
for item in dm.getTablesStructure(self.tbl):
|
||||||
|
print(item)
|
||||||
|
# установка заголовков столбцов таблицы
|
||||||
|
#character = chr(ord('A') + n)
|
||||||
|
self.setHorizontalHeaderItem(n, QTableWidgetItem(item))
|
||||||
|
n = n+1
|
||||||
|
|
||||||
def setmydata(self):
|
def setmydata(self):
|
||||||
n = 0
|
n = 0
|
||||||
|
|
||||||
for key in self.data:
|
for key in self.data:
|
||||||
#print(key)
|
|
||||||
m = 0
|
m = 0
|
||||||
for item in key:
|
for item in key:
|
||||||
#print(item)
|
|
||||||
newitem = QTableWidgetItem(item)
|
newitem = QTableWidgetItem(item)
|
||||||
self.setItem(m, n, newitem)
|
self.setItem(m, n, newitem)
|
||||||
n += 1
|
n += 1
|
||||||
|
@ -134,12 +141,9 @@ class WorkArea(QWidget):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.initUI()
|
self.initUI()
|
||||||
|
|
||||||
|
|
||||||
def initUI(self):
|
def initUI(self):
|
||||||
|
|
||||||
hbox = QHBoxLayout(self)
|
hbox = QHBoxLayout(self)
|
||||||
# список таблиц
|
# список таблиц
|
||||||
listTablesWidget = QListWidget()
|
listTablesWidget = QListWidget()
|
||||||
|
@ -161,7 +165,7 @@ class WorkArea(QWidget):
|
||||||
|
|
||||||
# выводим список таблиц в левом поле
|
# выводим список таблиц в левом поле
|
||||||
for i in dm.initDBstructure():
|
for i in dm.initDBstructure():
|
||||||
listTablesWidget.addItem(i)
|
listTablesWidget.addItem(i[0])
|
||||||
|
|
||||||
# заполняем правый список данными из выбранной таблицы
|
# заполняем правый список данными из выбранной таблицы
|
||||||
def addData(tbl_name):
|
def addData(tbl_name):
|
||||||
|
@ -172,10 +176,6 @@ class WorkArea(QWidget):
|
||||||
if item is not None:
|
if item is not None:
|
||||||
#print(item)
|
#print(item)
|
||||||
item.deleteLater()
|
item.deleteLater()
|
||||||
|
|
||||||
#tablesDataWidget.deleteLater()
|
|
||||||
# rows = message.count('id') # считает количество строк в таблице
|
|
||||||
# print(c.fetchall())
|
|
||||||
data = c.fetchall()
|
data = c.fetchall()
|
||||||
# проверка на наличие записей в таблице
|
# проверка на наличие записей в таблице
|
||||||
if data:
|
if data:
|
||||||
|
@ -183,24 +183,18 @@ class WorkArea(QWidget):
|
||||||
rows = len(data)
|
rows = len(data)
|
||||||
# КОЛИЧЕСТВО КОЛОНОК
|
# КОЛИЧЕСТВО КОЛОНОК
|
||||||
cols = len(data[0])
|
cols = len(data[0])
|
||||||
table = MyTable(data, rows, cols)
|
table = MyTable(tbl_name, data, rows, cols)
|
||||||
table.setFrameShape(QFrame.StyledPanel)
|
table.setFrameShape(QFrame.StyledPanel)
|
||||||
splitter1.addWidget(table)
|
splitter1.addWidget(table)
|
||||||
#table.show()
|
|
||||||
#sys.exit(app.exec_())
|
|
||||||
|
|
||||||
# обработка нажатия мышой на списке
|
# обработка нажатия мышой на списке
|
||||||
#listTablesWidget.itemClicked.connect(lambda: dm.selectData(listTablesWidget.currentItem))
|
#listTablesWidget.itemClicked.connect(lambda: dm.selectData(listTablesWidget.currentItem))
|
||||||
listTablesWidget.itemClicked.connect(lambda: addData(listTablesWidget.model().data(listTablesWidget.currentIndex())))
|
listTablesWidget.itemClicked.connect(lambda: addData(listTablesWidget.model().data(listTablesWidget.currentIndex())))
|
||||||
|
|
||||||
|
|
||||||
def onChanged(self, text):
|
def onChanged(self, text):
|
||||||
|
|
||||||
self.lbl.setText(text)
|
self.lbl.setText(text)
|
||||||
self.lbl.adjustSize()
|
self.lbl.adjustSize()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
|
38
tables.json
38
tables.json
|
@ -2,46 +2,46 @@
|
||||||
"tables": [
|
"tables": [
|
||||||
{
|
{
|
||||||
"tableName": "users",
|
"tableName": "users",
|
||||||
"tableDescription": "Список пользователей",
|
"tableDescription": "Пользователи",
|
||||||
"fieldList": [
|
"fieldList": [
|
||||||
{
|
{
|
||||||
"fName": "id",
|
"fName": "id",
|
||||||
"fDescr": "Номер п.п.",
|
"fDescription": "Номер п.п.",
|
||||||
"fType": "int(6)",
|
"fType": "int(6)",
|
||||||
"index": "PRIMARY KEY",
|
"index": "PRIMARY KEY",
|
||||||
"autoIncrement": "yes"
|
"autoIncrement": "yes"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fName": "login",
|
"fName": "login",
|
||||||
"fDescr": "Логин",
|
"fDescription": "Логин",
|
||||||
"fType": "char(20)",
|
"fType": "char(20)",
|
||||||
"index": "yes",
|
"index": "yes",
|
||||||
"autoIncrement": "no"
|
"autoIncrement": "no"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fName": "password",
|
"fName": "password",
|
||||||
"fDescr": "Пароль",
|
"fDescription": "Пароль",
|
||||||
"fType": "char(20)",
|
"fType": "char(20)",
|
||||||
"index": "no",
|
"index": "no",
|
||||||
"autoIncrement": "no"
|
"autoIncrement": "no"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fName": "last_name",
|
"fName": "last_name",
|
||||||
"fDescr": "Фамилия",
|
"fDescription": "Фамилия",
|
||||||
"fType": "char(20)",
|
"fType": "char(20)",
|
||||||
"index": "no",
|
"index": "no",
|
||||||
"autoIncrement": "no"
|
"autoIncrement": "no"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fName": "name",
|
"fName": "name",
|
||||||
"fDescr": "Имя",
|
"fDescription": "Имя",
|
||||||
"fType": "char(20)",
|
"fType": "char(20)",
|
||||||
"index": "no",
|
"index": "no",
|
||||||
"autoIncrement": "no"
|
"autoIncrement": "no"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fName": "middle_name",
|
"fName": "middle_name",
|
||||||
"fDescr": "Отчество",
|
"fDescription": "Отчество",
|
||||||
"fType": "char(20)",
|
"fType": "char(20)",
|
||||||
"index": "no",
|
"index": "no",
|
||||||
"autoIncrement": "no"
|
"autoIncrement": "no"
|
||||||
|
@ -50,39 +50,39 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tableName": "docs",
|
"tableName": "docs",
|
||||||
"tableDescription": "Список документов",
|
"tableDescription": "Документы",
|
||||||
"fieldList": [
|
"fieldList": [
|
||||||
{
|
{
|
||||||
"fName": "id",
|
"fName": "id",
|
||||||
"fDescr": "Номер п.п.",
|
"fDescription": "Номер п.п.",
|
||||||
"fType": "int(6)",
|
"fType": "int(6)",
|
||||||
"index": "PRIMARY KEY",
|
"index": "PRIMARY KEY",
|
||||||
"autoIncrement": "yes"
|
"autoIncrement": "yes"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fName": "doc_name",
|
"fName": "doc_name",
|
||||||
"fDescr": "Наименование",
|
"fDescription": "Наименование",
|
||||||
"fType": "varchar(100)",
|
"fType": "varchar(100)",
|
||||||
"index": "yes",
|
"index": "yes",
|
||||||
"autoIncrement": "no"
|
"autoIncrement": "no"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fName": "description",
|
"fName": "description",
|
||||||
"fDescr": "Описание",
|
"fDescription": "Описание",
|
||||||
"fType": "varchar(200)",
|
"fType": "varchar(200)",
|
||||||
"index": "no",
|
"index": "no",
|
||||||
"autoIncrement": "no"
|
"autoIncrement": "no"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fName": "user_id",
|
"fName": "user_id",
|
||||||
"fDescr": "Владелец",
|
"fDescription": "Владелец",
|
||||||
"fType": "int(6)",
|
"fType": "int(6)",
|
||||||
"index": "no",
|
"index": "no",
|
||||||
"autoIncrement": "no"
|
"autoIncrement": "no"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fName": "parent_id",
|
"fName": "parent_id",
|
||||||
"fDescr": "Имя",
|
"fDescription": "Имя",
|
||||||
"fType": "int(6)",
|
"fType": "int(6)",
|
||||||
"index": "no",
|
"index": "no",
|
||||||
"autoIncrement": "no"
|
"autoIncrement": "no"
|
||||||
|
@ -91,39 +91,39 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tableName": "address",
|
"tableName": "address",
|
||||||
"tableDescription": "Список адресов",
|
"tableDescription": "Адреса",
|
||||||
"fieldList": [
|
"fieldList": [
|
||||||
{
|
{
|
||||||
"fName": "id",
|
"fName": "id",
|
||||||
"fDescr": "Номер п.п.",
|
"fDescription": "Номер п.п.",
|
||||||
"fType": "int(6)",
|
"fType": "int(6)",
|
||||||
"index": "PRIMARY KEY",
|
"index": "PRIMARY KEY",
|
||||||
"autoIncrement": "yes"
|
"autoIncrement": "yes"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fName": "region",
|
"fName": "region",
|
||||||
"fDescr": "Регион",
|
"fDescription": "Регион",
|
||||||
"fType": "varchar(100)",
|
"fType": "varchar(100)",
|
||||||
"index": "yes",
|
"index": "yes",
|
||||||
"autoIncrement": "no"
|
"autoIncrement": "no"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fName": "city",
|
"fName": "city",
|
||||||
"fDescr": "Населеннй пункт",
|
"fDescription": "Населеннй пункт",
|
||||||
"fType": "varchar(200)",
|
"fType": "varchar(200)",
|
||||||
"index": "no",
|
"index": "no",
|
||||||
"autoIncrement": "no"
|
"autoIncrement": "no"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fName": "street",
|
"fName": "street",
|
||||||
"fDescr": "Улица",
|
"fDescription": "Улица",
|
||||||
"fType": "varchar(100)",
|
"fType": "varchar(100)",
|
||||||
"index": "no",
|
"index": "no",
|
||||||
"autoIncrement": "no"
|
"autoIncrement": "no"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fName": "house",
|
"fName": "house",
|
||||||
"fDescr": "Дом",
|
"fDescription": "Дом",
|
||||||
"fType": "char(6)",
|
"fType": "char(6)",
|
||||||
"index": "no",
|
"index": "no",
|
||||||
"autoIncrement": "no"
|
"autoIncrement": "no"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user