eric6/Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesListGuardsDialog.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7192
a22eee00b052
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
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 show the guards of a selected patch.
8 """
9
10 from __future__ import unicode_literals
11 try:
12 str = unicode
13 except NameError:
14 pass
15
16 import os
17
18 from PyQt5.QtCore import pyqtSlot, Qt, QProcess, QTimer, QCoreApplication
19 from PyQt5.QtWidgets import QDialog, QListWidgetItem
20
21 from .Ui_HgQueuesListGuardsDialog import Ui_HgQueuesListGuardsDialog
22
23 import UI.PixmapCache
24
25
26 class HgQueuesListGuardsDialog(QDialog, Ui_HgQueuesListGuardsDialog):
27 """
28 Class implementing a dialog to show the guards of a selected patch.
29 """
30 def __init__(self, vcs, patchesList, parent=None):
31 """
32 Constructor
33
34 @param vcs reference to the vcs object
35 @param patchesList list of patches (list of strings)
36 @param parent reference to the parent widget (QWidget)
37 """
38 super(HgQueuesListGuardsDialog, self).__init__(parent)
39 self.setupUi(self)
40 self.setWindowFlags(Qt.Window)
41
42 self.process = QProcess()
43 self.vcs = vcs
44 self.__hgClient = vcs.getClient()
45
46 self.patchSelector.addItems([""] + patchesList)
47
48 self.show()
49 QCoreApplication.processEvents()
50
51 def closeEvent(self, e):
52 """
53 Protected slot implementing a close event handler.
54
55 @param e close event (QCloseEvent)
56 """
57 if self.__hgClient:
58 if self.__hgClient.isExecuting():
59 self.__hgClient.cancel()
60 else:
61 if self.process is not None and \
62 self.process.state() != QProcess.NotRunning:
63 self.process.terminate()
64 QTimer.singleShot(2000, self.process.kill)
65 self.process.waitForFinished(3000)
66
67 e.accept()
68
69 def start(self, path):
70 """
71 Public slot to start the list command.
72
73 @param path name of directory to be listed (string)
74 """
75 dname, fname = self.vcs.splitPath(path)
76
77 # find the root of the repo
78 repodir = dname
79 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
80 repodir = os.path.dirname(repodir)
81 if os.path.splitdrive(repodir)[1] == os.sep:
82 return
83
84 self.__repodir = repodir
85 self.on_patchSelector_activated("")
86
87 @pyqtSlot(str)
88 def on_patchSelector_activated(self, patch):
89 """
90 Private slot to get the list of guards for the given patch name.
91
92 @param patch selected patch name (empty for current patch)
93 """
94 self.guardsList.clear()
95 self.patchNameLabel.setText("")
96
97 args = self.vcs.initCommand("qguard")
98 if patch:
99 args.append(patch)
100
101 output = ""
102 if self.__hgClient:
103 output = self.__hgClient.runcommand(args)[0].strip()
104 else:
105 process = QProcess()
106 process.setWorkingDirectory(self.__repodir)
107 process.start('hg', args)
108 procStarted = process.waitForStarted(5000)
109 if procStarted:
110 finished = process.waitForFinished(30000)
111 if finished and process.exitCode() == 0:
112 output = str(process.readAllStandardOutput(),
113 self.vcs.getEncoding(), 'replace').strip()
114
115 if output:
116 patchName, guards = output.split(":", 1)
117 self.patchNameLabel.setText(patchName)
118 guardsList = guards.strip().split()
119 for guard in guardsList:
120 if guard.startswith("+"):
121 icon = UI.PixmapCache.getIcon("plus.png")
122 guard = guard[1:]
123 elif guard.startswith("-"):
124 icon = UI.PixmapCache.getIcon("minus.png")
125 guard = guard[1:]
126 else:
127 icon = None
128 guard = self.tr("Unguarded")
129 itm = QListWidgetItem(guard, self.guardsList)
130 if icon:
131 itm.setIcon(icon)

eric ide

mercurial