[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r7523 - trunk/gnue-forms/src/uidrivers/curses/widgets
From: |
johannes |
Subject: |
[gnue] r7523 - trunk/gnue-forms/src/uidrivers/curses/widgets |
Date: |
Wed, 4 May 2005 09:22:19 -0500 (CDT) |
Author: johannes
Date: 2005-05-04 09:22:18 -0500 (Wed, 04 May 2005)
New Revision: 7523
Modified:
trunk/gnue-forms/src/uidrivers/curses/widgets/entry.py
Log:
Not yet finished multiline textfields
Modified: trunk/gnue-forms/src/uidrivers/curses/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/curses/widgets/entry.py 2005-05-04
13:00:26 UTC (rev 7522)
+++ trunk/gnue-forms/src/uidrivers/curses/widgets/entry.py 2005-05-04
14:22:18 UTC (rev 7523)
@@ -50,7 +50,11 @@
self.__offset = {}
self.__selection = {}
self.__enabled = {}
+ self.__voffset = {}
+ self.__isMultiline = (self.__style in ['default', 'password'] and \
+ self.__height > 1)
+
# additional indices for listboxes
self.__index = {}
self.__pindex = {}
@@ -76,6 +80,7 @@
self.__selection [index] = None
self.__enabled [index] = True
self.__offset [index] = 0
+ self.__voffset [index] = 0
self.__index [index] = 0
self.__pindex [index] = 1
@@ -123,7 +128,80 @@
def setCursorPosition (self, position, index = 0):
- if not self.__style in ['checkbox', 'listbox']:
+ gDebug (2, "----- new position: %s" % position)
+ gDebug (2, " Value : %r" % self.__value [index])
+ gDebug (2, " Curr.Offset : %s/%s" % (self.__offset [index],
+ self.__voffset [index]))
+
+ if self.__style in ['checkbox', 'listbox']:
+ return
+
+ if self.__isMultiline:
+ if position == 0 or self.__value [index] is None:
+ self.__offset [index] = 0
+ self.__voffset [index] = 0
+ self.__repaint (index)
+ self._setCursor (0, 0)
+ return
+
+ # Grab the text portion, which is everything up to position. If the last
+ # character is a newline, we can remove this, since it would result in a
+ # wrong vertical offset
+ value = self.__value [index][:position+1]
+ vcorr = [0, 1][value [-1] == '\n']
+
+ gDebug (2, " Cut-Part : %r" % value)
+ gDebug (2, " Vert.Correct: %s" % vcorr)
+
+ # Get the vertical cursor-position and offset
+ cpVertical = value.count ('\n') - self.__voffset [index] - vcorr
+ needRepaint = False
+
+ if cpVertical < 0:
+ # the position is not visible right now, so we need to scroll up (which
+ # means changing the voffset). We set the cursor-position to line 0.
+ self.__voffset [index] += cpVertical
+ cpVertical = 1
+ needRepaint = True
+
+ elif cpVertical >= self.__height:
+ # the position is not visible right now, so we need to scroll down
+ # (which means changing the voffset).
+ self.__voffset [index] = value.count ('\n') - self.__height + 1 - vcorr
+ cpVertical = self.__height # Pos. are Zero-based
+ needRepaint = True
+
+ # Now, after having a valid row, we need to determine the horizontal
+ # offset based on the last line holding our requested position.
+ currentLine = value.splitlines () [-1]
+ cpHorizontal = len (currentLine) - self.__offset [index] - 1
+
+ if cpHorizontal < 0:
+ # Beyond left margin, so scroll to the left
+ self.__offset [index] += cpHorizontal
+ cpHorizontal = 0
+ needRepaint = True
+
+ elif cpHorizontal > self.__length:
+ self.__offset [index] = len (currentLine) - self.__length
+ cpHorizontal = self.__length
+ needRepaint = True
+
+ if needRepaint:
+ self.__repaint (index)
+
+ cpHorizontal = min (cpHorizontal, self.__length)
+ cpHorizontal = max (cpHorizontal, 0)
+ cpVertical = min (cpVertical, self.__height - 1)
+ cpVertical = max (cpVertical, 0)
+
+ gDebug (2, "H/V: %s/%s - Offsets %s/%s" % (cpHorizontal, cpVertical,
+ self.__offset [index], self.__voffset [index]))
+
+ self._setCursor (cpHorizontal, cpVertical)
+
+
+ else:
if self.__length:
npos = position - self.__offset [index]
if npos > self.__length:
@@ -167,20 +245,32 @@
for (line, value) in enumerate (lines):
text = value.ljust (self.__length) [:self.__length]
+ attr = self.__getAttr (index)
- if not self.__enabled [index]:
- attr = self._uiDriver.attr ['disabled']
- elif line == self.__pindex [index] - 1:
- attr = self._uiDriver.attr ['focusentry']
- else:
- attr = self._uiDriver.attr ['entry']
-
# Note: this is not safe if there's a gap !
self._setText (index + line, text, attr, self.__selection [index])
self._parent.move (self._x, self._y + self.__pindex [index] - 1)
+ elif self.__isMultiline:
+ # Create all visible, empty lines
+ data = [''.ljust (self.__length)] * self.__height
+ hOffset = self.__offset [index]
+ vOffset = self.__voffset [index]
+ # Overwrite these empty lines with the data as stated by v/h-Offset
+ if self.__value [index]:
+ add = self.__value [index].splitlines ()
[vOffset:vOffset+self.__height]
+ for (ix, text) in enumerate (add):
+ text = text [hOffset:hOffset + self.__length]
+ data [ix] = text.ljust (self.__length) [:self.__length]
+
+ attr = self.__getAttr (index)
+
+ # And write everything to screen
+ for (ix, text) in enumerate (data):
+ self._setText (index + ix, text, attr, self.__selection [index])
+
else:
value = self.__value [index]
offset = self.__offset [index]
@@ -201,19 +291,30 @@
else:
text = '[ ]'
- if self.__style == 'label':
- attr = self._uiDriver.attr ['background']
- elif not self.__enabled [index]:
- attr = self._uiDriver.attr ['disabled']
- elif index == self._focusIndex:
- attr = self._uiDriver.attr ['focusentry']
- else:
- attr = self._uiDriver.attr ['entry']
+ attr = self.__getAttr (index)
self._setText (index, text, attr, self.__selection [index])
# ---------------------------------------------------------------------------
+ # Get the current screen attributes to be used
+ # ---------------------------------------------------------------------------
+
+ def __getAttr (self, index):
+
+ if self.__style == 'label':
+ attr = self._uiDriver.attr ['background']
+ elif not self.__enabled [index]:
+ attr = self._uiDriver.attr ['disabled']
+ elif index == self._focusIndex:
+ attr = self._uiDriver.attr ['focusentry']
+ else:
+ attr = self._uiDriver.attr ['entry']
+
+ return attr
+
+
+ # ---------------------------------------------------------------------------
# handle keypress
# ---------------------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r7523 - trunk/gnue-forms/src/uidrivers/curses/widgets,
johannes <=