src/eric7/EricWidgets/EricClickableLabel.py

Sat, 26 Apr 2025 12:34:32 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 26 Apr 2025 12:34:32 +0200
branch
eric7
changeset 11240
c48c615c04a3
parent 11090
f5f5f5803935
permissions
-rw-r--r--

MicroPython
- Added a configuration option to disable the support for the no longer produced Pimoroni Pico Wireless Pack.

1963
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
11090
f5f5f5803935 Updated copyright for 2025.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10439
diff changeset
3 # Copyright (c) 2012 - 2025 Detlev Offenbach <detlev@die-offenbachs.de>
1963
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a clickable label.
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
10 from PyQt6.QtCore import QPoint, Qt, pyqtSignal
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
11 from PyQt6.QtWidgets import QLabel
1963
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8319
diff changeset
14 class EricClickableLabel(QLabel):
1963
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 """
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 Class implementing a clickable label.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
17
1963
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 @signal clicked(QPoint) emitted upon a click on the label
3349
2a034a7f1f54 Made the status LED (right lower corner) clickable (depending on overall VCS status it will show the log browser or the status dialog).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
19 with the left button
1963
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 @signal middleClicked(QPoint) emitted upon a click on the label
3349
2a034a7f1f54 Made the status LED (right lower corner) clickable (depending on overall VCS status it will show the log browser or the status dialog).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
21 with the middle button or CTRL and left button
1963
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
23
1963
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 clicked = pyqtSignal(QPoint)
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 middleClicked = pyqtSignal(QPoint)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
26
1963
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 def __init__(self, parent=None):
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
30
10423
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
31 @param parent reference to the parent widget
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
32 @type QWidget
1963
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
34 super().__init__(parent)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
35
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
36 self.setCursor(Qt.CursorShape.PointingHandCursor)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
37
1963
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 def mouseReleaseEvent(self, evt):
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 Protected method handling mouse release events.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
41
10423
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
42 @param evt mouse event
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
43 @type QMouseEvent
1963
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
45 if evt.button() == Qt.MouseButton.LeftButton and self.rect().contains(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
46 evt.position().toPoint()
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
47 ):
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
48 if evt.modifiers() == Qt.KeyboardModifier.ControlModifier:
8319
ea11a3948f40 Continued porting eric to PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
49 self.middleClicked.emit(evt.globalPosition().toPoint())
1963
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 else:
8319
ea11a3948f40 Continued porting eric to PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
51 self.clicked.emit(evt.globalPosition().toPoint())
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
52 elif evt.button() == Qt.MouseButton.MiddleButton and self.rect().contains(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
53 evt.position().toPoint()
7252
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
54 ):
8319
ea11a3948f40 Continued porting eric to PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
55 self.middleClicked.emit(evt.globalPosition().toPoint())
1963
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 else:
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
57 super().mouseReleaseEvent(evt)

eric ide

mercurial