Merge from trunk

This commit is contained in:
Charles Haley 2010-11-30 17:25:28 +00:00
commit 3f60393533
6 changed files with 36 additions and 21 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 693 B

View File

@ -10,7 +10,8 @@ Scheduler for automated recipe downloads
from datetime import timedelta from datetime import timedelta
from PyQt4.Qt import QDialog, SIGNAL, Qt, QTime, QObject, QMenu, \ from PyQt4.Qt import QDialog, SIGNAL, Qt, QTime, QObject, QMenu, \
QAction, QIcon, QMutex, QTimer, pyqtSignal QAction, QIcon, QMutex, QTimer, pyqtSignal, QWidget, QHBoxLayout, \
QLabel
from calibre.gui2.dialogs.scheduler_ui import Ui_Dialog from calibre.gui2.dialogs.scheduler_ui import Ui_Dialog
from calibre.gui2.search_box import SearchBox2 from calibre.gui2.search_box import SearchBox2
@ -28,15 +29,21 @@ class SchedulerDialog(QDialog, Ui_Dialog):
self.recipe_model = recipe_model self.recipe_model = recipe_model
self.recipe_model.do_refresh() self.recipe_model.do_refresh()
self._cont = QWidget(self)
self._cont.l = QHBoxLayout()
self._cont.setLayout(self._cont.l)
self._cont.la = QLabel(_('&Search:'))
self._cont.l.addWidget(self._cont.la, 1)
self.search = SearchBox2(self) self.search = SearchBox2(self)
self._cont.l.addWidget(self.search, 100)
self._cont.la.setBuddy(self.search)
self.search.setMinimumContentsLength(25) self.search.setMinimumContentsLength(25)
self.search.initialize('scheduler_search_history') self.search.initialize('scheduler_search_history')
self.recipe_box.layout().insertWidget(0, self.search) self.recipe_box.layout().insertWidget(0, self._cont)
self.search.search.connect(self.recipe_model.search) self.search.search.connect(self.recipe_model.search)
self.connect(self.recipe_model, SIGNAL('searched(PyQt_PyObject)'), self.recipe_model.searched.connect(self.search.search_done,
self.search.search_done) type=Qt.QueuedConnection)
self.connect(self.recipe_model, SIGNAL('searched(PyQt_PyObject)'), self.recipe_model.searched.connect(self.search_done)
self.search_done)
self.search.setFocus(Qt.OtherFocusReason) self.search.setFocus(Qt.OtherFocusReason)
self.commit_on_change = True self.commit_on_change = True

View File

@ -76,7 +76,6 @@ class SearchBox2(QComboBox):
self.activated.connect(self.history_selected) self.activated.connect(self.history_selected)
self.setEditable(True) self.setEditable(True)
self.as_you_type = True self.as_you_type = True
self.prev_search = ''
self.timer = QTimer() self.timer = QTimer()
self.timer.setSingleShot(True) self.timer.setSingleShot(True)
self.timer.timeout.connect(self.timer_event, type=Qt.QueuedConnection) self.timer.timeout.connect(self.timer_event, type=Qt.QueuedConnection)
@ -91,7 +90,11 @@ class SearchBox2(QComboBox):
self.as_you_type = config['search_as_you_type'] self.as_you_type = config['search_as_you_type']
self.opt_name = opt_name self.opt_name = opt_name
self.addItems(QStringList(list(set(config[opt_name])))) self.addItems(QStringList(list(set(config[opt_name]))))
self.line_edit.setPlaceholderText(help_text) try:
self.line_edit.setPlaceholderText(help_text)
except:
# Using Qt < 4.7
pass
self.colorize = colorize self.colorize = colorize
self.clear() self.clear()
@ -103,10 +106,11 @@ class SearchBox2(QComboBox):
def text(self): def text(self):
return self.currentText() return self.currentText()
def clear(self): def clear(self, emit_search=True):
self.normalize_state() self.normalize_state()
self.setEditText('') self.setEditText('')
self.search.emit('') if emit_search:
self.search.emit('')
self._in_a_search = False self._in_a_search = False
self.cleared.emit() self.cleared.emit()
@ -115,7 +119,7 @@ class SearchBox2(QComboBox):
self.setToolTip(ok) self.setToolTip(ok)
ok = False ok = False
if not unicode(self.currentText()).strip(): if not unicode(self.currentText()).strip():
self.clear() self.clear(emit_search=False)
return return
self._in_a_search = ok self._in_a_search = ok
col = 'rgba(0,255,0,20%)' if ok else 'rgb(255,0,0,20%)' col = 'rgba(0,255,0,20%)' if ok else 'rgb(255,0,0,20%)'
@ -126,7 +130,8 @@ class SearchBox2(QComboBox):
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,
Qt.Key_Home, Qt.Key_End, Qt.Key_PageUp, Qt.Key_PageDown): Qt.Key_Home, Qt.Key_End, Qt.Key_PageUp, Qt.Key_PageDown,
Qt.Key_unknown):
return return
self.normalize_state() self.normalize_state()
if self._in_a_search: if self._in_a_search:
@ -135,7 +140,7 @@ class SearchBox2(QComboBox):
if event.key() in (Qt.Key_Return, Qt.Key_Enter): if event.key() in (Qt.Key_Return, Qt.Key_Enter):
self.do_search() self.do_search()
self.focus_to_library.emit() self.focus_to_library.emit()
if self.as_you_type: elif self.as_you_type and unicode(event.text()):
self.timer.start(1500) self.timer.start(1500)
def timer_event(self): def timer_event(self):
@ -149,7 +154,6 @@ class SearchBox2(QComboBox):
text = unicode(self.currentText()).strip() text = unicode(self.currentText()).strip()
if not text: if not text:
return self.clear() return self.clear()
self.prev_search = text
self.search.emit(text) self.search.emit(text)
idx = self.findText(text, Qt.MatchFixedString) idx = self.findText(text, Qt.MatchFixedString)

