8 """ |
8 """ |
9 |
9 |
10 from __future__ import unicode_literals # __IGNORE_WARNING__ |
10 from __future__ import unicode_literals # __IGNORE_WARNING__ |
11 |
11 |
12 from PyQt4.QtCore import QRegExp |
12 from PyQt4.QtCore import QRegExp |
13 from PyQt4.QtGui import QSizePolicy, QSpacerItem, QWidget, QHBoxLayout, QLineEdit, \ |
13 from PyQt4.QtGui import QSizePolicy, QSpacerItem, QWidget, QHBoxLayout, \ |
14 QPushButton, QDialog, QScrollArea, QComboBox, QVBoxLayout, QRegExpValidator, QLabel |
14 QLineEdit, QPushButton, QDialog, QScrollArea, QComboBox, QVBoxLayout, \ |
15 |
15 QRegExpValidator, QLabel |
16 from .Ui_PyRegExpWizardCharactersDialog import Ui_PyRegExpWizardCharactersDialog |
16 |
17 |
17 from .Ui_PyRegExpWizardCharactersDialog import \ |
18 |
18 Ui_PyRegExpWizardCharactersDialog |
19 class PyRegExpWizardCharactersDialog(QDialog, Ui_PyRegExpWizardCharactersDialog): |
19 |
|
20 |
|
21 class PyRegExpWizardCharactersDialog( |
|
22 QDialog, Ui_PyRegExpWizardCharactersDialog): |
20 """ |
23 """ |
21 Class implementing a dialog for entering character classes. |
24 Class implementing a dialog for entering character classes. |
22 """ |
25 """ |
23 specialChars = { |
26 specialChars = { |
24 4: "\\a", |
27 4: "\\a", |
41 self.setupUi(self) |
44 self.setupUi(self) |
42 |
45 |
43 self.comboItems = [] |
46 self.comboItems = [] |
44 self.singleComboItems = [] # these are in addition to the above |
47 self.singleComboItems = [] # these are in addition to the above |
45 self.comboItems.append(self.trUtf8("Normal character")) |
48 self.comboItems.append(self.trUtf8("Normal character")) |
46 self.comboItems.append(self.trUtf8("Unicode character in hexadecimal notation")) |
49 self.comboItems.append( |
47 self.comboItems.append(self.trUtf8("Unicode character in octal notation")) |
50 self.trUtf8("Unicode character in hexadecimal notation")) |
|
51 self.comboItems.append( |
|
52 self.trUtf8("Unicode character in octal notation")) |
48 self.singleComboItems.append(self.trUtf8("---")) |
53 self.singleComboItems.append(self.trUtf8("---")) |
49 self.singleComboItems.append(self.trUtf8("Bell character (\\a)")) |
54 self.singleComboItems.append(self.trUtf8("Bell character (\\a)")) |
50 self.singleComboItems.append(self.trUtf8("Page break (\\f)")) |
55 self.singleComboItems.append(self.trUtf8("Page break (\\f)")) |
51 self.singleComboItems.append(self.trUtf8("Line feed (\\n)")) |
56 self.singleComboItems.append(self.trUtf8("Line feed (\\n)")) |
52 self.singleComboItems.append(self.trUtf8("Carriage return (\\r)")) |
57 self.singleComboItems.append(self.trUtf8("Carriage return (\\r)")) |
83 hlayout0.setObjectName("hlayout0") |
88 hlayout0.setObjectName("hlayout0") |
84 self.moreSinglesButton = QPushButton(self.trUtf8("Additional Entries"), |
89 self.moreSinglesButton = QPushButton(self.trUtf8("Additional Entries"), |
85 self.singlesBox) |
90 self.singlesBox) |
86 self.moreSinglesButton.setObjectName("moreSinglesButton") |
91 self.moreSinglesButton.setObjectName("moreSinglesButton") |
87 hlayout0.addWidget(self.moreSinglesButton) |
92 hlayout0.addWidget(self.moreSinglesButton) |
88 hspacer0 = QSpacerItem(30, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) |
93 hspacer0 = QSpacerItem( |
|
94 30, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) |
89 hlayout0.addItem(hspacer0) |
95 hlayout0.addItem(hspacer0) |
90 self.singlesBoxLayout.addLayout(hlayout0) |
96 self.singlesBoxLayout.addLayout(hlayout0) |
91 self.moreSinglesButton.clicked[()].connect(self.__addSinglesLine) |
97 self.moreSinglesButton.clicked[()].connect(self.__addSinglesLine) |
92 |
98 |
93 # generate dialog part for character ranges |
99 # generate dialog part for character ranges |
116 hlayout1.setObjectName("hlayout1") |
122 hlayout1.setObjectName("hlayout1") |
117 self.moreRangesButton = QPushButton(self.trUtf8("Additional Entries"), |
123 self.moreRangesButton = QPushButton(self.trUtf8("Additional Entries"), |
118 self.rangesBox) |
124 self.rangesBox) |
119 self.moreSinglesButton.setObjectName("moreRangesButton") |
125 self.moreSinglesButton.setObjectName("moreRangesButton") |
120 hlayout1.addWidget(self.moreRangesButton) |
126 hlayout1.addWidget(self.moreRangesButton) |
121 hspacer1 = QSpacerItem(30, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) |
127 hspacer1 = QSpacerItem( |
|
128 30, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) |
122 hlayout1.addItem(hspacer1) |
129 hlayout1.addItem(hspacer1) |
123 self.rangesBoxLayout.addLayout(hlayout1) |
130 self.rangesBoxLayout.addLayout(hlayout1) |
124 self.moreRangesButton.clicked[()].connect(self.__addRangesLine) |
131 self.moreRangesButton.clicked[()].connect(self.__addRangesLine) |
125 |
132 |
126 def __addSinglesLine(self): |
133 def __addSinglesLine(self): |
211 lineedit.setEnabled(False) |
218 lineedit.setEnabled(False) |
212 lineedit.clear() |
219 lineedit.clear() |
213 |
220 |
214 def __singlesCharTypeSelected(self, index): |
221 def __singlesCharTypeSelected(self, index): |
215 """ |
222 """ |
216 Private slot to handle the activated(int) signal of the single chars combo boxes. |
223 Private slot to handle the activated(int) signal of the single chars |
|
224 combo boxes. |
217 |
225 |
218 @param index selected list index (integer) |
226 @param index selected list index (integer) |
219 """ |
227 """ |
220 combo = self.sender() |
228 combo = self.sender() |
221 for entriesList in self.singlesEntries: |
229 for entriesList in self.singlesEntries: |
223 self.__performSelectedAction(index, entriesList[1]) |
231 self.__performSelectedAction(index, entriesList[1]) |
224 break |
232 break |
225 |
233 |
226 def __rangesCharTypeSelected(self, index): |
234 def __rangesCharTypeSelected(self, index): |
227 """ |
235 """ |
228 Private slot to handle the activated(int) signal of the char ranges combo boxes. |
236 Private slot to handle the activated(int) signal of the char ranges |
|
237 combo boxes. |
229 |
238 |
230 @param index selected list index (integer) |
239 @param index selected list index (integer) |
231 """ |
240 """ |
232 combo = self.sender() |
241 combo = self.sender() |
233 for entriesList in self.rangesEntries: |
242 for entriesList in self.rangesEntries: |
299 regexp += "{0}-{1}".format( |
308 regexp += "{0}-{1}".format( |
300 self.__formatCharacter(index, char1), |
309 self.__formatCharacter(index, char1), |
301 self.__formatCharacter(index, char2)) |
310 self.__formatCharacter(index, char2)) |
302 |
311 |
303 if regexp: |
312 if regexp: |
304 if (len(regexp) == 2 and \ |
313 if (len(regexp) == 2 and |
305 (regexp in self.predefinedClasses or regexp in self.specialChars)) or \ |
314 (regexp in self.predefinedClasses or |
|
315 regexp in self.specialChars)) or \ |
306 len(regexp) == 1: |
316 len(regexp) == 1: |
307 return regexp |
317 return regexp |
308 else: |
318 else: |
309 return "[{0}]".format(regexp) |
319 return "[{0}]".format(regexp) |
310 else: |
320 else: |