Ejemplo n.º 1
0
    def __init__(self, original_widget, title=''):
        self.color = 'header'
        if int(urwid_version[0]) == 1:
            utf8decode = lambda string: string

        def use_attr(a, t):
            if a:
                t = AttrMap(t, a)
            return t

        # top line
        tline = None
        tline_attr = Columns([
            ('fixed', 2, Divider(utf8decode("─"))),
            ('fixed', len(title), AttrMap(Text(title), self.color)),
            Divider(utf8decode("─")),
        ])
        tline = use_attr(tline, tline_attr)
        # bottom line
        bline = None
        bline = use_attr(bline, Divider(utf8decode("─")))
        # left line
        lline = None
        lline = use_attr(lline, SolidFill(utf8decode("│")))
        # right line
        rline = None
        rline = use_attr(rline, SolidFill(utf8decode("│")))
        # top left corner
        tlcorner = None
        tlcorner = use_attr(tlcorner, Text(utf8decode("┌")))
        # top right corner
        trcorner = None
        trcorner = use_attr(trcorner, Text(utf8decode("┐")))
        # bottom left corner
        blcorner = None
        blcorner = use_attr(blcorner, Text(utf8decode("└")))
        # bottom right corner
        brcorner = None
        brcorner = use_attr(brcorner, Text(utf8decode("┘")))

        # top
        top = Columns([
            ('fixed', 1, tlcorner),
            tline,
            ('fixed', 1, trcorner),
        ])
        # middle
        middle = Columns([('fixed', 1, lline), original_widget,
                          ('fixed', 1, rline)],
                         box_columns=[0, 2],
                         focus_column=1)
        # bottom
        bottom = Columns([('fixed', 1, blcorner), bline,
                          ('fixed', 1, brcorner)])

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

        WidgetDecoration.__init__(self, original_widget)
        WidgetWrap.__init__(self, pile)
Ejemplo n.º 2
0
Archivo: ui.py Proyecto: Erik-k/turses
    def __init__(self, original_widget, title="",
                 tlcorner=u'┌', tline=u'─', lline=u'│',
                 trcorner=u'┐', blcorner=u'└', rline=u'│',
                 bline=u'─', brcorner=u'┘'):
        """
        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)

        title_widget = ('fixed', len(title), AttrMap(Text(title), 'header'))
        top = Columns([
            ('fixed', 1, tlcorner),
            title_widget,
            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)

        # super?
        WidgetDecoration.__init__(self, original_widget)
        WidgetWrap.__init__(self, pile)
Ejemplo n.º 3
0
    def __init__(self, original_widget, title="",
                 tlcorner=u'┌', tline=u'─', lline=u'│',
                 trcorner=u'┐', blcorner=u'└', rline=u'│',
                 bline=u'─', brcorner=u'┘'):
        """
        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)

        title_widget = ('fixed', len(title), AttrMap(Text(title), 'header'))
        top = Columns([
            ('fixed', 1, tlcorner),
            title_widget,
            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)

        # super?
        WidgetDecoration.__init__(self, original_widget)
        WidgetWrap.__init__(self, pile)
Ejemplo n.º 4
0
    def __init__(self, original_widget, title=None, title_attr=None, attr=None):#{{{

        self.title = title
        self.title_attr = title_attr
        self.attr = attr
        self._attr = attr

        def _get_attr(w):
            if attr is not None:
                return AttrMap(w, attr)
            return w

        self.tline = _get_attr(Divider(utf8decode("─")))
        self.bline = _get_attr(Divider(utf8decode("─")))
        self.lline = _get_attr(SolidFill(utf8decode("│")))
        self.rline = _get_attr(SolidFill(utf8decode("│")))

        self.tlcorner = _get_attr(Text(utf8decode("┌")))
        self.trcorner = _get_attr(Text(utf8decode("┐")))
        self.blcorner = _get_attr(Text(utf8decode("└")))
        self.brcorner = _get_attr(Text(utf8decode("┘")))

        self._title_text = Text(" %s " % self.title, 'center')
        self._title = AttrMap(self._title_text, self.title_attr)

        top = Columns([('fixed', 1, self.tlcorner),
                       self.tline,
                       ('fixed', len(self.title)+2, self._title),
                       self.tline,
                       ('fixed', 1, self.trcorner)])

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

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

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

        WidgetDecoration.__init__(self, original_widget)
        WidgetWrap.__init__(self, pile)
Ejemplo n.º 5
0
Archivo: ui.py Proyecto: gigigi/turses
    def __init__(self, original_widget, title=''):
        self.color = 'header'

        def use_attr(a, t):
            if a:
                t = AttrMap(t, a)
            return t

        # top line
        tline = None
        tline_attr = Columns([('fixed', 2, 
                                        Divider(u"─")),
                                    ('fixed', len(title), 
                                        AttrMap(Text(title), self.color)),
                                    Divider(u"─"),])
        tline = use_attr(tline, tline_attr)
        # bottom line
        bline = None
        bline = use_attr(bline, Divider(u"─"))
        # left line
        lline = None
        lline = use_attr(lline, SolidFill(u"│"))
        # right line
        rline = None
        rline = use_attr(rline, SolidFill(u"│"))
        # top left corner
        tlcorner = None
        tlcorner = use_attr(tlcorner, Text(u"┌"))
        # top right corner
        trcorner = None
        trcorner = use_attr(trcorner, Text(u"┐"))
        # bottom left corner
        blcorner = None
        blcorner = use_attr(blcorner, Text(u"└"))
        # bottom right corner
        brcorner = None
        brcorner = use_attr(brcorner, Text(u"┘"))

        # top
        top = Columns([('fixed', 1, tlcorner),
                             tline, 
                             ('fixed', 1, trcorner),])
        # middle
        middle = Columns([('fixed', 1, lline),
                                original_widget, 
                                ('fixed', 1, rline)], 
                               box_columns = [0,2], 
                               focus_column = 1)
        # bottom
        bottom = Columns([('fixed', 1, blcorner),
                                bline, 
                                ('fixed', 1, brcorner)])

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

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