peterbrittain / asciimatics

A cross platform package to do curses-like operations, plus higher level APIs and widgets to create text UIs and ASCII art animations
Apache License 2.0
3.61k stars 238 forks source link

Layouts containing only disabled widgets still act as a tabstop #346

Closed DonvdH closed 2 years ago

DonvdH commented 2 years ago

Layouts containing only disabled widgets still act as a tabstop, pressing the up key on focus will cause an IndexError. Layouts with only disabled widgets are useful as a header with a different column layout for example.

In the example code below, pressing "Tab" twice followed by the "Up" key will cause an IndexError.

I really like the framework btw, great job!

from asciimatics.exceptions import ResizeScreenError
from asciimatics.scene import Scene
from asciimatics.screen import Screen
from asciimatics.widgets import Frame, Layout, TextBox

class MyFrame(Frame):
    def __init__(self, screen):
        Frame.__init__(self, screen, int(screen.height), int(screen.width), name="test")
        self.set_theme("bright")

        layout1 = Layout([1])
        self.add_layout(layout1)
        self.text_box1 = TextBox(5)
        layout1.add_widget(self.text_box1)
        self.text_box1.disabled = True
        self.text_box1.value = r'Disabled text box'.split('\n')

        layout2 = Layout([1])
        self.add_layout(layout2)
        self.text_box2 = TextBox(5)
        layout2.add_widget(self.text_box2)
        self.text_box2.value = r'Enabled text box'.split('\n')

        layout3 = Layout([1])
        self.add_layout(layout3)
        self.text_box3 = TextBox(5)
        layout3.add_widget(self.text_box3)
        self.text_box3.value = r'Enabled text box'.split('\n')

        self.fix()

def run(screen, scene):
    scenes = []
    scenes.append(Scene([MyFrame(screen)], duration=-1))
    screen.play(scenes, stop_on_resize=True, start_scene=scene)

def show():
    last_scene = None
    while True:
        try:
            Screen.wrapper(run, arguments=[last_scene])
            break
        except ResizeScreenError as e:
            last_scene = e.scene

if __name__ == "__main__":
    show()
peterbrittain commented 2 years ago

Nice spot! Should be fixed now is master.