eric7/WebBrowser/Tools/WebIconDialog.py

branch
eric7
changeset 8312
800c432b34c8
parent 8218
7c09585bd960
child 8318
962bce857696
diff -r 4e8b98454baa -r 800c432b34c8 eric7/WebBrowser/Tools/WebIconDialog.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/eric7/WebBrowser/Tools/WebIconDialog.py	Sat May 15 18:45:04 2021 +0200
@@ -0,0 +1,100 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2016 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing a dialog to manage the Favicons.
+"""
+
+from PyQt5.QtCore import pyqtSlot, Qt, QPoint
+from PyQt5.QtWidgets import QDialog, QListWidgetItem, QMenu
+
+from .Ui_WebIconDialog import Ui_WebIconDialog
+
+
+class WebIconDialog(QDialog, Ui_WebIconDialog):
+    """
+    Class implementing a dialog to manage the Favicons.
+    """
+    def __init__(self, iconsDB, parent=None):
+        """
+        Constructor
+        
+        @param iconsDB icons database
+        @type dict
+        @param parent reference to the parent widget
+        @type QWidget
+        """
+        super().__init__(parent)
+        self.setupUi(self)
+        
+        for url, icon in iconsDB.items():
+            QListWidgetItem(icon, url, self.iconsList)
+        self.iconsList.sortItems(Qt.SortOrder.AscendingOrder)
+        
+        self.__setRemoveButtons()
+    
+    def __setRemoveButtons(self):
+        """
+        Private method to set the state of the 'remove' buttons.
+        """
+        self.removeAllButton.setEnabled(self.iconsList.count() > 0)
+        self.removeButton.setEnabled(len(self.iconsList.selectedItems()) > 0)
+    
+    @pyqtSlot(QPoint)
+    def on_iconsList_customContextMenuRequested(self, pos):
+        """
+        Private slot to show the context menu.
+        
+        @param pos cursor position
+        @type QPoint
+        """
+        menu = QMenu()
+        menu.addAction(
+            self.tr("Remove Selected"),
+            self.on_removeButton_clicked).setEnabled(
+            len(self.iconsList.selectedItems()) > 0)
+        menu.addAction(
+            self.tr("Remove All"),
+            self.on_removeAllButton_clicked).setEnabled(
+            self.iconsList.count() > 0)
+        
+        menu.exec(self.iconsList.mapToGlobal(pos))
+    
+    @pyqtSlot()
+    def on_iconsList_itemSelectionChanged(self):
+        """
+        Private slot handling the selection of entries.
+        """
+        self.__setRemoveButtons()
+    
+    @pyqtSlot()
+    def on_removeButton_clicked(self):
+        """
+        Private slot to remove the selected items.
+        """
+        for itm in self.iconsList.selectedItems():
+            row = self.iconsList.row(itm)
+            self.iconsList.takeItem(row)
+            del itm
+    
+    @pyqtSlot()
+    def on_removeAllButton_clicked(self):
+        """
+        Private slot to remove all entries.
+        """
+        self.iconsList.clear()
+    
+    def getUrls(self):
+        """
+        Public method to get the list of URLs.
+        
+        @return list of URLs
+        @rtype list of str
+        """
+        urls = []
+        for row in range(self.iconsList.count()):
+            urls.append(self.iconsList.item(row).text())
+        
+        return urls

eric ide

mercurial