|
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 get the data for a new patch. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import pyqtSlot, QDateTime |
|
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
|
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(HgQueuesNewPatchDialog, self).__init__(parent) |
|
36 self.setupUi(self) |
|
37 |
|
38 self.__mode = mode |
|
39 if self.__mode == HgQueuesNewPatchDialog.REFRESH_MODE: |
|
40 self.nameLabel.hide() |
|
41 self.nameEdit.hide() |
|
42 elif self.__mode == HgQueuesNewPatchDialog.NEW_MODE: |
|
43 # nothing special here |
|
44 pass |
|
45 else: |
|
46 raise ValueError("invalid value for mode") |
|
47 |
|
48 if message: |
|
49 self.messageEdit.setPlainText(message) |
|
50 |
|
51 self.dateTimeEdit.setDateTime(QDateTime.currentDateTime()) |
|
52 |
|
53 self.__updateUI() |
|
54 |
|
55 def __updateUI(self): |
|
56 """ |
|
57 Private slot to update the UI. |
|
58 """ |
|
59 if self.__mode == HgQueuesNewPatchDialog.REFRESH_MODE: |
|
60 enable = self.messageEdit.toPlainText() != "" |
|
61 else: |
|
62 enable = self.nameEdit.text() != "" and \ |
|
63 self.messageEdit.toPlainText() != "" |
|
64 if self.userGroup.isChecked(): |
|
65 enable = enable and \ |
|
66 (self.currentUserCheckBox.isChecked() or |
|
67 self.userEdit.text() != "") |
|
68 |
|
69 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable) |
|
70 |
|
71 @pyqtSlot(str) |
|
72 def on_nameEdit_textChanged(self, txt): |
|
73 """ |
|
74 Private slot to handle changes of the patch name. |
|
75 |
|
76 @param txt text of the edit (string) |
|
77 """ |
|
78 self.__updateUI() |
|
79 |
|
80 @pyqtSlot() |
|
81 def on_messageEdit_textChanged(self): |
|
82 """ |
|
83 Private slot to handle changes of the patch message. |
|
84 """ |
|
85 self.__updateUI() |
|
86 |
|
87 @pyqtSlot(bool) |
|
88 def on_userGroup_toggled(self, checked): |
|
89 """ |
|
90 Private slot to handle changes of the user group state. |
|
91 |
|
92 @param checked flag giving the checked state (boolean) |
|
93 """ |
|
94 self.__updateUI() |
|
95 |
|
96 @pyqtSlot(bool) |
|
97 def on_currentUserCheckBox_toggled(self, checked): |
|
98 """ |
|
99 Private slot to handle changes of the currentuser state. |
|
100 |
|
101 @param checked flag giving the checked state (boolean) |
|
102 """ |
|
103 self.__updateUI() |
|
104 |
|
105 @pyqtSlot(str) |
|
106 def on_userEdit_textChanged(self, txt): |
|
107 """ |
|
108 Private slot to handle changes of the user name. |
|
109 |
|
110 @param txt text of the edit (string) |
|
111 """ |
|
112 self.__updateUI() |
|
113 |
|
114 def getData(self): |
|
115 """ |
|
116 Public method to retrieve the entered data. |
|
117 |
|
118 @return tuple giving the patch name and message, a tuple giving a |
|
119 flag indicating to set the user, a flag indicating to use the |
|
120 current user and the user name and another tuple giving a flag |
|
121 indicating to set the date, a flag indicating to use the |
|
122 current date and the date (string, string, (boolean, boolean, |
|
123 string), (boolean, boolean, string)) |
|
124 """ |
|
125 userData = (self.userGroup.isChecked(), |
|
126 self.currentUserCheckBox.isChecked(), |
|
127 self.userEdit.text()) |
|
128 dateData = (self.dateGroup.isChecked(), |
|
129 self.currentDateCheckBox.isChecked(), |
|
130 self.dateTimeEdit.dateTime().toString("yyyy-MM-dd hh:mm")) |
|
131 return (self.nameEdit.text().replace(" ", "_"), |
|
132 self.messageEdit.toPlainText(), userData, dateData) |