VCS/StatusMonitorLed.py

branch
Py2 comp.
changeset 3484
645c12de6b0c
parent 3178
f25fc1364c88
parent 3351
935482dff2f8
child 3539
0c2dc1446ebf
equal deleted inserted replaced
3456:96232974dcdb 3484:645c12de6b0c
11 from __future__ import unicode_literals 11 from __future__ import unicode_literals
12 12
13 from PyQt4.QtCore import Qt 13 from PyQt4.QtCore import Qt
14 from PyQt4.QtGui import QColor, QInputDialog, QMenu 14 from PyQt4.QtGui import QColor, QInputDialog, QMenu
15 15
16 from E5Gui.E5Led import E5Led, E5LedRectangular 16 from E5Gui.E5Led import E5ClickableLed, E5LedRectangular
17 17
18 import Preferences 18 import Preferences
19 19
20 20
21 class StatusMonitorLed(E5Led): 21 class StatusMonitorLed(E5ClickableLed):
22 """ 22 """
23 Class implementing a LED to indicate the status of the VCS status monitor 23 Class implementing a LED to indicate the status of the VCS status monitor
24 thread. 24 thread.
25 """ 25 """
26 def __init__(self, project, parent): 26 def __init__(self, project, parent):
28 Constructor 28 Constructor
29 29
30 @param project reference to the project object (Project.Project) 30 @param project reference to the project object (Project.Project)
31 @param parent reference to the parent object (QWidget) 31 @param parent reference to the parent object (QWidget)
32 """ 32 """
33 E5Led.__init__(self, parent, shape=E5LedRectangular, rectRatio=1.0) 33 super(StatusMonitorLed, self).__init__(
34 parent, shape=E5LedRectangular, rectRatio=1.0)
34 35
36 self.__vcsClean = True
35 self.project = project 37 self.project = project
38
36 self.vcsMonitorLedColors = { 39 self.vcsMonitorLedColors = {
37 "off": QColor(Qt.lightGray), 40 "off": QColor(Qt.lightGray),
38 "ok": QColor(Qt.green), 41 "ok": QColor(Qt.green),
39 "nok": QColor(Qt.red), 42 "nok": QColor(Qt.red),
40 "op": QColor(Qt.yellow), 43 "op": QColor(Qt.yellow),
42 "wait": QColor(Qt.cyan), 45 "wait": QColor(Qt.cyan),
43 "timeout": QColor(Qt.darkRed) 46 "timeout": QColor(Qt.darkRed)
44 } 47 }
45 self.__on = False 48 self.__on = False
46 49
47 self.setWhatsThis(self.trUtf8( 50 self.setWhatsThis(self.tr(
48 """<p>This LED indicates the operating""" 51 """<p>This LED indicates the operating"""
49 """ status of the VCS monitor thread (off = monitoring off,""" 52 """ status of the VCS monitor thread (off = monitoring off,"""
50 """ green = monitoring on and ok, red = monitoring on, but""" 53 """ green = monitoring on and ok, red = monitoring on, but"""
51 """ not ok, yellow = checking VCS status). A status description""" 54 """ not ok, yellow = checking VCS status). A status description"""
52 """ is given in the tooltip.</p>""" 55 """ is given in the tooltip.</p>"""
53 )) 56 ))
54 self.setToolTip( 57 self.setToolTip(
55 self.trUtf8("Repository status checking is switched off") 58 self.tr("Repository status checking is switched off")
56 ) 59 )
57 self.setColor(self.vcsMonitorLedColors["off"]) 60 self.setColor(self.vcsMonitorLedColors["off"])
58 61
59 # define a context menu 62 # define a context menu
60 self.__menu = QMenu(self) 63 self.__menu = QMenu(self)
61 self.__checkAct = self.__menu.addAction( 64 self.__checkAct = self.__menu.addAction(
62 self.trUtf8("Check status"), self.__checkStatus) 65 self.tr("Check status"), self.__checkStatus)
63 self.__intervalAct = self.__menu.addAction( 66 self.__intervalAct = self.__menu.addAction(
64 self.trUtf8("Set interval..."), self.__setInterval) 67 self.tr("Set interval..."), self.__setInterval)
65 self.__menu.addSeparator() 68 self.__menu.addSeparator()
66 self.__onAct = self.__menu.addAction( 69 self.__onAct = self.__menu.addAction(
67 self.trUtf8("Switch on"), self.__switchOn) 70 self.tr("Switch on"), self.__switchOn)
68 self.__offAct = self.__menu.addAction( 71 self.__offAct = self.__menu.addAction(
69 self.trUtf8("Switch off"), self.__switchOff) 72 self.tr("Switch off"), self.__switchOff)
70 self.__checkActions() 73 self.__checkActions()
71 74
72 # connect signals to our slots 75 # connect signals to our slots
73 self.setContextMenuPolicy(Qt.CustomContextMenu) 76 self.setContextMenuPolicy(Qt.CustomContextMenu)
74 self.customContextMenuRequested.connect(self._showContextMenu) 77 self.customContextMenuRequested.connect(self._showContextMenu)
75 self.project.vcsStatusMonitorStatus.connect( 78 self.project.vcsStatusMonitorStatus.connect(
76 self.__projectVcsMonitorStatus) 79 self.__projectVcsMonitorStatus)
80 self.project.getModel().vcsStateChanged.connect(self.__vcsStateChanged)
81 self.clicked.connect(self.__ledClicked)
77 82
78 def __checkActions(self): 83 def __checkActions(self):
79 """ 84 """
80 Private method to set the enabled status of the context menu actions. 85 Private method to set the enabled status of the context menu actions.
81 """ 86 """
125 """ 130 """
126 Private slot to change the status check interval. 131 Private slot to change the status check interval.
127 """ 132 """
128 interval, ok = QInputDialog.getInt( 133 interval, ok = QInputDialog.getInt(
129 None, 134 None,
130 self.trUtf8("VCS Status Monitor"), 135 self.tr("VCS Status Monitor"),
131 self.trUtf8("Enter monitor interval [s]"), 136 self.tr("Enter monitor interval [s]"),
132 self.project.getStatusMonitorInterval(), 137 self.project.getStatusMonitorInterval(),
133 0, 3600, 1) 138 0, 3600, 1)
134 if ok: 139 if ok:
135 self.project.setStatusMonitorInterval(interval) 140 self.project.setStatusMonitorInterval(interval)
136 141
143 def __switchOff(self): 148 def __switchOff(self):
144 """ 149 """
145 Private slot to switch the status monitor thread to Off. 150 Private slot to switch the status monitor thread to Off.
146 """ 151 """
147 self.project.stopStatusMonitor() 152 self.project.stopStatusMonitor()
153
154 def __vcsStateChanged(self, state):
155 """
156 Private slot to handle a change in the vcs state.
157
158 @param state new vcs state (string)
159 """
160 self.__vcsClean = state == " "
161
162 def __ledClicked(self, pos):
163 """
164 Private slot to react upon clicks on the LED.
165
166 @param pos position of the click (QPoint)
167 """
168 if self.__on:
169 vcs = self.project.getVcs()
170 if vcs:
171 if self.__vcsClean:
172 # call log browser dialog
173 vcs.vcsLogBrowser(self.project.getProjectPath())
174 else:
175 # call status dialog
176 vcs.vcsStatus(self.project.getProjectPath())

eric ide

mercurial