diff --git a/docs/examples/on_top.md b/docs/examples/on_top.md index c7e3a588..8864ec32 100644 --- a/docs/examples/on_top.md +++ b/docs/examples/on_top.md @@ -1,21 +1,22 @@ # Topmost window -Create a window that stays on top of, or in front of, other windows. +Create a window that stays on top of other windows. ``` python -import pywebview +import webview import time + def deactivate(window): - #window starts on top and is changed later - time.sleep(5) + #window starts as on top of and reverts back to normal after 20 seconds + time.sleep(20) window.on_top = False + window.load_html("

This window is no longer on top of other windows

") if __name__ == '__main__': - # Create webview window that stays on top of, or in front of, all other windows - window = webview.create_window('Topmost window', - 'https://pywebview.flowrl.com/hello', + # Create webview window that stays on top of, all other windows + window = webview.create_window('Topmost window', html="

This window is on top of other windows

", on_top=True) webview.start(deactivate, window) ``` \ No newline at end of file diff --git a/examples/on_top.py b/examples/on_top.py index 8aa905a3..de47087d 100644 --- a/examples/on_top.py +++ b/examples/on_top.py @@ -6,14 +6,14 @@ """ def deactivate(window): - #window starts on top and is changed later - time.sleep(5) + #window starts as on top of and reverts back to normal after 20 seconds + time.sleep(20) window.on_top = False + window.load_html("

This window is no longer on top of other windows

") if __name__ == '__main__': - # Create webview window that stays on top of, or in front of, all other windows - window = webview.create_window('Topmost window', - 'https://pywebview.flowrl.com/hello', + # Create webview window that stays on top of, all other windows + window = webview.create_window('Topmost window', html="

This window is on top of other windows

", on_top=True) webview.start(deactivate, window) diff --git a/webview/platforms/cef.py b/webview/platforms/cef.py index 85571251..28eb56f6 100644 --- a/webview/platforms/cef.py +++ b/webview/platforms/cef.py @@ -258,9 +258,10 @@ def _create(): cef_browser.SetJavascriptBindings(bindings) cef_browser.SetClientHandler(LoadHandler()) - instances[window.uid] = browser window.events.shown.set() + cef_browser.SendFocusEvent(True) + window_info = cef.WindowInfo() window_info.SetAsChild(handle) diff --git a/webview/platforms/winforms.py b/webview/platforms/winforms.py index 51dc14e7..064f80f1 100644 --- a/webview/platforms/winforms.py +++ b/webview/platforms/winforms.py @@ -238,10 +238,9 @@ def on_activated(self, sender, args): CEF.focus(self.uid) def on_shown(self, sender, args): - if is_cef: - CEF.focus(self.uid) - else: - self.shown.set() + self.shown.set() + + if not is_cef: self.browser.web_view.Focus() def on_close(self, sender, args):