WebBrowser/WebBrowserTabWidget.py

changeset 5113
d394e20f7467
parent 5039
200f12184a43
child 5181
1948b27d7b21
--- a/WebBrowser/WebBrowserTabWidget.py	Thu Aug 25 17:21:25 2016 +0200
+++ b/WebBrowser/WebBrowserTabWidget.py	Fri Aug 26 18:56:54 2016 +0200
@@ -12,7 +12,7 @@
 import os
 
 from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QUrl, QFile
-from PyQt5.QtGui import QIcon
+from PyQt5.QtGui import QIcon, QPixmap, QPainter
 from PyQt5.QtWidgets import QWidget, QHBoxLayout, QMenu, QToolButton, QDialog
 from PyQt5.QtPrintSupport import QPrinter, QPrintDialog
 
@@ -21,6 +21,7 @@
 from E5Gui.E5Application import e5App
 
 from .WebBrowserView import WebBrowserView
+from .WebBrowserPage import WebBrowserPage
 from .Tools import WebBrowserTools
 from . import WebInspector
 
@@ -189,6 +190,12 @@
                 UI.PixmapCache.getIcon("printPdf.png"),
                 self.tr('Print as PDF'), self.__tabContextMenuPrintPdf)
         self.__tabContextMenu.addSeparator()
+        if hasattr(WebBrowserPage, "isAudioMuted"):
+            self.__audioAct = self.__tabContextMenu.addAction(
+                "", self.__tabContextMenuAudioMute)
+            self.__tabContextMenu.addSeparator()
+        else:
+            self.__audioAct = None
         self.__tabContextMenu.addAction(
             UI.PixmapCache.getIcon("reload.png"),
             self.tr('Reload All'), self.reloadAllBrowsers)
@@ -230,6 +237,17 @@
             
             self.tabContextCloseOthersAct.setEnabled(self.count() > 1)
             
+            if self.__audioAct is not None:
+                if self.widget(self.__tabContextMenuIndex).page()\
+                        .isAudioMuted():
+                    self.__audioAct.setText(self.tr("Unmute Tab"))
+                    self.__audioAct.setIcon(
+                        UI.PixmapCache.getIcon("audioVolumeHigh.png"))
+                else:
+                    self.__audioAct.setText(self.tr("Mute Tab"))
+                    self.__audioAct.setIcon(
+                        UI.PixmapCache.getIcon("audioVolumeMuted.png"))
+            
             self.__tabContextMenu.popup(coord)
     
     def __tabContextMenuMoveLeft(self):
@@ -295,6 +313,49 @@
         browser = self.widget(self.__tabContextMenuIndex)
         self.printPreviewBrowser(browser)
     
+    def __tabContextMenuAudioMute(self):
+        """
+        Private method to mute or unmute the selected tab.
+        """
+        page = self.widget(self.__tabContextMenuIndex).page()
+        muted = page.isAudioMuted()
+        page.setAudioMuted(not muted)
+    
+    @pyqtSlot(bool)
+    def __recentlyAudibleChanged(self, recentlyAudible):
+        """
+        Private slot to react on the audible state of a page.
+        
+        @param recentlyAudible flag indicating the new audible state
+        @type bool
+        """
+        page = self.sender()
+        if page is None:
+            return
+        
+        browser = page.view()
+        if browser is None:
+            return
+        
+        index = self.indexOf(browser)
+        icon = page.icon()
+        
+        if page.isAudioMuted() or (
+                not page.isAudioMuted() and recentlyAudible):
+            pix = QPixmap(32, 32)
+            pix.fill(Qt.transparent)
+            painter = QPainter(pix)
+            icon.paint(painter, 0, 0, 22, 22)
+            if page.isAudioMuted():
+                audioIcon = UI.PixmapCache.getIcon("audioMuted.png")
+            else:
+                audioIcon = UI.PixmapCache.getIcon("audioPlaying.png")
+            audioIcon.paint(painter, 13, 13, 18, 18)
+            painter.end()
+            self.setTabIcon(index, QIcon(pix))
+        else:
+            self.setTabIcon(index, icon)
+    
     @pyqtSlot()
     def __newBrowser(self):
         """
@@ -357,6 +418,9 @@
         browser.page().windowCloseRequested.connect(
             self.__windowCloseRequested)
         browser.zoomValueChanged.connect(self.browserZoomValueChanged)
+        if hasattr(WebBrowserPage, "recentlyAudibleChanged"):
+            browser.page().recentlyAudibleChanged.connect(
+                self.__recentlyAudibleChanged)
         
         if position == -1:
             index = self.addTab(browser, self.tr("..."))

eric ide

mercurial