|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2016 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter the histedit parameters. |
|
8 """ |
|
9 |
|
10 from PyQt5.QtCore import pyqtSlot |
|
11 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QButtonGroup |
|
12 |
|
13 from .Ui_HgHisteditConfigDialog import Ui_HgHisteditConfigDialog |
|
14 |
|
15 |
|
16 class HgHisteditConfigDialog(QDialog, Ui_HgHisteditConfigDialog): |
|
17 """ |
|
18 Class implementing a dialog to enter the histedit parameters. |
|
19 """ |
|
20 def __init__(self, tagsList, branchesList, bookmarksList=None, rev="", |
|
21 parent=None): |
|
22 """ |
|
23 Constructor |
|
24 |
|
25 @param tagsList list of tags |
|
26 @type list of str |
|
27 @param branchesList list of branches |
|
28 @type list of str |
|
29 @param bookmarksList list of bookmarks |
|
30 @type list of str |
|
31 @param rev revision to strip from |
|
32 @type str |
|
33 @param parent reference to the parent widget |
|
34 @type QWidget |
|
35 """ |
|
36 super().__init__(parent) |
|
37 self.setupUi(self) |
|
38 |
|
39 self.__sourceRevisionButtonGroup = QButtonGroup(self) |
|
40 self.__sourceRevisionButtonGroup.addButton(self.defaultButton) |
|
41 self.__sourceRevisionButtonGroup.addButton(self.outgoingButton) |
|
42 self.__sourceRevisionButtonGroup.addButton(self.revisionButton) |
|
43 |
|
44 self.tagCombo.addItems(sorted(tagsList)) |
|
45 self.branchCombo.addItems(["default"] + sorted(branchesList)) |
|
46 if bookmarksList is not None: |
|
47 self.bookmarkCombo.addItems(sorted(bookmarksList)) |
|
48 |
|
49 self.idEdit.setText(rev) |
|
50 if rev: |
|
51 self.revisionButton.setChecked(True) |
|
52 else: |
|
53 self.defaultButton.setChecked(True) |
|
54 |
|
55 msh = self.minimumSizeHint() |
|
56 self.resize(max(self.width(), msh.width()), msh.height()) |
|
57 |
|
58 self.__updateOK() |
|
59 |
|
60 def __updateOK(self): |
|
61 """ |
|
62 Private slot to update the OK button. |
|
63 """ |
|
64 enabled = True |
|
65 |
|
66 if self.revisionButton.isChecked(): |
|
67 if self.idButton.isChecked(): |
|
68 enabled = enabled and bool(self.idEdit.text()) |
|
69 elif self.tagButton.isChecked(): |
|
70 enabled = enabled and bool(self.tagCombo.currentText()) |
|
71 elif self.branchButton.isChecked(): |
|
72 enabled = enabled and bool(self.branchCombo.currentText()) |
|
73 elif self.bookmarkButton.isChecked(): |
|
74 enabled = enabled and bool(self.bookmarkCombo.currentText()) |
|
75 |
|
76 self.buttonBox.button( |
|
77 QDialogButtonBox.StandardButton.Ok).setEnabled(enabled) |
|
78 |
|
79 @pyqtSlot(bool) |
|
80 def on_defaultButton_toggled(self, checked): |
|
81 """ |
|
82 Private slot to handle changes of the Default select button. |
|
83 |
|
84 @param checked state of the button |
|
85 @type bool |
|
86 """ |
|
87 self.__updateOK() |
|
88 |
|
89 @pyqtSlot(bool) |
|
90 def on_outgoingButton_toggled(self, checked): |
|
91 """ |
|
92 Private slot to handle changes of the Outgoing select button. |
|
93 |
|
94 @param checked state of the button |
|
95 @type bool |
|
96 """ |
|
97 self.__updateOK() |
|
98 |
|
99 @pyqtSlot(bool) |
|
100 def on_revisionButton_toggled(self, checked): |
|
101 """ |
|
102 Private slot to handle changes of the Revision select button. |
|
103 |
|
104 @param checked state of the button |
|
105 @type bool |
|
106 """ |
|
107 self.__updateOK() |
|
108 |
|
109 @pyqtSlot(bool) |
|
110 def on_idButton_toggled(self, checked): |
|
111 """ |
|
112 Private slot to handle changes of the ID select button. |
|
113 |
|
114 @param checked state of the button (boolean) |
|
115 """ |
|
116 self.__updateOK() |
|
117 |
|
118 @pyqtSlot(bool) |
|
119 def on_tagButton_toggled(self, checked): |
|
120 """ |
|
121 Private slot to handle changes of the Tag select button. |
|
122 |
|
123 @param checked state of the button (boolean) |
|
124 """ |
|
125 self.__updateOK() |
|
126 |
|
127 @pyqtSlot(bool) |
|
128 def on_branch1Button_toggled(self, checked): |
|
129 """ |
|
130 Private slot to handle changes of the Branch select button. |
|
131 |
|
132 @param checked state of the button (boolean) |
|
133 """ |
|
134 self.__updateOK() |
|
135 |
|
136 @pyqtSlot(bool) |
|
137 def on_bookmarkButton_toggled(self, checked): |
|
138 """ |
|
139 Private slot to handle changes of the Bookmark select button. |
|
140 |
|
141 @param checked state of the button (boolean) |
|
142 """ |
|
143 self.__updateOK() |
|
144 |
|
145 @pyqtSlot(int) |
|
146 def on_numberSpinBox_valueChanged(self, val): |
|
147 """ |
|
148 Private slot to handle changes of the Number spin box. |
|
149 |
|
150 @param val value of the spin box |
|
151 @type int |
|
152 """ |
|
153 self.__updateOK() |
|
154 |
|
155 @pyqtSlot(str) |
|
156 def on_idEdit_textChanged(self, txt): |
|
157 """ |
|
158 Private slot to handle changes of the ID edit. |
|
159 |
|
160 @param txt text of the edit |
|
161 @type str |
|
162 """ |
|
163 self.__updateOK() |
|
164 |
|
165 @pyqtSlot(str) |
|
166 def on_tagCombo_editTextChanged(self, txt): |
|
167 """ |
|
168 Private slot to handle changes of the Tag combo. |
|
169 |
|
170 @param txt text of the combo |
|
171 @type str |
|
172 """ |
|
173 self.__updateOK() |
|
174 |
|
175 @pyqtSlot(str) |
|
176 def on_branchCombo_editTextChanged(self, txt): |
|
177 """ |
|
178 Private slot to handle changes of the Branch combo. |
|
179 |
|
180 @param txt text of the combo |
|
181 @type str |
|
182 """ |
|
183 self.__updateOK() |
|
184 |
|
185 @pyqtSlot(str) |
|
186 def on_bookmarkCombo_editTextChanged(self, txt): |
|
187 """ |
|
188 Private slot to handle changes of the Bookmark combo. |
|
189 |
|
190 @param txt text of the combo |
|
191 @type str |
|
192 """ |
|
193 self.__updateOK() |
|
194 |
|
195 def __getRevision(self): |
|
196 """ |
|
197 Private method to generate the revision. |
|
198 |
|
199 @return revision |
|
200 @rtype str |
|
201 """ |
|
202 if self.defaultButton.isChecked(): |
|
203 return "" |
|
204 elif self.outgoingButton.isChecked(): |
|
205 return "--outgoing" |
|
206 else: |
|
207 if self.numberButton.isChecked(): |
|
208 return "rev({0})".format(self.numberSpinBox.value()) |
|
209 elif self.idButton.isChecked(): |
|
210 return "id({0})".format(self.idEdit.text()) |
|
211 elif self.tagButton.isChecked(): |
|
212 return self.tagCombo.currentText() |
|
213 elif self.branchButton.isChecked(): |
|
214 return self.branchCombo.currentText() |
|
215 elif self.bookmarkButton.isChecked(): |
|
216 return self.bookmarkCombo.currentText() |
|
217 |
|
218 return "" |
|
219 |
|
220 def getData(self): |
|
221 """ |
|
222 Public method to retrieve the data for the strip action. |
|
223 |
|
224 @return tuple with the revision, a flag indicating to to outgoing and a |
|
225 flag indicating to keep old nodes |
|
226 @rtype tuple (str, bool, bool) |
|
227 """ |
|
228 return ( |
|
229 self.__getRevision(), |
|
230 self.forceCheckBox.isChecked(), |
|
231 self.keepCheckBox.isChecked(), |
|
232 ) |