diff libervia/pages/_browser/dialog.py @ 1385:4b6f711b09cb

browser (dialog): new `ashow` method to use `Confirm` in async methods
author Goffi <goffi@goffi.org>
date Sat, 20 Feb 2021 13:58:01 +0100
parents 8729d2708f65
children 409d10211b20
line wrap: on
line diff
--- 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: