Beispiel #1
0
 def save_search_type(self):
     text = self.search_box.currentText()
     if text and not self.ignore_search_type_changes:
         sss = vprefs.get(f'saved-{self.panel_name}-settings') or {}
         sss[text] = {
             'case_sensitive': self.case_sensitive.isChecked(),
             'mode': self.query_type.currentData()
         }
         vprefs[f'saved-{self.panel_name}-settings'] = sss
Beispiel #2
0
 def history_saved(self, new_text, history):
     if new_text:
         sss = vprefs.get(f'saved-{self.panel_name}-settings') 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[f'saved-{self.panel_name}-settings'] = sss
Beispiel #3
0
 def configure(self, data):
     ui_settings = get_pref_group('tts').copy()
     key = 'tts_' + self.tts_client.name
     d = Config(self.tts_client,
                ui_settings,
                vprefs.get(key) or {},
                parent=self.parent())
     if d.exec_() == d.DialogCode.Accepted:
         vprefs[key] = d.backend_settings
         self.settings_changed.emit(d.ui_settings)
Beispiel #4
0
 def saved_search_selected(self):
     text = self.search_box.currentText()
     if text:
         s = (vprefs.get(f'saved-{self.panel_name}-settings')
              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 __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(f'viewer-{panel_name}-panel-expression')
        sb.item_selected.connect(self.saved_search_selected)
        sb.history_saved.connect(self.history_saved)
        sb.history_cleared.connect(self.history_cleared)
        sb.cleared.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.FocusPolicy.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.FocusPolicy.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.FocusPolicy.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(f'viewer-{self.panel_name}-mode', 'normal')
                or 'normal'))
        qt.currentIndexChanged.connect(self.save_search_type)
        h.addWidget(qt)

        self.case_sensitive = cs = QCheckBox(_('&Case sensitive'), self)
        cs.setFocusPolicy(Qt.FocusPolicy.NoFocus)
        cs.setChecked(
            bool(vprefs.get(f'viewer-{self.panel_name}-case-sensitive',
                            False)))
        cs.stateChanged.connect(self.save_search_type)
        h.addWidget(cs)

        self.return_button = rb = QToolButton(self)
        rb.setIcon(QIcon(I('back.png')))
        rb.setToolTip(_('Go back to where you were before searching'))
        rb.clicked.connect(self.go_back)
        h.addWidget(rb)
Beispiel #6
0
 def backend_settings(self):
     key = 'tts_' + self.tts_client_class.name
     return vprefs.get(key) or {}
Beispiel #7
0
 def backend_settings(self):
     from calibre.gui2.tts.implementation import Client
     key = 'tts_' + Client.name
     return vprefs.get(key) or {}