eric6/WebBrowser/UrlBar/FavIconLabel.py

Sat, 27 Feb 2021 12:08:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Feb 2021 12:08:23 +0100
changeset 8138
169e65a6787c
parent 7923
91e843545d9a
child 8143
2c730d5fd177
permissions
-rw-r--r--

Shell: added functionality to show a prompt when the main client process has exited (e.g. a script ended).

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
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
3 # Copyright (c) 2010 - 2021 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
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
10 from PyQt5.QtCore import Qt, QPoint, QMimeData
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
11 from PyQt5.QtGui import QDrag, QPixmap
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
12 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
13
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
14
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 class FavIconLabel(QLabel):
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 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
18 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
19 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
20 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 Constructor
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 @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
24 """
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
25 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
26
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 self.__browser = None
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 self.__dragStartPos = QPoint()
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 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
31 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
32 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
33 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
34
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 self.__browserIconChanged()
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 def __browserIconChanged(self):
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 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
40 """
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
41 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
42 self.setPixmap(
4726
c26e2a2dc0cb Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
43 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
44
1539
b2d98c2e2e43 Fixed the icon handling in the help viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
45 def __clearIcon(self):
b2d98c2e2e43 Fixed the icon handling in the help viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
46 """
b2d98c2e2e43 Fixed the icon handling in the help viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
47 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
48 """
b2d98c2e2e43 Fixed the icon handling in the help viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
49 self.setPixmap(QPixmap())
b2d98c2e2e43 Fixed the icon handling in the help viewer.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
50
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 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
52 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 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
54
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 @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
56 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 self.__browser = browser
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 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
59 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
60 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
61
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 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
63 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 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
65
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 @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
67 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 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
69 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
70 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
71
6695
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
72 def mouseReleaseEvent(self, evt):
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
73 """
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
74 Protected method to handle mouse release events.
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 @param evt reference to the mouse event (QMouseEvent)
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 if evt.button() == Qt.LeftButton:
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
79 self.__showPopup(evt.globalPos())
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
80 super(FavIconLabel, self).mouseReleaseEvent(evt)
0a51887c13cd Web Browser (NG):
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
81
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 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
83 """
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 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
85
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 @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
87 """
7270
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
88 if (
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
89 evt.button() == Qt.LeftButton and
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
90 ((evt.pos() - self.__dragStartPos).manhattanLength() >
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
91 QApplication.startDragDistance()) and
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
92 self.__browser is not None
41d09cf20415 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
93 ):
653
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)
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
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