-
Notifications
You must be signed in to change notification settings - Fork 0
/
uiConnection.py
155 lines (132 loc) · 6.29 KB
/
uiConnection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
from ui.gui_main import Ui_MainWindow
from PyQt5.QtWidgets import QMainWindow, QWidget
from PyQt5.QtWidgets import QFileDialog
from PyQt5.QtGui import QStandardItemModel, QStandardItem, QFont, QColor
from PyQt5.QtCore import Qt
import re
import xml.etree.ElementTree as ET
import nodeeditor.node_editor_widget as wdg
from xmlToNode import getNodeEdgeList
from DataBaseConnection import DataBaseConnection
class UIConnection(QMainWindow):
NodeEditorWidget_class = wdg.NodeEditorWidget
def __init__(self, _dbClass: DataBaseConnection):
super().__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.dbClass = _dbClass
self.modelsList = []
self.uppaalDisplayer = None
self.currentFileName = None
self.lwModel = QStandardItemModel(self.ui.lwModelList)
self.ui.btnQuerySave.setEnabled(False)
self.ui.btnSaveDataBase.setEnabled(False)
self.fillLWFromDB()
self.UiComponents()
def UiComponents(self):
self.ui.btnFromLocal.clicked.connect(self.openFromLocal)
self.ui.btnSaveDataBase.clicked.connect(self.save2DataBase)
self.ui.lwModelList.doubleClicked.connect(self.listItemClicked)
self.ui.btnQuerySave.clicked.connect(self.saveQueryStates)
def setDisplayerWidget(self, nodeEdgeList):
self.ui.tabWidgetTemplates.clear()
for i in range(nodeEdgeList.__len__()):
currentTab = QWidget()
self.ui.tabWidgetTemplates.addTab(currentTab, nodeEdgeList[i].name)
self.uppaalDisplayer = self.__class__.NodeEditorWidget_class(currentTab)
self.uppaalDisplayer.setParent(currentTab)
self.uppaalDisplayer.resize(self.ui.tabWidgetTemplates.size())
self.uppaalDisplayer.setModel(nodeEdgeList)
self.uppaalDisplayer.addNodes(i)
self.uppaalDisplayer.setVisible(True)
def setNonDBQueriesToWidget(self, fileName):
f = open(fileName, "r")
xmlFile = f.read()
xmlFile = xmlFile.replace('\n', '')
pattern = "<queries>(.*)</queries>"
chopped = re.search(pattern, xmlFile)
if chopped:
xmlFile = "<queries> " + chopped.group(1) + " </queries>"
tree = ET.ElementTree(ET.fromstring(xmlFile))
root = tree.getroot()
queryListModel = QStandardItemModel(self.ui.listView)
for query in root.findall('query'):
item = QStandardItem(query[0].text + "\n" + query[1].text)
item.setEditable(False)
queryListModel.appendRow(item)
self.ui.listView.setModel(queryListModel)
def setQueriesToWidget(self, queryList):
queryListModel = QStandardItemModel(self.ui.listView)
for i in range(queryList.__len__()):
item = QStandardItem(queryList[i][0] + "\n" + queryList[i][1])
item.setEditable(False)
item.setCheckable(True)
item.setData(queryList[i][3])
if not queryList[i][2]:
item.setCheckState(Qt.CheckState.PartiallyChecked)
elif queryList[i][2] == '1':
item.setCheckState(Qt.CheckState.Checked)
item.setBackground(QColor(179, 217, 255))
elif queryList[i][2] == '0':
item.setCheckState(Qt.CheckState.Unchecked)
item.setBackground(QColor(255, 147, 149))
queryListModel.appendRow(item)
self.ui.listView.setModel(queryListModel)
def fillLWFromDB(self):
self.modelsList = self.dbClass.selectAllModelIDInfo()
self.lwModel.clear()
for model in self.modelsList:
item = QStandardItem(str(model[0]) + ": " + model[1])
item.setEditable(False)
item.setBackground(QColor(161, 172, 213))
self.lwModel.appendRow(item)
self.ui.lwModelList.setModel(self.lwModel)
def openFromLocal(self):
self.ui.btnQuerySave.setEnabled(False)
fname, filter = QFileDialog.getOpenFileName(self, 'Select xml file', '', 'Graph (*.xml);;All files (*)')
if fname:
with open(fname, "r") as f:
info = getNodeEdgeList(f.read())
self.setDisplayerWidget(info)
self.setLabelTexts(fileName=fname)
self.currentFileName = fname
item = QStandardItem("-: " + fname)
item.setBackground(QColor(230, 175, 175))
item.setEditable(False)
self.lwModel.appendRow(item)
self.modelsList.append(["-", fname, "-", "-"])
self.ui.btnSaveDataBase.setEnabled(True)
self.setNonDBQueriesToWidget(fname)
def setLabelTexts(self, modelId="-", fileName="-", createDate="-", description="-"):
self.ui.lblModelID.setText(modelId)
self.ui.lblFileName.setText(fileName)
self.ui.lblCreateDate.setText(createDate)
self.ui.lblDescription.setText(description)
def save2DataBase(self):
self.dbClass.insertXmlFile(self.currentFileName, "emptyDesc")
self.fillLWFromDB()
def listItemClicked(self, index):
index = index.row()
if str(self.modelsList[index][0]) == "-":
self.ui.btnSaveDataBase.setEnabled(True)
fname = self.modelsList[index][1]
with open(fname, "r") as f:
info = getNodeEdgeList(f.read())
self.setDisplayerWidget(info)
self.setLabelTexts(fileName=fname)
self.setNonDBQueriesToWidget(fname)
else:
self.ui.btnQuerySave.setEnabled(True)
self.ui.btnSaveDataBase.setEnabled(False)
self.currentFileName = None
xmlProp = getNodeEdgeList(self.dbClass.selectUppaalModelXml(self.modelsList[index][0]))
self.setLabelTexts(modelId=str(self.modelsList[index][0]), fileName=self.modelsList[index][1],
createDate=self.modelsList[index][2].strftime("%m/%d/%Y"),
description=self.modelsList[index][3])
self.setDisplayerWidget(xmlProp)
self.setQueriesToWidget(self.dbClass.selectUppaalQueries(self.modelsList[index][0]))
def saveQueryStates(self):
model = self.ui.listView.model()
for i in range(model.rowCount()):
item = model.item(i)
self.dbClass.setQueryState(item.data(), item.checkState())