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_descr_list.append(one_Table_descr)
|
||||||
tbl_struct_list.append(one_Table_struct)
|
tbl_struct_list.append(one_Table_struct)
|
||||||
print(qwery_create)
|
print(qwery_create)
|
||||||
c.execute(qwery_create)
|
#c.execute(qwery_create)
|
||||||
return tbl_names_list
|
return tbl_names_list
|
||||||
|
|
||||||
def initDBstructure():
|
def initDBstructure():
|
||||||
|
@ -176,7 +176,7 @@ def selectData(tbl):
|
||||||
field_replace = field_replace.replace(",", ",' ',")
|
field_replace = field_replace.replace(",", ",' ',")
|
||||||
subqwery = "(SELECT CONCAT(" + field_replace + ") FROM " + subqwery + " WHERE " + table1 + "." + field1 + "=" + tbl + "." + field + ") AS " + field
|
subqwery = "(SELECT CONCAT(" + field_replace + ") FROM " + subqwery + " WHERE " + table1 + "." + field1 + "=" + tbl + "." + field + ") AS " + field
|
||||||
elif db_type == "sqlite":
|
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
|
subqwery = "(SELECT (" + field_replace + ") FROM " + subqwery +" WHERE "+ table1 + "." + field1 +"="+ tbl +"."+ field +") AS " + field
|
||||||
qwery = qwery.replace(field, subqwery)
|
qwery = qwery.replace(field, subqwery)
|
||||||
qwery = qwery.rstrip(',') + " FROM " + tbl + " LIMIT 10000"
|
qwery = qwery.rstrip(',') + " FROM " + tbl + " LIMIT 10000"
|
||||||
|
|
44
gui.py
44
gui.py
|
@ -2,14 +2,9 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from PyQt5.QtWidgets import (QWidget, QHBoxLayout, QFrame,
|
|
||||||
QSplitter, QStyleFactory, QApplication)
|
|
||||||
from PyQt5.QtCore import Qt
|
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.QtGui import QIcon
|
||||||
from PyQt5.QtWidgets import *
|
from PyQt5.QtWidgets import *
|
||||||
#from PyQt5 import QtGui
|
|
||||||
from PyQt5.QtSql import *
|
|
||||||
|
|
||||||
#import pymysql
|
#import pymysql
|
||||||
import dm
|
import dm
|
||||||
|
@ -169,7 +164,10 @@ class MyTable(QTableWidget):
|
||||||
print("row:%d, col:%d" % (row, col))
|
print("row:%d, col:%d" % (row, col))
|
||||||
item = self.item(self.currentIndex().row(), self.currentIndex().column())
|
item = self.item(self.currentIndex().row(), self.currentIndex().column())
|
||||||
print(item.text())
|
print(item.text())
|
||||||
|
elif action == addRecord:
|
||||||
|
editForm = EditForm(self.tbl)
|
||||||
|
editForm.setParent(self)
|
||||||
|
editForm.show()
|
||||||
def on_click(self):
|
def on_click(self):
|
||||||
print(self.cursor().pos().x())
|
print(self.cursor().pos().x())
|
||||||
#self.contextMenuEvent(self.cursor())
|
#self.contextMenuEvent(self.cursor())
|
||||||
|
@ -259,27 +257,25 @@ class WorkArea(QWidget):
|
||||||
|
|
||||||
# Форма для добавления и редактирования
|
# Форма для добавления и редактирования
|
||||||
class EditForm(QWidget):
|
class EditForm(QWidget):
|
||||||
def __init__(self):
|
def __init__(self, tbl):
|
||||||
QWidget.__init__(self)
|
QWidget.__init__(self)
|
||||||
|
self.tbl = tbl
|
||||||
|
self.listFields = self.getTableStructure()
|
||||||
|
#print(listFields)
|
||||||
self.initUI()
|
self.initUI()
|
||||||
#self.setWindowFlags(Qt.SubWindow)
|
self.setWindowFlags(Qt.Dialog)
|
||||||
#print(self.parent)
|
#print(self.parent)
|
||||||
#self.parent = parent
|
#self.parent = parent
|
||||||
def initUI(self):
|
def initUI(self):
|
||||||
title = QLabel('Title')
|
n = 0
|
||||||
author = QLabel('Author')
|
itemsCount = len(self.listFields)
|
||||||
review = QLabel('Review')
|
|
||||||
titleEdit = QLineEdit()
|
|
||||||
authorEdit = QLineEdit()
|
|
||||||
reviewEdit = QTextEdit()
|
|
||||||
grid = QGridLayout()
|
grid = QGridLayout()
|
||||||
grid.setSpacing(10)
|
grid.setSpacing(10)
|
||||||
grid.addWidget(title, 1, 0)
|
for item in self.listFields:
|
||||||
grid.addWidget(titleEdit, 1, 1)
|
print(itemsCount)
|
||||||
grid.addWidget(author, 2, 0)
|
grid.addWidget(QLabel(item), n, 0)
|
||||||
grid.addWidget(authorEdit, 2, 1)
|
grid.addWidget(QLineEdit(), n, 1)
|
||||||
grid.addWidget(review, 3, 0)
|
n = n+1
|
||||||
grid.addWidget(reviewEdit, 3, 1, 5, 1)
|
|
||||||
|
|
||||||
self.setLayout(grid)
|
self.setLayout(grid)
|
||||||
|
|
||||||
|
@ -287,6 +283,14 @@ class EditForm(QWidget):
|
||||||
self.setWindowTitle('Review')
|
self.setWindowTitle('Review')
|
||||||
#self.setParent(parent)
|
#self.setParent(parent)
|
||||||
#self.show()
|
#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__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue
Block a user