calibre/src/pyj/widgets.pyj
2015-12-04 18:42:02 +05:30

36 lines
1.4 KiB
Plaintext

# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
from dom import build_rule
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:
cls = str.format('fa fa-{} fa-lg', icon)
text = '\xa0' + text
ans = E.button(E.i(class_=cls), text, class_='calibre-push-button', type='button', title=tooltip or '')
if action is not None:
ans.addEventListener('click', def(event): event.preventDefault(), action(event);)
return ans
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=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)')
def create_spinner():
return E.i(class_='fa fa-spin fa-spinner')
def get_widget_css():
ans = 'a, button:focus { outline: none }; a, button::-moz-focus-inner { border: 0 }\n'
ans += create_button.style
return ans