Esempio n. 1
0
def test_HelpBar_draw():
    mock_screen = MagicMock()
    mock_screen.getmaxyx.return_value = 50, 50
    mock_help_string = "HELP"
    test_bar = HelpBar(mock_screen)
    test_bar.help_string = mock_help_string
    test_bar.draw()
    mock_screen.addstr.assert_called_with(49, 2, mock_help_string)
Esempio n. 2
0
def test_HelpBar_build_help():
    mock_screen = MagicMock()
    mock_screen.getmaxyx.return_value = 50, 50
    mock_help_list = ["HELP", "MORE_HELP"]
    mock_help_print = "HELP"
    with patch('foolscap.display.render_composite.HELP_OPTIONS', mock_help_list):
        test_bar = HelpBar(mock_screen)
        test_bar.draw()
        mock_screen.addstr.assert_called_with(49, 2, mock_help_print)
Esempio n. 3
0
def test_HelpBar_build_help_short_width():
    """ Test smaller console where no string can fit in console.
    """
    mock_screen = MagicMock()
    mock_screen.getmaxyx.return_value = 50, 6
    mock_help_list = ["HELP", "MORE_HELP"]
    mock_help_print = '--'.join(mock_help_list[:1])
    with patch('foolscap.display.render_composite.HELP_OPTIONS', mock_help_list):
        test_bar = HelpBar(mock_screen)
        test_bar.draw()
        mock_screen.addstr.assert_called_with(49, 2, '')
Esempio n. 4
0
    def ui_collection(self):
        frame = Frame(self.screen)
        status_bar = StatusBar(self.screen, self.items, self.model)
        title_bar = TitleBar(self.screen)
        self.help_bar = HelpBar(self.screen)
        self.tabs = TabBar(self.screen, self.tab_title, self.books)
        if self.model.model_type == 'tags':
            self.tabs = TabBar(self.screen, self.model.model_type, self.books)
        self.menu = DisplayMenu(self.screen, self.items, self.model)

        self.render_objects = [
            frame, status_bar, title_bar, self.help_bar, self.tabs, self.menu
        ]
Esempio n. 5
0
def test_HelpBar_init():
    mock_screen = MagicMock()
    mock_screen.getmaxyx.return_value = 50, 50
    test_bar = HelpBar(mock_screen)
    assert isinstance(test_bar, HelpBar)
    assert mock_screen.getmaxyx.called_once()
    assert hasattr(test_bar, 'help_string')
Esempio n. 6
0
def test_HelpBar_update():
    mock_screen = MagicMock()
    mock_screen.getmaxyx.return_value = 50, 50
    test_bar = HelpBar(mock_screen)
    assert mock_screen.getmaxyx.called_once()
    test_bar.update()
Esempio n. 7
0
def test_HelpBar_next_hint():
    mock_screen = MagicMock()
    mock_screen.getmaxyx.return_value = 50, 50
    mock_help_list = ["HELP", "MORE_HELP"]
    with patch('foolscap.display.render_composite.HELP_OPTIONS', mock_help_list):
        test_bar = HelpBar(mock_screen)
        test_bar.draw()
        test_bar.next_hint()
        test_bar.update()
        test_bar.draw()
        test_bar.next_hint()
        test_bar.update()
        test_bar.draw()

        calls = [
            call(49, 2, "HELP"),
            call(49, 2, "MORE_HELP"),
            # Test it loops back to 0th item
            call(49, 2, "HELP"),
        ]
        mock_screen.addstr.assert_has_calls(calls)
Esempio n. 8
0
class FolioConsole:
    def __enter__(self):
        panel.update_panels()
        self.panel.hide()
        self.panel.top()
        self.panel.show()

        self.screen.keypad(1)
        self.screen.clear()
        return self

    def __exit__(self, _type, value, traceback):
        self.screen.clear()
        self.panel.hide()
        panel.update_panels()
        curses.doupdate()

    def __init__(self, stdscreen, data):
        self.items = data['titles']
        self.model = data['model']
        self.books = data['books']
        self.tab_title = data['tab_title']
        self.screen = stdscreen.subwin(0, 0)
        self.panel = panel.new_panel(self.screen)

        self.ui_collection()

        self.key_listener = KeyListener(self.screen, len(self.items))

    def ui_collection(self):
        frame = Frame(self.screen)
        status_bar = StatusBar(self.screen, self.items, self.model)
        title_bar = TitleBar(self.screen)
        self.help_bar = HelpBar(self.screen)
        self.tabs = TabBar(self.screen, self.tab_title, self.books)
        if self.model.model_type == 'tags':
            self.tabs = TabBar(self.screen, self.model.model_type, self.books)
        self.menu = DisplayMenu(self.screen, self.items, self.model)

        self.render_objects = [
            frame, status_bar, title_bar, self.help_bar, self.tabs, self.menu
        ]

    def render_all(self):
        self.screen.clear()
        for child in self.render_objects:
            child.update()
            child.draw()

    def show(self):
        """Displays Menus
        """
        selected = {'action': None, 'index': None}
        while not selected['action']:
            list_top, self.position = self.key_listener.get_position()

            self.menu.update_pointers(list_top, self.position)
            self.key_listener.set_max(len(self.menu))

            self.render_all()
            (
                selected['action'],
                selected['index'],
            ) = self.key_listener.get_action()

            if selected['action'] == 'help':
                self.help_bar.next_hint()
                selected['action'] = None
            if selected['action'] == 'expand':
                self.menu.expand_item(selected['index'])
                selected['action'] = None
            if _scroll_tab(selected['action']):
                if 'next' in selected['action']:
                    book = self.tabs.next_tab()
                else:
                    book = self.tabs.prev_tab()
                if book in self.books:
                    selected = {
                        'book': book,
                        'action': 'list',
                        'index': 0,
                    }
                else:
                    selected['action'] = None

        selected['item'] = self.menu.select_item(selected['index'])
        return selected