eric7/Plugins/WizardPlugins/PyRegExpWizard/PyRegExpWizardRepeatDialog.py

branch
eric7
changeset 8312
800c432b34c8
parent 8234
fcb6b4b96274
child 8318
962bce857696
equal deleted inserted replaced
8311:4e8b98454baa 8312:800c432b34c8
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2004 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog for entering repeat counts.
8 """
9
10 from PyQt5.QtCore import pyqtSlot
11 from PyQt5.QtWidgets import QDialog
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 super().__init__(parent)
27 self.setupUi(self)
28
29 self.unlimitedButton.setChecked(True)
30
31 msh = self.minimumSizeHint()
32 self.resize(max(self.width(), msh.width()), msh.height())
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 minimal = "?" if self.minimalCheckBox.isChecked() else ""
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 "{{{0:d},}}{1}".format(reps, minimal)
70 elif self.maxButton.isChecked():
71 reps = self.maxSpin.value()
72 if reps == 1:
73 return "?" + minimal
74 else:
75 return "{{,{0:d}}}{1}".format(reps, minimal)
76 elif self.exactButton.isChecked():
77 reps = self.exactSpin.value()
78 return "{{{0:d}}}{1}".format(reps, minimal)
79 elif self.betweenButton.isChecked():
80 repsMin = self.lowerSpin.value()
81 repsMax = self.upperSpin.value()
82 return "{{{0:d},{1:d}}}{2}".format(repsMin, repsMax, minimal)
83
84 return ""

eric ide

mercurial