Plugins/VcsPlugins/vcsMercurial/QueuesExtension/HgQueuesListAllGuardsDialog.py

Thu, 01 Sep 2011 08:33:53 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 01 Sep 2011 08:33:53 +0200
changeset 1260
9488a3aceb0e
parent 1254
c077fa008aae
child 1318
6fa303bd65d6
permissions
-rw-r--r--

Added code to some Mercurial dialogs to improve user experience.

1046
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de>
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog to show all guards for all patches.
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import os
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
1260
9488a3aceb0e Added code to some Mercurial dialogs to improve user experience.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1254
diff changeset
12 from PyQt4.QtCore import QProcess, QCoreApplication
1046
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from PyQt4.QtGui import QDialog, QTreeWidgetItem
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from .Ui_HgQueuesListAllGuardsDialog import Ui_HgQueuesListAllGuardsDialog
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 import Preferences
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 import UI.PixmapCache
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 class HgQueuesListAllGuardsDialog(QDialog, Ui_HgQueuesListAllGuardsDialog):
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 Class implementing a dialog to show all guards for all patches.
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 """
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 def __init__(self, vcs, parent=None):
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 Constructor
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 @param parent reference to the parent widget (QWidget)
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
1131
7781e396c903 Changed the code to use super() to access the superclass.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1061
diff changeset
31 super().__init__(parent)
1046
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 self.setupUi(self)
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 self.vcs = vcs
1254
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
35 self.__hgClient = vcs.getClient()
1260
9488a3aceb0e Added code to some Mercurial dialogs to improve user experience.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1254
diff changeset
36
9488a3aceb0e Added code to some Mercurial dialogs to improve user experience.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1254
diff changeset
37 self.show()
9488a3aceb0e Added code to some Mercurial dialogs to improve user experience.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1254
diff changeset
38 QCoreApplication.processEvents()
1046
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 def start(self, path):
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 """
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 Public slot to start the list command.
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 @param path name of directory to be listed (string)
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 """
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 dname, fname = self.vcs.splitPath(path)
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 # find the root of the repo
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 repodir = dname
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 repodir = os.path.dirname(repodir)
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 if repodir == os.sep:
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 return
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 args = []
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 args.append("qguard")
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 args.append("--list")
5dd14be5d6a1 Continued with support for Mercurial queues extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58
1254
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
59 output = ""
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
60 if self.__hgClient:
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
61 output = self.__hgClient.runcommand(args)[0]
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
62 else:
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
63 ioEncoding = Preferences.getSystem("IOEncoding")
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
64 process = QProcess()
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
65 process.setWorkingDirectory(repodir)
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
66 process.start('hg', args)
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
67 procStarted = process.waitForStarted()
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
68 if procStarted:
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
69 finished = process.waitForFinished(30000)
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
70 if finished and process.exitCode() == 0:
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
71 output = \
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
72 str(process.readAllStandardOutput(), ioEncoding, 'replace')
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
73
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
74 if output:
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
75 guardsDict = {}
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
76 for line in output.splitlines():
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
77 if line:
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
78 patchName, guards = line.strip().split(":", 1)
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
79 guardsDict[patchName] = guards.strip().split()
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
80 for patchName in sorted(guardsDict.keys()):
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
81 patchItm = QTreeWidgetItem(self.guardsTree, [patchName])
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
82 patchItm.setExpanded(True)
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
83 for guard in guardsDict[patchName]:
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
84 if guard.startswith("+"):
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
85 icon = UI.PixmapCache.getIcon("plus.png")
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
86 guard = guard[1:]
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
87 elif guard.startswith("-"):
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
88 icon = UI.PixmapCache.getIcon("minus.png")
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
89 guard = guard[1:]
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
90 else:
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
91 icon = None
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
92 guard = self.trUtf8("Unguarded")
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
93 itm = QTreeWidgetItem(patchItm, [guard])
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
94 if icon:
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
95 itm.setIcon(0, icon)
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
96 else:
c077fa008aae Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
97 QTreeWidgetItem(self.guardsTree, [self.trUtf8("no patches found")])

eric ide

mercurial