WebBrowser/Download/DownloadManagerButton.py

changeset 6134
cb0985e8da91
child 6645
ad476851d7e0
diff -r eba07240fac1 -r cb0985e8da91 WebBrowser/Download/DownloadManagerButton.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WebBrowser/Download/DownloadManagerButton.py	Sun Feb 11 16:04:47 2018 +0100
@@ -0,0 +1,65 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2018 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing a tool button for the download manager.
+"""
+
+from __future__ import unicode_literals
+
+from PyQt5.QtCore import pyqtSlot, Qt
+
+from E5Gui.E5ToolButton import E5ToolButton
+
+import UI.PixmapCache
+
+from WebBrowser.WebBrowserWindow import WebBrowserWindow
+
+
+class DownloadManagerButton(E5ToolButton):
+    """
+    Class implementing a tool button for the download manager.
+    """
+    def __init__(self, parent=None):
+        """
+        Constructor
+        
+        @param parent reference to the parent widget
+        @type QWidget
+        """
+        super(DownloadManagerButton, self).__init__(parent)
+        
+        self.__manager = WebBrowserWindow.downloadManager()
+        
+        self.setObjectName("navigation_download_manager_button")
+        self.setIcon(UI.PixmapCache.getIcon("downloads.png"))
+        self.setToolTip(self.tr("Open Download Manager"))
+        self.setToolButtonStyle(Qt.ToolButtonIconOnly)
+        self.setFocusPolicy(Qt.NoFocus)
+        self.setAutoRaise(True)
+        
+        self.clicked.connect(self.__buttonClicked)
+        self.__manager.downloadsCountChanged.connect(self.__updateState)
+        
+        self.__updateState()
+    
+    @pyqtSlot()
+    def __buttonClicked(self):
+        """
+        Private slot handling a user clicking the button.
+        """
+        self.__manager.show()
+    
+    @pyqtSlot()
+    def __updateState(self):
+        """
+        Private slot to update the button state.
+        """
+        self.setVisible(bool(self.__manager.downloadsCount()))
+        count = self.__manager.activeDownloadsCount()
+        if bool(count):
+            self.setBadgeText(str(count))
+        else:
+            self.setBadgeText("")

eric ide

mercurial