src/eric7/WebBrowser/Tools/WebIconDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9473
3f23dbf37dbe
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
15 15
16 class WebIconDialog(QDialog, Ui_WebIconDialog): 16 class WebIconDialog(QDialog, Ui_WebIconDialog):
17 """ 17 """
18 Class implementing a dialog to manage the Favicons. 18 Class implementing a dialog to manage the Favicons.
19 """ 19 """
20
20 def __init__(self, iconsDB, parent=None): 21 def __init__(self, iconsDB, parent=None):
21 """ 22 """
22 Constructor 23 Constructor
23 24
24 @param iconsDB icons database 25 @param iconsDB icons database
25 @type dict 26 @type dict
26 @param parent reference to the parent widget 27 @param parent reference to the parent widget
27 @type QWidget 28 @type QWidget
28 """ 29 """
29 super().__init__(parent) 30 super().__init__(parent)
30 self.setupUi(self) 31 self.setupUi(self)
31 32
32 for url, icon in iconsDB.items(): 33 for url, icon in iconsDB.items():
33 QListWidgetItem(icon, url, self.iconsList) 34 QListWidgetItem(icon, url, self.iconsList)
34 self.iconsList.sortItems(Qt.SortOrder.AscendingOrder) 35 self.iconsList.sortItems(Qt.SortOrder.AscendingOrder)
35 36
36 self.__setRemoveButtons() 37 self.__setRemoveButtons()
37 38
38 def __setRemoveButtons(self): 39 def __setRemoveButtons(self):
39 """ 40 """
40 Private method to set the state of the 'remove' buttons. 41 Private method to set the state of the 'remove' buttons.
41 """ 42 """
42 self.removeAllButton.setEnabled(self.iconsList.count() > 0) 43 self.removeAllButton.setEnabled(self.iconsList.count() > 0)
43 self.removeButton.setEnabled(len(self.iconsList.selectedItems()) > 0) 44 self.removeButton.setEnabled(len(self.iconsList.selectedItems()) > 0)
44 45
45 @pyqtSlot(QPoint) 46 @pyqtSlot(QPoint)
46 def on_iconsList_customContextMenuRequested(self, pos): 47 def on_iconsList_customContextMenuRequested(self, pos):
47 """ 48 """
48 Private slot to show the context menu. 49 Private slot to show the context menu.
49 50
50 @param pos cursor position 51 @param pos cursor position
51 @type QPoint 52 @type QPoint
52 """ 53 """
53 menu = QMenu() 54 menu = QMenu()
54 menu.addAction( 55 menu.addAction(
55 self.tr("Remove Selected"), 56 self.tr("Remove Selected"), self.on_removeButton_clicked
56 self.on_removeButton_clicked).setEnabled( 57 ).setEnabled(len(self.iconsList.selectedItems()) > 0)
57 len(self.iconsList.selectedItems()) > 0)
58 menu.addAction( 58 menu.addAction(
59 self.tr("Remove All"), 59 self.tr("Remove All"), self.on_removeAllButton_clicked
60 self.on_removeAllButton_clicked).setEnabled( 60 ).setEnabled(self.iconsList.count() > 0)
61 self.iconsList.count() > 0) 61
62
63 menu.exec(self.iconsList.mapToGlobal(pos)) 62 menu.exec(self.iconsList.mapToGlobal(pos))
64 63
65 @pyqtSlot() 64 @pyqtSlot()
66 def on_iconsList_itemSelectionChanged(self): 65 def on_iconsList_itemSelectionChanged(self):
67 """ 66 """
68 Private slot handling the selection of entries. 67 Private slot handling the selection of entries.
69 """ 68 """
70 self.__setRemoveButtons() 69 self.__setRemoveButtons()
71 70
72 @pyqtSlot() 71 @pyqtSlot()
73 def on_removeButton_clicked(self): 72 def on_removeButton_clicked(self):
74 """ 73 """
75 Private slot to remove the selected items. 74 Private slot to remove the selected items.
76 """ 75 """
77 for itm in self.iconsList.selectedItems(): 76 for itm in self.iconsList.selectedItems():
78 row = self.iconsList.row(itm) 77 row = self.iconsList.row(itm)
79 self.iconsList.takeItem(row) 78 self.iconsList.takeItem(row)
80 del itm 79 del itm
81 80
82 @pyqtSlot() 81 @pyqtSlot()
83 def on_removeAllButton_clicked(self): 82 def on_removeAllButton_clicked(self):
84 """ 83 """
85 Private slot to remove all entries. 84 Private slot to remove all entries.
86 """ 85 """
87 self.iconsList.clear() 86 self.iconsList.clear()
88 87
89 def getUrls(self): 88 def getUrls(self):
90 """ 89 """
91 Public method to get the list of URLs. 90 Public method to get the list of URLs.
92 91
93 @return list of URLs 92 @return list of URLs
94 @rtype list of str 93 @rtype list of str
95 """ 94 """
96 urls = [] 95 urls = []
97 for row in range(self.iconsList.count()): 96 for row in range(self.iconsList.count()):
98 urls.append(self.iconsList.item(row).text()) 97 urls.append(self.iconsList.item(row).text())
99 98
100 return urls 99 return urls

eric ide

mercurial