|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2010 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter the revisions for the hg diff command. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtCore import pyqtSlot |
|
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox |
|
12 |
|
13 from .Ui_HgRevisionsSelectionDialog import Ui_HgRevisionsSelectionDialog |
|
14 |
|
15 |
|
16 class HgRevisionsSelectionDialog(QDialog, Ui_HgRevisionsSelectionDialog): |
|
17 """ |
|
18 Class implementing a dialog to enter the revisions for the hg diff command. |
|
19 """ |
|
20 def __init__(self, tagsList, branchesList, bookmarksList=None, |
|
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 parent parent widget of the dialog |
|
32 @type QWidget |
|
33 """ |
|
34 super().__init__(parent) |
|
35 self.setupUi(self) |
|
36 |
|
37 self.buttonBox.button( |
|
38 QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
|
39 |
|
40 self.tag1Combo.addItems(sorted(tagsList)) |
|
41 self.tag2Combo.addItems(sorted(tagsList)) |
|
42 self.branch1Combo.addItems(["default"] + sorted(branchesList)) |
|
43 self.branch2Combo.addItems(["default"] + sorted(branchesList)) |
|
44 if bookmarksList is not None: |
|
45 self.bookmark1Combo.addItems(sorted(bookmarksList)) |
|
46 self.bookmark2Combo.addItems(sorted(bookmarksList)) |
|
47 else: |
|
48 self.bookmark1Button.setHidden(True) |
|
49 self.bookmark1Combo.setHidden(True) |
|
50 self.bookmark2Button.setHidden(True) |
|
51 self.bookmark2Combo.setHidden(True) |
|
52 |
|
53 # connect various radio buttons and input fields |
|
54 self.id1Button.toggled.connect(self.__updateOK) |
|
55 self.id2Button.toggled.connect(self.__updateOK) |
|
56 self.tag1Button.toggled.connect(self.__updateOK) |
|
57 self.tag2Button.toggled.connect(self.__updateOK) |
|
58 self.branch1Button.toggled.connect(self.__updateOK) |
|
59 self.branch2Button.toggled.connect(self.__updateOK) |
|
60 self.bookmark1Button.toggled.connect(self.__updateOK) |
|
61 self.bookmark2Button.toggled.connect(self.__updateOK) |
|
62 self.expression1Button.toggled.connect(self.__updateOK) |
|
63 self.expression2Button.toggled.connect(self.__updateOK) |
|
64 |
|
65 self.id1Edit.textChanged.connect(self.__updateOK) |
|
66 self.id2Edit.textChanged.connect(self.__updateOK) |
|
67 self.expression1Edit.textChanged.connect(self.__updateOK) |
|
68 self.expression2Edit.textChanged.connect(self.__updateOK) |
|
69 |
|
70 self.tag1Combo.editTextChanged.connect(self.__updateOK) |
|
71 self.tag2Combo.editTextChanged.connect(self.__updateOK) |
|
72 self.branch1Combo.editTextChanged.connect(self.__updateOK) |
|
73 self.branch2Combo.editTextChanged.connect(self.__updateOK) |
|
74 self.bookmark1Combo.editTextChanged.connect(self.__updateOK) |
|
75 self.bookmark2Combo.editTextChanged.connect(self.__updateOK) |
|
76 |
|
77 msh = self.minimumSizeHint() |
|
78 self.resize(max(self.width(), msh.width()), msh.height()) |
|
79 |
|
80 @pyqtSlot() |
|
81 def __updateOK(self): |
|
82 """ |
|
83 Private slot to update the OK button. |
|
84 """ |
|
85 enabled = True |
|
86 if self.id1Button.isChecked(): |
|
87 enabled = enabled and bool(self.id1Edit.text()) |
|
88 elif self.tag1Button.isChecked(): |
|
89 enabled = enabled and bool(self.tag1Combo.currentText()) |
|
90 elif self.branch1Button.isChecked(): |
|
91 enabled = enabled and bool(self.branch1Combo.currentText()) |
|
92 elif self.bookmark1Button.isChecked(): |
|
93 enabled = enabled and bool(self.bookmark1Combo.currentText()) |
|
94 elif self.expression1Button.isChecked(): |
|
95 enabled = enabled and bool(self.expression1Edit.text()) |
|
96 |
|
97 if self.id2Button.isChecked(): |
|
98 enabled = enabled and bool(self.id2Edit.text()) |
|
99 elif self.tag2Button.isChecked(): |
|
100 enabled = enabled and bool(self.tag2Combo.currentText()) |
|
101 elif self.branch2Button.isChecked(): |
|
102 enabled = enabled and bool(self.branch2Combo.currentText()) |
|
103 elif self.bookmark2Button.isChecked(): |
|
104 enabled = enabled and bool(self.bookmark2Combo.currentText()) |
|
105 elif self.expression2Button.isChecked(): |
|
106 enabled = enabled and bool(self.expression2Edit.text()) |
|
107 |
|
108 self.buttonBox.button( |
|
109 QDialogButtonBox.StandardButton.Ok).setEnabled(enabled) |
|
110 |
|
111 def __getRevision(self, no): |
|
112 """ |
|
113 Private method to generate the revision. |
|
114 |
|
115 @param no revision number to generate (1 or 2) |
|
116 @type int |
|
117 @return revision |
|
118 @rtype str |
|
119 """ |
|
120 if no == 1: |
|
121 numberButton = self.number1Button |
|
122 numberSpinBox = self.number1SpinBox |
|
123 idButton = self.id1Button |
|
124 idEdit = self.id1Edit |
|
125 tagButton = self.tag1Button |
|
126 tagCombo = self.tag1Combo |
|
127 branchButton = self.branch1Button |
|
128 branchCombo = self.branch1Combo |
|
129 bookmarkButton = self.bookmark1Button |
|
130 bookmarkCombo = self.bookmark1Combo |
|
131 expressionButton = self.expression1Button |
|
132 expressionEdit = self.expression1Edit |
|
133 tipButton = self.tip1Button |
|
134 prevButton = self.prev1Button |
|
135 noneButton = self.none1Button |
|
136 else: |
|
137 numberButton = self.number2Button |
|
138 numberSpinBox = self.number2SpinBox |
|
139 idButton = self.id2Button |
|
140 idEdit = self.id2Edit |
|
141 tagButton = self.tag2Button |
|
142 tagCombo = self.tag2Combo |
|
143 branchButton = self.branch2Button |
|
144 branchCombo = self.branch2Combo |
|
145 bookmarkButton = self.bookmark2Button |
|
146 bookmarkCombo = self.bookmark2Combo |
|
147 expressionButton = self.expression2Button |
|
148 expressionEdit = self.expression2Edit |
|
149 tipButton = self.tip2Button |
|
150 prevButton = self.prev2Button |
|
151 noneButton = self.none2Button |
|
152 |
|
153 if numberButton.isChecked(): |
|
154 return "rev({0})".format(numberSpinBox.value()) |
|
155 elif idButton.isChecked(): |
|
156 return "id({0})".format(idEdit.text()) |
|
157 elif tagButton.isChecked(): |
|
158 return tagCombo.currentText() |
|
159 elif branchButton.isChecked(): |
|
160 return branchCombo.currentText() |
|
161 elif bookmarkButton.isChecked(): |
|
162 return bookmarkCombo.currentText() |
|
163 elif expressionButton.isChecked(): |
|
164 return expressionEdit.text() |
|
165 elif tipButton.isChecked(): |
|
166 return "tip" |
|
167 elif prevButton.isChecked(): |
|
168 return "." |
|
169 elif noneButton.isChecked(): |
|
170 return "" |
|
171 |
|
172 return "" |
|
173 |
|
174 def getRevisions(self): |
|
175 """ |
|
176 Public method to get the revisions. |
|
177 |
|
178 @return list of two revisions |
|
179 @rtype list of [str, str] |
|
180 """ |
|
181 rev1 = self.__getRevision(1) |
|
182 rev2 = self.__getRevision(2) |
|
183 |
|
184 return [rev1, rev2] |