Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
✨ Mouse capture test
Browse files Browse the repository at this point in the history
To answer someone's question in Discord.
  • Loading branch information
davep committed Dec 12, 2022
1 parent 37e0582 commit 61ccb89
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions mouse_capture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from textual.app import App, ComposeResult
from textual.containers import Vertical
from textual.widgets import Static, TextLog
from textual.events import MouseMove, Key

class MouseArea( Static ):

def on_mount( self ) -> None:
self.capture_mouse()
self.screen.query_one( TextLog ).write( "Mouse area mounted" )

def on_mouse_move( self, event: MouseMove ) -> None:
self.screen.query_one( TextLog ).write( f"Mouse move: {event!r}" )

class Report( TextLog ):
pass

class MouseApp( App[ None ] ):

CSS = """
MouseArea {
height: 1fr;
background: #005500;
}
Report {
height: 1fr;
background: #888888;
color: black;
}
"""

def compose( self ) -> ComposeResult:
yield Vertical(
MouseArea(),
Report()
)

def on_key( self, event: Key ) -> None:
if event.key.isdecimal():
self.query_one( TextLog ).write( f"Key: {event!r}" )

if __name__ == "__main__":
MouseApp().run()

0 comments on commit 61ccb89

Please sign in to comment.