37 """ |
37 """ |
38 super().__init__(parent) |
38 super().__init__(parent) |
39 self.setupUi(self) |
39 self.setupUi(self) |
40 |
40 |
41 self.comboItems = [] |
41 self.comboItems = [] |
|
42 self.singleComboItems = [] # these are in addition to the above |
42 self.comboItems.append(self.trUtf8("Normal character")) |
43 self.comboItems.append(self.trUtf8("Normal character")) |
43 self.comboItems.append(self.trUtf8("Unicode character in hexadecimal notation")) |
44 self.comboItems.append(self.trUtf8("Unicode character in hexadecimal notation")) |
44 self.comboItems.append(self.trUtf8("Unicode character in octal notation")) |
45 self.comboItems.append(self.trUtf8("Unicode character in octal notation")) |
45 self.comboItems.append(self.trUtf8("---")) |
46 self.singleComboItems.append(self.trUtf8("---")) |
46 self.comboItems.append(self.trUtf8("Bell character (\\a)")) |
47 self.singleComboItems.append(self.trUtf8("Bell character (\\a)")) |
47 self.comboItems.append(self.trUtf8("Page break (\\f)")) |
48 self.singleComboItems.append(self.trUtf8("Page break (\\f)")) |
48 self.comboItems.append(self.trUtf8("Line feed (\\n)")) |
49 self.singleComboItems.append(self.trUtf8("Line feed (\\n)")) |
49 self.comboItems.append(self.trUtf8("Carriage return (\\r)")) |
50 self.singleComboItems.append(self.trUtf8("Carriage return (\\r)")) |
50 self.comboItems.append(self.trUtf8("Horizontal tabulator (\\t)")) |
51 self.singleComboItems.append(self.trUtf8("Horizontal tabulator (\\t)")) |
51 self.comboItems.append(self.trUtf8("Vertical tabulator (\\v)")) |
52 self.singleComboItems.append(self.trUtf8("Vertical tabulator (\\v)")) |
52 |
53 |
53 self.charValidator = QRegExpValidator(QRegExp(".{0,1}"), self) |
54 self.charValidator = QRegExpValidator(QRegExp(".{0,1}"), self) |
54 self.hexValidator = QRegExpValidator(QRegExp("[0-9a-fA-F]{0,4}"), self) |
55 self.hexValidator = QRegExpValidator(QRegExp("[0-9a-fA-F]{0,4}"), self) |
55 self.octValidator = QRegExpValidator(QRegExp("[0-3]?[0-7]{0,2}"), self) |
56 self.octValidator = QRegExpValidator(QRegExp("[0-3]?[0-7]{0,2}"), self) |
56 |
57 |
130 hboxLayout.setSpacing(6) |
131 hboxLayout.setSpacing(6) |
131 hbox.setLayout(hboxLayout) |
132 hbox.setLayout(hboxLayout) |
132 cb1 = QComboBox(hbox) |
133 cb1 = QComboBox(hbox) |
133 cb1.setEditable(False) |
134 cb1.setEditable(False) |
134 cb1.addItems(self.comboItems) |
135 cb1.addItems(self.comboItems) |
|
136 cb1.addItems(self.singleComboItems) |
135 hboxLayout.addWidget(cb1) |
137 hboxLayout.addWidget(cb1) |
136 le1 = QLineEdit(hbox) |
138 le1 = QLineEdit(hbox) |
137 le1.setValidator(self.charValidator) |
139 le1.setValidator(self.charValidator) |
138 hboxLayout.addWidget(le1) |
140 hboxLayout.addWidget(le1) |
139 cb2 = QComboBox(hbox) |
141 cb2 = QComboBox(hbox) |
140 cb2.setEditable(False) |
142 cb2.setEditable(False) |
141 cb2.addItems(self.comboItems) |
143 cb2.addItems(self.comboItems) |
|
144 cb2.addItems(self.singleComboItems) |
142 hboxLayout.addWidget(cb2) |
145 hboxLayout.addWidget(cb2) |
143 le2 = QLineEdit(hbox) |
146 le2 = QLineEdit(hbox) |
144 le2.setValidator(self.charValidator) |
147 le2.setValidator(self.charValidator) |
145 hboxLayout.addWidget(le2) |
148 hboxLayout.addWidget(le2) |
146 self.singlesItemsBoxLayout.addWidget(hbox) |
149 self.singlesItemsBoxLayout.addWidget(hbox) |
161 hbox = QWidget(self.rangesItemsBox) |
164 hbox = QWidget(self.rangesItemsBox) |
162 hboxLayout = QHBoxLayout(hbox) |
165 hboxLayout = QHBoxLayout(hbox) |
163 hboxLayout.setMargin(0) |
166 hboxLayout.setMargin(0) |
164 hboxLayout.setSpacing(6) |
167 hboxLayout.setSpacing(6) |
165 hbox.setLayout(hboxLayout) |
168 hbox.setLayout(hboxLayout) |
166 l1 = QLabel(self.trUtf8("Between:"), hbox) |
|
167 hboxLayout.addWidget(l1) |
|
168 cb1 = QComboBox(hbox) |
169 cb1 = QComboBox(hbox) |
169 cb1.setEditable(False) |
170 cb1.setEditable(False) |
170 cb1.addItems(self.comboItems) |
171 cb1.addItems(self.comboItems) |
171 hboxLayout.addWidget(cb1) |
172 hboxLayout.addWidget(cb1) |
|
173 l1 = QLabel(self.trUtf8("Between:"), hbox) |
|
174 hboxLayout.addWidget(l1) |
172 le1 = QLineEdit(hbox) |
175 le1 = QLineEdit(hbox) |
173 le1.setValidator(self.charValidator) |
176 le1.setValidator(self.charValidator) |
174 hboxLayout.addWidget(le1) |
177 hboxLayout.addWidget(le1) |
175 l2 = QLabel(self.trUtf8("And:"), hbox) |
178 l2 = QLabel(self.trUtf8("And:"), hbox) |
176 hboxLayout.addWidget(l2) |
179 hboxLayout.addWidget(l2) |
177 cb2 = QComboBox(hbox) |
|
178 cb2.setEditable(False) |
|
179 cb2.addItems(self.comboItems) |
|
180 hboxLayout.addWidget(cb2) |
|
181 le2 = QLineEdit(hbox) |
180 le2 = QLineEdit(hbox) |
182 le2.setValidator(self.charValidator) |
181 le2.setValidator(self.charValidator) |
183 hboxLayout.addWidget(le2) |
182 hboxLayout.addWidget(le2) |
184 self.rangesItemsBoxLayout.addWidget(hbox) |
183 self.rangesItemsBoxLayout.addWidget(hbox) |
185 |
184 |
186 cb1.activated[int].connect(self.__rangesCharTypeSelected) |
185 cb1.activated[int].connect(self.__rangesCharTypeSelected) |
187 cb2.activated[int].connect(self.__rangesCharTypeSelected) |
186 |
188 hbox.show() |
187 hbox.show() |
189 |
188 |
190 self.rangesItemsBox.adjustSize() |
189 self.rangesItemsBox.adjustSize() |
191 |
190 |
192 self.rangesEntries.append([cb1, le1, cb2, le2]) |
191 self.rangesEntries.append([cb1, le1, le2]) |
193 |
192 |
194 def __performSelectedAction(self, index, lineedit): |
193 def __performSelectedAction(self, index, lineedit): |
195 """ |
194 """ |
196 Private method performing some actions depending on the input. |
195 Private method performing some actions depending on the input. |
197 |
196 |
230 """ |
229 """ |
231 combo = self.sender() |
230 combo = self.sender() |
232 for entriesList in self.rangesEntries: |
231 for entriesList in self.rangesEntries: |
233 if combo == entriesList[0]: |
232 if combo == entriesList[0]: |
234 self.__performSelectedAction(index, entriesList[1]) |
233 self.__performSelectedAction(index, entriesList[1]) |
235 break |
234 self.__performSelectedAction(index, entriesList[2]) |
236 elif combo == entriesList[2]: |
|
237 self.__performSelectedAction(index, entriesList[3]) |
|
238 break |
235 break |
239 |
236 |
240 def __formatCharacter(self, index, char): |
237 def __formatCharacter(self, index, char): |
241 """ |
238 """ |
242 Private method to format the characters entered into the dialog. |
239 Private method to format the characters entered into the dialog. |
290 regexp += self.__formatCharacter(index, char) |
287 regexp += self.__formatCharacter(index, char) |
291 |
288 |
292 # character ranges |
289 # character ranges |
293 for entrieslist in self.rangesEntries: |
290 for entrieslist in self.rangesEntries: |
294 if entrieslist[1].text() == "" or \ |
291 if entrieslist[1].text() == "" or \ |
295 entrieslist[3].text() == "": |
292 entrieslist[2].text() == "": |
296 continue |
293 continue |
297 index = entrieslist[0].currentIndex() |
294 index = entrieslist[0].currentIndex() |
298 char = entrieslist[1].text() |
295 char1 = entrieslist[1].text() |
299 regexp += "{0}-".format(self.__formatCharacter(index, char)) |
296 char2 = entrieslist[2].text() |
300 index = entrieslist[2].currentIndex() |
297 regexp += "{0}-{1}".format( |
301 char = entrieslist[3].text() |
298 self.__formatCharacter(index, char1), |
302 regexp += self.__formatCharacter(index, char) |
299 self.__formatCharacter(index, char2)) |
303 |
300 |
304 if regexp: |
301 if regexp: |
305 if len(regexp) == 2 and regexp in self.predefinedClasses: |
302 if len(regexp) == 2 and regexp in self.predefinedClasses: |
306 return regexp |
303 return regexp |
307 else: |
304 else: |