|
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 show the commit message of the current patch. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtCore import Qt, QCoreApplication |
|
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox |
|
12 |
|
13 from .Ui_HgQueuesHeaderDialog import Ui_HgQueuesHeaderDialog |
|
14 |
|
15 import Utilities |
|
16 |
|
17 |
|
18 class HgQueuesHeaderDialog(QDialog, Ui_HgQueuesHeaderDialog): |
|
19 """ |
|
20 Class implementing a dialog to show the commit message of the current |
|
21 patch. |
|
22 """ |
|
23 def __init__(self, vcs, parent=None): |
|
24 """ |
|
25 Constructor |
|
26 |
|
27 @param vcs reference to the vcs object |
|
28 @param parent reference to the parent widget (QWidget) |
|
29 """ |
|
30 super().__init__(parent) |
|
31 self.setupUi(self) |
|
32 |
|
33 self.buttonBox.button( |
|
34 QDialogButtonBox.StandardButton.Close).setEnabled(False) |
|
35 self.buttonBox.button( |
|
36 QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
|
37 |
|
38 self.vcs = vcs |
|
39 self.__hgClient = vcs.getClient() |
|
40 |
|
41 self.show() |
|
42 QCoreApplication.processEvents() |
|
43 |
|
44 def closeEvent(self, e): |
|
45 """ |
|
46 Protected slot implementing a close event handler. |
|
47 |
|
48 @param e close event (QCloseEvent) |
|
49 """ |
|
50 if self.__hgClient.isExecuting(): |
|
51 self.__hgClient.cancel() |
|
52 |
|
53 e.accept() |
|
54 |
|
55 def start(self): |
|
56 """ |
|
57 Public slot to start the list command. |
|
58 """ |
|
59 self.activateWindow() |
|
60 |
|
61 args = self.vcs.initCommand("qheader") |
|
62 |
|
63 out, err = self.__hgClient.runcommand( |
|
64 args, output=self.__showOutput, error=self.__showError) |
|
65 if err: |
|
66 self.__showError(err) |
|
67 if out: |
|
68 self.__showOutPut(out) |
|
69 self.__finish() |
|
70 |
|
71 def __finish(self): |
|
72 """ |
|
73 Private slot called when the process finished or the user pressed |
|
74 the button. |
|
75 """ |
|
76 self.buttonBox.button( |
|
77 QDialogButtonBox.StandardButton.Close).setEnabled(True) |
|
78 self.buttonBox.button( |
|
79 QDialogButtonBox.StandardButton.Cancel).setEnabled(False) |
|
80 self.buttonBox.button( |
|
81 QDialogButtonBox.StandardButton.Close).setDefault(True) |
|
82 self.buttonBox.button( |
|
83 QDialogButtonBox.StandardButton.Close).setFocus( |
|
84 Qt.FocusReason.OtherFocusReason) |
|
85 |
|
86 def on_buttonBox_clicked(self, button): |
|
87 """ |
|
88 Private slot called by a button of the button box clicked. |
|
89 |
|
90 @param button button that was clicked (QAbstractButton) |
|
91 """ |
|
92 if button == self.buttonBox.button( |
|
93 QDialogButtonBox.StandardButton.Close |
|
94 ): |
|
95 self.close() |
|
96 elif button == self.buttonBox.button( |
|
97 QDialogButtonBox.StandardButton.Cancel |
|
98 ): |
|
99 if self.__hgClient: |
|
100 self.__hgClient.cancel() |
|
101 else: |
|
102 self.__finish() |
|
103 |
|
104 def __showOutput(self, out): |
|
105 """ |
|
106 Private slot to show some output. |
|
107 |
|
108 @param out output to be shown (string) |
|
109 """ |
|
110 self.messageEdit.appendPlainText(Utilities.filterAnsiSequences(out)) |
|
111 |
|
112 def __showError(self, out): |
|
113 """ |
|
114 Private slot to show some error. |
|
115 |
|
116 @param out error to be shown (string) |
|
117 """ |
|
118 self.messageEdit.appendPlainText(self.tr("Error: ")) |
|
119 self.messageEdit.appendPlainText(Utilities.filterAnsiSequences(out)) |