Package libxyz :: Package ui :: Module border
[hide private]
[frames] | no frames]

Source Code for Module libxyz.ui.border

  1  #-*- coding: utf8 -* 
  2  # 
  3  # Max E. Kuznecov ~syhpoon <syhpoon@syhpoon.name> 2008 
  4  # 
  5  # This file is part of XYZCommander. 
  6  # XYZCommander is free software: you can redistribute it and/or modify 
  7  # it under the terms of the GNU Lesser Public License as published by 
  8  # the Free Software Foundation, either version 3 of the License, or 
  9  # (at your option) any later version. 
 10  # XYZCommander is distributed in the hope that it will be useful, 
 11  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
 13  # GNU Lesser Public License for more details. 
 14  # You should have received a copy of the GNU Lesser Public License 
 15  # along with XYZCommander. If not, see <http://www.gnu.org/licenses/>. 
 16   
 17  from libxyz.ui import lowui 
 18  from libxyz.ui import align 
 19   
 20  from libxyz.exceptions import UIError 
 21   
22 -class Border(lowui.BoxWidget):
23 - def __init__(self, widget, title=None, title_attr=None, attr=None):
24 """ 25 Draw a line border around widget and set up a title 26 @param widget: Widget to wrap 27 @param title: Title 28 @type title: libxyz.ui.lowui.Text object 29 @param title_attr: Title attribute 30 @param attr: Attribute of border 31 """ 32 33 super(Border, self).__init__() 34 35 self.widget = widget 36 self.title = title 37 self.title_attr = title_attr 38 self.attr = attr 39 self._attr = self.attr 40 41 self.utf8decode = lowui.escape.utf8decode 42 43 self.tline = self._get_attr(lowui.Divider(self.utf8decode("─"))) 44 self.bline = self._get_attr(lowui.Divider(self.utf8decode("─"))) 45 self.lline = self._get_attr(lowui.SolidFill(self.utf8decode("│"))) 46 self.rline = self._get_attr(lowui.SolidFill(self.utf8decode("│"))) 47 48 self.tlcorner = self._get_attr(lowui.Text(self.utf8decode("┌"))) 49 self.trcorner = self._get_attr(lowui.Text(self.utf8decode("┐"))) 50 self.blcorner = self._get_attr(lowui.Text(self.utf8decode("└"))) 51 self.brcorner = self._get_attr(lowui.Text(self.utf8decode("┘")))
52 53 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 54
55 - def render(self, (maxcol, maxrow), focus=False):
56 """ 57 Render widget 58 """ 59 60 if self.title is not None: 61 _len = len(self.title) 62 63 if self.title_attr is not None: 64 self._title = lowui.AttrWrap(lowui.Text(" %s " % self.title, 65 align.CENTER), self.title_attr) 66 else: 67 self._title = lowui.Text(self.title, align.CENTER) 68 69 _len += 2 # " text " 70 71 tline_widgets = [('fixed', 1, self.tlcorner), self.tline] 72 73 if self.title is not None: 74 tline_widgets.append(("fixed", _len, self._title)) 75 76 tline_widgets.extend([self.tline, ("fixed", 1, self.trcorner)]) 77 78 self.top = lowui.Columns(tline_widgets) 79 self.middle = lowui.Columns([('fixed', 1, self.lline), 80 self.widget, ('fixed', 1, self.rline)], 81 box_columns=[0,2], focus_column=1) 82 83 self.bottom = lowui.Columns([('fixed', 1, self.blcorner), 84 self.bline, ('fixed', 1, self.brcorner)]) 85 86 self.pile = lowui.Pile([('flow',self.top), self.middle, 87 ('flow', self.bottom)], focus_item=1) 88 89 return self.pile.render((maxcol, maxrow), focus)
90 91 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 92
93 - def _get_attr(self, widget):
94 if self.attr is None: 95 return widget 96 97 return lowui.AttrWrap(widget, self.attr)
98 99 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 100
101 - def set_title_attr(self, attr):
102 """ 103 Set title attribute 104 """ 105 106 self.title_attr = attr 107 self._invalidate()
108 109 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 110
111 - def set_title(self, text):
112 """ 113 Set title 114 """ 115 116 self.title = text 117 self._invalidate()
118