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