E5Gui/E5SqueezeLabels.py

changeset 1131
7781e396c903
parent 945
8cd4d08fa9f6
child 1509
c0b5e693b0eb
equal deleted inserted replaced
1130:3e9f0330f833 1131:7781e396c903
21 """ 21 """
22 Constructor 22 Constructor
23 23
24 @param parent reference to the parent Widget (QWidget) 24 @param parent reference to the parent Widget (QWidget)
25 """ 25 """
26 QLabel.__init__(self, parent) 26 super().__init__(parent)
27 27
28 self.__text = '' 28 self.__text = ''
29 self.__elided = '' 29 self.__elided = ''
30 30
31 def paintEvent(self, event): 31 def paintEvent(self, event):
35 @param event reference to the paint event (QPaintEvent) 35 @param event reference to the paint event (QPaintEvent)
36 """ 36 """
37 fm = self.fontMetrics() 37 fm = self.fontMetrics()
38 if fm.width(self.__text) > self.contentsRect().width(): 38 if fm.width(self.__text) > self.contentsRect().width():
39 self.__elided = fm.elidedText(self.text(), Qt.ElideMiddle, self.width()) 39 self.__elided = fm.elidedText(self.text(), Qt.ElideMiddle, self.width())
40 QLabel.setText(self, self.__elided) 40 super().setText(self.__elided)
41 else: 41 else:
42 QLabel.setText(self, self.__text) 42 super().setText(self.__text)
43 QLabel.paintEvent(self, event) 43 super().paintEvent(event)
44 44
45 def setText(self, txt): 45 def setText(self, txt):
46 """ 46 """
47 Public method to set the label's text. 47 Public method to set the label's text.
48 48
49 @param txt the text to be shown (string) 49 @param txt the text to be shown (string)
50 """ 50 """
51 self.__text = txt 51 self.__text = txt
52 QLabel.setText(self, self.__text) 52 super().setText(self.__text)
53 53
54 54
55 class E5SqueezeLabelPath(QLabel): 55 class E5SqueezeLabelPath(QLabel):
56 """ 56 """
57 Class implementing a label showing a file path compacted to fit it's size. 57 Class implementing a label showing a file path compacted to fit it's size.
60 """ 60 """
61 Constructor 61 Constructor
62 62
63 @param parent reference to the parent Widget (QWidget) 63 @param parent reference to the parent Widget (QWidget)
64 """ 64 """
65 QLabel.__init__(self, parent) 65 super().__init__(parent)
66 66
67 self.__path = '' 67 self.__path = ''
68 self.__surrounding = "{0}" 68 self.__surrounding = "{0}"
69 69
70 def setSurrounding(self, surrounding): 70 def setSurrounding(self, surrounding):
72 Public method to set the surrounding of the path string. 72 Public method to set the surrounding of the path string.
73 73
74 @param surrounding the a string containg placeholders for the path (string) 74 @param surrounding the a string containg placeholders for the path (string)
75 """ 75 """
76 self.__surrounding = surrounding 76 self.__surrounding = surrounding
77 QLabel.setText(self, self.__surrounding.format(self.__path)) 77 super().setText(self.__surrounding.format(self.__path))
78 78
79 def setPath(self, path): 79 def setPath(self, path):
80 """ 80 """
81 Public method to set the path of the label. 81 Public method to set the path of the label.
82 82
83 @param path path to be shown (string) 83 @param path path to be shown (string)
84 """ 84 """
85 self.__path = path 85 self.__path = path
86 QLabel.setText(self, self.__surrounding.format(self.__path)) 86 super().setText(self.__surrounding.format(self.__path))
87 87
88 def setTextPath(self, surrounding, path): 88 def setTextPath(self, surrounding, path):
89 """ 89 """
90 Public method to set the surrounding and the path of the label. 90 Public method to set the surrounding and the path of the label.
91 91
92 @param surrounding the a string containg placeholders for the path (string) 92 @param surrounding the a string containg placeholders for the path (string)
93 @param path path to be shown (string) 93 @param path path to be shown (string)
94 """ 94 """
95 self.__surrounding = surrounding 95 self.__surrounding = surrounding
96 self.__path = path 96 self.__path = path
97 QLabel.setText(self, self.__surrounding.format(self.__path)) 97 super().setText(self.__surrounding.format(self.__path))
98 98
99 def paintEvent(self, event): 99 def paintEvent(self, event):
100 """ 100 """
101 Protected method called when some painting is required. 101 Protected method called when some painting is required.
102 102
103 @param event reference to the paint event (QPaintEvent) 103 @param event reference to the paint event (QPaintEvent)
104 """ 104 """
105 fm = self.fontMetrics() 105 fm = self.fontMetrics()
106 if fm.width(self.__surrounding.format(self.__path)) > self.contentsRect().width(): 106 if fm.width(self.__surrounding.format(self.__path)) > self.contentsRect().width():
107 QLabel.setText(self, 107 super().setText(
108 self.__surrounding.format(compactPath(self.__path, 108 self.__surrounding.format(compactPath(self.__path,
109 self.contentsRect().width(), 109 self.contentsRect().width(),
110 self.length)) 110 self.length))
111 ) 111 )
112 else: 112 else:
113 QLabel.setText(self, self.__surrounding.format(self.__path)) 113 super().setText(self.__surrounding.format(self.__path))
114 QLabel.paintEvent(self, event) 114 super().paintEvent(event)
115 115
116 def length(self, txt): 116 def length(self, txt):
117 """ 117 """
118 Public method to return the length of a text in pixels. 118 Public method to return the length of a text in pixels.
119 119

eric ide

mercurial