|
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 guards of a selected patch. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtCore import pyqtSlot, Qt, QCoreApplication |
|
11 from PyQt6.QtWidgets import QDialog, QListWidgetItem |
|
12 |
|
13 from .Ui_HgQueuesListGuardsDialog import Ui_HgQueuesListGuardsDialog |
|
14 |
|
15 import UI.PixmapCache |
|
16 |
|
17 |
|
18 class HgQueuesListGuardsDialog(QDialog, Ui_HgQueuesListGuardsDialog): |
|
19 """ |
|
20 Class implementing a dialog to show the guards of a selected patch. |
|
21 """ |
|
22 def __init__(self, vcs, patchesList, parent=None): |
|
23 """ |
|
24 Constructor |
|
25 |
|
26 @param vcs reference to the vcs object |
|
27 @param patchesList list of patches (list of strings) |
|
28 @param parent reference to the parent widget (QWidget) |
|
29 """ |
|
30 super().__init__(parent) |
|
31 self.setupUi(self) |
|
32 self.setWindowFlags(Qt.WindowType.Window) |
|
33 |
|
34 self.vcs = vcs |
|
35 self.__hgClient = vcs.getClient() |
|
36 |
|
37 self.patchSelector.addItems([""] + patchesList) |
|
38 |
|
39 self.show() |
|
40 QCoreApplication.processEvents() |
|
41 |
|
42 def closeEvent(self, e): |
|
43 """ |
|
44 Protected slot implementing a close event handler. |
|
45 |
|
46 @param e close event (QCloseEvent) |
|
47 """ |
|
48 if self.__hgClient.isExecuting(): |
|
49 self.__hgClient.cancel() |
|
50 |
|
51 e.accept() |
|
52 |
|
53 def start(self): |
|
54 """ |
|
55 Public slot to start the list command. |
|
56 """ |
|
57 self.on_patchSelector_activated(0) |
|
58 |
|
59 @pyqtSlot(int) |
|
60 def on_patchSelector_activated(self, index): |
|
61 """ |
|
62 Private slot to get the list of guards for the given patch name. |
|
63 |
|
64 @param index index of the selected entry |
|
65 @type int |
|
66 """ |
|
67 patch = self.patchSelector.itemText(index) |
|
68 self.guardsList.clear() |
|
69 self.patchNameLabel.setText("") |
|
70 |
|
71 args = self.vcs.initCommand("qguard") |
|
72 if patch: |
|
73 args.append(patch) |
|
74 |
|
75 output = self.__hgClient.runcommand(args)[0].strip() |
|
76 |
|
77 if output: |
|
78 patchName, guards = output.split(":", 1) |
|
79 self.patchNameLabel.setText(patchName) |
|
80 guardsList = guards.strip().split() |
|
81 for guard in guardsList: |
|
82 if guard.startswith("+"): |
|
83 icon = UI.PixmapCache.getIcon("plus") |
|
84 guard = guard[1:] |
|
85 elif guard.startswith("-"): |
|
86 icon = UI.PixmapCache.getIcon("minus") |
|
87 guard = guard[1:] |
|
88 else: |
|
89 icon = None |
|
90 guard = self.tr("Unguarded") |
|
91 itm = QListWidgetItem(guard, self.guardsList) |
|
92 if icon: |
|
93 itm.setIcon(icon) |