hytos / DTI_PID / DTI_PID / OPCRelationDialog.py @ 9c4d97e2
이력 | 보기 | 이력해설 | 다운로드 (9.36 KB)
1 |
# coding: utf-8
|
---|---|
2 |
""" This is OPC Relation dialog module """
|
3 |
|
4 |
import os |
5 |
import sys |
6 |
from PyQt5.QtCore import * |
7 |
from PyQt5.QtGui import * |
8 |
from PyQt5.QtWidgets import * |
9 |
from AppDocData import AppDocData, MessageType |
10 |
|
11 |
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '\\UI') |
12 |
import OPCRelation_UI |
13 |
|
14 |
|
15 |
class QOPCRelationDialog(QDialog): |
16 |
""" This OPC Relation dialog class """
|
17 |
|
18 |
def __init__(self, parent): |
19 |
QDialog.__init__(self, parent)
|
20 |
|
21 |
self._opcs = None |
22 |
|
23 |
self.ui = OPCRelation_UI.Ui_OPCRelationDialog()
|
24 |
self.ui.setupUi(self) |
25 |
self.ui.buttonBox.button(QDialogButtonBox.Ok).setIcon(QIcon(':/newPrefix/OK.svg')) |
26 |
self.ui.buttonBox.button(QDialogButtonBox.Cancel).setIcon(QIcon(':/newPrefix/Remove.svg')) |
27 |
self.ui.tableWidgetSource.installEventFilter(self) |
28 |
self.ui.tableWidgetTarget.itemDoubleClicked.connect(self.on_target_item_double_clicked) |
29 |
self.ui.pushButtonAutoFill.clicked.connect(self.on_auto_fill_clicked) |
30 |
self.ui.pushButtonLineNoAttr.clicked.connect(self.on_line_no_target_clicked) |
31 |
self.init_table_widget()
|
32 |
|
33 |
def init_table_widget(self): |
34 |
""" initialize table widget """
|
35 |
from AppDocData import AppDocData |
36 |
|
37 |
self.ui.tableWidgetSource.setColumnCount(6) |
38 |
self.ui.tableWidgetSource.setHorizontalHeaderLabels(
|
39 |
[self.tr('Drawing'), self.tr('Line No'), self.tr('OPC'), self.tr('Drawing'), self.tr('Line No'), |
40 |
self.tr('OPC')]) |
41 |
self.ui.tableWidgetSource.horizontalHeaderItem(0).setSizeHint(QSize(25, 25)) |
42 |
self.ui.tableWidgetSource.verticalHeader().hide()
|
43 |
self.ui.tableWidgetSource.horizontalHeader().setStretchLastSection(True) |
44 |
self.ui.tableWidgetSource.currentItemChanged.connect(self.on_source_opc_changed) |
45 |
|
46 |
app_doc_data = AppDocData.instance() |
47 |
self._opcs = app_doc_data.get_opcs()
|
48 |
self._opc_relations = app_doc_data.get_opc_relations()
|
49 |
self.ui.tableWidgetSource.setRowCount(len(self._opcs)) |
50 |
row = 0
|
51 |
for opc in self._opcs: |
52 |
item = QTableWidgetItem(opc['Drawing'])
|
53 |
item.setFlags(Qt.ItemIsEnabled) |
54 |
self.ui.tableWidgetSource.setItem(row, 0, item) |
55 |
item = QTableWidgetItem(opc['Line No'])
|
56 |
item.setFlags(Qt.ItemIsEnabled) |
57 |
self.ui.tableWidgetSource.setItem(row, 1, item) |
58 |
item = QTableWidgetItem(opc['OPC'])
|
59 |
item.setFlags(Qt.ItemIsEnabled) |
60 |
self.ui.tableWidgetSource.setItem(row, 2, item) |
61 |
|
62 |
matches = [relation for relation in self._opc_relations if relation['From_OPC_UID'] == opc['OPC']] |
63 |
item = QTableWidgetItem(matches[0]['To_Drawing'] if matches else '') |
64 |
item.setFlags(Qt.ItemIsEnabled) |
65 |
self.ui.tableWidgetSource.setItem(row, 3, item) |
66 |
item = QTableWidgetItem(matches[0]['To_LineNo'] if matches else '') |
67 |
item.setFlags(Qt.ItemIsEnabled) |
68 |
self.ui.tableWidgetSource.setItem(row, 4, item) |
69 |
item = QTableWidgetItem(matches[0]['To_OPC_UID'] if matches else '') |
70 |
item.setFlags(Qt.ItemIsEnabled) |
71 |
self.ui.tableWidgetSource.setItem(row, 5, item) |
72 |
row += 1
|
73 |
|
74 |
self.ui.tableWidgetTarget.setColumnCount(3) |
75 |
self.ui.tableWidgetTarget.setHorizontalHeaderLabels([self.tr('Drawing'), self.tr('Line No'), self.tr('OPC')]) |
76 |
self.ui.tableWidgetTarget.horizontalHeaderItem(0).setSizeHint(QSize(25, 25)) |
77 |
self.ui.tableWidgetTarget.verticalHeader().hide()
|
78 |
self.ui.tableWidgetTarget.horizontalHeader().setStretchLastSection(True) |
79 |
|
80 |
def on_source_opc_changed(self, current, previous): |
81 |
""" list up target opc list """
|
82 |
drawing = self.ui.tableWidgetSource.item(current.row(), 0).text() |
83 |
line_no = self.ui.tableWidgetSource.item(current.row(), 1).text() |
84 |
item = self.ui.tableWidgetSource.item(current.row(), 5) |
85 |
target_opc = item.text() if item else None |
86 |
self.ui.tableWidgetTarget.setRowCount(0) |
87 |
if self._opcs: |
88 |
opcs = [opc for opc in self._opcs if |
89 |
opc['Drawing'] != drawing and opc['Line No'] == line_no and opc['OPC'] != target_opc] |
90 |
self.ui.tableWidgetTarget.setRowCount(len(opcs)) |
91 |
row = 0
|
92 |
for opc in opcs: |
93 |
item = QTableWidgetItem(opc['Drawing'])
|
94 |
item.setFlags(Qt.ItemIsEnabled) |
95 |
self.ui.tableWidgetTarget.setItem(row, 0, item) |
96 |
item = QTableWidgetItem(opc['Line No'])
|
97 |
item.setFlags(Qt.ItemIsEnabled) |
98 |
self.ui.tableWidgetTarget.setItem(row, 1, item) |
99 |
item = QTableWidgetItem(opc['OPC'])
|
100 |
item.setFlags(Qt.ItemIsEnabled) |
101 |
self.ui.tableWidgetTarget.setItem(row, 2, item) |
102 |
row += 1
|
103 |
|
104 |
def on_line_no_target_clicked(self): |
105 |
from PSNLineNoAttrTargetDialog import PSNLineNoAttrTargetDialog |
106 |
|
107 |
dialog = PSNLineNoAttrTargetDialog(self)
|
108 |
(isAccept) = dialog.showDialog() |
109 |
|
110 |
def on_auto_fill_clicked(self): |
111 |
""" fill target opc if only one line no exists """
|
112 |
for row in range(self.ui.tableWidgetSource.rowCount()): |
113 |
drawing = self.ui.tableWidgetSource.item(row, 0).text() |
114 |
line_no = self.ui.tableWidgetSource.item(row, 1).text() |
115 |
opcs = [opc for opc in self._opcs if opc['Drawing'] != drawing and opc['Line No'] == line_no] |
116 |
if not opcs: |
117 |
item = self.ui.tableWidgetSource.item(row, 3) |
118 |
item.setText('') if item else self.ui.tableWidgetSource.setItem(row, 3, QTableWidgetItem('')) |
119 |
item = self.ui.tableWidgetSource.item(row, 4) |
120 |
item.setText('') if item else self.ui.tableWidgetSource.setItem(row, 4, QTableWidgetItem('')) |
121 |
item = self.ui.tableWidgetSource.item(row, 5) |
122 |
item.setText('') if item else self.ui.tableWidgetSource.setItem(row, 5, QTableWidgetItem('')) |
123 |
elif len(opcs) == 1: |
124 |
item = QTableWidgetItem(opcs[0]['Drawing']) |
125 |
item.setFlags(Qt.ItemIsEnabled) |
126 |
self.ui.tableWidgetSource.setItem(row, 3, item) |
127 |
item = QTableWidgetItem(opcs[0]['Line No']) |
128 |
item.setFlags(Qt.ItemIsEnabled) |
129 |
self.ui.tableWidgetSource.setItem(row, 4, item) |
130 |
item = QTableWidgetItem(opcs[0]['OPC']) |
131 |
item.setFlags(Qt.ItemIsEnabled) |
132 |
self.ui.tableWidgetSource.setItem(row, 5, item) |
133 |
|
134 |
def on_target_item_double_clicked(self, item): |
135 |
""" assign target opc with double clicked item """
|
136 |
current = self.ui.tableWidgetSource.currentItem()
|
137 |
if current:
|
138 |
self.ui.tableWidgetSource.item(current.row(), 3).setText( |
139 |
self.ui.tableWidgetTarget.item(item.row(), 0).text()) |
140 |
self.ui.tableWidgetSource.item(current.row(), 4).setText( |
141 |
self.ui.tableWidgetTarget.item(item.row(), 1).text()) |
142 |
self.ui.tableWidgetSource.item(current.row(), 5).setText( |
143 |
self.ui.tableWidgetTarget.item(item.row(), 2).text()) |
144 |
|
145 |
def eventFilter(self, source, event): |
146 |
""" display mouse position of graphics view """
|
147 |
if (event.type() == QKeyEvent.KeyPress):
|
148 |
pass
|
149 |
return QDialog.eventFilter(self, source, event) |
150 |
|
151 |
def keyPressEvent(self, e): |
152 |
""" clear target opc information when user press delete key """
|
153 |
try:
|
154 |
if (e.key() == Qt.Key_Delete) and self.ui.tableWidgetSource.hasFocus(): |
155 |
current = self.ui.tableWidgetSource.currentItem()
|
156 |
if current:
|
157 |
self.ui.tableWidgetSource.item(current.row(), 3).setText('') |
158 |
self.ui.tableWidgetSource.item(current.row(), 4).setText('') |
159 |
self.ui.tableWidgetSource.item(current.row(), 5).setText('') |
160 |
|
161 |
except Exception as ex: |
162 |
from App import App |
163 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
164 |
sys.exc_info()[-1].tb_lineno)
|
165 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
166 |
|
167 |
def accept(self): |
168 |
""" save sql information to database """
|
169 |
from AppDocData import AppDocData |
170 |
|
171 |
try:
|
172 |
QApplication.setOverrideCursor(Qt.WaitCursor) |
173 |
|
174 |
app_doc_data = AppDocData.instance() |
175 |
|
176 |
opcs = [] |
177 |
for row in range(self.ui.tableWidgetSource.rowCount()): |
178 |
from_drawing = self.ui.tableWidgetSource.item(row, 0).text() |
179 |
from_line_no = self.ui.tableWidgetSource.item(row, 1).text() |
180 |
from_opc = self.ui.tableWidgetSource.item(row, 2).text() |
181 |
to_drawing = self.ui.tableWidgetSource.item(row, 3).text() |
182 |
to_line_no = self.ui.tableWidgetSource.item(row, 4).text() |
183 |
to_opc = self.ui.tableWidgetSource.item(row, 5).text() |
184 |
opcs.append([from_drawing, from_line_no, from_opc, to_drawing, to_line_no, to_opc]) |
185 |
|
186 |
app_doc_data.save_opc_relations(opcs) |
187 |
|
188 |
QDialog.accept(self)
|
189 |
except Exception as ex: |
190 |
from App import App |
191 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
192 |
sys.exc_info()[-1].tb_lineno)
|
193 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
194 |
finally:
|
195 |
QApplication.restoreOverrideCursor() |