Ejemplo n.º 1
0
    def __init__(self):
        self.lira = LiraApp()
        self.lira.setup()

        self.content = ContentArea(self)
        self.status = StatusBar(self)

        self.menu = SidebarMenu(self)
        self.menu.reset(BooksList(self))

        self.container = HSplit(
            [
                VSplit(
                    [
                        self.menu,
                        self.content,
                    ],
                    padding=Dimension.exact(1),
                    padding_char="│",
                    padding_style=theme["separator"],
                ),
                self.status,
            ],
            padding=Dimension.exact(1),
            padding_char="─",
            padding_style=theme["separator"],
        )
        self.app = Application(
            layout=Layout(self.container),
            key_bindings=self.get_key_bindings(),
            mouse_support=True,
            full_screen=True,
            style=style,
            after_render=self._ready,
        )
Ejemplo n.º 2
0
 def setup_method(self):
     tui = mock.MagicMock()
     self.window = SidebarMenu(tui=tui)
Ejemplo n.º 3
0
class TestSidebarMenu:
    def setup_method(self):
        tui = mock.MagicMock()
        self.window = SidebarMenu(tui=tui)

    def test_default_menu(self):
        """The default menu has 2 buttons and a label."""
        children = to_container(self.window).get_children()
        assert len(children) == 3

        empty_label = children[0].get_container().content
        back_button = children[1]
        exit_button = to_widget(children[2])

        assert empty_label.text() == "Empty container"

        # Back button is not visible
        assert to_widget(back_button.content).text == "Back"
        assert not back_button.filter()

        # Exit button is visible
        assert isinstance(exit_button, Button)
        assert exit_button.text == "Exit"

    def test_toggle_back_button(self):
        """The back button is only visible if there are at least 2 pages."""
        first_label = Label("First")
        second_label = Label("Second")

        self.window.push(first_label)
        self.window.push(second_label)

        children = to_container(self.window).get_children()
        back_button = children[1]
        exit_button = to_widget(children[2])

        assert exit_button.text == "Exit"

        # Back button is visible
        assert to_widget(back_button.content).text == "Back"
        assert back_button.filter()

        label = children[0].get_container()
        assert label.text == "Second"

        self.window.pop()

        # Back button is't visible
        assert to_widget(back_button.content).text == "Back"
        assert not back_button.filter()

        label = children[0].get_container()
        assert label.text == "First"

    def test_pop_all_pages(self):
        first_label = Label("First")
        self.window.push(first_label)
        assert len(self.window.pages) == 1

        # We can't pop the last page.
        self.window.pop()
        self.window.pop()
        assert len(self.window.pages) == 1

        children = to_container(self.window).get_children()
        label = children[0].get_container()
        assert label.text == "First"

        # We can reset the pages to the default container.
        self.window.reset()
        assert len(self.window.pages) == 1
        children = to_container(self.window).get_children()
        label = children[0].get_container()
        assert label.content.text() == "Empty container"
Ejemplo n.º 4
0
class TerminalUI:
    def __init__(self):
        self.lira = LiraApp()
        self.lira.setup()

        self.content = ContentArea(self)
        self.status = StatusBar(self)

        self.menu = SidebarMenu(self)
        self.menu.reset(BooksList(self))

        self.container = HSplit(
            [
                VSplit(
                    [
                        self.menu,
                        self.content,
                    ],
                    padding=Dimension.exact(1),
                    padding_char="│",
                    padding_style=theme["separator"],
                ),
                self.status,
            ],
            padding=Dimension.exact(1),
            padding_char="─",
            padding_style=theme["separator"],
        )
        self.app = Application(
            layout=Layout(self.container),
            key_bindings=self.get_key_bindings(),
            mouse_support=True,
            full_screen=True,
            style=style,
            after_render=self._ready,
        )

    def get_key_bindings(self):
        keys = KeyBindings()

        @keys.add(Keys.Tab)
        def _(event):
            focus_next(event)

        @keys.add(Keys.BackTab)
        def _(event):
            focus_previous(event)

        @keys.add(Keys.ControlC)
        @keys.add(Keys.ControlQ)
        def _(event):
            exit_app()

        return keys

    def _ready(self, app):
        key = "__is_ready"
        if not hasattr(self, key):
            set_title()
            self.status.notify("Ready!")
            setattr(self, key, True)

    def run(self):
        self.app.run()