Giter Club home page Giter Club logo

Comments (6)

JoeZiminski avatar JoeZiminski commented on May 24, 2024 1

Thanks @davep! that did the trick, I had played around with that parameter but in an inconsistent way and with too small I size I believe. Yet again a super quick response describing an easy-to-implement solution to an issue, thanks!!

from textual.

davep avatar davep commented on May 24, 2024 1

Glad to hear that solved it for you. :-)

from textual.

github-actions avatar github-actions commented on May 24, 2024

We found the following entry in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

from textual.

davep avatar davep commented on May 24, 2024

I would imagine that the issue is what the exception says:

Target offset is outside of currently-visible screen region.

The click is happening outside of the screen; that that happens when adding/removing margin is, I would imagine, coincidental, and just happens to be bumping where the click would happen outside of the screen. Consider this extreme example:

from asyncio import run
from textual.app import App, ComposeResult
from textual.widget import Widget

class PilotMarginApp(App[None]):

    CSS = """
    #click-me {
        margin: 200;
        width: 20;
        height: 10;
        border: solid red;
        background: green;
    }
    """

    def compose(self) -> ComposeResult:
        yield Widget(id="click-me")

async def test_app():
    async with PilotMarginApp().run_test() as pilot:
        await pilot.click("#click-me")

if __name__ == "__main__":
    run(test_app())

This throws the same exception. Remove the margin from this, or drop to something like 1, and it runs fine.

You probably want to make your "terminal" big enough to handle the display you're attempting to test. For example, I can make my code above work by making the "terminal" 400x400 (note the size parameter for run_test):

from asyncio import run
from textual.app import App, ComposeResult
from textual.widget import Widget

class PilotMarginApp(App[None]):

    CSS = """
    #click-me {
        margin: 200;
        width: 20;
        height: 10;
        border: solid red;
        background: green;
    }
    """

    def compose(self) -> ComposeResult:
        yield Widget(id="click-me")

async def test_app():
    async with PilotMarginApp().run_test(size=(400, 400)) as pilot:
        await pilot.click("#click-me")

if __name__ == "__main__":
    run(test_app())

Long story short: your test seems to be trying to do something the user can't do; click on a widget that isn't visible to click.

from textual.

github-actions avatar github-actions commented on May 24, 2024

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

from textual.

willmcgugan avatar willmcgugan commented on May 24, 2024

@JoeZiminski you can do pilot.app.save_screenshot() and have a look at the resulting SVG file, to see if the thing you are clicking is really on-screen at that moment.

from textual.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.