Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesListAllGuardsDialog.py

changeset 1046
5dd14be5d6a1
child 1061
3e21869872e3
equal deleted inserted replaced
1044:11aca34cce20 1046:5dd14be5d6a1
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to show all guards for all patches.
8 """
9
10 import os
11
12 from PyQt4.QtCore import QProcess, QTimer
13 from PyQt4.QtGui import QDialog, QTreeWidgetItem
14
15 from .Ui_HgQueuesListAllGuardsDialog import Ui_HgQueuesListAllGuardsDialog
16
17 import Preferences
18 import UI.PixmapCache
19
20
21 class HgQueuesListAllGuardsDialog(QDialog, Ui_HgQueuesListAllGuardsDialog):
22 """
23 Class implementing a dialog to show all guards for all patches.
24 """
25 def __init__(self, vcs, parent=None):
26 """
27 Constructor
28
29 @param parent reference to the parent widget (QWidget)
30 """
31 QDialog.__init__(self, parent)
32 self.setupUi(self)
33
34 self.process = QProcess()
35 self.vcs = vcs
36
37 def closeEvent(self, e):
38 """
39 Private slot implementing a close event handler.
40
41 @param e close event (QCloseEvent)
42 """
43 if self.process is not None and \
44 self.process.state() != QProcess.NotRunning:
45 self.process.terminate()
46 QTimer.singleShot(2000, self.process.kill)
47 self.process.waitForFinished(3000)
48
49 e.accept()
50
51 def start(self, path):
52 """
53 Public slot to start the list command.
54
55 @param path name of directory to be listed (string)
56 """
57 dname, fname = self.vcs.splitPath(path)
58
59 # find the root of the repo
60 repodir = dname
61 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
62 repodir = os.path.dirname(repodir)
63 if repodir == os.sep:
64 return
65
66
67 ioEncoding = Preferences.getSystem("IOEncoding")
68 process = QProcess()
69 args = []
70 args.append("qguard")
71 args.append("--list")
72
73 process.setWorkingDirectory(repodir)
74 process.start('hg', args)
75 procStarted = process.waitForStarted()
76 if procStarted:
77 finished = process.waitForFinished(30000)
78 if finished and process.exitCode() == 0:
79 output = \
80 str(process.readAllStandardOutput(), ioEncoding, 'replace')
81 if output:
82 guardsDict = {}
83 for line in output.splitlines():
84 if line:
85 patchName, guards = line.strip().split(":", 1)
86 guardsDict[patchName] = guards.strip().split()
87 for patchName in sorted(guardsDict.keys()):
88 patchItm = QTreeWidgetItem(self.guardsTree, [patchName])
89 patchItm.setExpanded(True)
90 for guard in guardsDict[patchName]:
91 if guard.startswith("+"):
92 icon = UI.PixmapCache.getIcon("plus.png")
93 guard = guard[1:]
94 elif guard.startswith("-"):
95 icon = UI.PixmapCache.getIcon("minus.png")
96 guard = guard[1:]
97 else:
98 icon = None
99 guard = self.trUtf8("Unguarded")
100 itm = QTreeWidgetItem(patchItm, [guard])
101 if icon:
102 itm.setIcon(0, icon)
103 else:
104 QTreeWidgetItem(self.guardsTree, [self.trUtf8("no patches found")])

eric ide

mercurial