|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2013 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog for entering repeat counts. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtCore import pyqtSlot |
|
11 from PyQt4.QtGui import QDialog |
|
12 |
|
13 from .Ui_QRegularExpressionWizardRepeatDialog import \ |
|
14 Ui_QRegularExpressionWizardRepeatDialog |
|
15 |
|
16 |
|
17 class QRegularExpressionWizardRepeatDialog( |
|
18 QDialog, Ui_QRegularExpressionWizardRepeatDialog): |
|
19 """ |
|
20 Class implementing a dialog for entering repeat counts. |
|
21 """ |
|
22 def __init__(self, parent=None): |
|
23 """ |
|
24 Constructor |
|
25 |
|
26 @param parent reference to the parent widget (QWidget) |
|
27 """ |
|
28 super().__init__(parent) |
|
29 self.setupUi(self) |
|
30 |
|
31 self.unlimitedButton.setChecked(True) |
|
32 self.greedyButton.setChecked(True) |
|
33 |
|
34 @pyqtSlot(int) |
|
35 def on_lowerSpin_valueChanged(self, value): |
|
36 """ |
|
37 Private slot to handle the lowerSpin valueChanged signal. |
|
38 |
|
39 @param value value of the spinbox (integer) |
|
40 """ |
|
41 if self.upperSpin.value() < value: |
|
42 self.upperSpin.setValue(value) |
|
43 |
|
44 @pyqtSlot(int) |
|
45 def on_upperSpin_valueChanged(self, value): |
|
46 """ |
|
47 Private slot to handle the upperSpin valueChanged signal. |
|
48 |
|
49 @param value value of the spinbox (integer) |
|
50 """ |
|
51 if self.lowerSpin.value() > value: |
|
52 self.lowerSpin.setValue(value) |
|
53 |
|
54 def getRepeat(self): |
|
55 """ |
|
56 Public method to retrieve the dialog's result. |
|
57 |
|
58 @return ready formatted repeat string (string) |
|
59 """ |
|
60 if self.possessiveButton.isChecked(): |
|
61 greedy = "+" |
|
62 elif self.lazyButton.isChecked(): |
|
63 greedy = "?" |
|
64 else: |
|
65 greedy = "" |
|
66 |
|
67 if self.unlimitedButton.isChecked(): |
|
68 return "*" + greedy |
|
69 elif self.minButton.isChecked(): |
|
70 reps = self.minSpin.value() |
|
71 if reps == 1: |
|
72 return "+" + greedy |
|
73 else: |
|
74 return "{{{0:d},}}{1}".format(reps, greedy) |
|
75 elif self.maxButton.isChecked(): |
|
76 reps = self.maxSpin.value() |
|
77 if reps == 1: |
|
78 return "?" + greedy |
|
79 else: |
|
80 return "{{0,{0:d}}}{1}".format(reps, greedy) |
|
81 elif self.exactButton.isChecked(): |
|
82 reps = self.exactSpin.value() |
|
83 return "{{{0:d}}}".format(reps) |
|
84 elif self.betweenButton.isChecked(): |
|
85 repsMin = self.lowerSpin.value() |
|
86 repsMax = self.upperSpin.value() |
|
87 return "{{{0:d},{1:d}}}{2}".format(repsMin, repsMax, greedy) |