Change GUI view and usability

This commit is contained in:
Sergey Kalinin 2017-03-17 17:17:17 +03:00
parent 76712014cd
commit e8eca97b6b
4 changed files with 82 additions and 8 deletions

Binary file not shown.

3
dm.py
View File

@ -9,7 +9,6 @@ host='kis',
charset='utf8')
c = conn.cursor()
def createTables(tbl_list):
global tbl_descr_list, tbl_struct_list
i = 0
@ -59,6 +58,7 @@ def createTables(tbl_list):
i = i + 1
tbl_descr_list.append(one_Table_descr)
tbl_struct_list.append(one_Table_struct)
print(qwery_create)
c.execute(qwery_create)
return tbl_names_list
@ -98,6 +98,7 @@ def selectData(tbl):
subqwery = "(SELECT CONCAT(" + field_replace + ") FROM " + subqwery +" WHERE "+ table1 + "." + field1 +"="+ tbl +"."+ field +") AS " + field
qwery = qwery.replace(field, subqwery)
qwery = qwery.rstrip(',') + " FROM " + tbl + " LIMIT 10000"
print(qwery)
c.execute(qwery)
return c.fetchall()

57
gui.py
View File

@ -5,9 +5,12 @@ 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
#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 *
#import PyQt5.QtGui
from PyQt5.QtSql import *
#import pymysql
import dm
@ -27,7 +30,10 @@ class MainWin(QMainWindow):
self.initUI()
#заглушка
def qqqq(self):
print("ddddddddd")
print("Нажата клавиша DEL")
#tablesDataWidget.setCellWidget(0, 0, edit)
#callEdit = tablesDataWidget.cellWidget(0, 0)
#callEdit.text()
def initUI(self):
@ -126,6 +132,7 @@ class MyTable(QTableWidget):
# изменение ширины столбцов по размеру текста
self.horizontalHeader().setSectionResizeMode(3)
self.horizontalHeader().setStyleSheet("color: blue;")
#print(self.tbl)
n = 0
for item in dm.getTablesStructure(self.tbl):
@ -133,12 +140,44 @@ class MyTable(QTableWidget):
self.setHorizontalHeaderItem(n, QTableWidgetItem(item))
n = n+1
# обработка нажатия мышой на таблице
self.doubleClicked.connect(self.on_click)
# self.doubleClicked.connect(self.contextMenuEvent(self.cursor()))
# добавлем кнопку в ячейку
#self.clicked.connect(self.addButtonToCell())
def addButtonToCell(self):
modelIndex = self.currentIndex()
col = modelIndex.column()
row = modelIndex.row()
button = QPushButton('...', self)
self.setCellWidget(row, col + 1, button)
# показ контекстного меню
def contextMenuEvent(self, event):
Rmenu = QMenu(self)
delRecord = Rmenu.addAction("Удалить запись")
relations = Rmenu.addAction("Показать связанные документы")
action = Rmenu.exec_(self.mapToGlobal(event.pos()))
if action == delRecord:
row = self.rowAt(event.pos().y())
col = self.columnAt(event.pos().x())
print("row:%d, col:%d" % (row, col))
item = self.item(self.currentIndex().row(), self.currentIndex().column())
print(item.text())
def on_click(self):
print(self.cursor().pos().x())
#self.contextMenuEvent(self.cursor())
for currentQTableWidgetItem in self.selectedItems():
print(currentQTableWidgetItem.row(), currentQTableWidgetItem.column(), currentQTableWidgetItem.text())
def setmydata(self):
n = 0
for key in self.data:
m = 0
for item in key:
newitem = QTableWidgetItem(item)
# преобразуем все типы в строку
newitem = QTableWidgetItem(str(item))
self.setItem(m, n, newitem)
n += 1
m += 1
@ -197,10 +236,14 @@ class WorkArea(QWidget):
rows = len(data)
# КОЛИЧЕСТВО КОЛОНОК
cols = len(data[0])
table = MyTable(tbl_name, data, rows, cols)
table.setFrameShape(QFrame.StyledPanel)
splitter1.addWidget(table)
tablesDataWidget = MyTable(tbl_name, data, rows, cols)
tablesDataWidget.setFrameShape(QFrame.StyledPanel)
splitter1.addWidget(tablesDataWidget)
else:
# если данных в БД нет выводим пустую табличку
tablesDataWidget = QTableView()
tablesDataWidget.setFrameShape(QFrame.StyledPanel)
splitter1.addWidget(tablesDataWidget)
# обработка нажатия мышой на списке
#listTablesWidget.itemClicked.connect(lambda: dm.selectData(listTablesWidget.currentItem))
listTablesWidget.itemClicked.connect(lambda: addData(listTablesWidget.model().data(listTablesWidget.currentIndex())))

View File

@ -167,6 +167,36 @@
"relation": ["users.id", "last_name, name, middle_name"]
}
]
},
{
"tableName": "test2",
"tableDescription": "Шляпа2",
"fieldList": [
{
"fName": "id",
"fDescription": "Номер п.п.",
"fType": "int(11)",
"index": "PRIMARY KEY",
"autoIncrement": "yes",
"relation": []
},
{
"fName": "ins_date",
"fDescription": "Дата добавления",
"fType": "DATETIME",
"index": "no",
"autoIncrement": "no",
"relation": []
},
{
"fName": "user",
"fDescription": "Юзер шляпы",
"fType": "int(11)",
"index": "no",
"autoIncrement": "no",
"relation": ["users.id", "last_name, name, middle_name"]
}
]
}
]
}