View File

@ -237,9 +237,9 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
self.connect(self.action_previous_page, SIGNAL('triggered(bool)'), self.connect(self.action_previous_page, SIGNAL('triggered(bool)'),
lambda x:self.view.previous_page()) lambda x:self.view.previous_page())
self.connect(self.action_find_next, SIGNAL('triggered(bool)'), self.connect(self.action_find_next, SIGNAL('triggered(bool)'),
lambda x:self.find(self.search.text(), repeat=True)) lambda x:self.find(unicode(self.search.text()), repeat=True))
self.connect(self.action_find_previous, SIGNAL('triggered(bool)'), self.connect(self.action_find_previous, SIGNAL('triggered(bool)'),
lambda x:self.find(self.search.text(), lambda x:self.find(unicode(self.search.text()),
repeat=True, backwards=True)) repeat=True, backwards=True))
self.connect(self.action_full_screen, SIGNAL('triggered(bool)'), self.connect(self.action_full_screen, SIGNAL('triggered(bool)'),

View File

@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en'
import os, copy import os, copy
from PyQt4.Qt import QAbstractItemModel, QVariant, Qt, QColor, QFont, QIcon, \ from PyQt4.Qt import QAbstractItemModel, QVariant, Qt, QColor, QFont, QIcon, \
QModelIndex, SIGNAL, QMetaObject, pyqtSlot QModelIndex, QMetaObject, pyqtSlot, pyqtSignal
from calibre.utils.search_query_parser import SearchQueryParser from calibre.utils.search_query_parser import SearchQueryParser
from calibre.gui2 import NONE from calibre.gui2 import NONE
@ -120,6 +120,7 @@ class NewsItem(NewsTreeItem):
class RecipeModel(QAbstractItemModel, SearchQueryParser): class RecipeModel(QAbstractItemModel, SearchQueryParser):
LOCATIONS = ['all'] LOCATIONS = ['all']
searched = pyqtSignal(object)
def __init__(self, db, *args): def __init__(self, db, *args):
QAbstractItemModel.__init__(self, *args) QAbstractItemModel.__init__(self, *args)
@ -254,14 +255,17 @@ class RecipeModel(QAbstractItemModel, SearchQueryParser):
return results return results
def search(self, query): def search(self, query):
results = []
try: try:
results = self.parse(unicode(query)) query = unicode(query).strip()
if not results: if query:
results = None results = self.parse(query)
if not results:
results = None
except ParseException: except ParseException:
results = [] results = []
self.do_refresh(restrict_to_urns=results) self.do_refresh(restrict_to_urns=results)
self.emit(SIGNAL('searched(PyQt_PyObject)'), True) self.searched.emit(True)
def columnCount(self, parent): def columnCount(self, parent):
return 1 return 1