diff --git a/mouse_capture.py b/mouse_capture.py new file mode 100644 index 0000000..f154a2e --- /dev/null +++ b/mouse_capture.py @@ -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()