9412:45e7bb09c120 | 9413:80c06d472826 |
---|---|
8 """ | 8 """ |
9 | 9 |
10 from PyQt6.QtCore import Qt | 10 from PyQt6.QtCore import Qt |
11 from PyQt6.QtWidgets import QMenu | 11 from PyQt6.QtWidgets import QMenu |
12 | 12 |
13 from EricWidgets.EricClickableLabel import EricClickableLabel | 13 from eric7.EricWidgets.EricClickableLabel import EricClickableLabel |
14 | 14 |
15 import UI.PixmapCache | 15 from eric7.EricGui import EricPixmapCache |
16 | 16 |
17 | 17 |
18 class AdBlockIcon(EricClickableLabel): | 18 class AdBlockIcon(EricClickableLabel): |
19 """ | 19 """ |
20 Class implementing the AdBlock icon for the main window status bar. | 20 Class implementing the AdBlock icon for the main window status bar. |
51 """ | 51 """ |
52 self.__enabled = enabled | 52 self.__enabled = enabled |
53 if enabled: | 53 if enabled: |
54 self.currentChanged() | 54 self.currentChanged() |
55 else: | 55 else: |
56 self.setPixmap(UI.PixmapCache.getPixmap("adBlockPlusDisabled16")) | 56 self.setPixmap(EricPixmapCache.getPixmap("adBlockPlusDisabled16")) |
57 | 57 |
58 def __aboutToShowMenu(self): | 58 def __aboutToShowMenu(self): |
59 """ | 59 """ |
60 Private slot to show the context menu. | 60 Private slot to show the context menu. |
61 """ | 61 """ |
63 | 63 |
64 manager = self.__mw.adBlockManager() | 64 manager = self.__mw.adBlockManager() |
65 | 65 |
66 if manager.isEnabled(): | 66 if manager.isEnabled(): |
67 act = self.__menu.addAction( | 67 act = self.__menu.addAction( |
68 UI.PixmapCache.getIcon("adBlockPlusDisabled"), | 68 EricPixmapCache.getIcon("adBlockPlusDisabled"), |
69 self.tr("Disable AdBlock"), | 69 self.tr("Disable AdBlock"), |
70 ) | 70 ) |
71 act.triggered.connect(lambda: self.__enableAdBlock(False)) | 71 act.triggered.connect(lambda: self.__enableAdBlock(False)) |
72 else: | 72 else: |
73 act = self.__menu.addAction( | 73 act = self.__menu.addAction( |
74 UI.PixmapCache.getIcon("adBlockPlus"), self.tr("Enable AdBlock") | 74 EricPixmapCache.getIcon("adBlockPlus"), self.tr("Enable AdBlock") |
75 ) | 75 ) |
76 act.triggered.connect(lambda: self.__enableAdBlock(True)) | 76 act.triggered.connect(lambda: self.__enableAdBlock(True)) |
77 self.__menu.addSeparator() | 77 self.__menu.addSeparator() |
78 if manager.isEnabled() and self.__mw.currentBrowser().url().host(): | 78 if manager.isEnabled() and self.__mw.currentBrowser().url().host(): |
79 if self.__isCurrentHostExcepted(): | 79 if self.__isCurrentHostExcepted(): |
80 act = self.__menu.addAction( | 80 act = self.__menu.addAction( |
81 UI.PixmapCache.getIcon("adBlockPlus"), | 81 EricPixmapCache.getIcon("adBlockPlus"), |
82 self.tr("Remove AdBlock Exception"), | 82 self.tr("Remove AdBlock Exception"), |
83 ) | 83 ) |
84 act.triggered.connect(lambda: self.__setException(False)) | 84 act.triggered.connect(lambda: self.__setException(False)) |
85 else: | 85 else: |
86 act = self.__menu.addAction( | 86 act = self.__menu.addAction( |
87 UI.PixmapCache.getIcon("adBlockPlusGreen"), | 87 EricPixmapCache.getIcon("adBlockPlusGreen"), |
88 self.tr("Add AdBlock Exception"), | 88 self.tr("Add AdBlock Exception"), |
89 ) | 89 ) |
90 act.triggered.connect(lambda: self.__setException(True)) | 90 act.triggered.connect(lambda: self.__setException(True)) |
91 self.__menu.addAction( | 91 self.__menu.addAction( |
92 UI.PixmapCache.getIcon("adBlockPlusGreen"), | 92 EricPixmapCache.getIcon("adBlockPlusGreen"), |
93 self.tr("AdBlock Exceptions..."), | 93 self.tr("AdBlock Exceptions..."), |
94 manager.showExceptionsDialog, | 94 manager.showExceptionsDialog, |
95 ) | 95 ) |
96 self.__menu.addSeparator() | 96 self.__menu.addSeparator() |
97 self.__menu.addAction( | 97 self.__menu.addAction( |
98 UI.PixmapCache.getIcon("adBlockPlus"), | 98 EricPixmapCache.getIcon("adBlockPlus"), |
99 self.tr("AdBlock Configuration..."), | 99 self.tr("AdBlock Configuration..."), |
100 manager.showDialog, | 100 manager.showDialog, |
101 ) | 101 ) |
102 | 102 |
103 def menu(self): | 103 def menu(self): |
106 | 106 |
107 @return reference to the menu | 107 @return reference to the menu |
108 @rtype QMenu | 108 @rtype QMenu |
109 """ | 109 """ |
110 if self.__enabled: | 110 if self.__enabled: |
111 self.__menu.setIcon(UI.PixmapCache.getIcon("adBlockPlus")) | 111 self.__menu.setIcon(EricPixmapCache.getIcon("adBlockPlus")) |
112 else: | 112 else: |
113 self.__menu.setIcon(UI.PixmapCache.getIcon("adBlockPlusDisabled")) | 113 self.__menu.setIcon(EricPixmapCache.getIcon("adBlockPlusDisabled")) |
114 | 114 |
115 return self.__menu | 115 return self.__menu |
116 | 116 |
117 def __showMenu(self, pos): | 117 def __showMenu(self, pos): |
118 """ | 118 """ |
152 """ | 152 """ |
153 Public slot to handle a change of the current browser tab. | 153 Public slot to handle a change of the current browser tab. |
154 """ | 154 """ |
155 if self.__enabled: | 155 if self.__enabled: |
156 if self.__isCurrentHostExcepted(): | 156 if self.__isCurrentHostExcepted(): |
157 self.setPixmap(UI.PixmapCache.getPixmap("adBlockPlusGreen16")) | 157 self.setPixmap(EricPixmapCache.getPixmap("adBlockPlusGreen16")) |
158 else: | 158 else: |
159 self.setPixmap(UI.PixmapCache.getPixmap("adBlockPlus16")) | 159 self.setPixmap(EricPixmapCache.getPixmap("adBlockPlus16")) |
160 | 160 |
161 def __setException(self, enable): | 161 def __setException(self, enable): |
162 """ | 162 """ |
163 Private slot to add or remove the current host from the list of | 163 Private slot to add or remove the current host from the list of |
164 exceptions. | 164 exceptions. |