2017-03-13 15:18:52 +03:00
|
|
|
|
#!/usr/bin/python3
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
from PyQt5.QtWidgets import (QWidget, QHBoxLayout, QFrame,
|
|
|
|
|
QSplitter, QStyleFactory, QApplication)
|
|
|
|
|
from PyQt5.QtCore import Qt
|
2017-03-14 14:09:31 +03:00
|
|
|
|
from PyQt5.QtWidgets import QMainWindow, QTextEdit, QAction, QApplication, QListView, QListWidget, QTableWidget , QTableView, QTableWidgetItem
|
2017-03-13 15:18:52 +03:00
|
|
|
|
from PyQt5.QtGui import QIcon
|
2017-03-14 14:09:31 +03:00
|
|
|
|
from PyQt5.QtSql import *
|
2017-03-15 15:58:26 +03:00
|
|
|
|
#import pymysql
|
2017-03-13 15:18:52 +03:00
|
|
|
|
import dm
|
|
|
|
|
|
2017-03-15 15:58:26 +03:00
|
|
|
|
# conn = pymysql.connect(
|
|
|
|
|
# db='ats',
|
|
|
|
|
# user='dba',
|
|
|
|
|
# passwd='AlsprofilinE',
|
|
|
|
|
# host='kis',
|
|
|
|
|
# charset='utf8')
|
|
|
|
|
# c = conn.cursor()
|
2017-03-14 14:09:31 +03:00
|
|
|
|
|
2017-03-13 15:18:52 +03:00
|
|
|
|
class MainWin(QMainWindow):
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
|
|
self.initUI()
|
2017-03-14 14:09:31 +03:00
|
|
|
|
#заглушка
|
|
|
|
|
def qqqq(self):
|
|
|
|
|
print("ddddddddd")
|
2017-03-13 15:18:52 +03:00
|
|
|
|
|
|
|
|
|
def initUI(self):
|
|
|
|
|
|
|
|
|
|
textEdit = QTextEdit()
|
|
|
|
|
splitter = WorkArea()
|
|
|
|
|
self.setCentralWidget(splitter)
|
|
|
|
|
#self.setCentralWidget(textEdit)
|
|
|
|
|
|
2017-03-14 14:09:31 +03:00
|
|
|
|
newAction = QAction(QIcon('img/new.gif'), 'Добавить', self)
|
|
|
|
|
newAction.setShortcut('Ins')
|
|
|
|
|
newAction.setStatusTip('Добавить')
|
|
|
|
|
newAction.triggered.connect(self.qqqq)
|
|
|
|
|
|
|
|
|
|
deleteAction = QAction(QIcon('img/delete.gif'), 'Удалить', self)
|
|
|
|
|
deleteAction.setShortcut('Del')
|
|
|
|
|
deleteAction.setStatusTip('Удалить')
|
|
|
|
|
deleteAction.triggered.connect(self.qqqq)
|
|
|
|
|
|
|
|
|
|
exitAction = QAction(QIcon('img/exit.gif'), 'Выход', self)
|
2017-03-13 15:18:52 +03:00
|
|
|
|
exitAction.setShortcut('Ctrl+Q')
|
|
|
|
|
exitAction.setStatusTip('Выход')
|
|
|
|
|
exitAction.triggered.connect(self.close)
|
|
|
|
|
|
2017-03-14 14:09:31 +03:00
|
|
|
|
cutAction = QAction(QIcon('img/cut.gif'), 'Вырезать', self)
|
|
|
|
|
cutAction.setShortcut('Ctrl+X')
|
|
|
|
|
cutAction.setStatusTip('Вырезать')
|
|
|
|
|
#cutAction.triggered.connect(self.close)
|
|
|
|
|
|
|
|
|
|
copyAction = QAction(QIcon('img/copy.gif'), 'Копировать', self)
|
|
|
|
|
copyAction.setShortcut('Ctrl+С')
|
|
|
|
|
copyAction.setStatusTip('Копировать')
|
|
|
|
|
#copyAction.triggered.connect(self.close)
|
|
|
|
|
|
|
|
|
|
pasteAction = QAction(QIcon('img/paste.gif'), 'Вставить', self)
|
|
|
|
|
pasteAction.setShortcut('Ctrl+V')
|
|
|
|
|
pasteAction.setStatusTip('Вставить')
|
|
|
|
|
#pasteAction.triggered.connect(self.close)
|
|
|
|
|
|
|
|
|
|
findAction = QAction(QIcon('img/find.gif'), 'Копировать', self)
|
|
|
|
|
findAction.setShortcut('Ctrl+F')
|
|
|
|
|
findAction.setStatusTip('Искать')
|
|
|
|
|
# findAction.triggered.connect(self.close)
|
|
|
|
|
|
|
|
|
|
printAction = QAction(QIcon('img/print.gif'), 'Печатать', self)
|
|
|
|
|
printAction.setShortcut('Ctrl+P')
|
|
|
|
|
printAction.setStatusTip('Печатать')
|
|
|
|
|
# printAction.triggered.connect(self.close)
|
|
|
|
|
|
|
|
|
|
|
2017-03-13 15:18:52 +03:00
|
|
|
|
self.statusBar()
|
|
|
|
|
|
|
|
|
|
menubar = self.menuBar()
|
|
|
|
|
fileMenu = menubar.addMenu('&Файл')
|
2017-03-14 14:09:31 +03:00
|
|
|
|
fileMenu.addAction(newAction)
|
|
|
|
|
fileMenu.addAction(deleteAction)
|
|
|
|
|
fileMenu.addAction(printAction)
|
2017-03-13 15:18:52 +03:00
|
|
|
|
fileMenu.addAction(exitAction)
|
|
|
|
|
|
|
|
|
|
editMenu = menubar.addMenu('&Редактирование')
|
2017-03-14 14:09:31 +03:00
|
|
|
|
editMenu.addAction(copyAction)
|
|
|
|
|
editMenu.addAction(cutAction)
|
|
|
|
|
editMenu.addAction(pasteAction)
|
|
|
|
|
editMenu.addAction(printAction)
|
|
|
|
|
|
2017-03-13 15:18:52 +03:00
|
|
|
|
helpMenu = menubar.addMenu('&Помощь')
|
|
|
|
|
|
2017-03-14 14:09:31 +03:00
|
|
|
|
#toolbar = self.addToolBar('Редактирование')
|
|
|
|
|
|
|
|
|
|
toolbar = self.addToolBar('Панель инструментов')
|
|
|
|
|
toolbar.addAction(newAction)
|
|
|
|
|
toolbar.addAction(deleteAction)
|
|
|
|
|
toolbar.addAction(copyAction)
|
|
|
|
|
toolbar.addAction(cutAction)
|
|
|
|
|
toolbar.addAction(pasteAction)
|
|
|
|
|
toolbar.addAction(findAction)
|
|
|
|
|
toolbar.addAction(printAction)
|
|
|
|
|
#toolbar.addAction(exitAction)
|
2017-03-13 15:18:52 +03:00
|
|
|
|
|
|
|
|
|
self.setGeometry(300, 300, 850, 650)
|
|
|
|
|
self.setWindowTitle('Ацкый быдлокод')
|
|
|
|
|
self.show()
|
|
|
|
|
|
2017-03-14 14:09:31 +03:00
|
|
|
|
class MyTable(QTableWidget):
|
2017-03-14 17:01:30 +03:00
|
|
|
|
def __init__(self, tbl, thestruct, *args):
|
2017-03-14 14:09:31 +03:00
|
|
|
|
QTableWidget.__init__(self, *args)
|
|
|
|
|
self.data = thestruct
|
|
|
|
|
self.setmydata()
|
2017-03-14 17:01:30 +03:00
|
|
|
|
self.tbl = tbl
|
2017-03-14 14:09:31 +03:00
|
|
|
|
|
2017-03-14 17:01:30 +03:00
|
|
|
|
#print(self.tbl)
|
2017-03-14 14:09:31 +03:00
|
|
|
|
n = 0
|
2017-03-14 17:01:30 +03:00
|
|
|
|
for item in dm.getTablesStructure(self.tbl):
|
|
|
|
|
# установка заголовков столбцов таблицы
|
|
|
|
|
self.setHorizontalHeaderItem(n, QTableWidgetItem(item))
|
|
|
|
|
n = n+1
|
2017-03-14 14:09:31 +03:00
|
|
|
|
|
2017-03-14 17:01:30 +03:00
|
|
|
|
def setmydata(self):
|
|
|
|
|
n = 0
|
2017-03-14 14:09:31 +03:00
|
|
|
|
for key in self.data:
|
|
|
|
|
m = 0
|
|
|
|
|
for item in key:
|
|
|
|
|
newitem = QTableWidgetItem(item)
|
|
|
|
|
self.setItem(m, n, newitem)
|
|
|
|
|
n += 1
|
|
|
|
|
m += 1
|
|
|
|
|
|
2017-03-13 15:18:52 +03:00
|
|
|
|
|
|
|
|
|
class WorkArea(QWidget):
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super().__init__()
|
|
|
|
|
self.initUI()
|
|
|
|
|
|
|
|
|
|
def initUI(self):
|
|
|
|
|
hbox = QHBoxLayout(self)
|
2017-03-13 16:50:33 +03:00
|
|
|
|
# список таблиц
|
|
|
|
|
listTablesWidget = QListWidget()
|
|
|
|
|
listTablesWidget.setFrameShape(QFrame.StyledPanel)
|
|
|
|
|
# таблица для вывода данных
|
|
|
|
|
tablesDataWidget = QTableView()
|
|
|
|
|
tablesDataWidget.setFrameShape(QFrame.StyledPanel)
|
2017-03-13 15:18:52 +03:00
|
|
|
|
|
|
|
|
|
splitter1 = QSplitter(Qt.Horizontal)
|
2017-03-13 16:50:33 +03:00
|
|
|
|
splitter1.addWidget(listTablesWidget)
|
|
|
|
|
splitter1.addWidget(tablesDataWidget)
|
2017-03-13 15:18:52 +03:00
|
|
|
|
|
|
|
|
|
splitter2 = QSplitter(Qt.Vertical)
|
|
|
|
|
splitter2.addWidget(splitter1)
|
|
|
|
|
|
|
|
|
|
hbox.addWidget(splitter2)
|
|
|
|
|
|
|
|
|
|
self.setLayout(hbox)
|
|
|
|
|
|
2017-03-13 16:50:33 +03:00
|
|
|
|
# выводим список таблиц в левом поле
|
2017-03-13 15:18:52 +03:00
|
|
|
|
for i in dm.initDBstructure():
|
2017-03-14 17:01:30 +03:00
|
|
|
|
listTablesWidget.addItem(i[0])
|
2017-03-13 16:50:33 +03:00
|
|
|
|
|
|
|
|
|
# заполняем правый список данными из выбранной таблицы
|
2017-03-14 14:09:31 +03:00
|
|
|
|
def addData(tbl_name):
|
|
|
|
|
# удаляем предыдущий виджет таблицы
|
|
|
|
|
item = splitter1.widget(1)
|
|
|
|
|
if item is not None:
|
|
|
|
|
item.deleteLater()
|
2017-03-15 15:58:26 +03:00
|
|
|
|
|
|
|
|
|
data = dm.selectData(tbl_name)
|
2017-03-14 14:09:31 +03:00
|
|
|
|
# проверка на наличие записей в таблице
|
|
|
|
|
if data:
|
|
|
|
|
# количество строк
|
|
|
|
|
rows = len(data)
|
|
|
|
|
# КОЛИЧЕСТВО КОЛОНОК
|
|
|
|
|
cols = len(data[0])
|
2017-03-14 17:01:30 +03:00
|
|
|
|
table = MyTable(tbl_name, data, rows, cols)
|
2017-03-14 14:09:31 +03:00
|
|
|
|
table.setFrameShape(QFrame.StyledPanel)
|
|
|
|
|
splitter1.addWidget(table)
|
2017-03-13 16:50:33 +03:00
|
|
|
|
|
|
|
|
|
# обработка нажатия мышой на списке
|
|
|
|
|
#listTablesWidget.itemClicked.connect(lambda: dm.selectData(listTablesWidget.currentItem))
|
2017-03-14 14:09:31 +03:00
|
|
|
|
listTablesWidget.itemClicked.connect(lambda: addData(listTablesWidget.model().data(listTablesWidget.currentIndex())))
|
2017-03-13 15:18:52 +03:00
|
|
|
|
|
|
|
|
|
def onChanged(self, text):
|
|
|
|
|
self.lbl.setText(text)
|
|
|
|
|
self.lbl.adjustSize()
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
|
ex = MainWin()
|
|
|
|
|
sys.exit(app.exec_())
|
|
|
|
|
|