Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesListGuardsDialog.py

changeset 1046
5dd14be5d6a1
child 1131
7781e396c903
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 the guards of a selected patch.
8 """
9
10 import os
11
12 from PyQt4.QtCore import pyqtSlot, QProcess, QTimer
13 from PyQt4.QtGui import QDialog, QListWidgetItem
14
15 from .Ui_HgQueuesListGuardsDialog import Ui_HgQueuesListGuardsDialog
16
17 import Preferences
18 import UI.PixmapCache
19
20
21 class HgQueuesListGuardsDialog(QDialog, Ui_HgQueuesListGuardsDialog):
22 """
23 Class implementing a dialog to show the guards of a selected patch.
24 """
25 def __init__(self, vcs, patchesList, parent=None):
26 """
27 Constructor
28
29 @param vcs reference to the vcs object
30 @param patchesList list of patches (list of strings)
31 @param parent reference to the parent widget (QWidget)
32 """
33 QDialog.__init__(self, parent)
34 self.setupUi(self)
35
36 self.process = QProcess()
37 self.vcs = vcs
38
39 self.patchSelector.addItems([""] + patchesList)
40
41 def closeEvent(self, e):
42 """
43 Private slot implementing a close event handler.
44
45 @param e close event (QCloseEvent)
46 """
47 if self.process is not None and \
48 self.process.state() != QProcess.NotRunning:
49 self.process.terminate()
50 QTimer.singleShot(2000, self.process.kill)
51 self.process.waitForFinished(3000)
52
53 e.accept()
54
55 def start(self, path):
56 """
57 Public slot to start the list command.
58
59 @param path name of directory to be listed (string)
60 """
61 dname, fname = self.vcs.splitPath(path)
62
63 # find the root of the repo
64 repodir = dname
65 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
66 repodir = os.path.dirname(repodir)
67 if repodir == os.sep:
68 return
69
70 self.__repodir = repodir
71 self.on_patchSelector_activated("")
72
73 @pyqtSlot(str)
74 def on_patchSelector_activated(self, patch):
75 """
76 Private slot to get the list of guards for the given patch name.
77
78 @param patch selected patch name (empty for current patch)
79 """
80 self.guardsList.clear()
81 self.patchNameLabel.setText("")
82
83 ioEncoding = Preferences.getSystem("IOEncoding")
84 process = QProcess()
85 args = []
86 args.append("qguard")
87 if patch:
88 args.append(patch)
89
90 process.setWorkingDirectory(self.__repodir)
91 process.start('hg', args)
92 procStarted = process.waitForStarted()
93 if procStarted:
94 finished = process.waitForFinished(30000)
95 if finished and process.exitCode() == 0:
96 output = \
97 str(process.readAllStandardOutput(), ioEncoding, 'replace').strip()
98 if output:
99 patchName, guards = output.split(":", 1)
100 self.patchNameLabel.setText(patchName)
101 guardsList = guards.strip().split()
102 for guard in guardsList:
103 if guard.startswith("+"):
104 icon = UI.PixmapCache.getIcon("plus.png")
105 guard = guard[1:]
106 elif guard.startswith("-"):
107 icon = UI.PixmapCache.getIcon("minus.png")
108 guard = guard[1:]
109 else:
110 icon = None
111 guard = self.trUtf8("Unguarded")
112 itm = QListWidgetItem(guard, self.guardsList)
113 if icon:
114 itm.setIcon(icon)

eric ide

mercurial