프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / DTI_PID / DTI_PID / CustomCodeTablesDialog.py @ 0a77ad35

이력 | 보기 | 이력해설 | 다운로드 (6.41 KB)

1
# coding: utf-8
2
"""
3
    This is area configuration module
4
"""
5
import os
6
import sys
7
from PyQt5.QtCore import *
8
from PyQt5.QtGui import *
9
from PyQt5.QtWidgets import *
10
from AppDocData import AppDocData
11

    
12
import CustomCodeTables_UI
13

    
14
class CustomCodeTablesDialog(QDialog):
15
    def __init__(self, parent, replace=False):
16
        QDialog.__init__(self, parent)
17

    
18
        self.ui = CustomCodeTables_UI.Ui_CustomCodeTables()
19
        self.ui.setupUi(self)
20

    
21
        self.ui.tableWidgetCustomCodeTable.setSortingEnabled(True)
22

    
23
        self.ui.tableWidgetCustomCodeTable.setColumnCount(4)
24
        self.ui.tableWidgetCustomCodeTable.setHorizontalHeaderLabels(['UID', 'Name', 'Description', 'Table'])
25
        self.ui.tableWidgetCustomCodeTable.hideColumn(0)
26
        self.ui.tableWidgetCustomCodeTable.horizontalHeader().setStretchLastSection(True)
27

    
28
        self.isAccepted = False
29
        
30
        self.replace = replace
31

    
32
        self.ui.buttonBox.accepted.connect(self.accept)
33
        self.ui.buttonBox.rejected.connect(self.reject)
34
        self.ui.pushButtonAdd.clicked.connect(self.addTable)
35
        self.ui.pushButtonDelete.clicked.connect(self.delTable)
36
        self.ui.tableWidgetCustomCodeTable.cellDoubleClicked.connect(self.cell_double_clicked)
37

    
38
        if self.replace:
39
            self.setWindowTitle('Replace Code Tables')
40
            self.ui.groupBoxTitleBlock.setTitle('Replace Talbes')
41

    
42
        self.loadData()
43

    
44
    def loadData(self):
45
        """ load custom code tables """
46

    
47
        appDocData = AppDocData.instance()
48

    
49
        if not self.replace:
50
            tables = appDocData.getCustomTables()
51
        else:
52
            tables = appDocData.getReplaceTables()
53
        self.ui.tableWidgetCustomCodeTable.setRowCount(len(tables))
54

    
55
        row = 0
56
        for table in tables:
57
            item = QTableWidgetItem(str(table[0]))              # UID
58
            self.ui.tableWidgetCustomCodeTable.setItem(row, 0, item)
59

    
60
            item = QTableWidgetItem(table[1])             # Name
61
            self.ui.tableWidgetCustomCodeTable.setItem(row, 1, item)
62

    
63
            item = QTableWidgetItem(table[2])      # Description
64
            self.ui.tableWidgetCustomCodeTable.setItem(row, 2, item)
65

    
66
            item = QTableWidgetItem('...')          # Codes
67
            item.tag = table[3].values
68
            item.setTextAlignment(Qt.AlignHCenter)
69
            item.setFlags(Qt.ItemIsEnabled)
70
            self.ui.tableWidgetCustomCodeTable.setItem(row, 3, item)
71

    
72
            row = row + 1
73

    
74
    def cell_double_clicked(self, row, column):
75
        from SymbolAttrCodeTableDialog import SymbolAttrCodeTableDialog
76
        from App import App
77

    
78
        try:
79
            if column == 3:
80
                if not self.replace:
81
                    dialog = SymbolAttrCodeTableDialog(self, self.ui.tableWidgetCustomCodeTable.item(row, 0).text(), tableDatas=self.ui.tableWidgetCustomCodeTable.item(row, 3).tag, Table_Name='CustomCodes')
82
                else:
83
                    dialog = SymbolAttrCodeTableDialog(self, self.ui.tableWidgetCustomCodeTable.item(row, 0).text(), tableDatas=self.ui.tableWidgetCustomCodeTable.item(row, 3).tag, Table_Name='InstCodes')
84
                (isAccept, code_data) = dialog.showDialog()
85
    
86
                if isAccept:
87
                    self.ui.tableWidgetCustomCodeTable.item(row, 3).tag = code_data
88

    
89
                graphicsView = App.mainWnd().graphicsView
90
                if dialog.code_area:
91
                    if dialog.code_area.scene():
92
                        graphicsView.scene().removeItem(dialog.code_area)
93
                if dialog.desc_area:
94
                    if dialog.desc_area.scene():
95
                        graphicsView.scene().removeItem(dialog.desc_area)
96
                graphicsView.useDefaultCommand()
97

    
98
        except Exception as ex:
99
            from App import App
100
            from AppDocData import MessageType
101

    
102
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
103
            App.mainWnd().addMessage.emit(MessageType.Error, message)
104

    
105
    def addTable(self):
106
        import uuid
107

    
108
        rows = self.ui.tableWidgetCustomCodeTable.rowCount()
109
        self.ui.tableWidgetCustomCodeTable.setRowCount(rows + 1)
110

    
111
        item = QTableWidgetItem('...')
112
        item.tag = []
113
        item.setTextAlignment(Qt.AlignHCenter)
114
        item.setFlags(Qt.ItemIsEnabled)
115
        self.ui.tableWidgetCustomCodeTable.setItem(rows, 3, item)
116

    
117
        item = QTableWidgetItem(str(uuid.uuid4()))
118
        self.ui.tableWidgetCustomCodeTable.setItem(rows, 0, item)
119

    
120
    def delTable(self):
121
        model = self.ui.tableWidgetCustomCodeTable.model()
122
        row = self.ui.tableWidgetCustomCodeTable.currentRow()
123
        
124
        if row != -1:
125
            model.removeRow(row)
126

    
127
    '''
128
        @brief  accept dialog
129
    '''
130
    def accept(self):
131
        import uuid
132

    
133
        try:
134
            self.isAccepted = False
135

    
136
            appDocData = AppDocData.instance()
137

    
138
            tables = []
139
            table = self.ui.tableWidgetCustomCodeTable
140
        
141
            for index in range(table.rowCount()):
142
                attr = []
143
                attr.append(table.item(index, 0).text() if table.item(index, 0) is not None else '')
144
                attr.append(table.item(index, 1).text() if table.item(index, 1) is not None else '')
145
                attr.append(table.item(index, 2).text() if table.item(index, 2) is not None else '')
146
                attr.append(table.item(index, 3).tag if table.item(index, 3) is not None else [])
147
                tables.append(attr)
148

    
149
            if not self.replace:
150
                appDocData.saveCustomCodes(tables)
151
            else:
152
                appDocData.saveReplaceCodes(tables)
153

    
154
            self.isAccepted = True
155
            QDialog.accept(self)
156

    
157
        except Exception as ex:
158
            from App import App
159
            from AppDocData import MessageType
160

    
161
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
162
            App.mainWnd().addMessage.emit(MessageType.Error, message)
163
        
164
    def reject(self):
165
        try:
166
            self.isAccepted = False
167
            QDialog.reject(self)
168

    
169
        except Exception as ex:
170
            from App import App
171
            from AppDocData import MessageType
172

    
173
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
174
            App.mainWnd().addMessage.emit(MessageType.Error, message)
클립보드 이미지 추가 (최대 크기: 500 MB)