src/eric7/VCS/StatusMonitorLed.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8881
54e42bc2437a
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2007 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a LED to indicate the status of the VCS status monitor
8 thread.
9 """
10
11 from PyQt6.QtCore import Qt
12 from PyQt6.QtGui import QColor
13 from PyQt6.QtWidgets import QWidget, QInputDialog, QMenu, QHBoxLayout, QLabel
14
15 from EricWidgets.EricLed import EricClickableLed, EricLedType
16
17 import Preferences
18
19
20 class StatusMonitorLed(EricClickableLed):
21 """
22 Class implementing a LED to indicate the status of the VCS status monitor
23 thread.
24 """
25 def __init__(self, project, parent):
26 """
27 Constructor
28
29 @param project reference to the project object (Project.Project)
30 @param parent reference to the parent object (QWidget)
31 """
32 super().__init__(
33 parent, shape=EricLedType.RECTANGULAR, rectRatio=1.0)
34
35 self.__vcsClean = True
36 self.project = project
37
38 self.vcsMonitorLedColors = {
39 "off": QColor(Qt.GlobalColor.lightGray),
40 "ok": QColor(Qt.GlobalColor.green),
41 "nok": QColor(Qt.GlobalColor.red),
42 "op": QColor(Qt.GlobalColor.yellow),
43 "send": QColor(Qt.GlobalColor.blue),
44 "wait": QColor(Qt.GlobalColor.cyan),
45 "timeout": QColor(Qt.GlobalColor.darkRed)
46 }
47 self.__on = False
48
49 self.setWhatsThis(self.tr(
50 """<p>This LED indicates the operating"""
51 """ status of the VCS monitor thread (off = monitoring off,"""
52 """ green = monitoring on and ok, red = monitoring on, but"""
53 """ not ok, yellow = checking VCS status). A status description"""
54 """ is given in the tooltip.</p>"""
55 ))
56 self.setToolTip(
57 self.tr("Repository status checking is switched off")
58 )
59 self.setColor(self.vcsMonitorLedColors["off"])
60
61 # define a context menu
62 self.__menu = QMenu(self)
63 self.__checkAct = self.__menu.addAction(
64 self.tr("Check status"), self.__checkStatus)
65 self.__intervalAct = self.__menu.addAction(
66 self.tr("Set interval..."), self.__setInterval)
67 self.__menu.addSeparator()
68 self.__onAct = self.__menu.addAction(
69 self.tr("Switch on"), self.__switchOn)
70 self.__offAct = self.__menu.addAction(
71 self.tr("Switch off"), self.__switchOff)
72 self.__checkActions()
73
74 # connect signals to our slots
75 self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
76 self.customContextMenuRequested.connect(self._showContextMenu)
77 self.project.vcsStatusMonitorStatus.connect(
78 self.__projectVcsMonitorStatus)
79 self.project.getModel().vcsStateChanged.connect(self.__vcsStateChanged)
80 self.clicked.connect(self.__ledClicked)
81
82 def __checkActions(self):
83 """
84 Private method to set the enabled status of the context menu actions.
85 """
86 vcsStatusMonitorInterval = (
87 self.project.pudata["VCSSTATUSMONITORINTERVAL"]
88 if self.project.pudata["VCSSTATUSMONITORINTERVAL"] else
89 Preferences.getVCS("StatusMonitorInterval")
90 )
91 self.__checkAct.setEnabled(self.__on)
92 self.__intervalAct.setEnabled(self.__on)
93 self.__onAct.setEnabled(
94 (not self.__on) and vcsStatusMonitorInterval > 0)
95 self.__offAct.setEnabled(self.__on)
96
97 def __projectVcsMonitorStatus(self, status, statusMsg):
98 """
99 Private method to receive the status monitor status.
100
101 @param status status of the monitoring thread (string, ok, nok or off)
102 @param statusMsg explanotory text for the signaled status (string)
103 """
104 self.setColor(self.vcsMonitorLedColors[status])
105 self.setToolTip(statusMsg)
106
107 self.__on = status != 'off'
108
109 def _showContextMenu(self, coord):
110 """
111 Protected slot to show the context menu.
112
113 @param coord the position of the mouse pointer (QPoint)
114 """
115 if not self.project.isOpen():
116 return
117
118 self.__checkActions()
119 self.__menu.popup(self.mapToGlobal(coord))
120
121 def __checkStatus(self):
122 """
123 Private slot to initiate a new status check.
124 """
125 self.project.checkVCSStatus()
126
127 def __setInterval(self):
128 """
129 Private slot to change the status check interval.
130 """
131 interval, ok = QInputDialog.getInt(
132 None,
133 self.tr("VCS Status Monitor"),
134 self.tr("Enter monitor interval [s]"),
135 self.project.getStatusMonitorInterval(),
136 0, 3600, 1)
137 if ok:
138 self.project.setStatusMonitorInterval(interval)
139
140 def __switchOn(self):
141 """
142 Private slot to switch the status monitor thread to On.
143 """
144 self.project.startStatusMonitor()
145
146 def __switchOff(self):
147 """
148 Private slot to switch the status monitor thread to Off.
149 """
150 self.project.stopStatusMonitor()
151
152 def __vcsStateChanged(self, state):
153 """
154 Private slot to handle a change in the vcs state.
155
156 @param state new vcs state (string)
157 """
158 self.__vcsClean = state == " "
159
160 def __ledClicked(self, pos):
161 """
162 Private slot to react upon clicks on the LED.
163
164 @param pos position of the click (QPoint)
165 """
166 if self.__on:
167 vcs = self.project.getVcs()
168 if vcs:
169 if self.__vcsClean:
170 # call log browser dialog
171 vcs.vcsLogBrowser(self.project.getProjectPath())
172 else:
173 # call status dialog
174 vcs.vcsStatus(self.project.getProjectPath())
175
176
177 class StatusMonitorLedWidget(QWidget):
178 """
179 Class implementing a widget containing a LED to indicate the status of the
180 VCS status monitor thread and a short info message.
181 """
182 def __init__(self, project, parent):
183 """
184 Constructor
185
186 @param project reference to the project object
187 @type Project.Project
188 @param parent reference to the parent object
189 @type QWidget
190 """
191 super().__init__(parent)
192
193 self.__layout = QHBoxLayout(self)
194 self.__layout.setContentsMargins(0, 0, 0, 0)
195
196 self.__led = StatusMonitorLed(project, self)
197 self.__infoLabel = QLabel(self)
198
199 self.__layout.addWidget(self.__led)
200 self.__layout.addWidget(self.__infoLabel)
201
202 self.__projectVcsStatusMonitorInfo("")
203
204 project.vcsStatusMonitorInfo.connect(
205 self.__projectVcsStatusMonitorInfo)
206
207 def __projectVcsStatusMonitorInfo(self, info):
208 """
209 Private slot handling the receipt of an info message.
210
211 @param info received info message
212 @type str
213 """
214 self.__infoLabel.setVisible(bool(info))
215 self.__infoLabel.setText(info)

eric ide

mercurial