Code cleaning, and added some function for add record dialog.
This commit is contained in:
parent
07bb927271
commit
1e8a4a38ac
4
dm.py
4
dm.py
|
@ -135,7 +135,7 @@ def createTables(tbl_list):
|
|||
tbl_descr_list.append(one_Table_descr)
|
||||
tbl_struct_list.append(one_Table_struct)
|
||||
print(qwery_create)
|
||||
c.execute(qwery_create)
|
||||
#c.execute(qwery_create)
|
||||
return tbl_names_list
|
||||
|
||||
def initDBstructure():
|
||||
|
@ -176,7 +176,7 @@ def selectData(tbl):
|
|||
field_replace = field_replace.replace(",", ",' ',")
|
||||
subqwery = "(SELECT CONCAT(" + field_replace + ") FROM " + subqwery + " WHERE " + table1 + "." + field1 + "=" + tbl + "." + field + ") AS " + field
|
||||
elif db_type == "sqlite":
|
||||
field_replace = field_replace.replace(",", " || ")
|
||||
field_replace = field_replace.replace(",", " || ' ' ||")
|
||||
subqwery = "(SELECT (" + field_replace + ") FROM " + subqwery +" WHERE "+ table1 + "." + field1 +"="+ tbl +"."+ field +") AS " + field
|
||||
qwery = qwery.replace(field, subqwery)
|
||||
qwery = qwery.rstrip(',') + " FROM " + tbl + " LIMIT 10000"
|
||||
|
|
44
gui.py
44
gui.py
|
@ -2,14 +2,9 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
from PyQt5.QtWidgets import (QWidget, QHBoxLayout, QFrame,
|
||||
QSplitter, QStyleFactory, QApplication)
|
||||
from PyQt5.QtCore import Qt
|
||||
#from PyQt5.QtWidgets import QMainWindow, QTextEdit, QAction, QApplication, QListView, QListWidget, QTableWidget , QTableView, QTableWidgetItem, QHeaderView, QPushButton, QMenu
|
||||
from PyQt5.QtGui import QIcon
|
||||
from PyQt5.QtWidgets import *
|
||||
#from PyQt5 import QtGui
|
||||
from PyQt5.QtSql import *
|
||||
|
||||
#import pymysql
|
||||
import dm
|
||||
|
@ -169,7 +164,10 @@ class MyTable(QTableWidget):
|
|||
print("row:%d, col:%d" % (row, col))
|
||||
item = self.item(self.currentIndex().row(), self.currentIndex().column())
|
||||
print(item.text())
|
||||
|
||||
elif action == addRecord:
|
||||
editForm = EditForm(self.tbl)
|
||||
editForm.setParent(self)
|
||||
editForm.show()
|
||||
def on_click(self):
|
||||
print(self.cursor().pos().x())
|
||||
#self.contextMenuEvent(self.cursor())
|
||||
|
@ -259,27 +257,25 @@ class WorkArea(QWidget):
|
|||
|
||||
# Форма для добавления и редактирования
|
||||
class EditForm(QWidget):
|
||||
def __init__(self):
|
||||
def __init__(self, tbl):
|
||||
QWidget.__init__(self)
|
||||
self.tbl = tbl
|
||||
self.listFields = self.getTableStructure()
|
||||
#print(listFields)
|
||||
self.initUI()
|
||||
#self.setWindowFlags(Qt.SubWindow)
|
||||
self.setWindowFlags(Qt.Dialog)
|
||||
#print(self.parent)
|
||||
#self.parent = parent
|
||||
def initUI(self):
|
||||
title = QLabel('Title')
|
||||
author = QLabel('Author')
|
||||
review = QLabel('Review')
|
||||
titleEdit = QLineEdit()
|
||||
authorEdit = QLineEdit()
|
||||
reviewEdit = QTextEdit()
|
||||
n = 0
|
||||
itemsCount = len(self.listFields)
|
||||
grid = QGridLayout()
|
||||
grid.setSpacing(10)
|
||||
grid.addWidget(title, 1, 0)
|
||||
grid.addWidget(titleEdit, 1, 1)
|
||||
grid.addWidget(author, 2, 0)
|
||||
grid.addWidget(authorEdit, 2, 1)
|
||||
grid.addWidget(review, 3, 0)
|
||||
grid.addWidget(reviewEdit, 3, 1, 5, 1)
|
||||
for item in self.listFields:
|
||||
print(itemsCount)
|
||||
grid.addWidget(QLabel(item), n, 0)
|
||||
grid.addWidget(QLineEdit(), n, 1)
|
||||
n = n+1
|
||||
|
||||
self.setLayout(grid)
|
||||
|
||||
|
@ -287,6 +283,14 @@ class EditForm(QWidget):
|
|||
self.setWindowTitle('Review')
|
||||
#self.setParent(parent)
|
||||
#self.show()
|
||||
def getTableStructure(self):
|
||||
listFields = []
|
||||
for item in dm.getTablesStructure(self.tbl):
|
||||
listFields.append(item)
|
||||
# установка заголовков столбцов таблицы
|
||||
#self.setHorizontalHeaderItem(n, QTableWidgetItem(item))
|
||||
return listFields
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue
Block a user