hytos / HYTOS / HYTOS / FluidCodeDialog.py @ 29485992
이력 | 보기 | 이력해설 | 다운로드 (7.24 KB)
1 |
# coding: utf-8
|
---|---|
2 |
"""
|
3 |
This is fluid code dialog module
|
4 |
"""
|
5 |
import sys |
6 |
import sqlite3 |
7 |
from PyQt5.QtCore import * |
8 |
from PyQt5.QtGui import * |
9 |
from PyQt5.QtWidgets import * |
10 |
|
11 |
from AppDocData import AppDocData |
12 |
import FluidCode_UI |
13 |
|
14 |
class QFluidCodeDialog(QDialog): |
15 |
'''
|
16 |
@brief constructor
|
17 |
@author humkyung
|
18 |
@date 2018.07.03
|
19 |
@history 2018.07.03 kyouho Add getFluidCodeData logic
|
20 |
'''
|
21 |
def __init__(self, parent): |
22 |
QDialog.__init__(self, parent)
|
23 |
|
24 |
self.ui = FluidCode_UI.Ui_DialogFluidCode()
|
25 |
self.ui.setupUi(self) |
26 |
|
27 |
self.removeFluidCode = []
|
28 |
self.currentCode = {}
|
29 |
|
30 |
docData = AppDocData.instance() |
31 |
fluidCodes = docData.getFluidCodeData() |
32 |
|
33 |
table = self.ui.tableWidgetFluidCode
|
34 |
|
35 |
table.setColumnCount(3)
|
36 |
table.setHorizontalHeaderLabels(['uid', 'Code', 'Desc.']) |
37 |
|
38 |
table.setRowCount(len(fluidCodes))
|
39 |
table.horizontalHeaderItem(0).setSizeHint(QSize(30, 30)) |
40 |
|
41 |
row = 0
|
42 |
for fluidCode in fluidCodes: |
43 |
table.setItem(row, 0, QTableWidgetItem(fluidCode.uid))
|
44 |
table.setItem(row, 1, QTableWidgetItem(fluidCode.code))
|
45 |
table.setItem(row, 2, QTableWidgetItem(fluidCode.description))
|
46 |
row += 1
|
47 |
|
48 |
table.horizontalHeaderItem(1).setSizeHint(QSize(30, 30)) |
49 |
if row != 0: |
50 |
table.resizeColumnToContents(2)
|
51 |
table.hideColumn(0)
|
52 |
table.cellChanged.connect(self.cellValueChanged)
|
53 |
self.checkRowAndAddRow()
|
54 |
self.setCurrentCode()
|
55 |
|
56 |
'''
|
57 |
@brief save fluid codes to sqlite
|
58 |
@author humkyungS
|
59 |
@date 2018.07.03
|
60 |
@history 2018.07.03 kyouho
|
61 |
'''
|
62 |
def accept(self): |
63 |
table = self.ui.tableWidgetFluidCode
|
64 |
fluidCodes = [] |
65 |
|
66 |
try:
|
67 |
rowCount = table.rowCount() |
68 |
for row in range(rowCount): |
69 |
data = self.getFluidCodeDataInRow(row)
|
70 |
if data.code:
|
71 |
fluidCodes.append(data) |
72 |
|
73 |
docData = AppDocData.instance() |
74 |
docData.setFluidCodeData(fluidCodes, self.removeFluidCode)
|
75 |
|
76 |
except Exception as ex: |
77 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
78 |
|
79 |
QDialog.accept(self)
|
80 |
|
81 |
'''
|
82 |
@brief key press event
|
83 |
@author kyouho
|
84 |
@date 2018.07.03
|
85 |
'''
|
86 |
def keyPressEvent(self, e): |
87 |
try:
|
88 |
if e.key() == Qt.Key_Delete:
|
89 |
table = self.ui.tableWidgetFluidCode
|
90 |
|
91 |
selectedIndexes = table.selectedIndexes() |
92 |
selectedRows = [item.row() for item in selectedIndexes] |
93 |
model = table.model() |
94 |
|
95 |
rowsIndex = [] |
96 |
for row in selectedRows: |
97 |
rowsIndex.append(row) |
98 |
|
99 |
#중복 제거
|
100 |
rowsIndex = list(set(rowsIndex)) |
101 |
rowsIndex.reverse() |
102 |
|
103 |
for row in rowsIndex: |
104 |
data = self.getFluidCodeDataInRow(row)
|
105 |
self.removeFluidCode.append(data)
|
106 |
model.removeRow(row) |
107 |
|
108 |
self.checkRowAndAddRow()
|
109 |
|
110 |
except Exception as ex: |
111 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
112 |
|
113 |
|
114 |
'''
|
115 |
@brief get FluidCodeData in QtTable
|
116 |
@author kyouho
|
117 |
@date 2018.07.03
|
118 |
'''
|
119 |
def getFluidCodeDataInRow(self, rowIndex): |
120 |
try:
|
121 |
from FluidCodeData import FluidCodeData |
122 |
table = self.ui.tableWidgetFluidCode
|
123 |
|
124 |
uid = table.item(rowIndex, 0)
|
125 |
codeItem = table.item(rowIndex, 1)
|
126 |
descriptionItem = table.item(rowIndex, 2)
|
127 |
|
128 |
data = FluidCodeData(uid.text() ,codeItem.text(), descriptionItem.text()) |
129 |
|
130 |
except Exception as ex: |
131 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
132 |
|
133 |
return data
|
134 |
|
135 |
'''
|
136 |
@brief cellValueChange event
|
137 |
@author kyouho
|
138 |
@date 2018.07.03
|
139 |
'''
|
140 |
def cellValueChanged(self, row, column): |
141 |
try:
|
142 |
table = self.ui.tableWidgetFluidCode
|
143 |
item = table.item(row, 1)
|
144 |
code = item.text() |
145 |
if column == 1: |
146 |
result = self.isExistCode(code)
|
147 |
if result:
|
148 |
self.checkRowAndAddRow()
|
149 |
self.setCurrentCode()
|
150 |
else:
|
151 |
item.setText(self.currentCode[row])
|
152 |
else:
|
153 |
table.resizeColumnToContents(2)
|
154 |
|
155 |
except Exception as ex: |
156 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
157 |
|
158 |
|
159 |
'''
|
160 |
@brief Check Duplicate Code
|
161 |
@author kyouho
|
162 |
@date 2018.07.03
|
163 |
'''
|
164 |
def isExistCode(self, editCode): |
165 |
try:
|
166 |
if not editCode: |
167 |
return False |
168 |
|
169 |
table = self.ui.tableWidgetFluidCode
|
170 |
rowCount = table.rowCount() |
171 |
codes = [] |
172 |
for row in range(rowCount): |
173 |
code = table.item(row, 1).text()
|
174 |
codes.append(code) |
175 |
|
176 |
count = codes.count(editCode) |
177 |
|
178 |
if count >=2: |
179 |
return False |
180 |
else:
|
181 |
return True |
182 |
|
183 |
except Exception as ex: |
184 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
185 |
|
186 |
'''
|
187 |
@brief save current Code (self.currentCode)
|
188 |
@author kyouho
|
189 |
@date 2018.07.03
|
190 |
'''
|
191 |
def setCurrentCode(self): |
192 |
try:
|
193 |
self.currentCode.clear()
|
194 |
|
195 |
table = self.ui.tableWidgetFluidCode
|
196 |
rowCount = table.rowCount() |
197 |
|
198 |
for row in range(rowCount): |
199 |
code = table.item(row, 1).text()
|
200 |
self.currentCode[row] = code
|
201 |
|
202 |
except Exception as ex: |
203 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
204 |
|
205 |
'''
|
206 |
@brief Add new row
|
207 |
@author kyouho
|
208 |
@date 2018.07.04
|
209 |
'''
|
210 |
def checkRowAndAddRow(self): |
211 |
try:
|
212 |
table = self.ui.tableWidgetFluidCode
|
213 |
rowCount = table.rowCount() |
214 |
result = True
|
215 |
for row in range(rowCount): |
216 |
code = table.item(row, 1).text()
|
217 |
if not code: |
218 |
result = False
|
219 |
|
220 |
if result:
|
221 |
table.cellChanged.disconnect(self.cellValueChanged)
|
222 |
table.setRowCount(rowCount + 1)
|
223 |
table.setItem(rowCount, 0, QTableWidgetItem('')) |
224 |
table.setItem(rowCount, 1, QTableWidgetItem('')) |
225 |
table.setItem(rowCount, 2, QTableWidgetItem('')) |
226 |
table.cellChanged.connect(self.cellValueChanged)
|
227 |
|
228 |
except Exception as ex: |
229 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
230 |
|
231 |
|
232 |
|