Skip to content

Commit

Permalink
Merge pull request #1863 from proneon267/patch-1
Browse files Browse the repository at this point in the history
Added support for `set_full_screen` in WinForms.
  • Loading branch information
freakboy3742 authored Apr 12, 2023
2 parents b5f6c6d + 0b9642c commit 652abad
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions changes/1863.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Winforms apps can now go full screen.
2 changes: 2 additions & 0 deletions cocoa/src/toga_cocoa/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ def enter_full_screen(self, windows):
# about its Toga representations.
window.content._impl.native.window._impl = window._impl
window.content._impl.native.window.interface = window
window.content.refresh()

def exit_full_screen(self, windows):
opts = NSMutableDictionary.alloc().init()
Expand All @@ -397,6 +398,7 @@ def exit_full_screen(self, windows):

for window in windows:
window.content._impl.native.exitFullScreenModeWithOptions(opts)
window.content.refresh()

def show_cursor(self):
if not self._cursor_visible:
Expand Down
10 changes: 10 additions & 0 deletions examples/window/window/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ def do_small(self, widget, **kwargs):
def do_large(self, widget, **kwargs):
self.main_window.size = (1500, 1000)

def do_full_screen(self, widget, **kwargs):
if self.is_full_screen:
self.exit_full_screen()
else:
self.set_full_screen(self.main_window)

def do_title(self, widget, **kwargs):
self.main_window.title = f"Time is {datetime.now()}"

Expand Down Expand Up @@ -121,6 +127,9 @@ def startup(self):
btn_do_large = toga.Button(
"Become large", on_press=self.do_large, style=btn_style
)
btn_do_full_screen = toga.Button(
"Become full screen", on_press=self.do_full_screen, style=btn_style
)
btn_do_title = toga.Button(
"Change title", on_press=self.do_title, style=btn_style
)
Expand All @@ -140,6 +149,7 @@ def startup(self):
btn_do_right,
btn_do_small,
btn_do_large,
btn_do_full_screen,
btn_do_title,
btn_do_new_windows,
btn_do_report,
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 @@ -293,10 +293,12 @@ def current_window(self):
self.interface.factory.not_implemented("App.current_window()")

def enter_full_screen(self, windows):
self.interface.factory.not_implemented("App.enter_full_screen()")
for window in windows:
window._impl.set_full_screen(True)

def exit_full_screen(self, windows):
self.interface.factory.not_implemented("App.exit_full_screen()")
for window in windows:
window._impl.set_full_screen(False)

def set_cursor(self, value):
self.interface.factory.not_implemented("App.set_cursor()")
Expand Down
7 changes: 6 additions & 1 deletion winforms/src/toga_winforms/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,12 @@ def winforms_FormClosing(self, sender, event):
event.Cancel = True

def set_full_screen(self, is_full_screen):
self.interface.factory.not_implemented("Window.set_full_screen()")
if is_full_screen:
self.native.FormBorderStyle = WinForms.FormBorderStyle(0)
self.native.WindowState = WinForms.FormWindowState.Maximized
else:
self.native.FormBorderStyle = WinForms.FormBorderStyle(1)
self.native.WindowState = WinForms.FormWindowState.Normal

def close(self):
self._is_closing = True
Expand Down

0 comments on commit 652abad

Please sign in to comment.