프로젝트

일반

사용자정보

개정판 8fd45efa

ID8fd45efa8865efcdd314c1406077797fc2c0dd88
상위 6929ebfb
하위 07a59831

gaqhf 이(가) 6년 이상 전에 추가함

dev issue #643: dev find text, replace

차이점 보기:

DTI_PID/DTI_PID/MainWindow.py
183 183
        @date       2018.08.27
184 184
    '''
185 185
    def findTextClicked(self):
186
        print('click')
187
        pass
186
        if not self.graphicsView.hasImage():
187
            self.showImageSelectionMessageBox()
188
            return
189

  
190
        from TextItemEditDialog import QTextItemEditDialog
191

  
192
        self.dlgTextItemEdit = QTextItemEditDialog(self)
193
        self.dlgTextItemEdit.show()
194
        self.dlgTextItemEdit.exec_()
188 195

  
189 196
    '''
190 197
        @brief      show unknownitem's count
......
192 199
        @date       2018.08.27
193 200
    '''
194 201
    def replaceTextClicked(self):
195
        print('click2')
196
        pass
202
        if not self.graphicsView.hasImage():
203
            self.showImageSelectionMessageBox()
204
            return
205

  
206
        from TextItemEditDialog import QTextItemEditDialog
207

  
208
        self.dlgTextItemEdit = QTextItemEditDialog(self)
209
        self.dlgTextItemEdit.show()
210
        self.dlgTextItemEdit.exec_()
197 211

  
198 212
    '''
199 213
        @brief      show unknownitem's count
DTI_PID/DTI_PID/TextItemEditDialog.py
7 7
import sqlite3
8 8
from AppDocData import AppDocData
9 9
from AppDocData import Config
10
import SelectAttribute_UI
10
import TextItemEdit_UI
11
from EngineeringTextItem import QEngineeringTextItem
11 12

  
12
class QSelectAttributeDialog(QDialog):
13
    def __init__(self, parent, symbolType):
13
class QTextItemEditDialog(QDialog):
14
    def __init__(self, parent):
14 15
        QDialog.__init__(self, parent)
15 16

  
16
        self.attrList = []
17
        self.removeUID = {}
18
        self.currentCode = {}
19

  
20
        self.ui = SelectAttribute_UI.Ui_SelectAttributeDialog()
17
        self.mainWindow = parent
18
        self.ui = TextItemEdit_UI.Ui_TextItemEditDialog()
21 19
        self.ui.setupUi(self)
22 20

  
23
        self.dialogResult = False
24
        self.selectedAttribute = ''
21
        self.ui.pushButtonFindText.clicked.connect(self.findTextClicked)
22
        self.ui.pushButtonReplaceText.clicked.connect(self.replaceTextClicked)
23

  
24
        self.prevText = ''
25
        self.textItems = []
26
        self.listIndex = 0
27

  
28
        self.ui.lineEditFindText.setFocus()
25 29

  
26
        self.settingComboBoxAttribute(symbolType)
30
    '''
31
        @brief      find text click event
32
        @author     kyouho
33
        @date       2018.08.27
34
    '''
35
    def findTextClicked(self):
36
        self.findText()
27 37

  
38
    '''
39
        @brief      find text
40
        @author     kyouho
41
        @date       2018.08.27
42
    '''
43
    def findText(self):
44
        text = self.ui.lineEditFindText.text()
45
        if text == '':
46
            return
28 47
        
48
        self.listIndex += 1
49

  
50
        if self.prevText != text:
51
            self.prevText = text
52
            self.textItems = [item for item in self.mainWindow.graphicsView.scene.items() if type(item) is QEngineeringTextItem and item.text().count(text)]
53
            self.listIndex = 0
54
        elif self.textItems and self.listIndex == len(self.textItems):
55
            self.listIndex = 0
56

  
57
        if self.textItems:
58
            item = self.textItems[self.listIndex]
59
            self.selectTextItem(item)
60

  
29 61

  
30 62
    '''
31
        @brief  setting comboboxAttribute
32
        @author kyouho
33
        @date   2018.07.18
63
        @brief      replace text
64
        @author     kyouho
65
        @date       2018.08.27
66
    '''
67
    def replaceTextClicked(self):
68
        text = self.ui.lineEditFindText.text()
69
        if self.prevText != text:
