eric6/E5Gui/E5LineEdit.py

Tue, 02 Mar 2021 17:17:09 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 02 Mar 2021 17:17:09 +0100
changeset 8143
2c730d5fd177
parent 7923
91e843545d9a
child 8176
31965986ecd1
child 8218
7c09585bd960
permissions
-rw-r--r--

Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.

55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7900
diff changeset
3 # Copyright (c) 2009 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
7 Module implementing specialized line edits.
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
5736
000ea446ff4b Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5726
diff changeset
10 from PyQt5.QtCore import pyqtSignal, Qt, QEvent
7252
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
11 from PyQt5.QtWidgets import (
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
12 QLineEdit, QWidget, QHBoxLayout, QBoxLayout, QLayout, QApplication,
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
13 QSpacerItem, QSizePolicy
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
14 )
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
15
2206
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
16 import UI.PixmapCache
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
17
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
18
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
19 class E5LineEditSideWidget(QWidget):
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
20 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
21 Class implementing the side widgets for the line edit class.
5726
e1dbd217214a Fixed a few source docu issues (forgotten signals and exceptions).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
22
e1dbd217214a Fixed a few source docu issues (forgotten signals and exceptions).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
23 @signal sizeHintChanged() emitted to indicate a change of the size hint
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
24 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
25 sizeHintChanged = pyqtSignal()
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
26
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
27 def __init__(self, parent=None):
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
28 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
29 Constructor
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
30
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
31 @param parent reference to the parent widget (QWidget)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
32 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2401
diff changeset
33 super(E5LineEditSideWidget, self).__init__(parent)
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
34
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
35 def event(self, evt):
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
36 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
37 Public method to handle events.
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
38
2953
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2401
diff changeset
39 @param evt reference to the event (QEvent)
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
40 @return flag indicating, whether the event was recognized (boolean)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
41 """
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
42 if evt.type() == QEvent.Type.LayoutRequest:
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
43 self.sizeHintChanged.emit()
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
44 return QWidget.event(self, evt)
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
46
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 class E5LineEdit(QLineEdit):
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 Class implementing a line edit widget showing some inactive text.
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
51 LeftSide = 0
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
52 RightSide = 1
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
53
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
54 def __init__(self, parent=None, inactiveText=""):
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 Constructor
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 @param parent reference to the parent widget (QWidget)
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 @param inactiveText text to be shown on inactivity (string)
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2401
diff changeset
61 super(E5LineEdit, self).__init__(parent)
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
63 self.setMinimumHeight(22)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
64
7198
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
65 self.setPlaceholderText(inactiveText)
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
66
2293
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
67 self.__mainLayout = QHBoxLayout(self)
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
68 self.__mainLayout.setContentsMargins(0, 0, 0, 0)
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
69 self.__mainLayout.setSpacing(0)
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
70
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
71 self.__leftMargin = 0
2206
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
72 self.__leftWidget = E5LineEditSideWidget(self)
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
73 self.__leftWidget.resize(0, 0)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
74 self.__leftLayout = QHBoxLayout(self.__leftWidget)
2293
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
75 self.__leftLayout.setContentsMargins(0, 0, 2, 0)
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
76 if QApplication.isRightToLeft():
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
77 self.__leftLayout.setDirection(QBoxLayout.Direction.RightToLeft)
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
78 else:
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
79 self.__leftLayout.setDirection(QBoxLayout.Direction.LeftToRight)
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
80 self.__leftLayout.setSizeConstraint(
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
81 QLayout.SizeConstraint.SetFixedSize)
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
82
2206
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
83 self.__rightWidget = E5LineEditSideWidget(self)
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
84 self.__rightWidget.resize(0, 0)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
85 self.__rightLayout = QHBoxLayout(self.__rightWidget)
2293
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
86 self.__rightLayout.setContentsMargins(0, 0, 2, 0)
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
87 if self.isRightToLeft():
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
88 self.__rightLayout.setDirection(QBoxLayout.Direction.RightToLeft)
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
89 else:
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
90 self.__rightLayout.setDirection(QBoxLayout.Direction.LeftToRight)
2293
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
91
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
92 horizontalSpacer = QSpacerItem(
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
93 0, 0, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum)
2293
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
94 self.__mainLayout.addWidget(
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
95 self.__leftWidget, 0,
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
96 Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignLeft)
2293
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
97 self.__mainLayout.addItem(horizontalSpacer)
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
98 self.__mainLayout.addWidget(
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
99 self.__rightWidget, 0,
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
100 Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignRight)
2293
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
101 if self.isRightToLeft():
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
102 self.__mainLayout.setDirection(QBoxLayout.Direction.RightToLeft)
2293
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
103 else:
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
104 self.__mainLayout.setDirection(QBoxLayout.Direction.LeftToRight)
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
105
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
106 self.setWidgetSpacing(3)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
107 self.__leftWidget.sizeHintChanged.connect(self._updateTextMargins)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
108 self.__rightWidget.sizeHintChanged.connect(self._updateTextMargins)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
109
2293
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
110 def setLeftMargin(self, margin):
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
111 """
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
112 Public method to set the left margin.
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
113
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
114 @param margin left margin in pixel (integer)
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
115 """
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
116 self.__leftMargin = margin
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
117
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
118 def leftMargin(self):
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
119 """
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
120 Public method to get the size of the left margin.
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
121
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
122 @return left margin in pixel (integer)
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
123 """
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
124 return self.__leftMargin
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
125
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
126 def event(self, evt):
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
127 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
128 Public method to handle events.
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
129
2953
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2401
diff changeset
130 @param evt reference to the event (QEvent)
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
131 @return flag indicating, whether the event was recognized (boolean)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
132 """
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
133 if evt.type() == QEvent.Type.LayoutDirectionChange:
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
134 if self.isRightToLeft():
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
135 self.__mainLayout.setDirection(
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
136 QBoxLayout.Direction.RightToLeft)
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
137 self.__leftLayout.setDirection(
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
138 QBoxLayout.Direction.RightToLeft)
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
139 self.__rightLayout.setDirection(
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
140 QBoxLayout.Direction.RightToLeft)
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
141 else:
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
142 self.__mainLayout.setDirection(
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
143 QBoxLayout.Direction.LeftToRight)
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
144 self.__leftLayout.setDirection(
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
145 QBoxLayout.Direction.LeftToRight)
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
146 self.__rightLayout.setDirection(
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
147 QBoxLayout.Direction.LeftToRight)
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
148 return QLineEdit.event(self, evt)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
149
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
150 def _updateTextMargins(self):
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
151 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
152 Protected slot to update the text margins.
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
153 """
2293
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
154 if self.__leftMargin == 0:
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
155 left = self.__leftWidget.sizeHint().width()
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
156 else:
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
157 left = self.__leftMargin
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
158 right = self.__rightWidget.sizeHint().width()
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
159 top = 0
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
160 bottom = 0
ec6c1459f5b3 Fixed an issue caused by Qt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2206
diff changeset
161 self.setTextMargins(left, top, right, bottom)
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
162
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
163 def addWidget(self, widget, position):
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
164 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
165 Public method to add a widget to a side.
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
166
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
167 @param widget reference to the widget to add (QWidget)
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
168 @param position position to add to (E5LineEdit.LeftSide,
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
169 E5LineEdit.RightSide)
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
170 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
171 if widget is None:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
172 return
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
173
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
174 if self.isRightToLeft():
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
175 if position == self.LeftSide:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
176 position = self.RightSide
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
177 else:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
178 position = self.LeftSide
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
179 if position == self.LeftSide:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
180 self.__leftLayout.addWidget(widget)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
181 else:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
182 self.__rightLayout.insertWidget(1, widget)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
183
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
184 def removeWidget(self, widget):
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
185 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
186 Public method to remove a widget from a side.
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
187
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
188 @param widget reference to the widget to remove (QWidget)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
189 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
190 if widget is None:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
191 return
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
192
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
193 self.__leftLayout.removeWidget(widget)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
194 self.__rightLayout.removeWidget(widget)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
195 widget.hide()
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
196
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
197 def widgetSpacing(self):
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
198 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
199 Public method to get the side widget spacing.
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
200
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
201 @return side widget spacing (integer)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
202 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
203 return self.__leftLayout.spacing()
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
204
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
205 def setWidgetSpacing(self, spacing):
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
206 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
207 Public method to set the side widget spacing.
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
208
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
209 @param spacing side widget spacing (integer)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
210 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
211 self.__leftLayout.setSpacing(spacing)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
212 self.__rightLayout.setSpacing(spacing)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
213 self._updateTextMargins()
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
214
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
215 def textMargin(self, position):
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
216 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
217 Public method to get the text margin for a side.
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
218
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
219 @param position side to get margin for (E5LineEdit.LeftSide,
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
220 E5LineEdit.RightSide)
2953
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2401
diff changeset
221 @return text margin (integer)
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
222 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
223 spacing = self.__rightLayout.spacing()
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
224 w = 0
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
225 if position == self.LeftSide:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
226 w = self.__leftWidget.sizeHint().width()
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
227 else:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
228 w = self.__rightWidget.sizeHint().width()
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
229 if w == 0:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
230 return 0
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
231 return w + spacing * 2
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 def inactiveText(self):
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235 Public method to get the inactive text.
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236
2953
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2401
diff changeset
237 @return inactive text (string)
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 """
7198
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
239 return self.placeholderText()
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 def setInactiveText(self, inactiveText):
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 Public method to set the inactive text.
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 @param inactiveText text to be shown on inactivity (string)
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 """
7198
684261ef2165 Removed the Qt4 runtime stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
247 self.setPlaceholderText(inactiveText)
2206
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
248
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
249
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
250 class E5ClearableLineEdit(E5LineEdit):
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
251 """
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
252 Class implementing a line edit widget showing some inactive text and a
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
253 clear button, if it has some contents.
2206
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
254 """
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
255 def __init__(self, parent=None, inactiveText="",
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
256 side=E5LineEdit.RightSide):
2206
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
257 """
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
258 Constructor
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
259
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
260 @param parent reference to the parent widget (QWidget)
7900
72b88fb20261 Corrected the use of '@keyparam' in the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
261 @param inactiveText text to be shown on inactivity (string)
72b88fb20261 Corrected the use of '@keyparam' in the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
262 @param side side the clear button should be shown at
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
263 (E5LineEdit.RightSide, E5LineEdit.LeftSide)
7628
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
264 @exception ValueError raised to indicate a bad parameter value
2206
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
265 """
7628
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
266 if side not in [E5LineEdit.RightSide, E5LineEdit.LeftSide]:
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
267 raise ValueError("Bad value for 'side' parameter.")
2206
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
268
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2401
diff changeset
269 super(E5ClearableLineEdit, self).__init__(parent, inactiveText)
2206
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
270
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
271 from E5Gui.E5LineEditButton import E5LineEditButton
2206
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
272 self.__clearButton = E5LineEditButton(self)
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
273 self.__clearButton.setIcon(UI.PixmapCache.getIcon("clearLeft"))
2206
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
274 self.addWidget(self.__clearButton, side)
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
275 self.__clearButton.setVisible(False)
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
276
3345
071afe8be2a1 Changed signal/slot usage to not use constructs like 'triggered[()].connect(...)' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
277 self.__clearButton.clicked.connect(self.clear)
2206
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
278 self.textChanged.connect(self.__textChanged)
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
279
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
280 def __textChanged(self, txt):
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
281 """
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
282 Private slot to handle changes of the text.
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
283
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
284 @param txt text (string)
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
285 """
b2da5a8d7f15 Added a line edit widget with an internal clear button to E5LineEdit.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
286 self.__clearButton.setVisible(txt != "")

eric ide

mercurial