mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
commit
d4f7c5ee3f
@ -94,6 +94,7 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
self.bool_blank_icon = QIcon(I('blank.png'))
|
self.bool_blank_icon = QIcon(I('blank.png'))
|
||||||
self.device_connected = False
|
self.device_connected = False
|
||||||
self.rows_matching = set()
|
self.rows_matching = set()
|
||||||
|
self.lowest_row_matching = None
|
||||||
self.highlight_only = False
|
self.highlight_only = False
|
||||||
self.read_config()
|
self.read_config()
|
||||||
|
|
||||||
@ -233,7 +234,8 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
|
|
||||||
def set_highlight_only(self, toWhat):
|
def set_highlight_only(self, toWhat):
|
||||||
self.highlight_only = toWhat
|
self.highlight_only = toWhat
|
||||||
self.research()
|
if self.last_search:
|
||||||
|
self.research()
|
||||||
|
|
||||||
def search(self, text, reset=True):
|
def search(self, text, reset=True):
|
||||||
try:
|
try:
|
||||||
@ -241,11 +243,15 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
self.db.search('')
|
self.db.search('')
|
||||||
if not text:
|
if not text:
|
||||||
self.rows_matching = set()
|
self.rows_matching = set()
|
||||||
|
self.lowest_row_matching = None
|
||||||
else:
|
else:
|
||||||
self.rows_matching = set(self.db.search(text,
|
self.rows_matching = self.db.search(text, return_matches=True)
|
||||||
return_matches=True))
|
if self.rows_matching:
|
||||||
|
self.lowest_row_matching = self.db.row(self.rows_matching[0])
|
||||||
|
self.rows_matching = set(self.rows_matching)
|
||||||
else:
|
else:
|
||||||
self.rows_matching = set()
|
self.rows_matching = set()
|
||||||
|
self.lowest_row_matching = None
|
||||||
self.db.search(text)
|
self.db.search(text)
|
||||||
except ParseException as e:
|
except ParseException as e:
|
||||||
self.searched.emit(e.msg)
|
self.searched.emit(e.msg)
|
||||||
|
@ -682,6 +682,8 @@ class BooksView(QTableView): # {{{
|
|||||||
|
|
||||||
def search_proxy(self, txt):
|
def search_proxy(self, txt):
|
||||||
self._model.search(txt)
|
self._model.search(txt)
|
||||||
|
if self._model.lowest_row_matching is not None:
|
||||||
|
self.select_rows([self._model.lowest_row_matching], using_ids=False)
|
||||||
self.setFocus(Qt.OtherFocusReason)
|
self.setFocus(Qt.OtherFocusReason)
|
||||||
|
|
||||||
def connect_to_search_box(self, sb, search_done):
|
def connect_to_search_box(self, sb, search_done):
|
||||||
|
@ -16,6 +16,7 @@ from calibre.gui2 import config
|
|||||||
from calibre.gui2.dialogs.confirm_delete import confirm
|
from calibre.gui2.dialogs.confirm_delete import confirm
|
||||||
from calibre.gui2.dialogs.saved_search_editor import SavedSearchEditor
|
from calibre.gui2.dialogs.saved_search_editor import SavedSearchEditor
|
||||||
from calibre.gui2.dialogs.search import SearchDialog
|
from calibre.gui2.dialogs.search import SearchDialog
|
||||||
|
from calibre.utils.config import dynamic
|
||||||
from calibre.utils.search_query_parser import saved_searches
|
from calibre.utils.search_query_parser import saved_searches
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
|
|
||||||
@ -376,6 +377,8 @@ class SearchBoxMixin(object): # {{{
|
|||||||
self.advanced_search_button.setStatusTip(self.advanced_search_button.toolTip())
|
self.advanced_search_button.setStatusTip(self.advanced_search_button.toolTip())
|
||||||
self.clear_button.setStatusTip(self.clear_button.toolTip())
|
self.clear_button.setStatusTip(self.clear_button.toolTip())
|
||||||
self.search_highlight_only.stateChanged.connect(self.highlight_only_changed)
|
self.search_highlight_only.stateChanged.connect(self.highlight_only_changed)
|
||||||
|
self.search_highlight_only.setChecked(
|
||||||
|
dynamic.get('search_highlight_only', False))
|
||||||
|
|
||||||
def focus_search_box(self, *args):
|
def focus_search_box(self, *args):
|
||||||
self.search.setFocus(Qt.OtherFocusReason)
|
self.search.setFocus(Qt.OtherFocusReason)
|
||||||
@ -403,6 +406,7 @@ class SearchBoxMixin(object): # {{{
|
|||||||
self.current_view().setFocus(Qt.OtherFocusReason)
|
self.current_view().setFocus(Qt.OtherFocusReason)
|
||||||
|
|
||||||
def highlight_only_changed(self, toWhat):
|
def highlight_only_changed(self, toWhat):
|
||||||
|
dynamic.set('search_highlight_only', toWhat)
|
||||||
self.current_view().model().set_highlight_only(toWhat)
|
self.current_view().model().set_highlight_only(toWhat)
|
||||||
self.focus_to_library()
|
self.focus_to_library()
|
||||||
|
|
||||||
|
@ -18,6 +18,24 @@ class _Parser(object):
|
|||||||
LEX_NUM = 4
|
LEX_NUM = 4
|
||||||
LEX_EOF = 5
|
LEX_EOF = 5
|
||||||
|
|
||||||
|
def _python(self, func):
|
||||||
|
locals = {}
|
||||||
|
exec func in locals
|
||||||
|
if 'evaluate' not in locals:
|
||||||
|
self.error('no evaluate function in python')
|
||||||
|
try:
|
||||||
|
result = locals['evaluate'](self.parent.kwargs)
|
||||||
|
if isinstance(result, (float, int)):
|
||||||
|
result = unicode(result)
|
||||||
|
elif isinstance(result, list):
|
||||||
|
result = ','.join(result)
|
||||||
|
elif isinstance(result, str):
|
||||||
|
result = unicode(result)
|
||||||
|
return result
|
||||||
|
except Exception as e:
|
||||||
|
self.error('python function threw exception: ' + e.msg)
|
||||||
|
|
||||||
|
|
||||||
def _strcmp(self, x, y, lt, eq, gt):
|
def _strcmp(self, x, y, lt, eq, gt):
|
||||||
v = strcmp(x, y)
|
v = strcmp(x, y)
|
||||||
if v < 0:
|
if v < 0:
|
||||||
@ -79,6 +97,7 @@ class _Parser(object):
|
|||||||
'field' : (1, lambda s, x: s.parent.get_value(x, [], s.parent.kwargs)),
|
'field' : (1, lambda s, x: s.parent.get_value(x, [], s.parent.kwargs)),
|
||||||
'multiply' : (2, partial(_math, op='*')),
|
'multiply' : (2, partial(_math, op='*')),
|
||||||
'print' : (-1, _print),
|
'print' : (-1, _print),
|
||||||
|
'python' : (1, _python),
|
||||||
'strcat' : (-1, _concat),
|
'strcat' : (-1, _concat),
|
||||||
'strcmp' : (5, _strcmp),
|
'strcmp' : (5, _strcmp),
|
||||||
'substr' : (3, lambda s, x, y, z: x[int(y): len(x) if int(z) == 0 else int(z)]),
|
'substr' : (3, lambda s, x, y, z: x[int(y): len(x) if int(z) == 0 else int(z)]),
|
||||||
@ -362,7 +381,7 @@ class TemplateFormatter(string.Formatter):
|
|||||||
(r'\'.*?((?<!\\)\')', lambda x,t: (3, t[1:-1])),
|
(r'\'.*?((?<!\\)\')', lambda x,t: (3, t[1:-1])),
|
||||||
(r'\n#.*?(?=\n)', None),
|
(r'\n#.*?(?=\n)', None),
|
||||||
(r'\s', None)
|
(r'\s', None)
|
||||||
])
|
], flags=re.DOTALL)
|
||||||
|
|
||||||
def _eval_program(self, val, prog):
|
def _eval_program(self, val, prog):
|
||||||
# keep a cache of the lex'ed program under the theory that re-lexing
|
# keep a cache of the lex'ed program under the theory that re-lexing
|
||||||
|
Loading…
x
Reference in New Issue
Block a user