E5Gui/E5LineEdit.py

Sun, 19 Jun 2011 15:19:46 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 19 Jun 2011 15:19:46 +0200
changeset 1127
b1802ebe0066
parent 945
8cd4d08fa9f6
child 1131
7781e396c903
permissions
-rw-r--r--

Added capability to encrypt saved passwords with a master password and rearranged some configuration parameters related to security.

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
791
9ec2ac20e54e Updated copyright notice.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 653
diff changeset
3 # Copyright (c) 2009 - 2011 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
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
10 from PyQt4.QtCore import pyqtSignal, Qt, QEvent
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
11 from PyQt4.QtGui import QLineEdit, QStyleOptionFrameV2, QStyle, QPainter, QPalette, \
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
12 QWidget, QHBoxLayout, QBoxLayout, QLayout, QApplication, QSpacerItem, QSizePolicy
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
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: 55
diff changeset
15 class SideWidget(QWidget):
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
16 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
17 Class implementing the side widgets for the line edit class.
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
18 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
19 sizeHintChanged = pyqtSignal()
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
20
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
21 def __init__(self, parent=None):
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
22 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
23 Constructor
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 @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
26 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
27 QWidget.__init__(self, parent)
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 def event(self, evt):
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 Protected method to handle events.
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
32
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
33 @param reference to the event (QEvent)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
34 @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
35 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
36 if evt.type() == QEvent.LayoutRequest:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
37 self.sizeHintChanged.emit()
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
38 return QWidget.event(self, evt)
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
40
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 class E5LineEdit(QLineEdit):
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 Class implementing a line edit widget showing some inactive text.
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
45 LeftSide = 0
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
46 RightSide = 1
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
47
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
48 def __init__(self, parent=None, inactiveText=""):
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 Constructor
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 @param parent reference to the parent widget (QWidget)
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 @param inactiveText text to be shown on inactivity (string)
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 QLineEdit.__init__(self, parent)
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
57 self.setMinimumHeight(22)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
58
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 self.__inactiveText = inactiveText
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
60
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
61 self.__leftWidget = SideWidget(self)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
62 self.__leftWidget.resize(0, 0)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
63 self.__leftLayout = QHBoxLayout(self.__leftWidget)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
64 self.__leftLayout.setContentsMargins(0, 0, 0, 0)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
65 if QApplication.isRightToLeft():
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
66 self.__leftLayout.setDirection(QBoxLayout.RightToLeft)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
67 else:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
68 self.__leftLayout.setDirection(QBoxLayout.LeftToRight)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
69 self.__leftLayout.setSizeConstraint(QLayout.SetFixedSize)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
70
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
71 self.__rightWidget = SideWidget(self)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
72 self.__rightWidget.resize(0, 0)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
73 self.__rightLayout = QHBoxLayout(self.__rightWidget)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
74 self.__rightLayout.setContentsMargins(0, 0, 0, 0)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
75 if self.isRightToLeft():
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
76 self.__rightLayout.setDirection(QBoxLayout.RightToLeft)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
77 else:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
78 self.__rightLayout.setDirection(QBoxLayout.LeftToRight)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
79 horizontalSpacer = QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Minimum)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
80 self.__rightLayout.addItem(horizontalSpacer)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
81
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
82 self.setWidgetSpacing(3)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
83 self.__leftWidget.sizeHintChanged.connect(self._updateTextMargins)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
84 self.__rightWidget.sizeHintChanged.connect(self._updateTextMargins)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
85
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
86 def event(self, evt):
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
87 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
88 Protected method to handle events.
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
89
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
90 @param reference to the event (QEvent)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
91 @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
92 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
93 if evt.type() == QEvent.LayoutDirectionChange:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
94 if self.isRightToLeft():
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
95 self.__leftLayout.setDirection(QBoxLayout.RightToLeft)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
96 self.__rightLayout.setDirection(QBoxLayout.RightToLeft)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
97 else:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
98 self.__leftLayout.setDirection(QBoxLayout.LeftToRight)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
99 self.__rightLayout.setDirection(QBoxLayout.LeftToRight)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
100 return QLineEdit.event(self, evt)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
101
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
102 def resizeEvent(self, evt):
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
103 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
104 Protected method to handle resize events.
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 @param evt reference to the resize event (QResizeEvent)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
107 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
108 self.__updateSideWidgetLocations()
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
109 QLineEdit.resizeEvent(self, evt)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
110
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
111 def paintEvent(self, evt):
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
112 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
113 Protected method handling a paint event.
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
114
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
115 @param evt reference to the paint event (QPaintEvent)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
116 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
117 QLineEdit.paintEvent(self, evt)
653
0540f3c52b46 Changed the web browser to give it a more modern look.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 643
diff changeset
118
643
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
119 if not self.text() and \
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
120 self.__inactiveText and \
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
121 not self.hasFocus():
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
122 panel = QStyleOptionFrameV2()
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
123 self.initStyleOption(panel)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
124 textRect = \
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
125 self.style().subElementRect(QStyle.SE_LineEditContents, panel, self)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
126 textRect.adjust(2, 0, 0, 0)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
127 left = self.textMargin(self.LeftSide)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
128 right = self.textMargin(self.RightSide)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
129 textRect.adjust(left, 0, -right, 0)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
130 painter = QPainter(self)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
131 painter.setPen(self.palette().brush(QPalette.Disabled, QPalette.Text).color())
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
132 painter.drawText(
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
133 textRect, Qt.AlignLeft | Qt.AlignVCenter, self.__inactiveText)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
134
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
135 def __updateSideWidgetLocations(self):
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
136 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
137 Private method to update the side widget locations.
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
138 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
139 opt = QStyleOptionFrameV2()
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
140 self.initStyleOption(opt)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
141 textRect = \
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
142 self.style().subElementRect(QStyle.SE_LineEditContents, opt, self)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
143 textRect.adjust(2, 0, 0, 0)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
144
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
145 left = self.textMargin(self.LeftSide)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
146
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
147 midHeight = textRect.center().y() + 1
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
148
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
149 if self.__leftLayout.count() > 0:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
150 leftHeight = midHeight - self.__leftWidget.height() // 2
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
151 leftWidth = self.__leftWidget.width()
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
152 if leftWidth == 0:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
153 leftHeight = midHeight - self.__leftWidget.sizeHint().height() // 2
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
154 self.__leftWidget.move(textRect.x(), leftHeight)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
155
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
156 textRect.setX(left)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
157 textRect.setY(midHeight - self.__rightWidget.sizeHint().height() // 2)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
158 textRect.setHeight(self.__rightWidget.sizeHint().height())
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
159 self.__rightWidget.setGeometry(textRect)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
160
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
161 def _updateTextMargins(self):
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 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
164 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
165 left = self.textMargin(self.LeftSide)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
166 right = self.textMargin(self.RightSide)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
167 self.setTextMargins(left, 0, right, 0)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
168 self.__updateSideWidgetLocations()
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
169
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
170 def addWidget(self, widget, position):
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
171 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
172 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
173
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
174 @param widget reference to the widget to add (QWidget)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
175 @param position position to add to (E5LineEdit.LeftSide, E5LineEdit.RightSide)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
176 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
177 if widget is None:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
178 return
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
179
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
180 if self.isRightToLeft():
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
181 if position == self.LeftSide:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
182 position = self.RightSide
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
183 else:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
184 position = self.LeftSide
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
185 if position == self.LeftSide:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
186 self.__leftLayout.addWidget(widget)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
187 else:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
188 self.__rightLayout.insertWidget(1, widget)
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 def removeWidget(self, widget):
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
191 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
192 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
193
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
194 @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
195 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
196 if widget is None:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
197 return
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 self.__leftLayout.removeWidget(widget)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
200 self.__rightLayout.removeWidget(widget)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
201 widget.hide()
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 def widgetSpacing(self):
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 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
206
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
207 @return side widget spacing (integer)
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 return self.__leftLayout.spacing()
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 def setWidgetSpacing(self, spacing):
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
212 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
213 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
214
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
215 @param spacing side widget spacing (integer)
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 self.__leftLayout.setSpacing(spacing)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
218 self.__rightLayout.setSpacing(spacing)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
219 self._updateTextMargins()
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
220
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
221 def textMargin(self, position):
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 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
224
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
225 @param position side to get margin for (E5LineEdit.LeftSide, E5LineEdit.RightSide)
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
226 """
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
227 spacing = self.__rightLayout.spacing()
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
228 w = 0
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
229 if position == self.LeftSide:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
230 w = self.__leftWidget.sizeHint().width()
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
231 else:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
232 w = self.__rightWidget.sizeHint().width()
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
233 if w == 0:
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
234 return 0
719db11dd4df Added a line widget with embeddable buttons.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
235 return w + spacing * 2
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 def inactiveText(self):
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 Public method to get the inactive text.
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 return inactive text (string)
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 return self.__inactiveText
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 def setInactiveText(self, inactiveText):
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 Public method to set the inactive text.
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 @param inactiveText text to be shown on inactivity (string)
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 self.__inactiveText = inactiveText
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 self.update()

eric ide

mercurial