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 cursor visibility in WinForms. #1894

Merged
merged 6 commits into from
May 1, 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/1894.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Winforms now supports hiding and re-showing the app cursor.
15 changes: 15 additions & 0 deletions examples/window/window/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ async def do_current_window_cycling(self, widget, **kwargs):
self.label.text = f"Current window is {self.current_window.id}"
await asyncio.sleep(1)

async def do_hide_cursor(self, widget, **kwargs):
self.hide_cursor()
self.label.text = "Momentarily hiding cursor..."

await asyncio.sleep(2)

self.show_cursor()
self.label.text = "Cursor should be back!"

def do_report(self, widget, **kwargs):
self.label.text = (
f"Window {self.main_window.title!r} "
Expand Down Expand Up @@ -148,6 +157,11 @@ def startup(self):
on_press=self.do_current_window_cycling,
style=btn_style,
)
btn_do_hide_cursor = toga.Button(
"Hide cursor",
on_press=self.do_hide_cursor,
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 @@ -165,6 +179,7 @@ def startup(self):
btn_do_title,
btn_do_new_windows,
btn_do_current_window_cycling,
btn_do_hide_cursor,
btn_do_report,
btn_change_content,
btn_hide,
Expand Down
16 changes: 11 additions & 5 deletions winforms/src/toga_winforms/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ def __init__(self, interface):
# window-level close handling.
self._is_exiting = False

# Winforms cursor visibility is a stack; If you call hide N times, you
# need to call Show N times to make the cursor re-appear. Store a local
# boolean to allow us to avoid building a deep stack.
self._cursor_visible = True

self.loop = WinformsProactorEventLoop()
asyncio.set_event_loop(self.loop)

Expand Down Expand Up @@ -305,14 +310,15 @@ def exit_full_screen(self, windows):
for window in windows:
window._impl.set_full_screen(False)

def set_cursor(self, value):
self.interface.factory.not_implemented("App.set_cursor()")

def show_cursor(self):
self.interface.factory.not_implemented("App.show_cursor()")
if not self._cursor_visible:
WinForms.Cursor.Show()
self._cursor_visible = True

def hide_cursor(self):
self.interface.factory.not_implemented("App.hide_cursor()")
if self._cursor_visible:
WinForms.Cursor.Hide()
self._cursor_visible = False


class DocumentApp(App):
Expand Down