eric6/E5Gui/E5LineEditButton.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).

643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
3 # Copyright (c) 2010 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a button class to be used with E5LineEdit.
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
10 from PyQt5.QtCore import Qt, QPoint, QPointF
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
11 from PyQt5.QtGui import QPainter, QPainterPath
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
12 from PyQt5.QtWidgets import QAbstractButton
643
719db11dd4df Added a line widget with embeddable buttons.
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
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 class E5LineEditButton(QAbstractButton):
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 Class implementing a button to be used with E5LineEdit.
719db11dd4df Added a line widget with embeddable buttons.
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):
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 Constructor
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 @param parent reference to the parent widget (QWidget)
719db11dd4df Added a line widget with embeddable buttons.
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: 2302
diff changeset
25 super(E5LineEditButton, self).__init__(parent)
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 self.__menu = None
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 self.__image = None
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 self.setFocusPolicy(Qt.NoFocus)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 self.setCursor(Qt.ArrowCursor)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 self.setMinimumSize(16, 16)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
3345
071afe8be2a1 Changed signal/slot usage to not use constructs like 'triggered[()].connect(...)' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
34 self.clicked.connect(self.__clicked)
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 def setMenu(self, menu):
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 Public method to set the button menu.
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 @param menu reference to the menu (QMenu)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 self.__menu = menu
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 self.update()
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 def menu(self):
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 Public method to get a reference to the menu.
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 @return reference to the associated menu (QMenu)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 return self.__menu
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 def setIcon(self, icon):
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 Public method to set the button icon.
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 @param icon icon to be set (QIcon)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 if icon.isNull():
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 self.__image = None
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 else:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 self.__image = icon.pixmap(16, 16).toImage()
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
63 super(E5LineEditButton, self).setIcon(icon)
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 def __clicked(self):
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 Private slot to handle a button click.
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 if self.__menu:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 pos = self.mapToGlobal(QPoint(0, self.height()))
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
71 self.__menu.exec(pos)
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 def paintEvent(self, evt):
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 Protected method handling a paint event.
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 @param evt reference to the paint event (QPaintEvent)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 painter = QPainter(self)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 if self.__image is not None and not self.__image.isNull():
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 x = (self.width() - self.__image.width()) // 2 - 1
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 y = (self.height() - self.__image.height()) // 2 - 1
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 painter.drawImage(x, y, self.__image)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 if self.__menu is not None:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 triagPath = QPainterPath()
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 startPos = QPointF(self.width() - 5, self.height() - 3)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 triagPath.moveTo(startPos)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 triagPath.lineTo(startPos.x() + 4, startPos.y())
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 triagPath.lineTo(startPos.x() + 2, startPos.y() + 2)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 triagPath.closeSubpath()
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 painter.setPen(Qt.black)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 painter.setBrush(Qt.black)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 painter.setRenderHint(QPainter.Antialiasing, False)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 painter.drawPath(triagPath)

eric ide

mercurial