-
Notifications
You must be signed in to change notification settings - Fork 814
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
Unable to switch tabs in TabbedContent using a key binding #4955
Comments
What do the |
I've just had a thought. Remember that the default size of a simulated app is (80, 24). so maybe your input widgets aren't positioned where you expect? |
The This only breaks on the second part being executed. My work-around was to separate the tests. I do notice Input changes my bindings, though its likely unrelated. Any time I click into an I set these bindings:
The bottom line of my display has shortcuts for control+{AFTNSQ}, when I click in an input field, the bindings for A and F disappear, presumably because Input binds them to beginning of line and delete word right. |
Try calling |
Well, I looked at it again. I have a work around, so its not really a priority. Here's the weird stuff: I use this for screenshots: I use this for widget hierarchy: First, bindings break as soon as an Second, pilot happily tries to click on fields not currently displayed. When I click on Third, breakpoints in PyCharm are flaky for asynchronous function when run as the 'current file'. Made debugging a bit harder. Fourth, at least on my MacOS system, My instincts are to back away slowly and try to get on with my work. |
Thanks for reporting back, I was a bit stumped why the command palette was being launched but forgot about that feature in the header! The
It depends on your terminal emulator and the escape sequences it generates for certain key combinations. For example, |
OK. The bindings issue is not that Thie pilot issue is that I do not get a KeyError or ValueError when trying to click on a control that is not displayed. The odd keys are indeed emulator specific. For example, MacOS Terminal refuses to do anything with control plus the number row. |
As a personal failing, I cannot put a problem down.... First, I attached a random file of tabbed content. I have not added tests for it. bug4955.py.zip Second, I noticed this additional oddity which may be the cause of some of the other effects. I thought the correct way to switch the active tab is to set the reactive element, e.g., |
Thanks - I see the problem now. To clarify the steps to reproduce:
The new tab is briefly activated, but the app seems confused about what widget should now be focused. This causes the original tab to be re-activated again instead. Minimized examplefrom textual.app import App, ComposeResult
from textual.widgets import Button, Footer, Input, TabbedContent, TabPane
class Bug4955App(App):
BINDINGS = [
("ctrl+s", "ctrl_s", "S"),
("ctrl+t", "ctrl_t", "T"),
]
def action_ctrl_s(self) -> None:
self.query_one(TabbedContent).active = "s-tab"
def action_ctrl_t(self) -> None:
self.query_one(TabbedContent).active = "t-tab"
def compose(self) -> ComposeResult:
with TabbedContent(initial="s-tab"):
with TabPane("S Group", id="s-tab"):
yield Input("sss")
yield Button("S")
with TabPane("T Group", id="t-tab"):
yield Input("ttt")
yield Button("T")
yield Footer()
if __name__ == "__main__":
app = Bug4955App()
app.run() |
# The new tab is activated...
TabActivated(TabbedContent(), ContentTab(id='--content-tab-t-tab'), TabPane(id='t-tab'))
# ... which hides the old tab
Hide() >>> TabPane(id='s-tab') method=<Widget.on_hide>
Hide() >>> Input(id='s-input') method=<Widget.on_hide>
# The problem is that after the input is hidden, the focus moves to the button...
Button(id='s-btn') was focused
# ...which causes a TabPane.Focused event...
TabPane.Focused(tab_pane=TabPane(id='s-tab'))
# ... which re-activates the original tab again
TabActivated(TabbedContent(), ContentTab(id='--content-tab-s-tab'), TabPane(id='s-tab')) |
This is due to the automatic tab switching added in 9a28549 - when you focus a widget that's inside a tab, the tab is automatically made active. This is clashing with Textual's logic to automatically switch focus to the next widget when a widget is hidden. |
Should there be a second bug for Pilot allowing clicks on non-displayed buttons? Or do you want to treat that as an acceptable tester error? |
As far as I remember we agreed when that feature was first added that we weren't going to check that the button was actually visible on screen. |
So I have this annoying issue. I haven't pulled it down to a minimum example, as the area is poorly documented and it may be a user error. The only relevant points are that
fills-search
andtxs-search
areInput
widgets and thatctrl+f
andctrl+t
are bindings.So I have this test:
On the second part, even if I switch part A and B, the
pilot.click
function will causeapp.screen_stack
to acquire a CommandPalette, which means theget_widget_by_id
is looking at the wrong screen. That is, the app works differently in testing than in execution. I don't know why Textual does this, but I look side-eyed atpilot.py/345
. If I try to work around the problem by addingENABLE_COMMAND_PALETTE = False
to my app, then it does not bring up the COMMAND_PALETTE, but it stops causing the@on(Input.Changed,...)
to fire. Again, Pilot not working like my app.Is this a bug or am I using it wrong?
The text was updated successfully, but these errors were encountered: