[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r9171 - trunk/gnue-forms/src/uidrivers/curses/widgets
From: |
johannes |
Subject: |
[gnue] r9171 - trunk/gnue-forms/src/uidrivers/curses/widgets |
Date: |
Mon, 18 Dec 2006 08:55:10 -0600 (CST) |
Author: johannes
Date: 2006-12-18 08:55:09 -0600 (Mon, 18 Dec 2006)
New Revision: 9171
Added:
trunk/gnue-forms/src/uidrivers/curses/widgets/grid.py
trunk/gnue-forms/src/uidrivers/curses/widgets/gridline.py
Modified:
trunk/gnue-forms/src/uidrivers/curses/widgets/_base.py
trunk/gnue-forms/src/uidrivers/curses/widgets/button.py
trunk/gnue-forms/src/uidrivers/curses/widgets/entry.py
Log:
Added first version of grid-support to curses
Modified: trunk/gnue-forms/src/uidrivers/curses/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/curses/widgets/_base.py 2006-12-18
14:54:23 UTC (rev 9170)
+++ trunk/gnue-forms/src/uidrivers/curses/widgets/_base.py 2006-12-18
14:55:09 UTC (rev 9171)
@@ -157,6 +157,7 @@
if func and func(key):
return
+ gDebug(2, "Key: %r" % key)
UIWidget._keypress(self, key)
@@ -471,6 +472,14 @@
result = (cwidth + 1, 0)
+ self._add_label_(child, index)
+
+ return result
+
+ # -------------------------------------------------------------------------
+
+ def _add_label_(self, child, index):
+
label = getattr(child._gfObject, 'label', None)
if label and self._hints_[index][2]:
attr = self._uiDriver.attr['background']
@@ -484,9 +493,7 @@
self._parent.write(left, top, label, attr)
- return result
-
# =============================================================================
# Draw a box on a given parent
# =============================================================================
Modified: trunk/gnue-forms/src/uidrivers/curses/widgets/button.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/curses/widgets/button.py 2006-12-18
14:54:23 UTC (rev 9170)
+++ trunk/gnue-forms/src/uidrivers/curses/widgets/button.py 2006-12-18
14:55:09 UTC (rev 9171)
@@ -90,6 +90,9 @@
def __repaint(self, index, focused):
+ if not self.ready():
+ return
+
if focused:
attr = self._uiDriver.attr['focusentry']
elif not self.__enabled[index]:
Modified: trunk/gnue-forms/src/uidrivers/curses/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/curses/widgets/entry.py 2006-12-18
14:54:23 UTC (rev 9170)
+++ trunk/gnue-forms/src/uidrivers/curses/widgets/entry.py 2006-12-18
14:55:09 UTC (rev 9171)
@@ -49,6 +49,7 @@
if not build:
build = self.__build_default
+ gDebug(2, "building ENTRY: %s (%s)" % (spacer, self._gfObject.name))
(self.label, self.widget) = build(spacer * (self._gfObject._gap + 1))
return self.widget
@@ -70,6 +71,13 @@
# -------------------------------------------------------------------------
+ def __build_multiline(self, row_offset):
+
+ result = MultiLineTextEntry(self, row_offset)
+ return (None, result)
+
+ # -------------------------------------------------------------------------
+
def __build_dropdown(self, row_offset):
result = DropDownEntry(self, row_offset)
@@ -473,6 +481,76 @@
# =============================================================================
+# Multiline text entry
+# =============================================================================
+
+class MultiLineTextEntry(TextEntry):
+
+ # -------------------------------------------------------------------------
+ # Draw the widget
+ # -------------------------------------------------------------------------
+
+ def _repaint_(self):
+
+ data = [''.ljust(self.width)] * self.height
+ text = self.value or ''
+
+ for (row, line) in enumerate(text.splitlines()):
+ data[row] = line[self.offset:].ljust(self.width)[:self.width]
+
+ for (row, line) in enumerate(data):
+ self.entry._parent.write(self.left, self.top + row, line,
+ self.attribute)
+
+
+ # -------------------------------------------------------------------------
+ # UI event handler
+ # -------------------------------------------------------------------------
+
+ def _ui_set_cursor_position_(self, position):
+
+ # If there is a selection atm, we have to unselected it. Thus we need
+ # a repaint
+ need_repaint = self.selection is not None
+ self.selection = None
+
+ if not self.entry.ready():
+ return
+
+ (row, col) = self.__position_to_coord(position)
+ if col > self.width - 1:
+ self.offset = col - self.width + 1
+ col = self.width - 1
+ need_repaint = True
+
+ elif col < 0:
+ self.offset += col
+ col = 0
+ need_repaint = True
+
+ if need_repaint:
+ self._repaint_()
+
+ if self.has_focus:
+ self.entry._parent.move(self.left + col, self.top + row)
+
+ # -------------------------------------------------------------------------
+ # Map a GF position into a row/column tuple suitable for cursor positioning
+ # -------------------------------------------------------------------------
+
+ def __position_to_coord(self, position):
+
+ part = (self.value or '')[self.offset:position]
+ paragraph = part.count('\n')
+ offset = position
+ if paragraph > 0:
+ offset = len(part.split('\n')[-1])
+
+ return (paragraph, offset)
+
+
+
+# =============================================================================
# Drodown Entry
# =============================================================================
Added: trunk/gnue-forms/src/uidrivers/curses/widgets/grid.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/curses/widgets/grid.py 2006-12-18
14:54:23 UTC (rev 9170)
+++ trunk/gnue-forms/src/uidrivers/curses/widgets/grid.py 2006-12-18
14:55:09 UTC (rev 9171)
@@ -0,0 +1,136 @@
+# GNU Enterprise Forms - Curses UI Driver - Grid Widget
+#
+# Copyright 2000-2006 Free Software Foundation
+#
+# This file is part of GNU Enterprise.
+#
+# GNU Enterprise is free software; you can redistribute it
+# and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2, or (at your option) any later version.
+#
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id$
+
+import curses
+
+from gnue.forms.uidrivers.curses.widgets import _base
+
+__all__ = ['UIGrid']
+
+# =============================================================================
+# Grid widget class
+# =============================================================================
+
+class UIGrid(_base.UIHelper):
+ """
+ Interface implementation for <grid> widgets.
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, event):
+
+ _base.UIHelper.__init__(self, event)
+
+ self._column_header_ = {} # Labels per column header
+ self.__max = 0
+ self.__visible = 0
+
+
+ # -------------------------------------------------------------------------
+ # Widget creation
+ # -------------------------------------------------------------------------
+
+ def _create_widget_(self, event, spacer):
+
+ _base.UIHelper._create_widget_(self, event, spacer)
+ self._parent = event.container
+ self._container = self._parent
+
+ self.__max = self._gfObject.rows
+ self.__visible = self.__max
+
+ gDebug(2, "building GRID: %s" % spacer)
+
+ return None
+
+
+ # -------------------------------------------------------------------------
+ # UI event handler
+ # -------------------------------------------------------------------------
+
+ def _ui_adjust_scrollbar_(self, *args):
+ pass
+
+
+ # -------------------------------------------------------------------------
+ # Set the size for the grid and it's children
+ # -------------------------------------------------------------------------
+
+ def set_size_and_fit(self, width, height):
+
+ self.width = width
+ self.height = height
+
+ # The header rows are not available to the grid's children
+ i_width = width
+ i_height = height - len(self._children)
+
+ self._repaint_()
+
+ for (row, child) in enumerate(self._children):
+ child.left = self.left
+ child.top = self.top + row
+
+ child.set_size_and_fit(i_width, i_height)
+
+
+ # -------------------------------------------------------------------------
+ # Get the size hints for an entry
+ # -------------------------------------------------------------------------
+
+ def get_size_hints(self, vertical=None):
+
+ hints = []
+ for child in self._children:
+ hints.append(child.get_size_hints())
+
+ minw = max([i[0] for i in hints])
+ minh = len(self._children) + self.__visible + 1
+
+ gDebug(2, "HINTS: %s %s, 0, %s" % (minw, minh, self.stretch))
+ return (minw, minh, 0, self.stretch)
+
+
+ # -------------------------------------------------------------------------
+ # Repaint the widget
+ # -------------------------------------------------------------------------
+
+ def _repaint_(self):
+
+ for row in range(self.height):
+ self._parent.write(self.left, self.top + row, ' ' * self.width,
+ self._uiDriver.attr['background'])
+
+
+# =============================================================================
+# Configuration data
+# =============================================================================
+
+configuration = {
+ 'baseClass' : UIGrid,
+ 'provides' : 'GFGrid',
+ 'container' : 1,
+}
Property changes on: trunk/gnue-forms/src/uidrivers/curses/widgets/grid.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/gnue-forms/src/uidrivers/curses/widgets/gridline.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/curses/widgets/gridline.py 2006-12-18
14:54:23 UTC (rev 9170)
+++ trunk/gnue-forms/src/uidrivers/curses/widgets/gridline.py 2006-12-18
14:55:09 UTC (rev 9171)
@@ -0,0 +1,93 @@
+# GNU Enterprise Forms - Curses UI Driver - Grid Line Widget
+#
+# Copyright 2000-2006 Free Software Foundation
+#
+# This file is part of GNU Enterprise.
+#
+# GNU Enterprise is free software; you can redistribute it
+# and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2, or (at your option) any later version.
+#
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id$
+
+import curses
+
+from gnue.forms.uidrivers.curses.widgets import _base
+
+__all__ = ['UIGridLine']
+
+# =============================================================================
+# Grid widget class
+# =============================================================================
+
+class UIGridLine(_base.ManagedBox):
+ """
+ Interface implementation for <gridline> widgets.
+ """
+
+ vertical = False
+
+ # -------------------------------------------------------------------------
+ # Widget creation
+ # -------------------------------------------------------------------------
+
+ def _create_widget_(self, event, spacer):
+
+ _base.ManagedBox._create_widget_(self, event, spacer)
+ self._parent = event.container
+ self._container = self._parent
+ gDebug(2, "Building LINE %s" % spacer)
+
+ return self
+
+
+ # -------------------------------------------------------------------------
+ # Virtual methods
+ # -------------------------------------------------------------------------
+
+ def _decoration_size_(self):
+ return (2, 0)
+
+ def _add_decoration_(self):
+ pass
+
+ # -------------------------------------------------------------------------
+ # Get the size hints for an entry
+ # -------------------------------------------------------------------------
+
+ def get_size_hints(self, vertical=None):
+
+ result = _base.ManagedBox.get_size_hints(self, False)
+ return (result[0], 1, 0, 0)
+
+ def _vertical_offset_(self):
+ result = len(self.getParent()._children) - 1
+ return result
+
+ def _add_label_(self, child, index):
+
+ label = getattr(child._gfObject, 'label', '')
+ if label:
+ self._parent.write(child.left, self.top, label,
+ self._uiDriver.attr['background'])
+
+# =============================================================================
+# Configuration data
+# =============================================================================
+
+configuration = {
+ 'baseClass' : UIGridLine,
+ 'provides' : 'GFGridLine',
+ 'container' : 1,
+}
Property changes on: trunk/gnue-forms/src/uidrivers/curses/widgets/gridline.py
___________________________________________________________________
Name: svn:keywords
+ Id
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r9171 - trunk/gnue-forms/src/uidrivers/curses/widgets,
johannes <=