コード例 #1
0
ファイル: graphics.py プロジェクト: bakotaco/urwid
 def __init__(self, original_widget):
     """Draw a line around original_widget."""
     
     tlcorner=None; tline=None; lline=None
     trcorner=None; blcorner=None; rline=None
     bline=None; brcorner=None
     
     def use_attr( a, t ):
         if a is not None:
             t = AttrWrap(t, a)
         return t
         
     tline = use_attr( tline, Divider(utf8decode("─")))
     bline = use_attr( bline, Divider(utf8decode("─")))
     lline = use_attr( lline, SolidFill(utf8decode("│")))
     rline = use_attr( rline, SolidFill(utf8decode("│")))
     tlcorner = use_attr( tlcorner, Text(utf8decode("┌")))
     trcorner = use_attr( trcorner, Text(utf8decode("┐")))
     blcorner = use_attr( blcorner, Text(utf8decode("└")))
     brcorner = use_attr( brcorner, Text(utf8decode("┘")))
     top = Columns([ ('fixed', 1, tlcorner),
         tline, ('fixed', 1, trcorner) ])
     middle = Columns( [('fixed', 1, lline),
         original_widget, ('fixed', 1, rline)], box_columns = [0,2],
         focus_column = 1)
     bottom = Columns([ ('fixed', 1, blcorner),
         bline, ('fixed', 1, brcorner) ])
     pile = Pile([('flow',top),middle,('flow',bottom)],
         focus_item = 1)
     
     WidgetDecoration.__init__(self, original_widget)
     WidgetWrap.__init__(self, pile)
コード例 #2
0
    def __init__(self,
                 original_widget,
                 title="",
                 tlcorner=u'┌',
                 tline=u'─',
                 lline=u'│',
                 trcorner=u'┐',
                 blcorner=u'└',
                 rline=u'│',
                 bline=u'─',
                 brcorner=u'┘'):
        """
        Draw a line around original_widget.

        Use 'title' to set an initial title text with will be centered
        on top of the box.

        You can also override the widgets used for the lines/corners:
            tline: top line
            bline: bottom line
            lline: left line
            rline: right line
            tlcorner: top left corner
            trcorner: top right corner
            blcorner: bottom left corner
            brcorner: bottom right corner

        """

        tline, bline = Divider(tline), Divider(bline)
        lline, rline = SolidFill(lline), SolidFill(rline)
        tlcorner, trcorner = Text(tlcorner), Text(trcorner)
        blcorner, brcorner = Text(blcorner), Text(brcorner)

        self.title_widget = Text(self.format_title(title))
        self.tline_widget = Columns([
            tline,
            ('flow', self.title_widget),
            tline,
        ])

        top = Columns([('fixed', 1, tlcorner), self.tline_widget,
                       ('fixed', 1, trcorner)])

        middle = Columns([
            ('fixed', 1, lline),
            original_widget,
            ('fixed', 1, rline),
        ],
                         box_columns=[0, 2],
                         focus_column=1)

        bottom = Columns([('fixed', 1, blcorner), bline,
                          ('fixed', 1, brcorner)])

        pile = Pile([('flow', top), middle, ('flow', bottom)], focus_item=1)

        WidgetDecoration.__init__(self, original_widget)
        WidgetWrap.__init__(self, pile)
コード例 #3
0
ファイル: graphics.py プロジェクト: beast-arena/beast-arena
    def __init__(
        self,
        original_widget,
        title="",
        tlcorner=None,
        tline=None,
        lline=None,
        trcorner=None,
        blcorner=None,
        rline=None,
        bline=None,
        brcorner=None,
    ):
        """
        Draw a line around original_widget.

        Use 'title' to set an initial title text with will be centered
        on top of the box.

        You can also override the widgets used for the lines/corners:
            tline: top line
            bline: bottom line
            lline: left line
            rline: right line
            tlcorner: top left corner
            trcorner: top right corner
            blcorner: bottom left corner
            brcorner: bottom right corner
        """
        self.title_widget = Text(self.format_title(title))

        def use_attr(a, t):
            if a is not None:
                t = AttrWrap(t, a)
                return t
            else:
                return t

        self.tline_widget = Columns([Divider(self.ACS_HLINE), ("flow", self.title_widget), Divider(self.ACS_HLINE)])

        tline = use_attr(tline, self.tline_widget)
        bline = use_attr(bline, Divider(self.ACS_HLINE))
        lline = use_attr(lline, SolidFill(self.ACS_VLINE))
        rline = use_attr(rline, SolidFill(self.ACS_VLINE))
        tlcorner = use_attr(tlcorner, Text(self.ACS_ULCORNER))
        trcorner = use_attr(trcorner, Text(self.ACS_URCORNER))
        blcorner = use_attr(blcorner, Text(self.ACS_LLCORNER))
        brcorner = use_attr(brcorner, Text(self.ACS_LRCORNER))
        top = Columns([("fixed", 1, tlcorner), tline, ("fixed", 1, trcorner)])
        middle = Columns(
            [("fixed", 1, lline), original_widget, ("fixed", 1, rline)], box_columns=[0, 2], focus_column=1
        )
        bottom = Columns([("fixed", 1, blcorner), bline, ("fixed", 1, brcorner)])
        pile = Pile([("flow", top), middle, ("flow", bottom)], focus_item=1)

        WidgetDecoration.__init__(self, original_widget)
        WidgetWrap.__init__(self, pile)
