VCS/StatusMonitorLed.py

Sat, 07 Apr 2012 21:19:24 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 07 Apr 2012 21:19:24 +0200
changeset 1770
c17e67e69ef5
parent 1509
c0b5e693b0eb
child 2092
987aa24ec704
permissions
-rw-r--r--

Added a tool to take screenshots (fullscreen or rectangular selection).

# -*- coding: utf-8 -*-

# Copyright (c) 2007 - 2012 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a LED to indicate the status of the VCS status monitor thread.
"""

from PyQt4.QtCore import Qt
from PyQt4.QtGui import QColor, QInputDialog, QMenu

from E5Gui.E5Led import E5Led, E5LedRectangular

import Preferences


class StatusMonitorLed(E5Led):
    """
    Class implementing a LED to indicate the status of the VCS status monitor thread.
    """
    def __init__(self, project, parent):
        """
        Constructor
        
        @param project reference to the project object (Project.Project)
        @param parent reference to the parent object (QWidget)
        """
        E5Led.__init__(self, parent, shape=E5LedRectangular, rectRatio=1.0)
        
        self.project = project
        self.vcsMonitorLedColors = {
            "off": QColor(Qt.lightGray),
            "ok": QColor(Qt.green),
            "nok": QColor(Qt.red),
            "op": QColor(Qt.yellow),
            "send": QColor(Qt.blue),
            "wait": QColor(Qt.cyan),
            "timeout": QColor(Qt.darkRed)
        }
        self.__on = False
        
        self.setWhatsThis(self.trUtf8(
            """<p>This LED indicates the operating"""
            """ status of the VCS monitor thread (off = monitoring off,"""
            """ green = monitoring on and ok, red = monitoring on, but not ok,"""
            """ yellow = checking VCS status). A status description is given"""
            """ in the tooltip.</p>"""
        ))
        self.setToolTip(
            self.trUtf8("Repository status checking is switched off")
        )
        self.setColor(self.vcsMonitorLedColors["off"])
        
        # define a context menu
        self.__menu = QMenu(self)
        self.__checkAct = \
            self.__menu.addAction(self.trUtf8("Check status"), self.__checkStatus)
        self.__intervalAct = \
            self.__menu.addAction(self.trUtf8("Set interval..."), self.__setInterval)
        self.__menu.addSeparator()
        self.__onAct = \
            self.__menu.addAction(self.trUtf8("Switch on"), self.__switchOn)
        self.__offAct = \
            self.__menu.addAction(self.trUtf8("Switch off"), self.__switchOff)
        self.__checkActions()
        
        # connect signals to our slots
        self.setContextMenuPolicy(Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(self._showContextMenu)
        self.project.vcsStatusMonitorStatus.connect(self.__projectVcsMonitorStatus)
    
    def __checkActions(self):
        """
        Private method to set the enabled status of the context menu actions.
        """
        if self.project.pudata["VCSSTATUSMONITORINTERVAL"]:
            vcsStatusMonitorInterval = self.project.pudata["VCSSTATUSMONITORINTERVAL"][0]
        else:
            vcsStatusMonitorInterval = Preferences.getVCS("StatusMonitorInterval")
        self.__checkAct.setEnabled(self.__on)
        self.__intervalAct.setEnabled(self.__on)
        self.__onAct.setEnabled((not self.__on) and vcsStatusMonitorInterval > 0)
        self.__offAct.setEnabled(self.__on)
        
    def __projectVcsMonitorStatus(self, status, statusMsg):
        """
        Private method to receive the status monitor status.
        
        @param status status of the monitoring thread (string, ok, nok or off)
        @param statusMsg explanotory text for the signaled status (string)
        """
        self.setColor(self.vcsMonitorLedColors[status])
        self.setToolTip(statusMsg)
        
        self.__on = status != 'off'
    
    def _showContextMenu(self, coord):
        """
        Protected slot to show the context menu.
        
        @param coord the position of the mouse pointer (QPoint)
        """
        if not self.project.isOpen():
            return
        
        self.__checkActions()
        self.__menu.popup(self.mapToGlobal(coord))
    
    def __checkStatus(self):
        """
        Private slot to initiate a new status check.
        """
        self.project.checkVCSStatus()
    
    def __setInterval(self):
        """
        Private slot to change the status check interval.
        """
        interval,  ok = QInputDialog.getInteger(
            None,
            self.trUtf8("VCS Status Monitor"),
            self.trUtf8("Enter monitor interval [s]"),
            self.project.getStatusMonitorInterval(),
            0, 3600, 1)
        if ok:
            self.project.setStatusMonitorInterval(interval)
    
    def __switchOn(self):
        """
        Private slot to switch the status monitor thread to On.
        """
        self.project.startStatusMonitor()
    
    def __switchOff(self):
        """
        Private slot to switch the status monitor thread to Off.
        """
        self.project.stopStatusMonitor()

eric ide

mercurial