eric6/WebBrowser/Tools/WebIconDialog.py

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

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:44 +0100
branch
maintenance
changeset 7924
8a96736d465e
parent 7781
607a6098cb44
child 8143
2c730d5fd177
permissions
-rw-r--r--

Updated copyright for 2021.

4820
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7924
8a96736d465e Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
3 # Copyright (c) 2016 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4820
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog to manage the Favicons.
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from PyQt5.QtCore import pyqtSlot, Qt, QPoint
4821
0ce09efa00da Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
11 from PyQt5.QtWidgets import QDialog, QListWidgetItem, QMenu
4820
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from .Ui_WebIconDialog import Ui_WebIconDialog
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 class WebIconDialog(QDialog, Ui_WebIconDialog):
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 """
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 Class implementing a dialog to manage the Favicons.
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 """
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 def __init__(self, iconsDB, parent=None):
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 Constructor
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 @param iconsDB icons database
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 @type dict
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 @param parent reference to the parent widget
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 @type QWidget
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 super(WebIconDialog, self).__init__(parent)
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 self.setupUi(self)
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 for url, icon in iconsDB.items():
4821
0ce09efa00da Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
33 QListWidgetItem(icon, url, self.iconsList)
0ce09efa00da Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
34 self.iconsList.sortItems(Qt.AscendingOrder)
4820
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 self.__setRemoveButtons()
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 def __setRemoveButtons(self):
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 Private method to set the state of the 'remove' buttons.
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 """
4821
0ce09efa00da Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
42 self.removeAllButton.setEnabled(self.iconsList.count() > 0)
4820
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 self.removeButton.setEnabled(len(self.iconsList.selectedItems()) > 0)
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 @pyqtSlot(QPoint)
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 def on_iconsList_customContextMenuRequested(self, pos):
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 """
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 Private slot to show the context menu.
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 @param pos cursor position
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 @type QPoint
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 """
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 menu = QMenu()
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 menu.addAction(
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 self.tr("Remove Selected"),
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 self.on_removeButton_clicked).setEnabled(
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 len(self.iconsList.selectedItems()) > 0)
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 menu.addAction(
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 self.tr("Remove All"),
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 self.on_removeAllButton_clicked).setEnabled(
4821
0ce09efa00da Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
61 self.iconsList.count() > 0)
4820
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
63 menu.exec(self.iconsList.mapToGlobal(pos))
4820
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 @pyqtSlot()
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 def on_iconsList_itemSelectionChanged(self):
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 """
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 Private slot handling the selection of entries.
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 """
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 self.__setRemoveButtons()
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 @pyqtSlot()
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 def on_removeButton_clicked(self):
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 """
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 Private slot to remove the selected items.
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 """
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 for itm in self.iconsList.selectedItems():
4821
0ce09efa00da Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
78 row = self.iconsList.row(itm)
0ce09efa00da Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
79 self.iconsList.takeItem(row)
4820
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 del itm
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 @pyqtSlot()
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 def on_removeAllButton_clicked(self):
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 """
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 Private slot to remove all entries.
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 """
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 self.iconsList.clear()
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 def getUrls(self):
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 """
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 Public method to get the list of URLs.
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 @return list of URLs
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 @rtype list of str
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 """
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 urls = []
4821
0ce09efa00da Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
97 for row in range(self.iconsList.count()):
0ce09efa00da Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4820
diff changeset
98 urls.append(self.iconsList.item(row).text())
4820
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99
f38e4fb83ecd Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 return urls

eric ide

mercurial