[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
r6309 - in trunk/gnue-forms/src/uidrivers/curses: . widgets
From: |
reinhard |
Subject: |
r6309 - in trunk/gnue-forms/src/uidrivers/curses: . widgets |
Date: |
Thu, 16 Sep 2004 11:25:00 -0500 (CDT) |
Author: reinhard
Date: 2004-09-16 11:25:00 -0500 (Thu, 16 Sep 2004)
New Revision: 6309
Modified:
trunk/gnue-forms/src/uidrivers/curses/UILoginHandler.py
trunk/gnue-forms/src/uidrivers/curses/UIdriver.py
trunk/gnue-forms/src/uidrivers/curses/widgets/form.py
Log:
made login handler and _showMessage/_showException functional after __init__.
Modified: trunk/gnue-forms/src/uidrivers/curses/UILoginHandler.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/curses/UILoginHandler.py 2004-09-16
15:26:53 UTC (rev 6308)
+++ trunk/gnue-forms/src/uidrivers/curses/UILoginHandler.py 2004-09-16
16:25:00 UTC (rev 6309)
@@ -21,9 +21,24 @@
#
# $Id$
+import curses
+
from gnue.common.datasources import GLoginHandler
-# For now, we reuse the basic login handler
+# =============================================================================
+# This class implements a login handler for curses
+# =============================================================================
-class UILoginHandler (GLoginHandler.BasicLoginHandler):
- pass
+class UILoginHandler (GLoginHandler.LoginHandler):
+
+ # ---------------------------------------------------------------------------
+ # Get input for all fields listed in loginData
+ # ---------------------------------------------------------------------------
+
+ def getLogin (self, loginData, error = None):
+
+ (connection, description, fields) = loginData
+
+ text = u_('Login required for "%s"') % (description or connection)
+
+ return self.uiDriver.askLogin (text, fields, error)
Modified: trunk/gnue-forms/src/uidrivers/curses/UIdriver.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/curses/UIdriver.py 2004-09-16 15:26:53 UTC
(rev 6308)
+++ trunk/gnue-forms/src/uidrivers/curses/UIdriver.py 2004-09-16 16:25:00 UTC
(rev 6309)
@@ -21,11 +21,12 @@
#
# $Id$
+import atexit
import curses
import string
-from gnue.common import events
from gnue.common.apps import i18n
+from gnue.common.datasources import GLoginHandler
from gnue.forms.GFKeyMapper import vk, KeyMapper
from gnue.forms.uidrivers._base.UIdriver import GFUserInterfaceBase
@@ -36,6 +37,49 @@
class GFUserInterface (GFUserInterfaceBase):
# ---------------------------------------------------------------------------
+ # Initialize library
+ # ---------------------------------------------------------------------------
+
+ def __init__ (self, eventHandler, name = "Undefined", disableSplash = None,
+ parentContainer = None):
+
+ GFUserInterfaceBase.__init__ (self, eventHandler, name, disableSplash,
+ parentContainer)
+
+ self.__screen = curses.initscr ()
+ atexit.register (curses.endwin)
+ curses.raw ()
+ curses.start_color ()
+
+ # Define colors
+ curses.init_pair (1, curses.COLOR_WHITE, curses.COLOR_BLUE)
+ curses.init_pair (2, curses.COLOR_BLACK, curses.COLOR_WHITE)
+ curses.init_pair (3, curses.COLOR_BLACK, curses.COLOR_CYAN)
+ curses.init_pair (4, curses.COLOR_BLACK, curses.COLOR_WHITE)
+ curses.init_pair (5, curses.COLOR_BLACK, curses.COLOR_CYAN)
+ curses.init_pair (6, curses.COLOR_WHITE, curses.COLOR_RED)
+ curses.init_pair (7, curses.COLOR_WHITE, curses.COLOR_BLUE)
+ curses.init_pair (8, curses.COLOR_WHITE, curses.COLOR_YELLOW)
+ curses.init_pair (9, curses.COLOR_WHITE, curses.COLOR_RED)
+
+ self.attr = {}
+ self.attr ['title'] = curses.color_pair (1)
+ self.attr ['page'] = curses.color_pair (2)
+ self.attr ['currentpage'] = curses.color_pair (3)
+ self.attr ['background'] = curses.color_pair (4)
+ self.attr ['entry'] = curses.color_pair (5)
+ self.attr ['focusentry'] = curses.color_pair (6) + curses.A_BOLD
+ self.attr ['disabled'] = curses.color_pair (5)
+ self.attr ['status'] = curses.color_pair (7)
+ self.attr ['fkeys'] = curses.color_pair (4)
+ self.attr ['infomsg'] = curses.color_pair (8) + curses.A_BOLD
+ self.attr ['warnmsg'] = curses.color_pair (9) + curses.A_BOLD
+ self.attr ['errormsg'] = curses.color_pair (9) + curses.A_BOLD \
+ + curses.A_BLINK
+
+ self.__currentForm = None
+
+ # ---------------------------------------------------------------------------
# Initialize user interface
# ---------------------------------------------------------------------------
@@ -46,60 +90,27 @@
self.textWidth = 1
self.textHeight = 1
- self.__screen = curses.initscr ()
- try:
- curses.raw ()
- curses.start_color ()
+ self.__exiting = False
- # Define colors
- curses.init_pair (1, curses.COLOR_WHITE, curses.COLOR_BLUE)
- curses.init_pair (2, curses.COLOR_BLACK, curses.COLOR_WHITE)
- curses.init_pair (3, curses.COLOR_BLACK, curses.COLOR_CYAN)
- curses.init_pair (4, curses.COLOR_BLACK, curses.COLOR_WHITE)
- curses.init_pair (5, curses.COLOR_BLACK, curses.COLOR_CYAN)
- curses.init_pair (6, curses.COLOR_WHITE, curses.COLOR_RED)
- curses.init_pair (7, curses.COLOR_WHITE, curses.COLOR_BLUE)
- curses.init_pair (8, curses.COLOR_WHITE, curses.COLOR_YELLOW)
- curses.init_pair (9, curses.COLOR_WHITE, curses.COLOR_RED)
+ KeyMapper.setUIKeyMap (self._keymap)
- self.attr = {}
- self.attr ['title'] = curses.color_pair (1)
- self.attr ['page'] = curses.color_pair (2)
- self.attr ['currentpage'] = curses.color_pair (3)
- self.attr ['background'] = curses.color_pair (4)
- self.attr ['entry'] = curses.color_pair (5)
- self.attr ['focusentry'] = curses.color_pair (6) + curses.A_BOLD
- self.attr ['disabled'] = curses.color_pair (5)
- self.attr ['status'] = curses.color_pair (7)
- self.attr ['fkeys'] = curses.color_pair (4)
- self.attr ['infomsg'] = curses.color_pair (8) + curses.A_BOLD
- self.attr ['warnmsg'] = curses.color_pair (9) + curses.A_BOLD
- self.attr ['errormsg'] = curses.color_pair (9) + curses.A_BOLD \
- + curses.A_BLINK
- self.__exiting = False
+ # Find out all functions mapped to function keys
+ # Both hold [eventname, enabled] pairs:
+ self.__events_fkey = {} # by curses keycode
+ self.__events_name = {} # by event name
+ for fkey in range (curses.KEY_F1, curses.KEY_F20):
+ if self.__shiftkeys.has_key (fkey):
+ (key, shift, ctrl, meta) = self.__shiftkeys [fkey]
+ else:
+ (key, shift, ctrl, meta) = (fkey, False, False, False)
+ name = KeyMapper.getEvent (key, shift, ctrl, meta)
+ if name:
+ event = [name, False]
+ self.__events_fkey [fkey] = event
+ self.__events_name [name] = event
+ self.registerEventListeners ({'can' + name: self.__canEvent,
+ 'cannot' + name: self.__cannotEvent})
- KeyMapper.setUIKeyMap (self._keymap)
-
- # Find out all functions mapped to function keys
- # Both hold [eventname, enabled]
pairs
- self.__events_fkey = {} # by curses keycode
- self.__events_name = {} # by event name
- for fkey in range (curses.KEY_F1, curses.KEY_F20):
- if self.__shiftkeys.has_key (fkey):
- (key, shift, ctrl, meta) = self.__shiftkeys [fkey]
- else:
- (key, shift, ctrl, meta) = (fkey, False, False, False)
- name = KeyMapper.getEvent (key, shift, ctrl, meta)
- if name:
- event = [name, False]
- self.__events_fkey [fkey] = event
- self.__events_name [name] = event
- self.registerEventListeners ({'can' + name: self.__canEvent,
- 'cannot' + name: self.__cannotEvent})
- except:
- curses.endwin ()
- raise
-
# ---------------------------------------------------------------------------
# Activate the given form
# ---------------------------------------------------------------------------
@@ -229,8 +240,53 @@
def _showMessage (self, message, kind, title, cancel):
- return self.__currentForm.showMessage (message, kind, cancel)
+ attr = {
+ 'Question': self.attr ['infomsg'],
+ 'Info': self.attr ['infomsg'],
+ 'Warning': self.attr ['warnmsg'],
+ 'Error': self.attr ['errormsg']
+ }
+ yes = _("Yes")
+ no = _("No")
+ ok = _("Ok")
+
+ self.__screen.bkgdset (' ', attr [kind])
+
+ (y, x) = self.__screen.getmaxyx ()
+
+ self.__screen.move (y - 2, 0)
+ self.__screen.clrtobot ()
+
+ self.__screen.addstr (y - 2, 1, o(message))
+
+ if kind == 'Question':
+ self.__screen.addstr (y - 1, 1, '(' + yes [:1] + ')' + yes [1:] + '/' + \
+ '(' + no [:1] + ')' + no [1:] + ' ? ')
+ else:
+ self.__screen.addstr (y - 1, 1, '[' + ok + ']')
+ self.__screen.move (y - 1, 2)
+
+ if kind == 'Question':
+ validKeys = {ord (yes [0]): True,
+ ord (no [0]): False}
+ else:
+ validKeys = {10: True}
+
+ if cancel:
+ validKeys [27] = None
+
+ while True:
+ key = self.__screen.getch ()
+ if validKeys.has_key (key):
+ result = validKeys [key]
+ break
+
+ if self.__currentForm: # repaint status line of form
+ self.__currentForm.statusMessage (None)
+
+ return result
+
# ---------------------------------------------------------------------------
# Show exception information
# ---------------------------------------------------------------------------
@@ -240,12 +296,93 @@
self.showMessage (message, kind = 'Error')
# ---------------------------------------------------------------------------
+ # Ask for login info
+ # ---------------------------------------------------------------------------
+
+ def askLogin (self, text, fields, error):
+
+ l = 0
+ for field in fields:
+ if l < len (field [1]):
+ l = len (field [1])
+ w = l + 18
+ if w < len (text):
+ w = len (text)
+ if error and w < len (error):
+ w = len (error)
+ w += 4
+
+ h = len (fields) + 4
+ if error:
+ h += 2
+
+ (screenX, screenY) = self.screenSize ()
+
+ win = curses.newwin (h, w, (screenY - h) / 2, (screenX - w) / 2)
+ win.keypad (1)
+ win.bkgd (' ', self.attr ['background'])
+ win.box ()
+
+ win.addstr (1, (w - len (text)) / 2, o(text))
+
+ y = 3
+ for field in fields:
+ win.addstr (y, 2, o(field [1]))
+ win.addstr (y, l + 3, ':')
+ win.addstr (y, l + 5, ' ' * 16, self.attr ['entry'])
+ y += 1
+
+ if error:
+ win.addstr (h - 2, (w - len (error)) / 2, o(error))
+
+ result = {}
+
+ y = 3
+ for field in fields:
+ input = ''
+ while True:
+
+ if field [2]:
+ out = '*' * len (input)
+ else:
+ out = input
+ out = out + ' ' * (16 - len (out))
+ win.addstr (y, l + 5, out, self.attr ['focusentry'])
+
+ win.move (y, l + 5 + len (input))
+ k = win.getkey ()
+
+ if k == 'KEY_BACKSPACE': # backspace
+ if len (input):
+ input = input [:-1]
+ continue
+ elif len (k) > 1: # ignore other function keys
+ continue
+ elif k == chr (10): # enter key
+ break
+ elif k == chr (27): # esc key
+ raise GLoginHandler.UserCanceledLogin
+ elif k < ' ': # ignore other control keys
+ continue
+
+ input = input + k
+ if len (input) > 16:
+ input = input [:16]
+
+ win.addstr (y, l + 5, out, self.attr ['entry']) # remove focus color
+ result [field [0]] = input
+ y += 1
+
+ self.__screen.refresh () # remove login box
+
+ return result
+
+ # ---------------------------------------------------------------------------
# Clean up everything
# ---------------------------------------------------------------------------
def _exit (self, formName):
- curses.endwin ()
self.__exiting = True
# ---------------------------------------------------------------------------
Modified: trunk/gnue-forms/src/uidrivers/curses/widgets/form.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/curses/widgets/form.py 2004-09-16
15:26:53 UTC (rev 6308)
+++ trunk/gnue-forms/src/uidrivers/curses/widgets/form.py 2004-09-16
16:25:00 UTC (rev 6309)
@@ -142,60 +142,6 @@
return self.__currentPage.wait ()
# ---------------------------------------------------------------------------
- # Show a message
- # ---------------------------------------------------------------------------
-
- def showMessage (self, message, kind, cancel):
-
- attr = {
- 'Question': self._uiDriver.attr ['infomsg'],
- 'Info': self._uiDriver.attr ['infomsg'],
- 'Warning': self._uiDriver.attr ['warnmsg'],
- 'Error': self._uiDriver.attr ['errormsg']
- }
-
- yes = _("Yes")
- no = _("No")
- ok = _("Ok")
-
- self.__window.bkgdset (' ', attr [kind])
-
- (y, x) = self.__window.getmaxyx ()
-
- self.__window.move (y - 2, 0)
- self.__window.clrtobot ()
-
- self.__window.addstr (y - 2, 1, o(message))
-
- if kind == 'Question':
- self.__window.addstr (y - 1, 1, '(' + yes [:1] + ')' + yes [1:] + '/' + \
- '(' + no [:1] + ')' + no [1:] + ' ? ')
- else:
- self.__window.addstr (y - 1, 1, '[' + ok + ']')
- self.__window.move (y - 1, 2)
-
- if kind == 'Question':
- validKeys = {ord (yes [0]): True,
- ord (no [0]): False}
- else:
- validKeys = {10: True}
-
- if cancel:
- validKeys [27] = None
-
- self.__window.refresh (y - 2, 0, y - 2, 0, y, x)
-
- while True:
- key = self.__window.getch ()
- if validKeys.has_key (key):
- result = validKeys [key]
- break
-
- self.__updateStatusBar ()
-
- return result
-
- # ---------------------------------------------------------------------------
# Get free area in the window
# ---------------------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- r6309 - in trunk/gnue-forms/src/uidrivers/curses: . widgets,
reinhard <=