VCS/StatusMonitorLed.py

changeset 0
de9c2efb9d02
child 6
52e8c820d0dd
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2007 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a LED to indicate the status of the VCS status monitor thread.
8 """
9
10 from PyQt4.QtCore import *
11 from PyQt4.QtGui import *
12
13 from E4Gui.E4Led import E4Led, E4LedRectangular
14
15 import Preferences
16
17 class StatusMonitorLed(E4Led):
18 """
19 Class implementing a LED to indicate the status of the VCS status monitor thread.
20 """
21 def __init__(self, project, parent):
22 """
23 Constructor
24
25 @param project reference to the project object (Project.Project)
26 @param parent reference to the parent object (QWidget)
27 """
28 E4Led.__init__(self, parent, shape = E4LedRectangular, rectRatio = 1.0)
29
30 self.project = project
31 self.vcsMonitorLedColors = {
32 "off" : QColor(Qt.lightGray),
33 "ok" : QColor(Qt.green),
34 "nok" : QColor(Qt.red),
35 "op" : QColor(Qt.yellow),
36 "send" : QColor(Qt.blue),
37 "wait" : QColor(Qt.cyan),
38 "timeout" : QColor(Qt.darkRed)
39 }
40 self.__on = False
41
42 self.setWhatsThis(self.trUtf8(
43 """<p>This LED indicates the operating"""
44 """ status of the VCS monitor thread (off = monitoring off,"""
45 """ green = monitoring on and ok, red = monitoring on, but not ok,"""
46 """ yellow = checking VCS status). A status description is given"""
47 """ in the tooltip.</p>"""
48 ))
49 self.setToolTip(\
50 self.trUtf8("Repository status checking is switched off")
51 )
52 self.setColor(self.vcsMonitorLedColors["off"])
53
54 # define a context menu
55 self.__menu = QMenu(self)
56 self.__checkAct = \
57 self.__menu.addAction(self.trUtf8("Check status"), self.__checkStatus)
58 self.__intervalAct = \
59 self.__menu.addAction(self.trUtf8("Set interval..."), self.__setInterval)
60 self.__menu.addSeparator()
61 self.__onAct = \
62 self.__menu.addAction(self.trUtf8("Switch on"), self.__switchOn)
63 self.__offAct = \
64 self.__menu.addAction(self.trUtf8("Switch off"), self.__switchOff)
65 self.__checkActions()
66
67 # connect signals to our slots
68 self.setContextMenuPolicy(Qt.CustomContextMenu)
69 self.connect(self, SIGNAL("customContextMenuRequested(const QPoint &)"),
70 self._showContextMenu)
71 self.connect(self.project, SIGNAL('vcsStatusMonitorStatus(QString, QString)'),
72 self.__projectVcsMonitorStatus)
73
74 def __checkActions(self):
75 """
76 Private method to set the enabled status of the context menu actions.
77 """
78 if self.project.pudata["VCSSTATUSMONITORINTERVAL"]:
79 vcsStatusMonitorInterval = self.project.pudata["VCSSTATUSMONITORINTERVAL"][0]
80 else:
81 vcsStatusMonitorInterval = Preferences.getVCS("StatusMonitorInterval")
82 self.__checkAct.setEnabled(self.__on)
83 self.__intervalAct.setEnabled(self.__on)
84 self.__onAct.setEnabled((not self.__on) and vcsStatusMonitorInterval > 0)
85 self.__offAct.setEnabled(self.__on)
86
87 def __projectVcsMonitorStatus(self, status, statusMsg):
88 """
89 Private method to receive the status monitor status.
90
91 @param status status of the monitoring thread (string, ok, nok or off)
92 @param statusMsg explanotory text for the signaled status (string)
93 """
94 self.setColor(self.vcsMonitorLedColors[unicode(status)])
95 self.setToolTip(statusMsg)
96
97 self.__on = status != 'off'
98
99 def _showContextMenu(self, coord):
100 """
101 Protected slot to show the context menu.
102
103 @param coord the position of the mouse pointer (QPoint)
104 """
105 if not self.project.isOpen():
106 return
107
108 self.__checkActions()
109 self.__menu.popup(self.mapToGlobal(coord))
110
111 def __checkStatus(self):
112 """
113 Private slot to initiate a new status check.
114 """
115 self.project.checkVCSStatus()
116
117 def __setInterval(self):
118 """
119 Private slot to change the status check interval.
120 """
121 interval, ok = QInputDialog.getInteger(\
122 None,
123 self.trUtf8("VCS Status Monitor"),
124 self.trUtf8("Enter monitor interval [s]"),
125 self.project.getStatusMonitorInterval(),
126 0, 3600, 1)
127 if ok:
128 self.project.setStatusMonitorInterval(interval)
129
130 def __switchOn(self):
131 """
132 Private slot to switch the status monitor thread to On.
133 """
134 self.project.startStatusMonitor()
135
136 def __switchOff(self):
137 """
138 Private slot to switch the status monitor thread to Off.
139 """
140 self.project.stopStatusMonitor()

eric ide

mercurial