Ejemplo n.º 1
0
    def streams_view(self) -> Any:
        streams_btn_list = [
                StreamButton(
                    stream,
                    controller=self.controller,
                    view=self.view,
                    width=self.width,
                    count=self.model.unread_counts['streams'].get(stream[1], 0)
                ) for stream in self.view.pinned_streams]

        if len(streams_btn_list):
            streams_btn_list += [StreamsViewDivider()]

        streams_btn_list += [
                StreamButton(
                    stream,
                    controller=self.controller,
                    view=self.view,
                    width=self.width,
                    count=self.model.unread_counts['streams'].get(stream[1], 0)
                ) for stream in self.view.unpinned_streams]

        self.view.stream_id_to_button = {stream.stream_id: stream
                                         for stream in streams_btn_list
                                         if hasattr(stream, 'stream_id')}

        self.view.stream_w = StreamsView(streams_btn_list, self.view)
        w = urwid.LineBox(
            self.view.stream_w, title="Streams",
            tlcorner=LIST_TITLE_BAR_LINE,
            tline=LIST_TITLE_BAR_LINE,
            trcorner=LIST_TITLE_BAR_LINE,
            blcorner='', rline='', lline='',
            bline='', brcorner='─'
            )
        return w
Ejemplo n.º 2
0
    def streams_view(self) -> Any:
        streams_btn_list = [
                StreamButton(
                    stream,
                    controller=self.controller,
                    view=self.view,
                    width=self.width,
                    count=self.model.unread_counts['streams'].get(stream[1], 0)
                ) for stream in self.view.pinned_streams]

        if len(streams_btn_list):
            unpinned_divider = urwid.Divider("-")

            # FIXME Necessary since the divider is treated as a StreamButton
            unpinned_divider.stream_id = -1
            unpinned_divider.caption = ''

            streams_btn_list += [unpinned_divider]

        streams_btn_list += [
                StreamButton(
                    stream,
                    controller=self.controller,
                    view=self.view,
                    width=self.width,
                    count=self.model.unread_counts['streams'].get(stream[1], 0)
                ) for stream in self.view.unpinned_streams]

        self.view.stream_w = StreamsView(streams_btn_list, self.view)
        w = urwid.LineBox(
            self.view.stream_w, title="Streams",
            tlcorner=u'─', tline=u'─', lline=u'',
            trcorner=u'─', blcorner=u'', rline=u'',
            bline=u'', brcorner=u'─'
            )
        return w
Ejemplo n.º 3
0
 def streams_view(self) -> Any:
     streams_btn_list = list()
     for stream in self.streams:
         unread_count = self.model.unread_counts.get(stream[1], 0)
         streams_btn_list.append(
                 StreamButton(
                     stream,
                     controller=self.controller,
                     view=self,
                     count=unread_count,
                 )
         )
     self.stream_w = StreamsView(streams_btn_list)
     w = urwid.LineBox(self.stream_w, title="Streams")
     return w
Ejemplo n.º 4
0
def stream_button(mocker):
    """
    Mocked stream button.
    """
    view_mock = mocker.Mock()
    view_mock.palette = [(None, 'black', 'white')]
    button = StreamButton(
        properties={'name': 'PTEST', 'id': 205,
                    'color': '#bfd56f', 'invite_only': False,
                    'description': "Test stream description"},
        controller=mocker.patch('zulipterminal.core.Controller'),
        width=40,
        view=view_mock,
        count=30
    )
    return button
Ejemplo n.º 5
0
def stream_button(mocker):
    """
    Mocked stream button.
    """
    view_mock = mocker.Mock()
    view_mock.palette = [(None, "black", "white")]
    button = StreamButton(
        properties={
            "name": "PTEST",
            "id": 205,
            "color": "#bfd56f",
            "invite_only": False,
            "description": "Test stream description",
        },
        controller=mocker.patch("zulipterminal.core.Controller"),
        view=view_mock,
        count=30,
    )
    return button
Ejemplo n.º 6
0
 def streams_view(self) -> Any:
     streams_btn_list = list()
     for stream in self.view.streams:
         unread_count = self.model.unread_counts.get(stream[1], 0)
         streams_btn_list.append(
             StreamButton(
                 stream,
                 controller=self.controller,
                 view=self.view,
                 count=unread_count,
             )
         )
     self.view.stream_w = StreamsView(streams_btn_list, self.view)
     w = urwid.LineBox(
         self.view.stream_w, title="Streams",
         tlcorner=u'─', tline=u'─', lline=u'',
         trcorner=u'─', blcorner=u'', rline=u'',
         bline=u'', brcorner=u'─'
         )
     return w
Ejemplo n.º 7
0
    def test_text_content(
        self,
        mocker,
        is_private,
        expected_prefix,
        width,
        count,
        short_text,
        caption="caption",
    ):
        controller = mocker.Mock()
        controller.model.is_muted_stream.return_value = False
        controller.model.muted_streams = {}
        properties = {
            "name": caption,
            "id": 5,
            "color": "#ffffff",
            "invite_only": is_private,
            "description": "Some Stream Description",
        }

        view_mock = mocker.Mock()
        view_mock.palette = [(None, "black", "white")]
        stream_button = StreamButton(properties,
                                     controller=controller,
                                     view=view_mock,
                                     width=width,
                                     count=count)

        text = stream_button._w._original_widget.get_text()
        count_str = "" if count == 0 else str(count)
        expected_text = " {} {}{}{}".format(
            expected_prefix,
            short_text,
            (width - 4 - len(short_text) - len(count_str)) * " ",
            count_str,
        )
        assert len(text[0]) == len(expected_text) == (width - 1)
        assert text[0] == expected_text