Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for current_window setter. #1887

Merged
merged 7 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/1887.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
An API for setting a window into active focus was added.
5 changes: 4 additions & 1 deletion cocoa/src/toga_cocoa/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
window._impl.native.makeKeyAndOrderFront(window._impl.native)

def enter_full_screen(self, windows):
# If we're already in full screen mode, exit so that
# we can re-assign windows to screens.
Expand Down
7 changes: 6 additions & 1 deletion core/src/toga/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 6 additions & 2 deletions dummy/src/toga_dummy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
13 changes: 13 additions & 0 deletions examples/window/window/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
from datetime import datetime

import toga
Expand Down Expand Up @@ -68,6 +69,12 @@ def do_new_windows(self, widget, **kwargs):
self.app.windows += no_close_handler_window
no_close_handler_window.show()

async def do_current_window_cycling(self, widget, **kwargs):
for window in self.windows:
self.current_window = 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 = (
f"Window {self.main_window.title!r} "
Expand Down Expand Up @@ -136,6 +143,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
Expand All @@ -152,6 +164,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,
Expand Down
5 changes: 4 additions & 1 deletion gtk/src/toga_gtk/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
window.native.present()

def enter_full_screen(self, windows):
for window in windows:
window._impl.set_full_screen(True)
Expand Down
7 changes: 5 additions & 2 deletions web/src/toga_web/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()")
Expand Down
6 changes: 4 additions & 2 deletions winforms/src/toga_winforms/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down