[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r7502 - in trunk/gnue-forms: . src/uidrivers/curses src/uidrivers
From: |
johannes |
Subject: |
[gnue] r7502 - in trunk/gnue-forms: . src/uidrivers/curses src/uidrivers/curses/widgets |
Date: |
Fri, 29 Apr 2005 05:53:27 -0500 (CDT) |
Author: johannes
Date: 2005-04-29 05:53:26 -0500 (Fri, 29 Apr 2005)
New Revision: 7502
Modified:
trunk/gnue-forms/BUGS
trunk/gnue-forms/src/uidrivers/curses/UIdriver.py
trunk/gnue-forms/src/uidrivers/curses/dialogs.py
trunk/gnue-forms/src/uidrivers/curses/widgets/entry.py
Log:
Added listbox widget to curses driver
Modified: trunk/gnue-forms/BUGS
===================================================================
--- trunk/gnue-forms/BUGS 2005-04-28 15:16:40 UTC (rev 7501)
+++ trunk/gnue-forms/BUGS 2005-04-29 10:53:26 UTC (rev 7502)
@@ -47,4 +47,3 @@
----------------
* crashes when form is bigger than screen (can't reproduce atm)
-* listbox not implelmented
Modified: trunk/gnue-forms/src/uidrivers/curses/UIdriver.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/curses/UIdriver.py 2005-04-28 15:16:40 UTC
(rev 7501)
+++ trunk/gnue-forms/src/uidrivers/curses/UIdriver.py 2005-04-29 10:53:26 UTC
(rev 7502)
@@ -200,6 +200,7 @@
(key, shift, ctrl, meta) = self.__shiftkeys [key]
else:
(shift, ctrl, meta) = (False, False, False)
+
self._uiFocusWidget._fkeypress (key, shift, ctrl, meta)
except:
self.showException ()
Modified: trunk/gnue-forms/src/uidrivers/curses/dialogs.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/curses/dialogs.py 2005-04-28 15:16:40 UTC
(rev 7501)
+++ trunk/gnue-forms/src/uidrivers/curses/dialogs.py 2005-04-29 10:53:26 UTC
(rev 7502)
@@ -1,4 +1,4 @@
-# Short line describing the purpose of this file
+# GNU Enterprise Forms - Curses UI Driver - UI specific dialogs
#
# Copyright 2001-2005 Free Software Foundation
#
Modified: trunk/gnue-forms/src/uidrivers/curses/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/curses/widgets/entry.py 2005-04-28
15:16:40 UTC (rev 7501)
+++ trunk/gnue-forms/src/uidrivers/curses/widgets/entry.py 2005-04-29
10:53:26 UTC (rev 7502)
@@ -45,14 +45,24 @@
else:
self.__length = None
+ self.__height = event.object ['Char:height']
self.__value = {}
self.__offset = {}
self.__selection = {}
self.__enabled = {}
- if self.__style in ['dropdown', 'listbox']:
+ # additional indices for listboxes
+ self.__index = {}
+ self.__pindex = {}
+ self.__oldCursor = 1
+
+ if self.__style == 'dropdown':
self.__allowedValues = event.object._field._allowedValues
+ elif self.__style == 'listbox':
+ self.__data = event.object._field._allowedValues.values ()
+ self.__data.sort ()
+
if self.__style == 'checkbox':
self._setCursor (1, 0)
@@ -65,7 +75,9 @@
self.__value [index] = None
self.__selection [index] = None
self.__enabled [index] = True
- self.__offset [index] = 0
+ self.__offset [index] = 0
+ self.__index [index] = 0
+ self.__pindex [index] = 1
# ---------------------------------------------------------------------------
# Focus has changed to this entry
@@ -73,6 +85,9 @@
def _getFocus (self, index):
+ if self.__style == 'listbox':
+ self.__oldCursor = curses.curs_set (0)
+
self.__repaint (index)
# ---------------------------------------------------------------------------
@@ -81,6 +96,9 @@
def _loseFocus (self, index):
+ if self.__style == 'listbox':
+ curses.curs_set (self.__oldCursor)
+
self.__repaint (index)
# ---------------------------------------------------------------------------
@@ -89,9 +107,14 @@
def setValue (self, value, index = 0, enabled = True):
+ if self.__style == 'listbox' and value in self.__data:
+ if self.__value [index] <> value:
+ self.__index [index] = self.__data.index (value)
+ self.__pindex [index] = 1
+ self.__offset [index] = self.__index [index]
+
self.__value [index] = value
self.__enabled [index] = enabled
-
self.__repaint (index)
# ---------------------------------------------------------------------------
@@ -100,7 +123,7 @@
def setCursorPosition (self, position, index = 0):
- if self.__style != 'checkbox':
+ if not self.__style in ['checkbox', 'listbox']:
if self.__length:
npos = position - self.__offset [index]
if npos > self.__length:
@@ -137,37 +160,59 @@
def __repaint (self, index):
- value = self.__value [index]
- offset = self.__offset [index]
+ if self.__style == 'listbox':
+ # First draw the visible items of the listbox
+ offset = self.__offset [index]
+ lines = self.__data [offset:offset + self.__height]
- if self.__style in ['default', 'label', 'dropdown', 'listbox']:
- text = value or ''
- text = text [offset:offset + self.__length]
- text += ' ' * (self.__length - len (text))
+ for (line, value) in enumerate (lines):
+ text = value.ljust (self.__length) [:self.__length]
- elif self.__style == 'password':
- text = '*' * len (value or '')
- text = text [offset:offset + self.__length]
- text += ' ' * (self.__length - len (text))
+ 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']
- elif self.__style == 'checkbox':
- if self.__value [index]:
- text = '[X]'
- else:
- text = '[ ]'
+ # Note: this is not safe if there's a gap !
+ self._setText (index + line, text, attr, self.__selection [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']
+ self._parent.move (self._x, self._y + self.__pindex [index] - 1)
+
+
else:
- attr = self._uiDriver.attr ['entry']
+ value = self.__value [index]
+ offset = self.__offset [index]
- self._setText (index, text, attr, self.__selection [index])
+ if self.__style in ['default', 'label', 'dropdown']:
+ text = value or ''
+ text = text [offset:offset + self.__length]
+ text += ' ' * (self.__length - len (text))
+ elif self.__style == 'password':
+ text = '*' * len (value or '')
+ text = text [offset:offset + self.__length]
+ text += ' ' * (self.__length - len (text))
+ elif self.__style == 'checkbox':
+ if self.__value [index]:
+ text = '[X]'
+ 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']
+
+ self._setText (index, text, attr, self.__selection [index])
+
+
# ---------------------------------------------------------------------------
# handle keypress
# ---------------------------------------------------------------------------
@@ -182,6 +227,43 @@
UIHelper._keypress (self, key)
+ # ---------------------------------------------------------------------------
+ # handle function keypress
+ # ---------------------------------------------------------------------------
+
+ def _fkeypress (self, key, shift, ctrl, meta):
+
+ if self.__style == 'listbox' and key in [curses.KEY_DOWN, curses.KEY_UP]:
+ self.__move ([1, -1][key == curses.KEY_UP])
+ else:
+ UIHelper._fkeypress (self, key, shift, ctrl, meta)
+
+
+ # ---------------------------------------------------------------------------
+
+ def __move (self, direction):
+
+ index = self._focusIndex
+ self.__pindex [index] += direction
+ self.__index [index] += direction
+
+ if self.__pindex [index] > self.__height:
+ if self.__index [index] < len (self.__data):
+ self.__offset [index] += direction
+
+ elif self.__pindex [index] < 1:
+ self.__offset [index] = max (0, self.__offset [index] - 1)
+
+ self.__index [index] = max (0, self.__index [index])
+ self.__index [index] = min (len (self.__data) - 1, self.__index [index])
+
+ self.__pindex [index] = max (1, self.__pindex [index])
+ self.__pindex [index] = min (self.__pindex [index], self.__height)
+
+ self.__value [index] = self.__data [self.__index [index]]
+ self._request ('REPLACEVALUE', text = self.__data [self.__index [index]])
+
+
# =============================================================================
# Configuration data
# =============================================================================
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r7502 - in trunk/gnue-forms: . src/uidrivers/curses src/uidrivers/curses/widgets,
johannes <=