mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Content server: Implement search
This commit is contained in:
parent
2adf2d324e
commit
faea3a7564
@ -2,6 +2,9 @@
|
||||
# License: GPL v3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
from elementmaker import E
|
||||
from gettext import gettext as _
|
||||
from widgets import create_button, BUTTON_VPADDING
|
||||
from book_list.globals import get_boss
|
||||
|
||||
sp_counter = 0
|
||||
|
||||
@ -15,10 +18,31 @@ class SearchPanel:
|
||||
style = ''
|
||||
div = E.div(
|
||||
id=self.container_id, style='display:none',
|
||||
E.style(style, type='text/css')
|
||||
E.style(style, type='text/css'),
|
||||
E.div(style="text-align:center; padding:1ex 1em; border-bottom: solid 1px currentColor; margin-bottom: 0.5ex"), # search input container
|
||||
E.div(
|
||||
E.div(),
|
||||
E.div()
|
||||
)
|
||||
)
|
||||
book_list_container.appendChild(div)
|
||||
|
||||
# Build search input
|
||||
search_container = div.firstChild.nextSibling
|
||||
search_container.appendChild(E.div(style="display: flex; width: 100%;",
|
||||
E.input(
|
||||
type='text', autocomplete='on', autosave='search', inputmode='latin', name='search-books',
|
||||
title=_('Search for books'), placeholder=_('Enter the search query'), spellcheck='false',
|
||||
style=str.format("flex-grow: 10; padding: {} 0.5em; margin-right: 0.5em", BUTTON_VPADDING)
|
||||
),
|
||||
create_button(_('Search'), icon='search', action=self.execute_search.bind(self), tooltip=_('Do the search'))
|
||||
))
|
||||
search_container.firstChild.firstChild.addEventListener('keypress', def(event):
|
||||
if event.keyCode == 13:
|
||||
self.execute_search()
|
||||
event.preventDefault(), event.stopPropagation()
|
||||
)
|
||||
|
||||
@property
|
||||
def container(self):
|
||||
return document.getElementById(self.container_id)
|
||||
@ -30,3 +54,7 @@ class SearchPanel:
|
||||
@is_visible.setter
|
||||
def is_visible(self, val):
|
||||
self.container.style.display = 'block' if val else 'none'
|
||||
|
||||
def execute_search(self):
|
||||
text = self.container.querySelector('input[name="search-books"]').value or ''
|
||||
get_boss().ui.books_view.change_search(text)
|
||||
|
@ -6,6 +6,8 @@ from elementmaker import E
|
||||
|
||||
from book_list.theme import get_color
|
||||
|
||||
BUTTON_VPADDING = '0.5ex'
|
||||
|
||||
def create_button(text, icon=None, action=None, tooltip=None):
|
||||
cls = ''
|
||||
if icon:
|
||||
@ -19,7 +21,7 @@ def create_button(text, icon=None, action=None, tooltip=None):
|
||||
create_button.style = build_rule('button.calibre-push-button',
|
||||
border_radius='1em', background_clip='padding-box', background_color=get_color('button-start'),
|
||||
background_image=str.format('linear-gradient(to bottom, {}, {})', get_color('button-start'), get_color('button-end')),
|
||||
padding='1ex 1em', color=get_color('button-text'), cursor='pointer', font_size='inherit'
|
||||
padding=BUTTON_VPADDING + ' 1em', color=get_color('button-text'), cursor='pointer', font_size='inherit'
|
||||
)
|
||||
create_button.style += build_rule('button.calibre-push-button:hover', transform='scale(1.2)')
|
||||
create_button.style += build_rule('button.calibre-push-button:active', transform='scale(2)')
|
||||
|
Loading…
x
Reference in New Issue
Block a user