|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2013 - 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_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 msh = self.minimumSizeHint() |
|
37 self.resize(max(self.width(), msh.width()), msh.height()) |
|
38 |
|
39 @pyqtSlot(int) |
|
40 def on_lowerSpin_valueChanged(self, value): |
|
41 """ |
|
42 Private slot to handle the lowerSpin valueChanged signal. |
|
43 |
|
44 @param value value of the spinbox (integer) |
|
45 """ |
|
46 if self.upperSpin.value() < value: |
|
47 self.upperSpin.setValue(value) |
|
48 |
|
49 @pyqtSlot(int) |
|
50 def on_upperSpin_valueChanged(self, value): |
|
51 """ |
|
52 Private slot to handle the upperSpin valueChanged signal. |
|
53 |
|
54 @param value value of the spinbox (integer) |
|
55 """ |
|
56 if self.lowerSpin.value() > value: |
|
57 self.lowerSpin.setValue(value) |
|
58 |
|
59 def getRepeat(self): |
|
60 """ |
|
61 Public method to retrieve the dialog's result. |
|
62 |
|
63 @return ready formatted repeat string (string) |
|
64 """ |
|
65 if self.possessiveButton.isChecked(): |
|
66 greedy = "+" |
|
67 elif self.lazyButton.isChecked(): |
|
68 greedy = "?" |
|
69 else: |
|
70 greedy = "" |
|
71 |
|
72 if self.unlimitedButton.isChecked(): |
|
73 return "*" + greedy |
|
74 elif self.minButton.isChecked(): |
|
75 reps = self.minSpin.value() |
|
76 if reps == 1: |
|
77 return "+" + greedy |
|
78 else: |
|
79 return "{{{0:d},}}{1}".format(reps, greedy) |
|
80 elif self.maxButton.isChecked(): |
|
81 reps = self.maxSpin.value() |
|
82 if reps == 1: |
|
83 return "?" + greedy |
|
84 else: |
|
85 return "{{0,{0:d}}}{1}".format(reps, greedy) |
|
86 elif self.exactButton.isChecked(): |
|
87 reps = self.exactSpin.value() |
|
88 return "{{{0:d}}}".format(reps) |
|
89 elif self.betweenButton.isChecked(): |
|
90 repsMin = self.lowerSpin.value() |
|
91 repsMax = self.upperSpin.value() |
|
92 return "{{{0:d},{1:d}}}{2}".format(repsMin, repsMax, greedy) |
|
93 |
|
94 return "" |