src/eric7/VCS/StatusMonitorLed.py

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

eric ide

mercurial