|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter the data to rename a patch. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import pyqtSlot |
|
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
|
14 |
|
15 from .Ui_HgQueuesRenamePatchDialog import Ui_HgQueuesRenamePatchDialog |
|
16 |
|
17 |
|
18 class HgQueuesRenamePatchDialog(QDialog, Ui_HgQueuesRenamePatchDialog): |
|
19 """ |
|
20 Class implementing a dialog to enter the data to rename a patch. |
|
21 """ |
|
22 def __init__(self, currentPatch, patchesList, parent=None): |
|
23 """ |
|
24 Constructor |
|
25 |
|
26 @param currentPatch name of the current patch (string) |
|
27 @param patchesList list of patches to select from (list of strings) |
|
28 @param parent reference to the parent widget (QWidget) |
|
29 """ |
|
30 super(HgQueuesRenamePatchDialog, self).__init__(parent) |
|
31 self.setupUi(self) |
|
32 |
|
33 self.currentButton.setText( |
|
34 self.tr("Current Patch ({0})").format(currentPatch)) |
|
35 self.nameCombo.addItems([""] + patchesList) |
|
36 |
|
37 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
|
38 |
|
39 msh = self.minimumSizeHint() |
|
40 self.resize(max(self.width(), msh.width()), msh.height()) |
|
41 |
|
42 def __updateUI(self): |
|
43 """ |
|
44 Private slot to update the UI. |
|
45 """ |
|
46 enable = self.nameEdit.text() != "" |
|
47 if self.namedButton.isChecked(): |
|
48 enable = enable and self.nameCombo.currentText() != "" |
|
49 |
|
50 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable) |
|
51 |
|
52 @pyqtSlot(str) |
|
53 def on_nameEdit_textChanged(self, txt): |
|
54 """ |
|
55 Private slot to handle changes of the new name. |
|
56 |
|
57 @param txt text of the edit (string) |
|
58 """ |
|
59 self.__updateUI() |
|
60 |
|
61 @pyqtSlot(bool) |
|
62 def on_namedButton_toggled(self, checked): |
|
63 """ |
|
64 Private slot to handle changes of the selection method. |
|
65 |
|
66 @param checked state of the check box (boolean) |
|
67 """ |
|
68 self.__updateUI() |
|
69 |
|
70 @pyqtSlot(str) |
|
71 def on_nameCombo_currentIndexChanged(self, txt): |
|
72 """ |
|
73 Private slot to handle changes of the selected patch name. |
|
74 |
|
75 @param txt selected patch name (string) |
|
76 """ |
|
77 self.__updateUI() |
|
78 |
|
79 def getData(self): |
|
80 """ |
|
81 Public method to retrieve the entered data. |
|
82 |
|
83 @return tuple of new name and selected patch (string, string) |
|
84 """ |
|
85 selectedPatch = "" |
|
86 if self.namedButton.isChecked(): |
|
87 selectedPatch = self.nameCombo.currentText() |
|
88 |
|
89 return self.nameEdit.text().replace(" ", "_"), selectedPatch |