70
            self.findText()
71
            self.listIndex = 0
72

  
73
        if self.textItems:
74
            item = self.textItems[self.listIndex]
75
            replace = self.ui.lineEditReplaceText.text()
76
            ## 기존 item이 replace가 전부 완료시 다음 item 선택
77
            if not item.text().count(text):
78
                self.textItems.remove(item)
79
                self.listIndex -= 1
80
                self.findText()
81

  
82
            if self.textItems:
83
                item = self.textItems[self.listIndex]
84
                if text == replace:
85
                    return
86
                item.setPlainText(item.text().replace(text, replace))
87
                print(item.text())
88

  
89
    '''
90
        @brief      key press event
91
        @author     kyouho 
92
        @date       2018.08.27
93
    '''
94
    def selectTextItem(self, item):
95
        rect = item.sceneBoundingRect()
96
        self.mainWindow.graphicsView.centerOn(rect.center())
97
        self.mainWindow.graphicsView.zoomImage(True, QMouseEvent(QEvent.MouseButtonPress, self.mainWindow.graphicsView.mapFromScene(QPointF(rect.left(), rect.top())), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier), 3)
98
        item.setSelected(True)
99

  
100
    def replaceTextItem(self, item):
101
        pass
102

  
103

  
104
    '''
105
        @brief      key press event
106
        @author     kyouho 
107
        @date       2018.08.27
34 108
    '''
35
    def settingComboBoxAttribute(self, symbolType):
36
        docData = AppDocData.instance()
37
        symbolAttrs = docData.getSymbolAttribute(symbolType)
38
        for attr in symbolAttrs:
39
            self.attrList.append((attr[0], attr[1], attr[2]))
40
            self.ui.comboBoxAttribute.addItem(attr[2])
109
    def keyPressEvent(self, event):
110
        if event.key() == Qt.Key_Return:
111
            if self.ui.lineEditFindText.hasFocus():
112
                self.findText()
113
            elif self.ui.lineEditReplaceText.hasFocus():
114
                self.replaceTextClicked()
41 115

  
42 116
    '''
43 117
        @brief  accept
44 118
        @author kyouho
45
        @date   2018.07.18
119
        @date   2018.08.27
46 120
    '''
47 121
    def accept(self):
48
        self.dialogResult = True
49
        index = self.ui.comboBoxAttribute.currentIndex()
50
        self.selectedAttribute = self.attrList[index][0]
51 122
        QDialog.accept(self)
DTI_PID/DTI_PID/TextItemEdit_UI.py
11 11
class Ui_TextItemEditDialog(object):
12 12
    def setupUi(self, TextItemEditDialog):
13 13
        TextItemEditDialog.setObjectName("TextItemEditDialog")
14
        TextItemEditDialog.resize(277, 67)
14
        TextItemEditDialog.resize(349, 99)
15 15
        self.gridLayout = QtWidgets.QGridLayout(TextItemEditDialog)
16 16
        self.gridLayout.setObjectName("gridLayout")
17
        self.label = QtWidgets.QLabel(TextItemEditDialog)
18
        self.label.setObjectName("label")
19
        self.gridLayout.addWidget(self.label, 1, 0, 1, 1)
20
        self.pushButtonReplaceText = QtWidgets.QPushButton(TextItemEditDialog)
21
        self.pushButtonReplaceText.setObjectName("pushButtonReplaceText")
22
        self.gridLayout.addWidget(self.pushButtonReplaceText, 1, 3, 1, 1)
23
        self.lineEditReplaceText = QtWidgets.QLineEdit(TextItemEditDialog)
24
        self.lineEditReplaceText.setObjectName("lineEditReplaceText")
25
        self.gridLayout.addWidget(self.lineEditReplaceText, 1, 2, 1, 1)
17 26
        self.buttonBox = QtWidgets.QDialogButtonBox(TextItemEditDialog)
18 27
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
19 28
        self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
20 29
        self.buttonBox.setObjectName("buttonBox")
21
        self.gridLayout.addWidget(self.buttonBox, 1, 1, 1, 1)
22
        self.comboBoxAttribute = QtWidgets.QComboBox(TextItemEditDialog)
23
        self.comboBoxAttribute.setObjectName("comboBoxAttribute")
24
        self.gridLayout.addWidget(self.comboBoxAttribute, 0, 1, 1, 1)
