# HG changeset patch # User Goffi # Date 1613825881 -3600 # Node ID 4b6f711b09cbc3405c650fa1110f30248b1092e0 # Parent b61509c47cac29e85f9da27475c1fad32a723d3b browser (dialog): new `ashow` method to use `Confirm` in async methods diff -r b61509c47cac -r 4b6f711b09cb libervia/pages/_browser/dialog.py --- a/libervia/pages/_browser/dialog.py Sat Feb 20 13:56:08 2021 +0100 +++ b/libervia/pages/_browser/dialog.py Sat Feb 20 13:58:01 2021 +0100 @@ -1,6 +1,6 @@ """manage common dialogs""" -from browser import document, timer +from browser import document, window, timer from template import Template @@ -34,6 +34,20 @@ for cancel_elt in notif_elt.select(".click_to_ok"): cancel_elt.bind("click", lambda evt: ok_cb(evt, notif_elt)) + def _ashow_cb(self, evt, notif_elt, resolve_cb, confirmed): + evt.stopPropagation() + notif_elt.remove() + resolve_cb(confirmed) + + async def ashow(self): + return window.Promise.new( + lambda resolve_cb, reject_cb: + self.show( + lambda evt, notif_elt: self._ashow_cb(evt, notif_elt, resolve_cb, True), + lambda evt, notif_elt: self._ashow_cb(evt, notif_elt, resolve_cb, False) + ) + ) + class Notification: