Plugins/WizardPlugins/PyRegExpWizard/PyRegExpWizardRepeatDialog.py

changeset 0
de9c2efb9d02
child 12
1d8dd9706f46
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2004 - 2009 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 *
11 from PyQt4.QtGui import *
12
13 from Ui_PyRegExpWizardRepeatDialog import Ui_PyRegExpWizardRepeatDialog
14
15
16 class PyRegExpWizardRepeatDialog(QDialog, Ui_PyRegExpWizardRepeatDialog):
17 """
18 Class implementing a dialog for entering repeat counts.
19 """
20 def __init__(self,parent = None):
21 """
22 Constructor
23
24 @param parent parent widget (QWidget)
25 """
26 QDialog.__init__(self,parent)
27 self.setupUi(self)
28
29 self.unlimitedButton.setChecked(True)
30
31 @pyqtSlot(int)
32 def on_lowerSpin_valueChanged(self, value):
33 """
34 Private slot to handle the lowerSpin valueChanged signal.
35
36 @param value value of the spinbox (integer)
37 """
38 if self.upperSpin.value() < value:
39 self.upperSpin.setValue(value)
40
41 @pyqtSlot(int)
42 def on_upperSpin_valueChanged(self, value):
43 """
44 Private slot to handle the upperSpin valueChanged signal.
45
46 @param value value of the spinbox (integer)
47 """
48 if self.lowerSpin.value() > value:
49 self.lowerSpin.setValue(value)
50
51 def getRepeat(self):
52 """
53 Public method to retrieve the dialog's result.
54
55 @return ready formatted repeat string (string)
56 """
57 if self.minimalCheckBox.isChecked():
58 minimal = "?"
59 else:
60 minimal = ""
61
62 if self.unlimitedButton.isChecked():
63 return "*" + minimal
64 elif self.minButton.isChecked():
65 reps = self.minSpin.value()
66 if reps == 1:
67 return "+" + minimal
68 else:
69 return "{%d,}%s" % (reps, minimal)
70 elif self.maxButton.isChecked():
71 reps = self.maxSpin.value()
72 if reps == 1:
73 return "?" + minimal
74 else:
75 return "{,%d}%s" % (reps, minimal)
76 elif self.exactButton.isChecked():
77 reps = self.exactSpin.value()
78 return "{%d}%s" % (reps, minimal)
79 elif self.betweenButton.isChecked():
80 repsMin = self.lowerSpin.value()
81 repsMax = self.upperSpin.value()
82 return "{%d,%d}%s" % (repsMin, repsMax, minimal)

eric ide

mercurial