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