14 |
14 |
15 |
15 |
16 class SearchWidget(QWidget): |
16 class SearchWidget(QWidget): |
17 """ |
17 """ |
18 Class implementing the search box for the shell and log viewer. |
18 Class implementing the search box for the shell and log viewer. |
19 |
19 |
20 @signal searchNext(text, caseSensitive, wholeWord, regexp) emitted when the |
20 @signal searchNext(text, caseSensitive, wholeWord, regexp) emitted when the |
21 user pressed the next button (string, boolean, boolean) |
21 user pressed the next button (string, boolean, boolean) |
22 @signal searchPrevious(text, caseSensitive, wholeWord, regexp) emitted when |
22 @signal searchPrevious(text, caseSensitive, wholeWord, regexp) emitted when |
23 the user pressed the previous button (string, boolean, boolean) |
23 the user pressed the previous button (string, boolean, boolean) |
24 """ |
24 """ |
|
25 |
25 searchNext = pyqtSignal(str, bool, bool, bool) |
26 searchNext = pyqtSignal(str, bool, bool, bool) |
26 searchPrevious = pyqtSignal(str, bool, bool, bool) |
27 searchPrevious = pyqtSignal(str, bool, bool, bool) |
27 |
28 |
28 def __init__(self, mainWindow, parent=None, spacer=True, showLine=False): |
29 def __init__(self, mainWindow, parent=None, spacer=True, showLine=False): |
29 """ |
30 """ |
30 Constructor |
31 Constructor |
31 |
32 |
32 @param mainWindow reference to the main window |
33 @param mainWindow reference to the main window |
33 @type QWidget |
34 @type QWidget |
34 @param parent reference to the parent widget |
35 @param parent reference to the parent widget |
35 @type QWidget |
36 @type QWidget |
36 @param spacer flag indicating to add a vertical spacer to the |
37 @param spacer flag indicating to add a vertical spacer to the |
38 @type bool |
39 @type bool |
39 @param showLine flag indicating to show all widget in one row |
40 @param showLine flag indicating to show all widget in one row |
40 @type bool |
41 @type bool |
41 """ |
42 """ |
42 super().__init__(parent) |
43 super().__init__(parent) |
43 |
44 |
44 if showLine: |
45 if showLine: |
45 from .Ui_SearchWidgetLine import Ui_SearchWidgetLine |
46 from .Ui_SearchWidgetLine import Ui_SearchWidgetLine |
|
47 |
46 self.__ui = Ui_SearchWidgetLine() |
48 self.__ui = Ui_SearchWidgetLine() |
47 else: |
49 else: |
48 from .Ui_SearchWidget import Ui_SearchWidget |
50 from .Ui_SearchWidget import Ui_SearchWidget |
|
51 |
49 self.__ui = Ui_SearchWidget() |
52 self.__ui = Ui_SearchWidget() |
50 self.__ui.setupUi(self) |
53 self.__ui.setupUi(self) |
51 |
54 |
52 if not showLine: |
55 if not showLine: |
53 if spacer: |
56 if spacer: |
54 spacerItem = QSpacerItem( |
57 spacerItem = QSpacerItem( |
55 20, 1, |
58 20, 1, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding |
56 QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding |
|
57 ) |
59 ) |
58 self.__ui.verticalLayout.addItem(spacerItem) |
60 self.__ui.verticalLayout.addItem(spacerItem) |
59 else: |
61 else: |
60 # change the size policy of the search combo if the spacer is |
62 # change the size policy of the search combo if the spacer is |
61 # not wanted, i.e. it is below the to be searched widget |
63 # not wanted, i.e. it is below the to be searched widget |
62 sizePolicy = self.__ui.findtextCombo.sizePolicy() |
64 sizePolicy = self.__ui.findtextCombo.sizePolicy() |
63 sizePolicy.setHorizontalPolicy(QSizePolicy.Policy.Expanding) |
65 sizePolicy.setHorizontalPolicy(QSizePolicy.Policy.Expanding) |
64 self.__ui.findtextCombo.setSizePolicy(sizePolicy) |
66 self.__ui.findtextCombo.setSizePolicy(sizePolicy) |
65 |
67 |
66 self.__mainWindow = mainWindow |
68 self.__mainWindow = mainWindow |
67 self.__findBackwards = True |
69 self.__findBackwards = True |
68 |
70 |
69 self.__ui.closeButton.setIcon( |
71 self.__ui.closeButton.setIcon(UI.PixmapCache.getIcon("close")) |
70 UI.PixmapCache.getIcon("close")) |
72 self.__ui.findPrevButton.setIcon(UI.PixmapCache.getIcon("1leftarrow")) |
71 self.__ui.findPrevButton.setIcon( |
73 self.__ui.findNextButton.setIcon(UI.PixmapCache.getIcon("1rightarrow")) |
72 UI.PixmapCache.getIcon("1leftarrow")) |
74 |
73 self.__ui.findNextButton.setIcon( |
|
74 UI.PixmapCache.getIcon("1rightarrow")) |
|
75 |
|
76 self.findHistory = [] |
75 self.findHistory = [] |
77 |
76 |
78 self.__ui.findtextCombo.setCompleter(None) |
77 self.__ui.findtextCombo.setCompleter(None) |
79 self.__ui.findtextCombo.lineEdit().returnPressed.connect( |
78 self.__ui.findtextCombo.lineEdit().returnPressed.connect( |
80 self.__findByReturnPressed) |
79 self.__findByReturnPressed |
81 |
80 ) |
|
81 |
82 msh = self.minimumSizeHint() |
82 msh = self.minimumSizeHint() |
83 self.resize(max(self.width(), msh.width()), msh.height()) |
83 self.resize(max(self.width(), msh.width()), msh.height()) |
84 |
84 |
85 @pyqtSlot() |
85 @pyqtSlot() |
86 def on_closeButton_clicked(self): |
86 def on_closeButton_clicked(self): |
87 """ |
87 """ |
88 Private slot to close the widget. |
88 Private slot to close the widget. |
89 """ |
89 """ |
90 self.close() |
90 self.close() |
91 |
91 |
92 def keyPressEvent(self, event): |
92 def keyPressEvent(self, event): |
93 """ |
93 """ |
94 Protected slot to handle key press events. |
94 Protected slot to handle key press events. |
95 |
95 |
96 @param event reference to the key press event (QKeyEvent) |
96 @param event reference to the key press event (QKeyEvent) |
97 """ |
97 """ |
98 if event.key() == Qt.Key.Key_Escape: |
98 if event.key() == Qt.Key.Key_Escape: |
99 self.__mainWindow.setFocus(Qt.FocusReason.ActiveWindowFocusReason) |
99 self.__mainWindow.setFocus(Qt.FocusReason.ActiveWindowFocusReason) |
100 event.accept() |
100 event.accept() |
101 self.close() |
101 self.close() |
102 |
102 |
103 @pyqtSlot() |
103 @pyqtSlot() |
104 def on_findNextButton_clicked(self): |
104 def on_findNextButton_clicked(self): |
105 """ |
105 """ |
106 Private slot to find the next occurrence. |
106 Private slot to find the next occurrence. |
107 """ |
107 """ |
108 txt = self.__ui.findtextCombo.currentText() |
108 txt = self.__ui.findtextCombo.currentText() |
109 if not txt and not self.isVisible(): |
109 if not txt and not self.isVisible(): |
110 self.showFind() |
110 self.showFind() |
111 return |
111 return |
112 |
112 |
113 self.__findBackwards = False |
113 self.__findBackwards = False |
114 |
114 |
115 # This moves any previous occurrence of this statement to the head |
115 # This moves any previous occurrence of this statement to the head |
116 # of the list and updates the combobox |
116 # of the list and updates the combobox |
117 if txt in self.findHistory: |
117 if txt in self.findHistory: |
118 self.findHistory.remove(txt) |
118 self.findHistory.remove(txt) |
119 self.findHistory.insert(0, txt) |
119 self.findHistory.insert(0, txt) |
120 self.__ui.findtextCombo.clear() |
120 self.__ui.findtextCombo.clear() |
121 self.__ui.findtextCombo.addItems(self.findHistory) |
121 self.__ui.findtextCombo.addItems(self.findHistory) |
122 |
122 |
123 self.searchNext.emit( |
123 self.searchNext.emit( |
124 txt, |
124 txt, |
125 self.__ui.caseCheckBox.isChecked(), |
125 self.__ui.caseCheckBox.isChecked(), |
126 self.__ui.wordCheckBox.isChecked(), |
126 self.__ui.wordCheckBox.isChecked(), |
127 self.__ui.regexpCheckBox.isChecked(), |
127 self.__ui.regexpCheckBox.isChecked(), |
128 ) |
128 ) |
129 |
129 |
130 @pyqtSlot() |
130 @pyqtSlot() |
131 def on_findPrevButton_clicked(self): |
131 def on_findPrevButton_clicked(self): |
132 """ |
132 """ |
133 Private slot to find the previous occurrence. |
133 Private slot to find the previous occurrence. |
134 """ |
134 """ |
135 txt = self.__ui.findtextCombo.currentText() |
135 txt = self.__ui.findtextCombo.currentText() |
136 if not txt and not self.isVisible(): |
136 if not txt and not self.isVisible(): |
137 self.showFind() |
137 self.showFind() |
138 return |
138 return |
139 |
139 |
140 self.__findBackwards = True |
140 self.__findBackwards = True |
141 |
141 |
142 # This moves any previous occurrence of this statement to the head |
142 # This moves any previous occurrence of this statement to the head |
143 # of the list and updates the combobox |
143 # of the list and updates the combobox |
144 if txt in self.findHistory: |
144 if txt in self.findHistory: |
145 self.findHistory.remove(txt) |
145 self.findHistory.remove(txt) |
146 self.findHistory.insert(0, txt) |
146 self.findHistory.insert(0, txt) |
147 self.__ui.findtextCombo.clear() |
147 self.__ui.findtextCombo.clear() |
148 self.__ui.findtextCombo.addItems(self.findHistory) |
148 self.__ui.findtextCombo.addItems(self.findHistory) |
149 |
149 |
150 self.searchPrevious.emit( |
150 self.searchPrevious.emit( |
151 txt, |
151 txt, |
152 self.__ui.caseCheckBox.isChecked(), |
152 self.__ui.caseCheckBox.isChecked(), |
153 self.__ui.wordCheckBox.isChecked(), |
153 self.__ui.wordCheckBox.isChecked(), |
154 self.__ui.regexpCheckBox.isChecked(), |
154 self.__ui.regexpCheckBox.isChecked(), |
155 ) |
155 ) |
156 |
156 |
157 @pyqtSlot(str) |
157 @pyqtSlot(str) |
158 def on_findtextCombo_editTextChanged(self, txt): |
158 def on_findtextCombo_editTextChanged(self, txt): |
159 """ |
159 """ |
160 Private slot to enable/disable the find buttons. |
160 Private slot to enable/disable the find buttons. |
161 |
161 |
162 @param txt text of the combobox (string) |
162 @param txt text of the combobox (string) |
163 """ |
163 """ |
164 self.__setSearchButtons(txt != "") |
164 self.__setSearchButtons(txt != "") |
165 |
165 |
166 def __setSearchButtons(self, enabled): |
166 def __setSearchButtons(self, enabled): |
167 """ |
167 """ |
168 Private slot to set the state of the search buttons. |
168 Private slot to set the state of the search buttons. |
169 |
169 |
170 @param enabled flag indicating the state (boolean) |
170 @param enabled flag indicating the state (boolean) |
171 """ |
171 """ |
172 self.__ui.findPrevButton.setEnabled(enabled) |
172 self.__ui.findPrevButton.setEnabled(enabled) |
173 self.__ui.findNextButton.setEnabled(enabled) |
173 self.__ui.findNextButton.setEnabled(enabled) |
174 |
174 |
175 def __findByReturnPressed(self): |
175 def __findByReturnPressed(self): |
176 """ |
176 """ |
177 Private slot to handle the returnPressed signal of the findtext |
177 Private slot to handle the returnPressed signal of the findtext |
178 combobox. |
178 combobox. |
179 """ |
179 """ |