Beispiel #1
0
    def __init__(self, parent=None, panel_name='search'):
        QWidget.__init__(self, parent)
        self.ignore_search_type_changes = False
        self.l = l = QVBoxLayout(self)
        l.setContentsMargins(0, 0, 0, 0)
        h = QHBoxLayout()
        h.setContentsMargins(0, 0, 0, 0)
        l.addLayout(h)

        self.search_box = sb = SearchBox(self)
        self.panel_name = panel_name
        sb.initialize('viewer-{}-panel-expression'.format(panel_name))
        sb.item_selected.connect(self.saved_search_selected)
        sb.history_saved.connect(self.history_saved)
        sb.lineEdit().setPlaceholderText(_('Search'))
        sb.lineEdit().setClearButtonEnabled(True)
        ac = sb.lineEdit().findChild(QAction, QT_HIDDEN_CLEAR_ACTION)
        if ac is not None:
            ac.triggered.connect(self.cleared)
        sb.lineEdit().returnPressed.connect(self.find_next)
        h.addWidget(sb)

        self.next_button = nb = QToolButton(self)
        h.addWidget(nb)
        nb.setFocusPolicy(Qt.NoFocus)
        nb.setIcon(QIcon(I('arrow-down.png')))
        nb.clicked.connect(self.find_next)
        nb.setToolTip(_('Find next match'))

        self.prev_button = nb = QToolButton(self)
        h.addWidget(nb)
        nb.setFocusPolicy(Qt.NoFocus)
        nb.setIcon(QIcon(I('arrow-up.png')))
        nb.clicked.connect(self.find_previous)
        nb.setToolTip(_('Find previous match'))

        h = QHBoxLayout()
        h.setContentsMargins(0, 0, 0, 0)
        l.addLayout(h)
        self.query_type = qt = QComboBox(self)
        qt.setFocusPolicy(Qt.NoFocus)
        qt.addItem(_('Contains'), 'normal')
        qt.addItem(_('Whole words'), 'word')
        qt.addItem(_('Regex'), 'regex')
        qt.setToolTip(('<p>' + _(
            'Choose the type of search: <ul>'
            '<li><b>Contains</b> will search for the entered text anywhere.'
            '<li><b>Whole words</b> will search for whole words that equal the entered text.'
            '<li><b>Regex</b> will interpret the text as a regular expression.'
        )))
        qt.setCurrentIndex(qt.findData(vprefs.get('viewer-{}-mode'.format(self.panel_name), 'normal') or 'normal'))
        qt.currentIndexChanged.connect(self.save_search_type)
        h.addWidget(qt)

        self.case_sensitive = cs = QCheckBox(_('&Case sensitive'), self)
        cs.setFocusPolicy(Qt.NoFocus)
        cs.setChecked(bool(vprefs.get('viewer-{}-case-sensitive'.format(self.panel_name), False)))
        cs.stateChanged.connect(self.save_search_type)
        h.addWidget(cs)
Beispiel #2
0
 def history_saved(self, new_text, history):
     if new_text:
         sss = vprefs.get('saved-{}-settings'.format(self.panel_name)) or {}
         sss[new_text] = {'case_sensitive': self.case_sensitive.isChecked(), 'mode': self.query_type.currentData()}
         history = frozenset(history)
         sss = {k: v for k, v in iteritems(sss) if k in history}
         vprefs['saved-{}-settings'.format(self.panel_name)] = sss
Beispiel #3
0
 def save_search_type(self):
     text = self.search_box.currentText()
     if text and not self.ignore_search_type_changes:
         sss = vprefs.get('saved-{}-settings'.format(self.panel_name)) or {}
         sss[text] = {
             'case_sensitive': self.case_sensitive.isChecked(),
             'mode': self.query_type.currentData()
         }
         vprefs['saved-{}-settings'.format(self.panel_name)] = sss
Beispiel #4
0
 def saved_search_selected(self):
     text = self.search_box.currentText()
     if text:
         s = (vprefs.get('saved-{}-settings'.format(self.panel_name)) or {}).get(text)
         if s:
             self.ignore_search_type_changes = True
             if 'case_sensitive' in s:
                 self.case_sensitive.setChecked(s['case_sensitive'])
             if 'mode' in s:
                 idx = self.query_type.findData(s['mode'])
                 if idx > -1:
                     self.query_type.setCurrentIndex(idx)
             self.ignore_search_type_changes = False
         self.find_next()
Beispiel #5
0
def current_actions():
    ans = vprefs.get('actions-toolbar-actions')
    if not ans:
        ans = DEFAULT_ACTIONS
    return tuple(ans)