eric6/WebBrowser/UrlBar/FavIconLabel.py

Sat, 31 Aug 2019 12:58:11 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 31 Aug 2019 12:58:11 +0200
branch
without_py2_and_pyqt4
changeset 7192
a22eee00b052
parent 6942
2602857055c5
child 7229
53054eb5b15a
permissions
-rw-r--r--

Started removing runtime support for Python2 and PyQt4.

653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
6645
ad476851d7e0 Updated copyright for 2019.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
3 # Copyright (c) 2010 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the label to show the web site icon.
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3057
diff changeset
10 from __future__ import unicode_literals
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
11
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
12 from PyQt5.QtCore import Qt, QPoint, QMimeData
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
13 from PyQt5.QtGui import QDrag, QPixmap
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
14 from PyQt5.QtWidgets import QLabel, QApplication
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
16
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 class FavIconLabel(QLabel):
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 Class implementing the label to show the web site icon.
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
21 def __init__(self, parent=None):
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 Constructor
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 @param parent reference to the parent widget (QWidget)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
27 super(FavIconLabel, self).__init__(parent)
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 self.__browser = None
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 self.__dragStartPos = QPoint()
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 self.setFocusPolicy(Qt.NoFocus)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 self.setCursor(Qt.ArrowCursor)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 self.setMinimumSize(16, 16)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 self.resize(16, 16)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 self.__browserIconChanged()
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 def __browserIconChanged(self):
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 Private slot to set the icon.
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 """
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
43 if self.__browser:
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
44 self.setPixmap(
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
45 self.__browser.icon().pixmap(16, 16))
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46
1539
b2d98c2e2e43 Fixed the icon handling in the help viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
47 def __clearIcon(self):
b2d98c2e2e43 Fixed the icon handling in the help viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
48 """
b2d98c2e2e43 Fixed the icon handling in the help viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
49 Private slot to clear the icon.
b2d98c2e2e43 Fixed the icon handling in the help viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
50 """
b2d98c2e2e43 Fixed the icon handling in the help viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
51 self.setPixmap(QPixmap())
b2d98c2e2e43 Fixed the icon handling in the help viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
52
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 def setBrowser(self, browser):
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 Public method to set the browser connection.
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 @param browser reference to the browser widegt (HelpBrowser)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 self.__browser = browser
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 self.__browser.loadFinished.connect(self.__browserIconChanged)
5039
200f12184a43 Renamed the iconChanged signal of WebBrowserView to faviconChanged in order to get rid of a name clash with Qt 5.7+.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4726
diff changeset
61 self.__browser.faviconChanged.connect(self.__browserIconChanged)
1539
b2d98c2e2e43 Fixed the icon handling in the help viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
62 self.__browser.loadStarted.connect(self.__clearIcon)
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 def mousePressEvent(self, evt):
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 Protected method to handle mouse press events.
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 @param evt reference to the mouse event (QMouseEvent)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 if evt.button() == Qt.LeftButton:
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 self.__dragStartPos = evt.pos()
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
72 super(FavIconLabel, self).mousePressEvent(evt)
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73
6695
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
74 def mouseReleaseEvent(self, evt):
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
75 """
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
76 Protected method to handle mouse release events.
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
77
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
78 @param evt reference to the mouse event (QMouseEvent)
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
79 """
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
80 if evt.button() == Qt.LeftButton:
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
81 self.__showPopup(evt.globalPos())
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
82 super(FavIconLabel, self).mouseReleaseEvent(evt)
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
83
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 def mouseMoveEvent(self, evt):
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 Protected method to handle mouse move events.
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 @param evt reference to the mouse event (QMouseEvent)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 if evt.button() == Qt.LeftButton and \
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 (evt.pos() - self.__dragStartPos).manhattanLength() > \
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 QApplication.startDragDistance() and \
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 self.__browser is not None:
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 drag = QDrag(self)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 mimeData = QMimeData()
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 title = self.__browser.title()
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 if title == "":
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
98 title = str(self.__browser.url().toEncoded(), encoding="utf-8")
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 mimeData.setText(title)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 mimeData.setUrls([self.__browser.url()])
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 p = self.pixmap()
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 if p:
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 drag.setPixmap(p)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 drag.setMimeData(mimeData)
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 drag.exec_()
6695
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
106
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
107 def __showPopup(self, pos):
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
108 """
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
109 Private method to show the site info popup.
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
110
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
111 @param pos position the popup should be shown at
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
112 @type QPoint
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
113 """
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
114 if self.__browser is None:
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
115 return
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
116
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
117 url = self.__browser.url()
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
118 if url.isValid() and url.scheme() not in [
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
119 "eric", "about", "data", "chrome"]:
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
120 from ..SiteInfo.SiteInfoWidget import SiteInfoWidget
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
121 info = SiteInfoWidget(self.__browser, self)
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
122 info.showAt(pos)

eric ide

mercurial