From 9ce4ce354f568351cf18162c25045f327fc76816 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 6 Sep 2016 15:00:03 +0530 Subject: [PATCH] Start working on Preferences UI for the viewer --- src/pyj/read_book/overlay.pyj | 1 + src/pyj/read_book/prefs.pyj | 49 +++++++++++++++++++++++++++++++++++ src/pyj/read_book/toc.pyj | 2 +- 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/pyj/read_book/prefs.pyj diff --git a/src/pyj/read_book/overlay.pyj b/src/pyj/read_book/overlay.pyj index 922c6b9d7c..f05eed5971 100644 --- a/src/pyj/read_book/overlay.pyj +++ b/src/pyj/read_book/overlay.pyj @@ -9,6 +9,7 @@ from book_list.globals import get_boss from widgets import create_spinner, create_button from gettext import gettext as _ from read_book.toc import create_toc_panel +from read_book.prefs import create_prefs_panel class LoadingMessage: # {{{ diff --git a/src/pyj/read_book/prefs.pyj b/src/pyj/read_book/prefs.pyj new file mode 100644 index 0000000000..526b8a4619 --- /dev/null +++ b/src/pyj/read_book/prefs.pyj @@ -0,0 +1,49 @@ +# vim:fileencoding=utf-8 +# License: GPL v3 Copyright: 2016, Kovid Goyal +from __python__ import hash_literals, bound_methods + +from gettext import gettext as _ +from dom import svgicon, ensure_id, clear +from elementmaker import E + +class Prefs: + + def __init__(self, container, close_func): + self.close_func = close_func + title = E.h2(_('Configure book reader')) + self.title_id = ensure_id(title) + container.appendChild(E.div( + style='display: flex; justify-content: space-between; padding: 1ex 1em; border-bottom: solid 1px currentColor', + title, + E.div(svgicon('close'), onclick=self.onclose, style='cursor:pointer'), + )) + container.appendChild(E.div()) + self.container_id = ensure_id(container.lastChild) + self.stack = v'["top"]' + self.display_top(container.lastChild) + + def onclose(self): + if self.stack.length > 1: + self.stack.pop() + self.display_panel(self.stack[-1]) + else: + self.close_func() + + @property + def container(self): + return document.getElementById(self.container_id) + + def display_panel(self, which): + container = self.container + clear(container) + getattr(self, 'display_' + which)(container) + + def show_panel(self, which): + self.stack.push(which) + self.display_panel(which) + + def display_top(self, container): + pass + +def create_prefs_panel(container, close_func): + Prefs(container, close_func) diff --git a/src/pyj/read_book/toc.pyj b/src/pyj/read_book/toc.pyj index 011f50dc51..3985919a5f 100644 --- a/src/pyj/read_book/toc.pyj +++ b/src/pyj/read_book/toc.pyj @@ -32,7 +32,7 @@ def create_toc_panel(book, container, onclick, onclose): container.appendChild(E.div( style='display: flex; justify-content: space-between; padding: 1ex 1em; border-bottom: solid 1px currentColor', E.h2(_('Table of Contents')), - E.div(svgicon('close'), onclick=def(event):event.preventDefault(), event.stopPropagation(), onclose(event);, class_='simple-link'), + E.div(svgicon('close'), style='cursor:pointer', onclick=def(event):event.preventDefault(), event.stopPropagation(), onclose(event);, class_='simple-link'), )) def handle_click(event, li): if event.button is 0: