mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Search box tweaks
This commit is contained in:
commit
f8b9e49eca
@ -164,12 +164,15 @@ class EditMetadataAction(InterfaceAction):
|
||||
self.gui.tags_view.blockSignals(True)
|
||||
changed = False
|
||||
try:
|
||||
current_tab = 0
|
||||
while True:
|
||||
dialog = MetadataBulkDialog(self.gui, rows, self.gui.library_view.model())
|
||||
dialog = MetadataBulkDialog(self.gui, rows,
|
||||
self.gui.library_view.model(), current_tab)
|
||||
if dialog.changed:
|
||||
changed = True
|
||||
if not dialog.do_again:
|
||||
break
|
||||
current_tab = dialog.central_widget.currentIndex()
|
||||
finally:
|
||||
self.gui.tags_view.blockSignals(False)
|
||||
if changed:
|
||||
|
@ -197,7 +197,7 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
||||
_('Append to field'),
|
||||
]
|
||||
|
||||
def __init__(self, window, rows, model):
|
||||
def __init__(self, window, rows, model, tab):
|
||||
QDialog.__init__(self, window)
|
||||
Ui_MetadataBulkDialog.__init__(self)
|
||||
self.setupUi(self)
|
||||
@ -238,6 +238,7 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
||||
'Immediately make all changes without closing the dialog. '
|
||||
'This operation cannot be canceled or undone'))
|
||||
self.do_again = False
|
||||
self.central_widget.setCurrentIndex(tab)
|
||||
self.exec_()
|
||||
|
||||
def button_clicked(self, which):
|
||||
|
@ -182,7 +182,7 @@ class SearchBar(QWidget): # {{{
|
||||
l.addWidget(self.search_button)
|
||||
self.search_button.setSizePolicy(QSizePolicy.Minimum,
|
||||
QSizePolicy.Minimum)
|
||||
self.search_button.clicked.connect(parent.search.do_search)
|
||||
self.search_button.clicked.connect(parent.do_search_button)
|
||||
self.search_button.setToolTip(
|
||||
_('Do Quick Search (you can also press the Enter key)'))
|
||||
|
||||
|
@ -9,7 +9,8 @@ __docformat__ = 'restructuredtext en'
|
||||
import re
|
||||
|
||||
from PyQt4.Qt import QComboBox, Qt, QLineEdit, QStringList, pyqtSlot, QDialog, \
|
||||
pyqtSignal, QCompleter, QAction, QKeySequence, QTimer
|
||||
pyqtSignal, QCompleter, QAction, QKeySequence, QTimer, \
|
||||
QString
|
||||
|
||||
from calibre.gui2 import config
|
||||
from calibre.gui2.dialogs.confirm_delete import confirm
|
||||
@ -24,10 +25,6 @@ class SearchLineEdit(QLineEdit):
|
||||
self.key_pressed.emit(event)
|
||||
QLineEdit.keyPressEvent(self, event)
|
||||
|
||||
def mouseReleaseEvent(self, event):
|
||||
QLineEdit.mouseReleaseEvent(self, event)
|
||||
QLineEdit.selectAll(self)
|
||||
|
||||
def dropEvent(self, ev):
|
||||
self.parent().normalize_state()
|
||||
return QLineEdit.dropEvent(self, ev)
|
||||
@ -66,8 +63,11 @@ class SearchBox2(QComboBox):
|
||||
self.normal_background = 'rgb(255, 255, 255, 0%)'
|
||||
self.line_edit = SearchLineEdit(self)
|
||||
self.setLineEdit(self.line_edit)
|
||||
|
||||
c = self.line_edit.completer()
|
||||
c.setCompletionMode(c.PopupCompletion)
|
||||
c.highlighted[QString].connect(self.completer_used)
|
||||
|
||||
self.line_edit.key_pressed.connect(self.key_pressed, type=Qt.DirectConnection)
|
||||
self.activated.connect(self.history_selected)
|
||||
self.setEditable(True)
|
||||
@ -126,6 +126,7 @@ class SearchBox2(QComboBox):
|
||||
col = self.normal_background
|
||||
self.line_edit.setStyleSheet('QLineEdit{color:black;background-color:%s;}' % col)
|
||||
|
||||
# Comes from the lineEdit control
|
||||
def key_pressed(self, event):
|
||||
k = event.key()
|
||||
if k in (Qt.Key_Left, Qt.Key_Right, Qt.Key_Up, Qt.Key_Down,
|
||||
@ -142,6 +143,21 @@ class SearchBox2(QComboBox):
|
||||
elif self.as_you_type and unicode(event.text()):
|
||||
self.timer.start(1500)
|
||||
|
||||
# Comes from the combobox itself
|
||||
def keyPressEvent(self, event):
|
||||
k = event.key()
|
||||
if k not in (Qt.Key_Up, Qt.Key_Down):
|
||||
QComboBox.keyPressEvent(self, event)
|
||||
else:
|
||||
self.blockSignals(True)
|
||||
self.normalize_state()
|
||||
QComboBox.keyPressEvent(self, event)
|
||||
self.blockSignals(False)
|
||||
|
||||
def completer_used(self, text):
|
||||
self.timer.stop()
|
||||
self.normalize_state()
|
||||
|
||||
def timer_event(self):
|
||||
self.do_search()
|
||||
|
||||
@ -183,14 +199,16 @@ class SearchBox2(QComboBox):
|
||||
self.set_search_string(joiner.join(tags))
|
||||
|
||||
def set_search_string(self, txt):
|
||||
self.setFocus(Qt.OtherFocusReason)
|
||||
if not txt:
|
||||
self.clear()
|
||||
return
|
||||
self.normalize_state()
|
||||
self.setEditText(txt)
|
||||
self.search.emit(txt)
|
||||
self.line_edit.end(False)
|
||||
self.initial_state = False
|
||||
else:
|
||||
self.normalize_state()
|
||||
self.setEditText(txt)
|
||||
self.search.emit(txt)
|
||||
self.line_edit.end(False)
|
||||
self.initial_state = False
|
||||
self.focus_to_library.emit()
|
||||
|
||||
def search_as_you_type(self, enabled):
|
||||
self.as_you_type = enabled
|
||||
@ -208,7 +226,6 @@ class SavedSearchBox(QComboBox):
|
||||
'''
|
||||
|
||||
changed = pyqtSignal()
|
||||
focus_to_library = pyqtSignal()
|
||||
|
||||
def __init__(self, parent=None):
|
||||
QComboBox.__init__(self, parent)
|
||||
@ -253,7 +270,6 @@ class SavedSearchBox(QComboBox):
|
||||
def key_pressed(self, event):
|
||||
if event.key() in (Qt.Key_Return, Qt.Key_Enter):
|
||||
self.saved_search_selected(self.currentText())
|
||||
self.focus_to_library.emit()
|
||||
|
||||
def saved_search_selected(self, qname):
|
||||
qname = unicode(qname)
|
||||
@ -267,7 +283,6 @@ class SavedSearchBox(QComboBox):
|
||||
self.search_box.set_search_string(u'search:"%s"' % qname)
|
||||
self.setEditText(qname)
|
||||
self.setToolTip(saved_searches().lookup(qname))
|
||||
self.focus_to_library.emit()
|
||||
|
||||
def initialize_saved_search_names(self):
|
||||
qnames = saved_searches().names()
|
||||
@ -355,6 +370,10 @@ class SearchBoxMixin(object):
|
||||
if d.exec_() == QDialog.Accepted:
|
||||
self.search.set_search_string(d.search_string())
|
||||
|
||||
def do_search_button(self):
|
||||
self.search.do_search()
|
||||
self.focus_to_library()
|
||||
|
||||
def focus_to_library(self):
|
||||
self.current_view().setFocus(Qt.OtherFocusReason)
|
||||
|
||||
@ -363,7 +382,6 @@ class SavedSearchBoxMixin(object):
|
||||
def __init__(self):
|
||||
self.saved_search.changed.connect(self.saved_searches_changed)
|
||||
self.clear_button.clicked.connect(self.saved_search.clear)
|
||||
self.saved_search.focus_to_library.connect(self.focus_to_library)
|
||||
self.save_search_button.clicked.connect(
|
||||
self.saved_search.save_search_button_clicked)
|
||||
self.delete_search_button.clicked.connect(
|
||||
@ -398,7 +416,3 @@ class SavedSearchBoxMixin(object):
|
||||
if d.result() == d.Accepted:
|
||||
self.saved_searches_changed()
|
||||
self.saved_search.clear()
|
||||
|
||||
def focus_to_library(self):
|
||||
self.current_view().setFocus(Qt.OtherFocusReason)
|
||||
|
||||
|
@ -4,6 +4,8 @@ Created on 10 Jun 2010
|
||||
@author: charles
|
||||
'''
|
||||
|
||||
from PyQt4.Qt import Qt
|
||||
|
||||
class SearchRestrictionMixin(object):
|
||||
|
||||
def __init__(self):
|
||||
@ -53,6 +55,7 @@ class SearchRestrictionMixin(object):
|
||||
self.saved_search.clear()
|
||||
self.tags_view.set_search_restriction(restriction)
|
||||
self.set_number_of_books_shown()
|
||||
self.current_view().setFocus(Qt.OtherFocusReason)
|
||||
|
||||
def set_number_of_books_shown(self):
|
||||
if self.current_view() == self.library_view and self.restriction_in_effect:
|
||||
|
Loading…
x
Reference in New Issue
Block a user