|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2004 - 2019 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 |
|
11 |
|
12 from PyQt5.QtCore import pyqtSlot |
|
13 from PyQt5.QtWidgets import QDialog |
|
14 |
|
15 from .Ui_PyRegExpWizardRepeatDialog import Ui_PyRegExpWizardRepeatDialog |
|
16 |
|
17 |
|
18 class PyRegExpWizardRepeatDialog(QDialog, Ui_PyRegExpWizardRepeatDialog): |
|
19 """ |
|
20 Class implementing a dialog for entering repeat counts. |
|
21 """ |
|
22 def __init__(self, parent=None): |
|
23 """ |
|
24 Constructor |
|
25 |
|
26 @param parent parent widget (QWidget) |
|
27 """ |
|
28 super(PyRegExpWizardRepeatDialog, self).__init__(parent) |
|
29 self.setupUi(self) |
|
30 |
|
31 self.unlimitedButton.setChecked(True) |
|
32 |
|
33 msh = self.minimumSizeHint() |
|
34 self.resize(max(self.width(), msh.width()), msh.height()) |
|
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.minimalCheckBox.isChecked(): |
|
63 minimal = "?" |
|
64 else: |
|
65 minimal = "" |
|
66 |
|
67 if self.unlimitedButton.isChecked(): |
|
68 return "*" + minimal |
|
69 elif self.minButton.isChecked(): |
|
70 reps = self.minSpin.value() |
|
71 if reps == 1: |
|
72 return "+" + minimal |
|
73 else: |
|
74 return "{{{0:d},}}{1}".format(reps, minimal) |
|
75 elif self.maxButton.isChecked(): |
|
76 reps = self.maxSpin.value() |
|
77 if reps == 1: |
|
78 return "?" + minimal |
|
79 else: |
|
80 return "{{,{0:d}}}{1}".format(reps, minimal) |
|
81 elif self.exactButton.isChecked(): |
|
82 reps = self.exactSpin.value() |
|
83 return "{{{0:d}}}{1}".format(reps, minimal) |
|
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, minimal) |
|
88 |
|
89 return "" |