7 Module implementing a specialized line edit for entering IRC messages. |
7 Module implementing a specialized line edit for entering IRC messages. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt5.QtCore import Qt |
10 from PyQt5.QtCore import Qt |
11 |
11 |
12 from E5Gui.E5LineEdit import E5LineEdit, E5ClearableLineEdit |
12 from E5Gui.E5LineEdit import E5LineEditSide, E5ClearableLineEdit |
13 |
13 |
14 |
14 |
15 class IrcMessageEdit(E5ClearableLineEdit): |
15 class IrcMessageEdit(E5ClearableLineEdit): |
16 """ |
16 """ |
17 Class implementing a specialized line edit for entering IRC messages. |
17 Class implementing a specialized line edit for entering IRC messages. |
18 """ |
18 """ |
19 MaxHistory = 100 |
19 MaxHistory = 100 |
20 |
20 |
21 def __init__(self, parent=None, inactiveText="", |
21 def __init__(self, parent=None, inactiveText="", |
22 side=E5LineEdit.RightSide): |
22 side=E5LineEditSide.RIGHT): |
23 """ |
23 """ |
24 Constructor |
24 Constructor |
25 |
25 |
26 @param parent reference to the parent widget (QWidget) |
26 @param parent reference to the parent widget |
27 @param inactiveText text to be shown on inactivity (string) |
27 @type QWidget |
|
28 @param inactiveText text to be shown on inactivity |
|
29 @type str |
28 @param side side the clear button should be shown at |
30 @param side side the clear button should be shown at |
29 (E5LineEdit.RightSide, E5LineEdit.LeftSide) |
31 @type E5LineEditSide |
30 """ |
32 """ |
31 super(IrcMessageEdit, self).__init__(parent, inactiveText, side) |
33 super().__init__(parent, inactiveText, side) |
32 |
34 |
33 self.__historyList = [""] # initialize with one empty line |
35 self.__historyList = [""] # initialize with one empty line |
34 self.__historyLine = 0 |
36 self.__historyLine = 0 |
35 |
37 |
36 def setText(self, text): |
38 def setText(self, text): |
40 Note: This reimplementation ensures, that the cursor is at the end of |
42 Note: This reimplementation ensures, that the cursor is at the end of |
41 the text. |
43 the text. |
42 |
44 |
43 @param text text to be set (string) |
45 @param text text to be set (string) |
44 """ |
46 """ |
45 super(IrcMessageEdit, self).setText(text) |
47 super().setText(text) |
46 self.setCursorPosition(len(text)) |
48 self.setCursorPosition(len(text)) |
47 |
49 |
48 def keyPressEvent(self, evt): |
50 def keyPressEvent(self, evt): |
49 """ |
51 """ |
50 Protected method implementing special key handling. |
52 Protected method implementing special key handling. |
63 self.__addHistory(self.text()) |
65 self.__addHistory(self.text()) |
64 elif evt.text() == chr(21): |
66 elif evt.text() == chr(21): |
65 # ^U: clear the text |
67 # ^U: clear the text |
66 self.setText("") |
68 self.setText("") |
67 |
69 |
68 super(IrcMessageEdit, self).keyPressEvent(evt) |
70 super().keyPressEvent(evt) |
69 |
71 |
70 def wheelEvent(self, evt): |
72 def wheelEvent(self, evt): |
71 """ |
73 """ |
72 Protected slot to support wheel events. |
74 Protected slot to support wheel events. |
73 |
75 |
77 if delta > 0: |
79 if delta > 0: |
78 self.__getHistory(True) |
80 self.__getHistory(True) |
79 elif delta < 0: |
81 elif delta < 0: |
80 self.__getHistory(False) |
82 self.__getHistory(False) |
81 |
83 |
82 super(IrcMessageEdit, self).wheelEvent(evt) |
84 super().wheelEvent(evt) |
83 |
85 |
84 def __addHistory(self, txt): |
86 def __addHistory(self, txt): |
85 """ |
87 """ |
86 Private method to add an entry to the history. |
88 Private method to add an entry to the history. |
87 |
89 |