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