mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Make the item list code re-useable
This commit is contained in:
parent
3172744e22
commit
4224233eca
@ -2,7 +2,7 @@
|
||||
# License: GPL v3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
from __python__ import hash_literals
|
||||
|
||||
from dom import build_rule, svgicon, add_extra_css
|
||||
from dom import build_rule, svgicon, add_extra_css, clear
|
||||
from elementmaker import E
|
||||
|
||||
from book_list.theme import get_font_size, get_color
|
||||
@ -21,39 +21,10 @@ add_extra_css(def():
|
||||
return style
|
||||
)
|
||||
|
||||
class ItemsView:
|
||||
|
||||
def __init__(self, interface_data, book_list_container):
|
||||
nonlocal iv_counter
|
||||
iv_counter += 1
|
||||
self.container_id = 'items-view-' + iv_counter
|
||||
div = E.div(
|
||||
id=self.container_id, style='display:none', class_=CLASS_NAME,
|
||||
)
|
||||
book_list_container.appendChild(div)
|
||||
|
||||
@property
|
||||
def container(self):
|
||||
return document.getElementById(self.container_id)
|
||||
|
||||
@property
|
||||
def is_visible(self):
|
||||
self.container.style.display is 'block'
|
||||
|
||||
@is_visible.setter
|
||||
def is_visible(self, val):
|
||||
self.container.style.display = 'block' if val else 'none'
|
||||
|
||||
def clear(self):
|
||||
c = self.container
|
||||
while c.lastChild is not c.firstChild:
|
||||
c.removeChild(c.lastChild)
|
||||
return c
|
||||
|
||||
def init(self, data):
|
||||
items = getattr(data, 'items', data)
|
||||
subtitle = getattr(data, 'subtitle', None)
|
||||
c = self.clear()
|
||||
def build_list(container, items, subtitle):
|
||||
c = container
|
||||
clear(c)
|
||||
c.classList.add(CLASS_NAME)
|
||||
if subtitle:
|
||||
c.appendChild(E.p(subtitle, style="font-style:italic; padding: 1em 1ex; border-bottom: solid 1px currentColor"))
|
||||
ul = E.ul()
|
||||
@ -80,6 +51,33 @@ class ItemsView:
|
||||
if item.action:
|
||||
ul.lastChild.addEventListener('click', item.action)
|
||||
|
||||
|
||||
def create_item(title, action=None, subtitle=None, icon_name=None):
|
||||
return {'title':title, 'action':action, 'subtitle':subtitle, 'icon_name':icon_name}
|
||||
|
||||
class ItemsView:
|
||||
|
||||
def __init__(self, interface_data, book_list_container):
|
||||
nonlocal iv_counter
|
||||
iv_counter += 1
|
||||
self.container_id = 'items-view-' + iv_counter
|
||||
div = E.div(
|
||||
id=self.container_id, style='display:none', class_=CLASS_NAME,
|
||||
)
|
||||
book_list_container.appendChild(div)
|
||||
|
||||
@property
|
||||
def container(self):
|
||||
return document.getElementById(self.container_id)
|
||||
|
||||
@property
|
||||
def is_visible(self):
|
||||
self.container.style.display is 'block'
|
||||
|
||||
@is_visible.setter
|
||||
def is_visible(self, val):
|
||||
self.container.style.display = 'block' if val else 'none'
|
||||
|
||||
def init(self, data):
|
||||
items = getattr(data, 'items', data)
|
||||
subtitle = getattr(data, 'subtitle', None)
|
||||
build_list(self.container, items, subtitle)
|
||||
|
Loading…
x
Reference in New Issue
Block a user