コード例 #4
0
ファイル: graphics.py プロジェクト: Julian/urwid
    def __init__(self, original_widget, title="",
                 tlcorner=u'┌', tline=u'─', lline=u'│',
                 trcorner=u'┐', blcorner=u'└', rline=u'│',
                 bline=u'─', brcorner=u'┘'):
        """
        Draw a line around original_widget.

        Use 'title' to set an initial title text with will be centered
        on top of the box.

        You can also override the widgets used for the lines/corners:
            tline: top line
            bline: bottom line
            lline: left line
            rline: right line
            tlcorner: top left corner
            trcorner: top right corner
            blcorner: bottom left corner
            brcorner: bottom right corner

        """

        tline, bline = Divider(tline), Divider(bline)
        lline, rline = SolidFill(lline), SolidFill(rline)
        tlcorner, trcorner = Text(tlcorner), Text(trcorner)
        blcorner, brcorner = Text(blcorner), Text(brcorner)

        self.title_widget = Text(self.format_title(title))
        self.tline_widget = Columns([
            tline,
            ('flow', self.title_widget),
            tline,
        ])

        top = Columns([
            ('fixed', 1, tlcorner),
            self.tline_widget,
            ('fixed', 1, trcorner)
        ])

        middle = Columns([
            ('fixed', 1, lline),
            original_widget,
            ('fixed', 1, rline),
        ], box_columns=[0, 2], focus_column=1)

        bottom = Columns([
            ('fixed', 1, blcorner), bline, ('fixed', 1, brcorner)
        ])

        pile = Pile([('flow', top), middle, ('flow', bottom)], focus_item=1)

        WidgetDecoration.__init__(self, original_widget)
        WidgetWrap.__init__(self, pile)
コード例 #5
0
ファイル: graphics.py プロジェクト: jamesros161/eximsearch
    def __init__(self, original_widget, title="",
                 title_align="center", title_attr=None,
                 tlcorner=u'┌', tline=u'─', lline=u'│',
                 trcorner=u'┐', blcorner=u'└', rline=u'│',
                 bline=u'─', brcorner=u'┘'):
        """
        Draw a line around original_widget.

        Use 'title' to set an initial title text with will be centered
        on top of the box.

        Use `title_attr` to apply a specific attribute to the title text.

        Use `title_align` to align the title to the 'left', 'right', or 'center'.
        The default is 'center'.

        You can also override the widgets used for the lines/corners:
            tline: top line
            bline: bottom line
            lline: left line
            rline: right line
            tlcorner: top left corner
            trcorner: top right corner
            blcorner: bottom left corner
            brcorner: bottom right corner

        If empty string is specified for one of the lines/corners, then no
        character will be output there.  This allows for seamless use of
        adjoining LineBoxes.
        """

        if tline:
            tline = Divider(tline)
        if bline:
            bline = Divider(bline)
        if lline:
            lline = SolidFill(lline)
        if rline:
            rline = SolidFill(rline)
        tlcorner, trcorner = Text(tlcorner), Text(trcorner)
        blcorner, brcorner = Text(blcorner), Text(brcorner)

        if not tline and title:
            raise ValueError('Cannot have a title when tline is empty string')

        if title_attr:
            self.title_widget = Text((title_attr, self.format_title(title)))
        else:
            self.title_widget = Text(self.format_title(title))

        if tline:
            if title_align not in ('left', 'center', 'right'):
                raise ValueError('title_align must be one of "left", "right", or "center"')
            if title_align == 'left':
                tline_widgets = [('flow', self.title_widget), tline]
            else:
                tline_widgets = [tline, ('flow', self.title_widget)]
                if title_align == 'center':
                    tline_widgets.append(tline)
            self.tline_widget = Columns(tline_widgets)
            top = Columns([
                ('fixed', 1, tlcorner),
                self.tline_widget,
                ('fixed', 1, trcorner)
            ])

        else:
            self.tline_widget = None
            top = None

        middle_widgets = []
        if lline:
            middle_widgets.append(('fixed', 1, lline))
        else:
            # Note: We need to define a fixed first widget (even if it's 0 width) so that the other
            # widgets have something to anchor onto
            middle_widgets.append(('fixed', 0, SolidFill(u"")))
        middle_widgets.append(original_widget)
        focus_col = len(middle_widgets) - 1
        if rline:
            middle_widgets.append(('fixed', 1, rline))

        middle = Columns(middle_widgets,
                box_columns=[0, 2], focus_column=focus_col)

        if bline:
            bottom = Columns([
                ('fixed', 1, blcorner), bline, ('fixed', 1, brcorner)
            ])
        else:
            bottom = None

        pile_widgets = []
        if top:
            pile_widgets.append(('flow', top))
        pile_widgets.append(middle)
        focus_pos = len(pile_widgets) - 1
        if bottom:
            pile_widgets.append(('flow', bottom))
        pile = Pile(pile_widgets, focus_item=focus_pos)

        WidgetDecoration.__init__(self, original_widget)
        WidgetWrap.__init__(self, pile)