25
        self.label = QtWidgets.QLabel(TextItemEditDialog)
26
        self.label.setObjectName("label")
27
        self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
30
        self.gridLayout.addWidget(self.buttonBox, 3, 2, 1, 2)
31
        self.label_2 = QtWidgets.QLabel(TextItemEditDialog)
32
        self.label_2.setObjectName("label_2")
33
        self.gridLayout.addWidget(self.label_2, 0, 0, 1, 1)
34
        self.pushButtonFindText = QtWidgets.QPushButton(TextItemEditDialog)
35
        self.pushButtonFindText.setObjectName("pushButtonFindText")
36
        self.gridLayout.addWidget(self.pushButtonFindText, 0, 3, 1, 1)
37
        self.lineEditFindText = QtWidgets.QLineEdit(TextItemEditDialog)
38
        self.lineEditFindText.setObjectName("lineEditFindText")
39
        self.gridLayout.addWidget(self.lineEditFindText, 0, 2, 1, 1)
28 40

  
29 41
        self.retranslateUi(TextItemEditDialog)
30 42
        self.buttonBox.accepted.connect(TextItemEditDialog.accept)
......
33 45

  
34 46
    def retranslateUi(self, TextItemEditDialog):
35 47
        _translate = QtCore.QCoreApplication.translate
36
        TextItemEditDialog.setWindowTitle(_translate("TextItemEditDialog", "Dialog"))
37
        self.label.setText(_translate("TextItemEditDialog", "Attribute"))
48
        TextItemEditDialog.setWindowTitle(_translate("TextItemEditDialog", "Find / Replace"))
49
        self.label.setText(_translate("TextItemEditDialog", "Replace"))
50
        self.pushButtonReplaceText.setText(_translate("TextItemEditDialog", "바꾸기"))
51
        self.label_2.setText(_translate("TextItemEditDialog", "Text"))
52
        self.pushButtonFindText.setText(_translate("TextItemEditDialog", "→"))
38 53

  
39 54

  
40 55
if __name__ == "__main__":
DTI_PID/DTI_PID/UI/TextItemEdit.ui
6 6
   <rect>
7 7
    <x>0</x>
8 8
    <y>0</y>
9
    <width>277</width>
10
    <height>67</height>
9
    <width>349</width>
10
    <height>99</height>
11 11
   </rect>
12 12
  </property>
13 13
  <property name="windowTitle">
14
   <string>Dialog</string>
14
   <string>Find / Replace</string>
15 15
  </property>
16 16
  <layout class="QGridLayout" name="gridLayout">
17
   <item row="1" column="1">
17
   <item row="1" column="0">
18
    <widget class="QLabel" name="label">
19
     <property name="text">
20
      <string>Replace</string>
21
     </property>
22
    </widget>
23
   </item>
24
   <item row="1" column="3">
25
    <widget class="QPushButton" name="pushButtonReplaceText">
26
     <property name="text">
27
      <string>바꾸기</string>
28
     </property>
29
    </widget>
30
   </item>
31
   <item row="1" column="2">
32
    <widget class="QLineEdit" name="lineEditReplaceText"/>
33
   </item>
34
   <item row="3" column="2" colspan="2">
18 35
    <widget class="QDialogButtonBox" name="buttonBox">
19 36
     <property name="orientation">
20 37
      <enum>Qt::Horizontal</enum>
......
24 41
     </property>
25 42
    </widget>
26 43
   </item>
27
   <item row="0" column="1">
28
    <widget class="QComboBox" name="comboBoxAttribute"/>
29
   </item>
30 44
   <item row="0" column="0">
31
    <widget class="QLabel" name="label">
45
    <widget class="QLabel" name="label_2">
46
     <property name="text">
47
      <string>Text</string>
48
     </property>
49
    </widget>
50
   </item>
51
   <item row="0" column="3">
52
    <widget class="QPushButton" name="pushButtonFindText">
32 53
     <property name="text">
33
      <string>Attribute</string>
54
      <string></string>
34 55
     </property>
35 56
    </widget>
36 57
   </item>
58
   <item row="0" column="2">
59
    <widget class="QLineEdit" name="lineEditFindText"/>
60
   </item>
37 61
  </layout>
38 62
 </widget>
39 63
 <resources/>

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)