eric7/Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesNewPatchDialog.py

branch
eric7
changeset 8312
800c432b34c8
parent 8259
2bbec88047dd
child 8318
962bce857696
equal deleted inserted replaced
8311:4e8b98454baa 8312:800c432b34c8
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2011 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to get the data for a new patch.
8 """
9
10 from PyQt5.QtCore import pyqtSlot, QDateTime
11 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
12
13 from .Ui_HgQueuesNewPatchDialog import Ui_HgQueuesNewPatchDialog
14
15
16 class HgQueuesNewPatchDialog(QDialog, Ui_HgQueuesNewPatchDialog):
17 """
18 Class implementing a dialog to get the data for a new patch.
19 """
20 NEW_MODE = 0
21 REFRESH_MODE = 1
22
23 def __init__(self, mode, message="", parent=None):
24 """
25 Constructor
26
27 @param mode mode of the dialog (HgQueuesNewPatchDialog.NEW_MODE,
28 HgQueuesNewPatchDialog.REFRESH_MODE)
29 @param message text to set as the commit message (string)
30 @param parent reference to the parent widget (QWidget)
31 @exception ValueError raised to indicate an invalid dialog mode
32 """
33 super().__init__(parent)
34 self.setupUi(self)
35
36 if mode not in (HgQueuesNewPatchDialog.REFRESH_MODE,
37 HgQueuesNewPatchDialog.NEW_MODE):
38 raise ValueError("invalid value for mode")
39
40 self.__mode = mode
41 if self.__mode == HgQueuesNewPatchDialog.REFRESH_MODE:
42 self.nameLabel.hide()
43 self.nameEdit.hide()
44
45 if message:
46 self.messageEdit.setPlainText(message)
47
48 self.dateTimeEdit.setDateTime(QDateTime.currentDateTime())
49
50 self.__updateUI()
51
52 def __updateUI(self):
53 """
54 Private slot to update the UI.
55 """
56 enable = (
57 self.messageEdit.toPlainText() != ""
58 if self.__mode == HgQueuesNewPatchDialog.REFRESH_MODE else
59 (self.nameEdit.text() != "" and
60 self.messageEdit.toPlainText() != "")
61 )
62 if self.userGroup.isChecked():
63 enable = (
64 enable and
65 (self.currentUserCheckBox.isChecked() or
66 self.userEdit.text() != "")
67 )
68
69 self.buttonBox.button(
70 QDialogButtonBox.StandardButton.Ok).setEnabled(enable)
71
72 @pyqtSlot(str)
73 def on_nameEdit_textChanged(self, txt):
74 """
75 Private slot to handle changes of the patch name.
76
77 @param txt text of the edit (string)
78 """
79 self.__updateUI()
80
81 @pyqtSlot()
82 def on_messageEdit_textChanged(self):
83 """
84 Private slot to handle changes of the patch message.
85 """
86 self.__updateUI()
87
88 @pyqtSlot(bool)
89 def on_userGroup_toggled(self, checked):
90 """
91 Private slot to handle changes of the user group state.
92
93 @param checked flag giving the checked state (boolean)
94 """
95 self.__updateUI()
96
97 @pyqtSlot(bool)
98 def on_currentUserCheckBox_toggled(self, checked):
99 """
100 Private slot to handle changes of the currentuser state.
101
102 @param checked flag giving the checked state (boolean)
103 """
104 self.__updateUI()
105
106 @pyqtSlot(str)
107 def on_userEdit_textChanged(self, txt):
108 """
109 Private slot to handle changes of the user name.
110
111 @param txt text of the edit (string)
112 """
113 self.__updateUI()
114
115 def getData(self):
116 """
117 Public method to retrieve the entered data.
118
119 @return tuple giving the patch name and message, a tuple giving a
120 flag indicating to set the user, a flag indicating to use the
121 current user and the user name and another tuple giving a flag
122 indicating to set the date, a flag indicating to use the
123 current date and the date (string, string, (boolean, boolean,
124 string), (boolean, boolean, string))
125 """
126 userData = (self.userGroup.isChecked(),
127 self.currentUserCheckBox.isChecked(),
128 self.userEdit.text())
129 dateData = (self.dateGroup.isChecked(),
130 self.currentDateCheckBox.isChecked(),
131 self.dateTimeEdit.dateTime().toString("yyyy-MM-dd hh:mm"))
132 return (self.nameEdit.text().replace(" ", "_"),
133 self.messageEdit.toPlainText(), userData, dateData)

eric ide

mercurial