コード例 #6
0
ファイル: graphics.py プロジェクト: andy-z/urwid
    def __init__(self, original_widget, title="",
                 title_align="center", title_attr=None,
                 tlcorner=u'┌', tline=u'─', lline=u'│',
                 trcorner=u'┐', blcorner=u'└', rline=u'│',
                 bline=u'─', brcorner=u'┘'):
        """
        Draw a line around original_widget.

        Use 'title' to set an initial title text with will be centered
        on top of the box.

        Use `title_attr` to apply a specific attribute to the title text.

        Use `title_align` to align the title to the 'left', 'right', or 'center'.
        The default is 'center'.

        You can also override the widgets used for the lines/corners:
            tline: top line
            bline: bottom line
            lline: left line
            rline: right line
            tlcorner: top left corner
            trcorner: top right corner
            blcorner: bottom left corner
            brcorner: bottom right corner

        If empty string is specified for one of the lines/corners, then no
        character will be output there.  This allows for seamless use of
        adjoining LineBoxes.
        """

        if tline:
            tline = Divider(tline)
        if bline:
            bline = Divider(bline)
        if lline:
            lline = SolidFill(lline)
        if rline:
            rline = SolidFill(rline)
        tlcorner, trcorner = Text(tlcorner), Text(trcorner)
        blcorner, brcorner = Text(blcorner), Text(brcorner)

        if not tline and title:
            raise ValueError('Cannot have a title when tline is empty string')

        if title_attr:
            self.title_widget = Text((title_attr, self.format_title(title)))
        else:
            self.title_widget = Text(self.format_title(title))

        if tline:
            if title_align not in ('left', 'center', 'right'):
                raise ValueError('title_align must be one of "left", "right", or "center"')
            if title_align == 'left':
                tline_widgets = [('flow', self.title_widget), tline]
            else:
                tline_widgets = [tline, ('flow', self.title_widget)]
                if title_align == 'center':
                    tline_widgets.append(tline)
            self.tline_widget = Columns(tline_widgets)
            top = Columns([
                ('fixed', 1, tlcorner),
                self.tline_widget,
                ('fixed', 1, trcorner)
            ])

        else:
            self.tline_widget = None
            top = None

        middle_widgets = []
        if lline:
            middle_widgets.append(('fixed', 1, lline))
        else:
            # Note: We need to define a fixed first widget (even if it's 0 width) so that the other
            # widgets have something to anchor onto
            middle_widgets.append(('fixed', 0, SolidFill(u"")))
        middle_widgets.append(original_widget)
        focus_col = len(middle_widgets) - 1
        if rline:
            middle_widgets.append(('fixed', 1, rline))

        middle = Columns(middle_widgets,
                box_columns=[0, 2], focus_column=focus_col)

        if bline:
            bottom = Columns([
                ('fixed', 1, blcorner), bline, ('fixed', 1, brcorner)
            ])
        else:
            bottom = None

        pile_widgets = []
        if top:
            pile_widgets.append(('flow', top))
        pile_widgets.append(middle)
        focus_pos = len(pile_widgets) - 1
        if bottom:
            pile_widgets.append(('flow', bottom))
        pile = Pile(pile_widgets, focus_item=focus_pos)

        WidgetDecoration.__init__(self, original_widget)
        WidgetWrap.__init__(self, pile)
