Mercurial > libervia-web
view libervia/pages/_browser/dialog.py @ 1344:472267dcd4d8
browser (alt_media_player): native player support + poster + flags + restricted area:
- alt_media_player will now use native player when possible. This allows to use its controls
and behaviour instead of native ones.
- a poster can be specified when instanciated manually
- video is not preloaded anymore
- handle events propagation to plays nicely when used in slideshow
- a "restricted area" mode can be used to let click propagation on video border, and thus
catch only play/pause in the center. This is notably useful when used in the slideshow,
as border can be used to show/hide slideshow controls
- player can be reset, in which case the play button overlay is put back, and video
is put at its beginning
- once video is played at least once, a `in_use` class is added to the element, play
button overlay is removed then. This fix a bug when the overlay was still appearing when
using bottom play button.
- VideoPlayer has been renamed to MediaPlayer
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 24 Aug 2020 23:04:35 +0200 |
parents | 8729d2708f65 |
children | 4b6f711b09cb |
line wrap: on
line source
"""manage common dialogs""" from browser import document, timer from template import Template class Confirm: def __init__(self, message, ok_label="", cancel_label="", ok_color="success"): self._tpl = Template("dialogs/confirm.html") self.message = message self.ok_label = ok_label assert ok_color in ("success", "danger") self.ok_color = ok_color self.cancel_label = cancel_label def cancel_cb(self, evt, notif_elt): notif_elt.remove() def show(self, ok_cb, cancel_cb=None): if cancel_cb is None: cancel_cb = self.cancel_cb notif_elt = self._tpl.get_elt({ "message": self.message, "ok_label": self.ok_label, "ok_color": self.ok_color, "cancel_label": self.cancel_label, }) document['notifs_area'] <= notif_elt timer.set_timeout(lambda: notif_elt.classList.add('state_appended'), 0) for cancel_elt in notif_elt.select(".click_to_cancel"): cancel_elt.bind("click", lambda evt: cancel_cb(evt, notif_elt)) for cancel_elt in notif_elt.select(".click_to_ok"): cancel_elt.bind("click", lambda evt: ok_cb(evt, notif_elt)) class Notification: def __init__(self): self._tpl = Template("dialogs/notification.html") def close(self, notif_elt): notif_elt.classList.remove('state_appended') notif_elt.bind("transitionend", lambda __: notif_elt.remove()) def show( self, message: str, level: str = "info", delay: int = 5 ) -> None: # we log in console error messages, may be useful if level in ("warning", "error"): print(f"[{level}] {message}") notif_elt = self._tpl.get_elt({ "message": message, "level": level, }) document["notifs_area"] <= notif_elt timer.set_timeout(lambda: notif_elt.classList.add('state_appended'), 0) timer.set_timeout(lambda: self.close(notif_elt), delay * 1000) for elt in notif_elt.select('.click_to_close'): elt.bind('click', lambda __: self.close(notif_elt)) notification = Notification()