Network/IRC/IrcMessageEdit.py

changeset 2992
dbdf27746da5
parent 2960
9453efa25fd5
child 3057
10516539f238
child 3160
209a07d7e401
equal deleted inserted replaced
2991:226481ff40d1 2992:dbdf27746da5
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="", side=E5LineEdit.RightSide): 21 def __init__(self, parent=None, inactiveText="",
22 side=E5LineEdit.RightSide):
22 """ 23 """
23 Constructor 24 Constructor
24 25
25 @param parent reference to the parent widget (QWidget) 26 @param parent reference to the parent widget (QWidget)
26 @keyparam inactiveText text to be shown on inactivity (string) 27 @keyparam inactiveText text to be shown on inactivity (string)
27 @keyparam side side the clear button should be shown at (E5LineEdit.RightSide, 28 @keyparam side side the clear button should be shown at
28 E5LineEdit.LeftSide) 29 (E5LineEdit.RightSide, E5LineEdit.LeftSide)
29 """ 30 """
30 super().__init__(parent, inactiveText, side) 31 super().__init__(parent, inactiveText, side)
31 32
32 self.__historyList = [""] # initialize with one empty line 33 self.__historyList = [""] # initialize with one empty line
33 self.__historyLine = 0 34 self.__historyLine = 0
34 35
35 def setText(self, text): 36 def setText(self, text):
36 """ 37 """
37 Public method to set the text. 38 Public method to set the text.
38 39
39 Note: This reimplementation ensures, that the cursor is at the end of the text. 40 Note: This reimplementation ensures, that the cursor is at the end of
41 the text.
40 42
41 @param text text to be set (string) 43 @param text text to be set (string)
42 """ 44 """
43 super().setText(text) 45 super().setText(text)
44 self.setCursorPosition(len(text)) 46 self.setCursorPosition(len(text))
105 if self.text(): 107 if self.text():
106 self.__historyList[self.__historyLine] = self.text() 108 self.__historyList[self.__historyLine] = self.text()
107 109
108 if up: 110 if up:
109 self.__historyLine += 1 111 self.__historyLine += 1
110 # If the position was moved past the end of the history, go to the last entry 112 # If the position was moved past the end of the history,
113 # go to the last entry
111 if self.__historyLine == len(self.__historyList): 114 if self.__historyLine == len(self.__historyList):
112 self.__historyLine -= 1 115 self.__historyLine -= 1
113 return 116 return
114 else: 117 else:
115 # If the position is at the top of the history, arrow-down shall add the text 118 # If the position is at the top of the history, arrow-down shall
116 # to the history and clear the line edit for new input 119 # add the text to the history and clear the line edit for new input
117 if self.__historyLine == 0: 120 if self.__historyLine == 0:
118 if self.text(): 121 if self.text():
119 self.__addHistory(self.text()) 122 self.__addHistory(self.text())
120 self.setText("") 123 self.setText("")
121 else: 124 else:
122 # If the position is not at the top of the history, decrement it 125 # If the position is not at the top of the history,
126 # decrement it
123 self.__historyLine -= 1 127 self.__historyLine -= 1
124 128
125 # replace the text of the line edit with the selected history entry 129 # replace the text of the line edit with the selected history entry
126 self.setText(self.__historyList[self.__historyLine]) 130 self.setText(self.__historyList[self.__historyLine])

eric ide

mercurial