コード例 #7
0
    def __init__(self,
                 original_widget,
                 title="",
                 title_align="center",
                 tlcorner='┌',
                 tline='─',
                 lline='│',
                 trcorner='┐',
                 blcorner='└',
                 rline='│',
                 bline='─',
                 brcorner='┘'):
        """
        Draw a line around original_widget.
        Use 'title' to set an initial title text with will be centered
        on top of the box.
        Use `title_align` to align the title to the 'left', 'right', or 'center'.
        The default is 'center'.
        You can also override the widgets used for the lines/corners:
            tline: top line
            bline: bottom line
            lline: left line
            rline: right line
            tlcorner: top left corner
            trcorner: top right corner
            blcorner: bottom left corner
            brcorner: bottom right corner
        .. note:: This differs from the vanilla urwid LineBox by discarding
            the a line if the middle of the line is set to either None or the
            empty string.
        """

        if tline:
            tline = Divider(tline)
        if bline:
            bline = Divider(bline)
        if lline:
            lline = SolidFill(lline)
        if rline:
            rline = SolidFill(rline)
        tlcorner, trcorner = Text(tlcorner), Text(trcorner)
        blcorner, brcorner = Text(blcorner), Text(brcorner)

        if not tline and title:
            raise ValueError('Cannot have a title when tline is unset')

        self.title_widget = Text(self.format_title(title))

        if tline:
            if title_align not in ('left', 'center', 'right'):
                raise ValueError(
                    'title_align must be one of "left", "right", or "center"')
            if title_align == 'left':
                tline_widgets = [('flow', self.title_widget), tline]
            else:
                tline_widgets = [tline, ('flow', self.title_widget)]
                if title_align == 'center':
                    tline_widgets.append(tline)
            self.tline_widget = Columns(tline_widgets)
            top = Columns([('fixed', 1, tlcorner), self.tline_widget,
                           ('fixed', 1, trcorner)])

        else:
            self.tline_widget = None
            top = None

        middle_widgets = []
        if lline:
            middle_widgets.append(('fixed', 1, lline))
        middle_widgets.append(original_widget)
        focus_col = len(middle_widgets) - 1
        if rline:
            middle_widgets.append(('fixed', 1, rline))

        middle = Columns(middle_widgets,
                         box_columns=[0, 2],
                         focus_column=focus_col)

        if bline:
            bottom = Columns([('fixed', 1, blcorner), bline,
                              ('fixed', 1, brcorner)])
        else:
            bottom = None

        pile_widgets = []
        if top:
            pile_widgets.append(('flow', top))
        pile_widgets.append(middle)
        focus_pos = len(pile_widgets) - 1
        if bottom:
            pile_widgets.append(('flow', bottom))
        pile = Pile(pile_widgets, focus_item=focus_pos)

        WidgetDecoration.__init__(self, original_widget)
        WidgetWrap.__init__(self, pile)
コード例 #8
0
    def __init__(self,
                 original_widget,
                 title="",
                 tlcorner=None,
                 tline=None,
                 lline=None,
                 trcorner=None,
                 blcorner=None,
                 rline=None,
                 bline=None,
                 brcorner=None):
        """
        Draw a line around original_widget.

        Use 'title' to set an initial title text with will be centered
        on top of the box.

        You can also override the widgets used for the lines/corners:
            tline: top line
            bline: bottom line
            lline: left line
            rline: right line
            tlcorner: top left corner
            trcorner: top right corner
            blcorner: bottom left corner
            brcorner: bottom right corner
        """
        self.title_widget = Text(self.format_title(title))

        def use_attr(a, t):
            if a is not None:
                t = AttrWrap(t, a)
                return t
            else:
                return t

        self.tline_widget = Columns([
            Divider(self.ACS_HLINE),
            ('flow', self.title_widget),
            Divider(self.ACS_HLINE),
        ])

        tline = use_attr(tline, self.tline_widget)
        bline = use_attr(bline, Divider(self.ACS_HLINE))
        lline = use_attr(lline, SolidFill(self.ACS_VLINE))
        rline = use_attr(rline, SolidFill(self.ACS_VLINE))
        tlcorner = use_attr(tlcorner, Text(self.ACS_ULCORNER))
        trcorner = use_attr(trcorner, Text(self.ACS_URCORNER))
        blcorner = use_attr(blcorner, Text(self.ACS_LLCORNER))
        brcorner = use_attr(brcorner, Text(self.ACS_LRCORNER))
        top = Columns([('fixed', 1, tlcorner), tline, ('fixed', 1, trcorner)])
        middle = Columns([('fixed', 1, lline), original_widget,
                          ('fixed', 1, rline)],
                         box_columns=[0, 2],
                         focus_column=1)
        bottom = Columns([('fixed', 1, blcorner), bline,
                          ('fixed', 1, brcorner)])
        pile = Pile([('flow', top), middle, ('flow', bottom)], focus_item=1)

        WidgetDecoration.__init__(self, original_widget)
        WidgetWrap.__init__(self, pile)