|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2018 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a tool button for the download manager. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import pyqtSlot, Qt |
|
13 |
|
14 from E5Gui.E5ToolButton import E5ToolButton |
|
15 |
|
16 import UI.PixmapCache |
|
17 |
|
18 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
|
19 |
|
20 |
|
21 class DownloadManagerButton(E5ToolButton): |
|
22 """ |
|
23 Class implementing a tool button for the download manager. |
|
24 """ |
|
25 def __init__(self, parent=None): |
|
26 """ |
|
27 Constructor |
|
28 |
|
29 @param parent reference to the parent widget |
|
30 @type QWidget |
|
31 """ |
|
32 super(DownloadManagerButton, self).__init__(parent) |
|
33 |
|
34 self.__manager = WebBrowserWindow.downloadManager() |
|
35 |
|
36 self.setObjectName("navigation_download_manager_button") |
|
37 self.setIcon(UI.PixmapCache.getIcon("downloads.png")) |
|
38 self.setToolTip(self.tr("Open Download Manager")) |
|
39 self.setToolButtonStyle(Qt.ToolButtonIconOnly) |
|
40 self.setFocusPolicy(Qt.NoFocus) |
|
41 self.setAutoRaise(True) |
|
42 |
|
43 self.clicked.connect(self.__buttonClicked) |
|
44 self.__manager.downloadsCountChanged.connect(self.__updateState) |
|
45 |
|
46 self.__updateState() |
|
47 |
|
48 @pyqtSlot() |
|
49 def __buttonClicked(self): |
|
50 """ |
|
51 Private slot handling a user clicking the button. |
|
52 """ |
|
53 self.__manager.show() |
|
54 |
|
55 @pyqtSlot() |
|
56 def __updateState(self): |
|
57 """ |
|
58 Private slot to update the button state. |
|
59 """ |
|
60 self.setVisible(bool(self.__manager.downloadsCount())) |
|
61 count = self.__manager.activeDownloadsCount() |
|
62 if bool(count): |
|
63 self.setBadgeText(str(count)) |
|
64 else: |
|
65 self.setBadgeText("") |