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