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

Review how the Paste event is handled and bubbled #1666

Closed
davep opened this issue Jan 25, 2023 · 2 comments · Fixed by #1698
Closed

Review how the Paste event is handled and bubbled #1666

davep opened this issue Jan 25, 2023 · 2 comments · Fixed by #1698
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@davep
Copy link
Contributor

davep commented Jan 25, 2023

Using the code below... Review how the Paste event is handled and bubbled in an application. Given the code below, ideally, if one were to run the app up and not focus anything, a paste would result in either/or the Screen or App getting a Paste and any on_paste event they have being able to handle it. At the moment no event appears at the on_paste for either.

from textual.app        import App, ComposeResult
from textual.containers import Vertical
from textual.screen     import Screen
from textual.widgets    import Header, Footer, TextLog, Button
from textual.events     import Paste
from textual.binding    import Binding

class PasteButton( Button ):

    def on_paste( self, event: Paste ) -> None:
        self.app.query_one( TextLog ).write(
            f"Button: {event}"
        )

class PasteVertical( Vertical ):

    def compose( self ) -> ComposeResult:
        """Compose the child widgets."""
        yield PasteButton( "This can get focus" )

    def on_paste( self, event: Paste ) -> None:
        self.app.query_one( TextLog ).write(
            f"Vertical: {event}"
        )

class PasteTextLog( TextLog ):

    def on_paste( self, event: Paste ) -> None:
        self.app.query_one( TextLog ).write(
            f"TextLog: {event}"
        )

class PasteScreen( Screen ):

    def on_paste( self, event: Paste ) -> None:
        self.query_one( TextLog ).write(
            f"Screen: {event}"
        )

    def compose( self ) -> ComposeResult:
        yield Header()
        yield PasteVertical()
        yield PasteTextLog()
        yield Footer()

class PasteExplorer( App[ None ] ):

    BINDINGS = [
        Binding( "c", "clear", "Clear Log" ),
    ]

    SCREENS = {
        "main": PasteScreen
    }

    CSS = """
    *:focus {
        border: double green;
    }

    Vertical {
        height: 1fr;
        border: round yellow;
    }

    TextLog {
        height: 80%;
        border: round red;
    }
    """

    def on_paste( self, event: Paste ) -> None:
        self.query_one( TextLog ).write(
            f"App: {event}"
        )

    def on_mount( self ) -> None:
        self.push_screen( "main" )

    def action_clear( self ) -> None:
        """Clear"""
        self.query_one( TextLog ).clear()

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

### paste_explorer.py ends here
@davep davep added bug Something isn't working enhancement New feature or request labels Jan 25, 2023
@davep davep self-assigned this Jan 25, 2023
@willmcgugan willmcgugan assigned willmcgugan and unassigned davep Jan 31, 2023
@willmcgugan
Copy link
Collaborator

@davep Stealing this

@github-actions
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants