10 from __future__ import unicode_literals |
10 from __future__ import unicode_literals |
11 |
11 |
12 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt |
12 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt |
13 from PyQt5.QtWidgets import QWidget, QSpacerItem, QSizePolicy |
13 from PyQt5.QtWidgets import QWidget, QSpacerItem, QSizePolicy |
14 |
14 |
15 from .Ui_SearchWidget import Ui_SearchWidget |
|
16 |
|
17 import UI.PixmapCache |
15 import UI.PixmapCache |
18 |
16 |
19 |
17 |
20 class SearchWidget(QWidget, Ui_SearchWidget): |
18 class SearchWidget(QWidget): |
21 """ |
19 """ |
22 Class implementing the search box for the shell, terminal and log viewer. |
20 Class implementing the search box for the shell, terminal and log viewer. |
23 |
21 |
24 @signal searchNext(text, caseSensitive, wholeWord) emitted when the user |
22 @signal searchNext(text, caseSensitive, wholeWord) emitted when the user |
25 pressed the next button (string, boolean, boolean) |
23 pressed the next button (string, boolean, boolean) |
27 user pressed the previous button (string, boolean, boolean) |
25 user pressed the previous button (string, boolean, boolean) |
28 """ |
26 """ |
29 searchNext = pyqtSignal(str, bool, bool) |
27 searchNext = pyqtSignal(str, bool, bool) |
30 searchPrevious = pyqtSignal(str, bool, bool) |
28 searchPrevious = pyqtSignal(str, bool, bool) |
31 |
29 |
32 def __init__(self, mainWindow, parent=None, spacer=True): |
30 def __init__(self, mainWindow, parent=None, spacer=True, showLine=False): |
33 """ |
31 """ |
34 Constructor |
32 Constructor |
35 |
33 |
36 @param mainWindow reference to the main window (QWidget) |
34 @param mainWindow reference to the main window (QWidget) |
37 @param parent reference to the parent widget (QWidget) |
35 @param parent reference to the parent widget (QWidget) |
38 @param spacer flag indicating to add a vertical spacer to the |
36 @param spacer flag indicating to add a vertical spacer to the |
39 main layout (boolean) |
37 main layout (boolean) |
|
38 @param showLine flag indicating to show all widget in one row (boolean) |
40 """ |
39 """ |
41 super(SearchWidget, self).__init__(parent) |
40 super(SearchWidget, self).__init__(parent) |
42 self.setupUi(self) |
41 |
43 if spacer: |
42 if showLine: |
44 spacerItem = QSpacerItem( |
43 from .Ui_SearchWidgetLine import Ui_SearchWidgetLine |
45 20, 1, QSizePolicy.Minimum, QSizePolicy.Expanding) |
44 self.__ui = Ui_SearchWidgetLine() |
46 self.verticalLayout.addItem(spacerItem) |
|
47 else: |
45 else: |
48 # change the size policy of the search combo if the spacer is not |
46 from .Ui_SearchWidget import Ui_SearchWidget |
49 # wanted, i.e. it is below the to be searched widget |
47 self.__ui = Ui_SearchWidget() |
50 sizePolicy = self.findtextCombo.sizePolicy() |
48 self.__ui.setupUi(self) |
51 sizePolicy.setHorizontalPolicy(QSizePolicy.Expanding) |
49 if not showLine: |
52 self.findtextCombo.setSizePolicy(sizePolicy) |
50 if spacer: |
|
51 spacerItem = QSpacerItem( |
|
52 20, 1, QSizePolicy.Minimum, QSizePolicy.Expanding) |
|
53 self.__ui.verticalLayout.addItem(spacerItem) |
|
54 else: |
|
55 # change the size policy of the search combo if the spacer is |
|
56 # not wanted, i.e. it is below the to be searched widget |
|
57 sizePolicy = self.__ui.findtextCombo.sizePolicy() |
|
58 sizePolicy.setHorizontalPolicy(QSizePolicy.Expanding) |
|
59 self.__ui.findtextCombo.setSizePolicy(sizePolicy) |
53 |
60 |
54 self.__mainWindow = mainWindow |
61 self.__mainWindow = mainWindow |
55 self.__findBackwards = True |
62 self.__findBackwards = True |
56 |
63 |
57 self.closeButton.setIcon(UI.PixmapCache.getIcon("close.png")) |
64 self.__ui.closeButton.setIcon( |
58 self.findPrevButton.setIcon(UI.PixmapCache.getIcon("1leftarrow.png")) |
65 UI.PixmapCache.getIcon("close.png")) |
59 self.findNextButton.setIcon(UI.PixmapCache.getIcon("1rightarrow.png")) |
66 self.__ui.findPrevButton.setIcon( |
|
67 UI.PixmapCache.getIcon("1leftarrow.png")) |
|
68 self.__ui.findNextButton.setIcon( |
|
69 UI.PixmapCache.getIcon("1rightarrow.png")) |
60 |
70 |
61 self.findHistory = [] |
71 self.findHistory = [] |
62 |
72 |
63 self.findtextCombo.setCompleter(None) |
73 self.__ui.findtextCombo.setCompleter(None) |
64 self.findtextCombo.lineEdit().returnPressed.connect( |
74 self.__ui.findtextCombo.lineEdit().returnPressed.connect( |
65 self.__findByReturnPressed) |
75 self.__findByReturnPressed) |
66 |
76 |
67 msh = self.minimumSizeHint() |
77 msh = self.minimumSizeHint() |
68 self.resize(max(self.width(), msh.width()), msh.height()) |
78 self.resize(max(self.width(), msh.width()), msh.height()) |
69 |
79 |
88 @pyqtSlot() |
98 @pyqtSlot() |
89 def on_findNextButton_clicked(self): |
99 def on_findNextButton_clicked(self): |
90 """ |
100 """ |
91 Private slot to find the next occurrence. |
101 Private slot to find the next occurrence. |
92 """ |
102 """ |
93 txt = self.findtextCombo.currentText() |
103 txt = self.__ui.findtextCombo.currentText() |
|
104 if not txt and not self.isVisible(): |
|
105 self.showFind() |
|
106 return |
|
107 |
94 self.__findBackwards = False |
108 self.__findBackwards = False |
95 |
109 |
96 # This moves any previous occurrence of this statement to the head |
110 # This moves any previous occurrence of this statement to the head |
97 # of the list and updates the combobox |
111 # of the list and updates the combobox |
98 if txt in self.findHistory: |
112 if txt in self.findHistory: |
99 self.findHistory.remove(txt) |
113 self.findHistory.remove(txt) |
100 self.findHistory.insert(0, txt) |
114 self.findHistory.insert(0, txt) |
101 self.findtextCombo.clear() |
115 self.__ui.findtextCombo.clear() |
102 self.findtextCombo.addItems(self.findHistory) |
116 self.__ui.findtextCombo.addItems(self.findHistory) |
103 |
117 |
104 self.searchNext.emit( |
118 self.searchNext.emit( |
105 txt, |
119 txt, |
106 self.caseCheckBox.isChecked(), |
120 self.__ui.caseCheckBox.isChecked(), |
107 self.wordCheckBox.isChecked()) |
121 self.__ui.wordCheckBox.isChecked()) |
108 |
122 |
109 @pyqtSlot() |
123 @pyqtSlot() |
110 def on_findPrevButton_clicked(self): |
124 def on_findPrevButton_clicked(self): |
111 """ |
125 """ |
112 Private slot to find the previous occurrence. |
126 Private slot to find the previous occurrence. |
113 """ |
127 """ |
114 txt = self.findtextCombo.currentText() |
128 txt = self.__ui.findtextCombo.currentText() |
|
129 if not txt and not self.isVisible(): |
|
130 self.showFind() |
|
131 return |
|
132 |
115 self.__findBackwards = True |
133 self.__findBackwards = True |
116 |
134 |
117 # This moves any previous occurrence of this statement to the head |
135 # This moves any previous occurrence of this statement to the head |
118 # of the list and updates the combobox |
136 # of the list and updates the combobox |
119 if txt in self.findHistory: |
137 if txt in self.findHistory: |
120 self.findHistory.remove(txt) |
138 self.findHistory.remove(txt) |
121 self.findHistory.insert(0, txt) |
139 self.findHistory.insert(0, txt) |
122 self.findtextCombo.clear() |
140 self.__ui.findtextCombo.clear() |
123 self.findtextCombo.addItems(self.findHistory) |
141 self.__ui.findtextCombo.addItems(self.findHistory) |
124 |
142 |
125 self.searchPrevious.emit( |
143 self.searchPrevious.emit( |
126 txt, |
144 txt, |
127 self.caseCheckBox.isChecked(), |
145 self.__ui.caseCheckBox.isChecked(), |
128 self.wordCheckBox.isChecked()) |
146 self.__ui.wordCheckBox.isChecked()) |
129 |
147 |
130 @pyqtSlot(str) |
148 @pyqtSlot(str) |
131 def on_findtextCombo_editTextChanged(self, txt): |
149 def on_findtextCombo_editTextChanged(self, txt): |
132 """ |
150 """ |
133 Private slot to enable/disable the find buttons. |
151 Private slot to enable/disable the find buttons. |