From e7c75c23e4aeab30e5bb947218b562e1febb4277 Mon Sep 17 00:00:00 2001 From: proneon267 Date: Sun, 23 Apr 2023 01:58:18 -0700 Subject: [PATCH 1/7] Added support for current_window setter. --- cocoa/src/toga_cocoa/app.py | 5 ++++- core/src/toga/app.py | 7 ++++++- dummy/src/toga_dummy/app.py | 8 ++++++-- gtk/src/toga_gtk/app.py | 5 ++++- web/src/toga_web/app.py | 7 +++++-- winforms/src/toga_winforms/app.py | 6 ++++-- 6 files changed, 29 insertions(+), 9 deletions(-) diff --git a/cocoa/src/toga_cocoa/app.py b/cocoa/src/toga_cocoa/app.py index 45489c7479..10e94d9e0b 100644 --- a/cocoa/src/toga_cocoa/app.py +++ b/cocoa/src/toga_cocoa/app.py @@ -366,9 +366,12 @@ def show_about_dialog(self): def exit(self): self.loop.stop() - def current_window(self): + def get_current_window(self): return self.native.keyWindow + def set_current_window(self, window): + self.interface.factory.not_implemented("App.set_current_window()") + def enter_full_screen(self, windows): # If we're already in full screen mode, exit so that # we can re-assign windows to screens. diff --git a/core/src/toga/app.py b/core/src/toga/app.py index 5c056b1e8b..ecd64235ea 100644 --- a/core/src/toga/app.py +++ b/core/src/toga/app.py @@ -515,7 +515,12 @@ def main_window(self, window): @property def current_window(self): """Return the currently active content window.""" - return self._impl.current_window().interface + return self._impl.get_current_window().interface + + @current_window.setter + def current_window(self, window): + """Set a window into current active focus.""" + self._impl.set_current_window(window) @property def is_full_screen(self): diff --git a/dummy/src/toga_dummy/app.py b/dummy/src/toga_dummy/app.py index 9eb15d6894..1379f674ac 100644 --- a/dummy/src/toga_dummy/app.py +++ b/dummy/src/toga_dummy/app.py @@ -43,8 +43,12 @@ def exit(self): self._action("exit") @not_required_on("mobile") - def current_window(self): - self._action("current_window") + def get_current_window(self): + self._action("get_current_window") + + @not_required_on("mobile") + def set_current_window(self): + self._action("set_current_window") @not_required_on("mobile") def enter_full_screen(self, windows): diff --git a/gtk/src/toga_gtk/app.py b/gtk/src/toga_gtk/app.py index 2afe2a1270..14780c6670 100644 --- a/gtk/src/toga_gtk/app.py +++ b/gtk/src/toga_gtk/app.py @@ -224,9 +224,12 @@ def exit(self): def set_on_exit(self, value): pass - def current_window(self): + def get_current_window(self): return self.native.get_active_window()._impl + def set_current_window(self, window): + self.interface.factory.not_implemented("App.set_current_window()") + def enter_full_screen(self, windows): for window in windows: window._impl.set_full_screen(True) diff --git a/web/src/toga_web/app.py b/web/src/toga_web/app.py index 4fa8741115..13246986c7 100644 --- a/web/src/toga_web/app.py +++ b/web/src/toga_web/app.py @@ -179,8 +179,11 @@ def show_dialog(promise): def exit(self): pass - def current_window(self): - self.interface.factory.not_implemented("App.current_window()") + def get_current_window(self): + self.interface.factory.not_implemented("App.get_current_window()") + + def set_current_window(self): + self.interface.factory.not_implemented("App.set_current_window()") def enter_full_screen(self, windows): self.interface.factory.not_implemented("App.enter_full_screen()") diff --git a/winforms/src/toga_winforms/app.py b/winforms/src/toga_winforms/app.py index 4a48362aab..85aa61e4a0 100644 --- a/winforms/src/toga_winforms/app.py +++ b/winforms/src/toga_winforms/app.py @@ -289,10 +289,12 @@ def exit(self): def set_main_window(self, window): self.app_context.MainForm = window._impl.native - @property - def current_window(self): + def get_current_window(self): return WinForms.Form.ActiveForm._impl + def set_current_window(self, window): + window._impl.native.Activate() + def enter_full_screen(self, windows): for window in windows: window._impl.set_full_screen(True) From baf0b4c1da164a6703b22c04119353eb9a2a51c8 Mon Sep 17 00:00:00 2001 From: proneon267 Date: Sun, 23 Apr 2023 02:02:37 -0700 Subject: [PATCH 2/7] Added a changelog. --- changes/1887.feature.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/1887.feature.rst diff --git a/changes/1887.feature.rst b/changes/1887.feature.rst new file mode 100644 index 0000000000..9a6030b167 --- /dev/null +++ b/changes/1887.feature.rst @@ -0,0 +1 @@ +An API for setting a window into active focus was added. From c0be32c2f037fd50d443a215003d499e8dfcf585 Mon Sep 17 00:00:00 2001 From: proneon267 Date: Mon, 24 Apr 2023 00:21:04 -0700 Subject: [PATCH 3/7] Added a test action in examples/window. --- examples/window/window/app.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/examples/window/window/app.py b/examples/window/window/app.py index f41b645f56..cb662b7cae 100644 --- a/examples/window/window/app.py +++ b/examples/window/window/app.py @@ -68,6 +68,11 @@ def do_new_windows(self, widget, **kwargs): self.app.windows += no_close_handler_window no_close_handler_window.show() + def do_current_window_cycling(self, widget, **kwargs): + for window in self.windows: + self.current_window = window + self.label = self.current_window + def do_report(self, widget, **kwargs): self.label.text = ( f"Window {self.main_window.title!r} " @@ -136,6 +141,11 @@ def startup(self): btn_do_new_windows = toga.Button( "Create Window", on_press=self.do_new_windows, style=btn_style ) + btn_do_current_window_cycling = toga.Button( + "Cycle between windows", + on_press=self.do_current_window_cycling, + style=btn_style, + ) btn_do_report = toga.Button("Report", on_press=self.do_report, style=btn_style) btn_change_content = toga.Button( "Change content", on_press=self.do_next_content, style=btn_style @@ -152,6 +162,7 @@ def startup(self): btn_do_full_screen, btn_do_title, btn_do_new_windows, + btn_do_current_window_cycling, btn_do_report, btn_change_content, btn_hide, From 54ccd945d1aff2068c7dc0327b2d245ea6e20cef Mon Sep 17 00:00:00 2001 From: proneon267 Date: Mon, 24 Apr 2023 00:24:45 -0700 Subject: [PATCH 4/7] Implemented on the cocoa backend. --- cocoa/src/toga_cocoa/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocoa/src/toga_cocoa/app.py b/cocoa/src/toga_cocoa/app.py index 10e94d9e0b..b5d684d052 100644 --- a/cocoa/src/toga_cocoa/app.py +++ b/cocoa/src/toga_cocoa/app.py @@ -370,7 +370,7 @@ def get_current_window(self): return self.native.keyWindow def set_current_window(self, window): - self.interface.factory.not_implemented("App.set_current_window()") + window.native.makeKeyAndFront() def enter_full_screen(self, windows): # If we're already in full screen mode, exit so that From 3dd8ee183f729533513dba071e26abeb78267225 Mon Sep 17 00:00:00 2001 From: proneon267 Date: Mon, 24 Apr 2023 00:27:11 -0700 Subject: [PATCH 5/7] Implemented on the gtk backend. --- gtk/src/toga_gtk/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtk/src/toga_gtk/app.py b/gtk/src/toga_gtk/app.py index 14780c6670..0b296d06e1 100644 --- a/gtk/src/toga_gtk/app.py +++ b/gtk/src/toga_gtk/app.py @@ -228,7 +228,7 @@ def get_current_window(self): return self.native.get_active_window()._impl def set_current_window(self, window): - self.interface.factory.not_implemented("App.set_current_window()") + window.native.present() def enter_full_screen(self, windows): for window in windows: From 06fb4661f9531454d1d260aeec5e24933253da74 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Sun, 23 Apr 2023 20:54:18 -0600 Subject: [PATCH 6/7] Update example to make window cycling more obvious --- examples/window/window/app.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/window/window/app.py b/examples/window/window/app.py index cb662b7cae..708d22f440 100644 --- a/examples/window/window/app.py +++ b/examples/window/window/app.py @@ -1,3 +1,4 @@ +import asyncio from datetime import datetime import toga @@ -68,10 +69,11 @@ def do_new_windows(self, widget, **kwargs): self.app.windows += no_close_handler_window no_close_handler_window.show() - def do_current_window_cycling(self, widget, **kwargs): + async def do_current_window_cycling(self, widget, **kwargs): for window in self.windows: self.current_window = window - self.label = self.current_window + self.label.text = f"Current window is {self.current_window.id}" + await asyncio.sleep(1) def do_report(self, widget, **kwargs): self.label.text = ( From 72a3ebb4d840865aacd79a6aa6f49ee3a1df00ad Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Sun, 23 Apr 2023 20:54:49 -0600 Subject: [PATCH 7/7] Correct call implementing current window set on Cocoa. --- cocoa/src/toga_cocoa/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocoa/src/toga_cocoa/app.py b/cocoa/src/toga_cocoa/app.py index b5d684d052..047d58a7b2 100644 --- a/cocoa/src/toga_cocoa/app.py +++ b/cocoa/src/toga_cocoa/app.py @@ -370,7 +370,7 @@ def get_current_window(self): return self.native.keyWindow def set_current_window(self, window): - window.native.makeKeyAndFront() + window._impl.native.makeKeyAndOrderFront(window._impl.native) def enter_full_screen(self, windows): # If we're already in full screen mode, exit so that