eric6/WebBrowser/OpenSearch/OpenSearchEngineAction.py

Wed, 30 Dec 2020 11:00:05 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:05 +0100
changeset 7923
91e843545d9a
parent 7781
607a6098cb44
child 8218
7c09585bd960
permissions
-rw-r--r--

Updated copyright for 2021.

# -*- coding: utf-8 -*-

# Copyright (c) 2009 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a QAction subclass for open search.
"""

from PyQt5.QtCore import QUrl
from PyQt5.QtGui import QPixmap, QIcon
from PyQt5.QtWidgets import QAction


class OpenSearchEngineAction(QAction):
    """
    Class implementing a QAction subclass for open search.
    """
    def __init__(self, engine, parent=None):
        """
        Constructor
        
        @param engine reference to the open search engine object
            (OpenSearchEngine)
        @param parent reference to the parent object (QObject)
        """
        super(OpenSearchEngineAction, self).__init__(parent)
        
        self.__engine = engine
        if self.__engine.networkAccessManager() is None:
            import WebBrowser.WebBrowserWindow
            self.__engine.setNetworkAccessManager(
                WebBrowser.WebBrowserWindow.WebBrowserWindow.networkManager())
        
        self.setText(engine.name())
        self.__imageChanged()
        
        engine.imageChanged.connect(self.__imageChanged)
    
    def __imageChanged(self):
        """
        Private slot handling a change of the associated image.
        """
        image = self.__engine.image()
        if image.isNull():
            import WebBrowser.WebBrowserWindow
            self.setIcon(
                WebBrowser.WebBrowserWindow.WebBrowserWindow.icon(
                    QUrl(self.__engine.imageUrl())))
        else:
            self.setIcon(QIcon(QPixmap.fromImage(image)))

eric ide

mercurial