# HG changeset patch # User Radek Brich # Date 1394789443 -3600 # Node ID 5cd40c30c4f2dbfe56c70a12a4f5c5ed45f4079f # Parent 573a9e76719d233da85bc5936dc0a436b5ca8cd0 Add frame method to Buffer. diff -r 573a9e76719d -r 5cd40c30c4f2 demos/demo_buffer.py --- a/demos/demo_buffer.py Fri Mar 14 10:03:36 2014 +0100 +++ b/demos/demo_buffer.py Fri Mar 14 10:30:43 2014 +0100 @@ -12,6 +12,7 @@ buf.hline(1, 6, 14, c='-') buf.vline(7, 2, 4, c='|') buf.puts(8, 4, 'Hello!') +buf.frame() for y in range(buf.size.h): for x in range(buf.size.w): diff -r 573a9e76719d -r 5cd40c30c4f2 tuikit/core/buffer.py --- a/tuikit/core/buffer.py Fri Mar 14 10:03:36 2014 +0100 +++ b/tuikit/core/buffer.py Fri Mar 14 10:30:43 2014 +0100 @@ -1,4 +1,5 @@ from tuikit.common import Size +from tuikit.core.unigraph import unigraph_default class Cell: @@ -63,6 +64,16 @@ cell = self._data[y * self._size.w + x] return cell.char, self._attr_descs[cell.attr] + def setattr(self, attr_desc): + """Set attribute to be used for subsequent draw operations.""" + if attr_desc in self._attr_map: + attr = self._attr_map[attr_desc] + else: + attr = len(self._attr_descs) + self._attr_descs.append(attr_desc) + self._attr_map[attr_desc] = attr + self._current_attr = attr + def putch(self, x, y, ch): """Set character on xy coords to c.""" self._data[y * self._size.w + x].set(ch, self._current_attr) @@ -83,19 +94,31 @@ self.putch(x, y + i, c) def fill(self, x=0, y=0, w=0, h=0, c=' '): - """Fill rectangular area.""" + """Fill rectangular area. + + Fill whole buffer if width or height is not specified (zero). + + """ w = self._size.w if not w else w h = self._size.h if not h else h for i in range(h): self.hline(x, y + i, w, c) - def setattr(self, attr_desc): - """Set attribute to be used for subsequent draw operations.""" - if attr_desc in self._attr_map: - attr = self._attr_map[attr_desc] - else: - attr = len(self._attr_descs) - self._attr_descs.append(attr_desc) - self._attr_map[attr_desc] = attr - self._current_attr = attr + def frame(self, x=0, y=0, w=0, h=0, style=unigraph_default): + """Draw rectangular frame. + + Frame whole buffer if width or height is not specified (zero). + Use line-drawing characters from `style` bank. + """ + w = self._size.w if not w else w + h = self._size.h if not h else h + self.putch(x, y, style.frame_ulcorner) + self.putch(x+w-1, y, style.frame_urcorner) + self.putch(x, y+h-1, style.frame_llcorner) + self.putch(x+w-1, y+h-1, style.frame_lrcorner) + self.hline(x+1, y, w-2, style.frame_hline) + self.hline(x+1, y+h-1, w-2, style.frame_hline) + self.vline(x, y+1, h-2, style.frame_vline) + self.vline(x+w-1, y+1, h-2, style.frame_vline) + diff -r 573a9e76719d -r 5cd40c30c4f2 tuikit/core/unigraph.py --- a/tuikit/core/unigraph.py Fri Mar 14 10:03:36 2014 +0100 +++ b/tuikit/core/unigraph.py Fri Mar 14 10:30:43 2014 +0100 @@ -69,3 +69,6 @@ def __getitem__(self, name): return getattr(self, name) + +# Default instance +unigraph_default = UnicodeGraphics()