src/eric7/WebBrowser/Network/ProtocolHandlerManagerDialog.py

Sat, 23 Dec 2023 15:48:12 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 23 Dec 2023 15:48:12 +0100
branch
eric7
changeset 10439
21c28b0f9e41
parent 10373
093dcebe5ecb
child 11090
f5f5f5803935
permissions
-rw-r--r--

Updated copyright for 2024.

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

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

"""
Module implementing a dialog to manage registered protocol handlers.
"""

from PyQt6.QtCore import Qt, pyqtSlot
from PyQt6.QtWidgets import QDialog, QTreeWidgetItem

from .Ui_ProtocolHandlerManagerDialog import Ui_ProtocolHandlerManagerDialog


class ProtocolHandlerManagerDialog(QDialog, Ui_ProtocolHandlerManagerDialog):
    """
    Class implementing a dialog to manage registered protocol handlers.
    """

    def __init__(self, manager, parent=None):
        """
        Constructor

        @param manager reference to the protocol handlers manager object
        @type ProtocolHandlerManager
        @param parent reference to the parent widget
        @type QWidget
        """
        super().__init__(parent)
        self.setupUi(self)
        self.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)

        self.__manager = manager
        handlers = self.__manager.protocolHandlers()
        for scheme in sorted(handlers):
            QTreeWidgetItem(
                self.protocolHandlersList, [scheme, handlers[scheme].toString()]
            )

        self.on_protocolHandlersList_itemSelectionChanged()

    @pyqtSlot()
    def on_protocolHandlersList_itemSelectionChanged(self):
        """
        Private slot handling a change of the selection.
        """
        self.deleteButton.setEnabled(
            len(self.protocolHandlersList.selectedItems()) == 1
        )

    @pyqtSlot()
    def on_deleteButton_clicked(self):
        """
        Private slot to delete the selected protocol handler.
        """
        itm = self.protocolHandlersList.selectedItems()[0]
        self.__manager.removeProtocolHandler(itm.text(0))

        self.protocolHandlersList.takeTopLevelItem(
            self.protocolHandlersList.indexOfTopLevelItem(itm)
        )
        del itm

eric ide

mercurial