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