commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/common/src/FormatMasks BaseMask.py DateMas...


From: Jason Cater
Subject: gnue/common/src/FormatMasks BaseMask.py DateMas...
Date: Thu, 03 Jan 2002 19:35:54 -0500

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    02/01/03 19:35:54

Modified files:
        common/src/FormatMasks: BaseMask.py DateMask.py 

Log message:
        more work on input masks

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/src/FormatMasks/BaseMask.py.diff?cvsroot=OldCVS&tr1=1.9&tr2=1.10&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/src/FormatMasks/DateMask.py.diff?cvsroot=OldCVS&tr1=1.13&tr2=1.14&r1=text&r2=text

Patches:
Index: gnue/common/src/FormatMasks/BaseMask.py
diff -c gnue/common/src/FormatMasks/BaseMask.py:1.9 
gnue/common/src/FormatMasks/BaseMask.py:1.10
*** gnue/common/src/FormatMasks/BaseMask.py:1.9 Thu Jan  3 00:49:16 2002
--- gnue/common/src/FormatMasks/BaseMask.py     Thu Jan  3 19:35:54 2002
***************
*** 6,19 ****
  # 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.
  #
  # Copyright 2001 Free Software Foundation
--- 6,19 ----
  # 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.
  #
  # Copyright 2001 Free Software Foundation
***************
*** 29,35 ****
  from gnue.common import GConfig, GDebug
  from FormatExceptions import *
  
- 
  # This is a class for a mask literal element
  class Literal:
    def __init__(self, literal):
--- 29,34 ----
***************
*** 41,46 ****
--- 40,48 ----
    def isValidEntry(self, value):
      return value == self.literal
  
+   def isCompleteEntry(self, value):
+     return 0
+ 
  class BaseMask:
    value = ""
    maskMappings = {}
***************
*** 53,80 ****
    literalClass = Literal
  
    def __init__(self, outputMask, inputMask=None, outputMask2=None):
      self.outputHandlers  = self.parseMask(outputMask)
      if inputMask != None:
        self.inputHandlers = self.parseMask(inputMask)
      if outputMask2 != None:
        self.output2Handlers = self.parseMask(outputMask2)
  
      self.reset()
  
  
    def reset(self):
  
      self.index = 0
      self.cursor = 0
      self.display = ""
      self.input = ""
-     self.inputMaskPos = []
-     self.inputMaskLen = []
-     self.inputDisplayLen = []
-     for i in range(len(self.inputHandlers)):
-       self.inputMaskPos.append(0)
-       self.inputMaskLen.append(0)
-       self.inputDisplayLen.append(0)
  
  
    # Take a mask string and break it into its elements and map it to handlers
--- 55,94 ----
    literalClass = Literal
  
    def __init__(self, outputMask, inputMask=None, outputMask2=None):
+ 
      self.outputHandlers  = self.parseMask(outputMask)
      if inputMask != None:
        self.inputHandlers = self.parseMask(inputMask)
      if outputMask2 != None:
        self.output2Handlers = self.parseMask(outputMask2)
  
+     # Calculate our array lengths once to speed up
+     # our code. This should always be equivalent to:
+     #   len(self.inputHandlers)
+     #   len(self.inputMaskPos)
+     #   len(self.inputMaskLen)
+     #   len(self.inputDisplayLen)
+     self.inputCount = len(self.inputHandlers)
+ 
      self.reset()
  
  
    def reset(self):
  
+     # Holds the starting positions of each element section...
+     self.inputMaskPos = [0] * self.inputCount
+ 
+     # Holds the length of each element section...
+     self.inputMaskLen = [0] * self.inputCount
+ 
+     # Holds the length of each formatted element section...
+     self.inputDisplayLen = [0] * self.inputCount
+ 
+ 
      self.index = 0
      self.cursor = 0
      self.display = ""
      self.input = ""
  
  
    # Take a mask string and break it into its elements and map it to handlers
***************
*** 86,99 ****
      # TODO: Should predefined masks be pulled from other than gnue.conf?
      if len(mask) > 1 and mask[0] == '&':
        if mask[1:] == self.basetype:
!         mask = GConfig.get('%smask_%s' % (self.basetype, self.basetype), \
!           self.defaultmask)
        else:
          try:
!           mask = GConfig.get('%smask_%s' % (self.basetype, self.basetype))
          except KeyError:
            raise PredefinedMaskNotFound, \
!               'The requested format mask %s is not defined' % mask[1:]
  
      # Process each character in mask at a time
      isLiteral = 0
--- 100,113 ----
      # TODO: Should predefined masks be pulled from other than gnue.conf?
      if len(mask) > 1 and mask[0] == '&':
        if mask[1:] == self.basetype:
!         mask = GConfig.get('%smask' % self.basetype, self.defaultmask)
        else:
          try:
!           mask = GConfig.get('%smask_%s' % (self.basetype, mask[1:]))
          except KeyError:
            raise PredefinedMaskNotFound, \
!               'The requested format mask "%s" is not defined for %s fields' \
!                   % (mask[1:], self.basetype)
  
      # Process each character in mask at a time
      isLiteral = 0
***************
*** 133,186 ****
    def deleteText(self, text, pos, characters):
      pass
  
    # Given a display cursor, calculate the index into the string
    def cursorToIndex(self, cursor):
!     return val
  
  
    # Given an index into the string, calculate the display cursor,
    def indexToCursor(self, index):
-     return val
- 
  
!   def moveCursor(self, relative):
  
      # Direction = -1 (left) or 1 (right).
      direction = relative == 0 or int(relative/abs(relative))
  
      self.cursor = self.cursor + relative
  
      if self.cursor <= 0:
        self.cursor = 0
        self.direction = 1
!     elif self.cursor >= len(self.display):
        self.cursor = len(self.display)
        self.direction = -1
  
      pos = 0
      section = 0
!     while section < len(self.inputMaskPos) and \
!           (pos + self.inputDisplayLen[section]) < self.cursor:
        section += 1
!       pos += self.inputDisplayLen[section]
  
  
!     if section == len(self.inputMaskPos):
!       self.cursor = len(self.display)
  
!     elif isinstance(self.inputMaskPos[section], Literal):
!       self.moveCursor(self, direction)
  
!     self.index = self.indexToCursor(self.cursor)
  
      return self.cursor
  
  
    def processEdit (self, value, str, pos=0, replaces=0):
      print "-"*50
      GDebug.printMesg(15,'processEdit(%s,%s,%s,%s)' % (value,str,pos,replaces))
      nv = value
!     print "%s == %s" % (pos, len(nv))
      if pos == len(nv):
        nv += str
      else:
--- 147,285 ----
    def deleteText(self, text, pos, characters):
      pass
  
+ 
+   #
    # Given a display cursor, calculate the index into the string
+   #
    def cursorToIndex(self, cursor):
!     # TODO
!     pos = 0
!     index = 0
!     i = 0
!     while ( i < self.inputCount - 1      ) and \
!           ( cursor < pos + self.inputDisplayLen[i] ) :
!       pos += self.inputDisplayLen[i]
!       i += 1
! 
! 
!     diff = cursor - pos - self.inputDisplayLen[i]
!     if diff > self.inputMaskLen[i]:
!       diff = self.inputMaskLen[i]
  
+     return max(self.inputMaskPos[i] + diff,0)
  
+ 
+   #
    # Given an index into the string, calculate the display cursor,
+   #
    def indexToCursor(self, index):
  
!     i = 0
!     while ( i < self.inputCount - 1 ) and \
!           ( index < self.inputMaskPos[i] ) :
!       i += 1
! 
!     pos = self.inputMaskPos[i]
! 
!     diff = index - pos - self.inputMaskLen[i]
! 
!     # TODO
!     return max(pos + diff,0)
! 
! 
!   #
!   # Move cursor using relative units
!   #
!   # If relative > 0, move cursor to the right <relative> units
!   # If relative < 0, move cursor to the left |<relative>| units
!   # This takes into account Literals, etc.
!   #
!   def moveCursorRelative(self, relative):
  
      # Direction = -1 (left) or 1 (right).
      direction = relative == 0 or int(relative/abs(relative))
  
+     print "relative=%s" % relative
+     print "direction=%s" % direction
+ 
      self.cursor = self.cursor + relative
  
+     print "cursor #1: %s" % self.cursor
+ 
      if self.cursor <= 0:
        self.cursor = 0
        self.direction = 1
!     elif self.cursor > len(self.display):
        self.cursor = len(self.display)
        self.direction = -1
  
+     print "cursor #2: %s" % self.cursor
+ 
      pos = 0
      section = 0
!     while section < self.inputCount and \
!           (pos + self.inputDisplayLen[section]) <= self.cursor:
        section += 1
!       if section < self.inputCount:
!         pos += self.inputDisplayLen[section]
  
+     print "pos=%s" % pos
  
!     if pos > self.cursor:
!       section += direction
  
!     if section == self.inputCount:
! #      self.cursor = pos + self.inputDisplayLen[-1]
!       print "cursor #3: %s" % self.cursor
!       section -= 1
  
!     print "section=%s" % section
!     if isinstance(self.inputHandlers[section], Literal):
!       self.moveCursorRelative(direction)
!       print "cursor #4: %s" % self.cursor
! 
!     self.index = self.cursorToIndex(self.cursor)
! 
!     print "New cursor position: %s" % self.cursor
  
      return self.cursor
  
  
+   #
+   # Move cursor to the beginning of the field
+   #
+   def moveCursorToBegin(self):
+ 
+     # Reset cursor to beginning
+     self.cursor = 0
+     self.index = 0
+ 
+     # This will handle if the first character is a literal
+     # (e.g., for phone numbers (999) 999-9999, this will move
+     # to the first '9', not the '('
+     return self.moveCursorRelative(0)
+ 
+ 
+   #
+   # Move cursor to the beginning of the field
+   #
+   def moveCursorToEnd(self):
+ 
+     # Reset cursor to beginning
+     self.cursor = self.indexToCursor(self.lastInputPos)
+ 
+     return self.moveCursorRelative(0)
+ 
+ 
+ 
+   #
+   # Edit the value
+   #
    def processEdit (self, value, str, pos=0, replaces=0):
      print "-"*50
      GDebug.printMesg(15,'processEdit(%s,%s,%s,%s)' % (value,str,pos,replaces))
      nv = value
! 
      if pos == len(nv):
        nv += str
      else:
***************
*** 191,201 ****
      print "pos=%s"%pos
  
      section = 0
!     while section < len(self.inputMaskPos) and \
            self.inputMaskPos[section] < pos and \
            self.inputMaskPos[section] > 0:
        section += 1
      i = pos
      while i < len(nv):
        if not self.inputHandlers[section]\
             .isValidEntry(nv[self.inputMaskPos[section]:i+1]):
--- 290,305 ----
      print "pos=%s"%pos
  
      section = 0
!     while section < self.inputCount and \
            self.inputMaskPos[section] < pos and \
            self.inputMaskPos[section] > 0:
        section += 1
      i = pos
+ 
+     # Debug...
+     section = 0
+     i = 0
+ 
      while i < len(nv):
        if not self.inputHandlers[section]\
             .isValidEntry(nv[self.inputMaskPos[section]:i+1]):
***************
*** 205,213 ****
            return nv
          else:
            self.inputMaskLen[section] = i - self.inputMaskPos[section]
!           if section == len(self.inputHandlers) - 1:
              if i != len(nv)-1:
                return nv
            else:
              section += 1
              self.inputMaskPos[section] = i
--- 309,319 ----
            return nv
          else:
            self.inputMaskLen[section] = i - self.inputMaskPos[section]
!           if section == self.inputCount - 1:
              if i != len(nv)-1:
                return nv
+             else:
+               break
            else:
              section += 1
              self.inputMaskPos[section] = i
***************
*** 217,224 ****
  
      self.inputMaskLen[section] = i - self.inputMaskPos[section]
  
!     for i in range(section+1, len(self.inputHandlers)):
        self.inputMaskLen[i] = 0
  
      GDebug.printMesg(15,"<< %s" % nv)
      return nv
--- 323,334 ----
  
      self.inputMaskLen[section] = i - self.inputMaskPos[section]
  
!     for i in range(section+1, self.inputCount):
        self.inputMaskLen[i] = 0
+ 
+     self.index = pos + len(value)
+     self.cursor = self.indexToCursor(self.index)
+     print "after processEdit, index=%s;cursor=%s" % (self.index, self.cursor)
  
      GDebug.printMesg(15,"<< %s" % nv)
      return nv
Index: gnue/common/src/FormatMasks/DateMask.py
diff -c gnue/common/src/FormatMasks/DateMask.py:1.13 
gnue/common/src/FormatMasks/DateMask.py:1.14
*** gnue/common/src/FormatMasks/DateMask.py:1.13        Thu Jan  3 00:49:16 2002
--- gnue/common/src/FormatMasks/DateMask.py     Thu Jan  3 19:35:54 2002
***************
*** 124,143 ****
  
      GDebug.printMesg(15,'getFormattedInput(%s,%s)' % (value,padding))
  
-     rv = ""
- 
      val = self._buildDate(value, 0)
  
      self.lastInputPos = 0
  
-     lastElement = len(self.inputHandlers) - 1
  
!     for i in range(lastElement+1):
  
        # Keep track of the last valid position
        if self.inputMaskLen[i]:
          self.lastInputPos = i + self.inputMaskLen[i] - 1
  
  
        # If this is a "literal" print it as is
        if isinstance(self.inputHandlers[i],Literal):
--- 124,147 ----
  
      GDebug.printMesg(15,'getFormattedInput(%s,%s)' % (value,padding))
  
      val = self._buildDate(value, 0)
  
+     self.display = ""
      self.lastInputPos = 0
+     lastElement = self.inputCount - 1
+ 
+     print "inputMaskPos=%s" % self.inputMaskLen
+     print "inputMaskLen=%s" % self.inputMaskLen
  
  
!     for i in range(self.inputCount):
  
        # Keep track of the last valid position
        if self.inputMaskLen[i]:
          self.lastInputPos = i + self.inputMaskLen[i] - 1
  
+       piece = ""
+       pad = ""
  
        # If this is a "literal" print it as is
        if isinstance(self.inputHandlers[i],Literal):
***************
*** 156,162 ****
  
            # Pad any extra space in this section
            if len(padding):
!             piece += padding * (self.inputHandlers[i].maxLength - len(piece))
  
          # .. or if we have data to output, format it appropriately
          elif self.inputMaskLen[i]:
--- 160,166 ----
  
            # Pad any extra space in this section
            if len(padding):
!             pad = padding * (self.inputHandlers[i].maxLength - len(piece))
  
          # .. or if we have data to output, format it appropriately
          elif self.inputMaskLen[i]:
***************
*** 164,184 ****
  
          # .. or if we have no data but are padding, pad appropriately
          elif len(padding):
!           piece = padding * self.inputHandlers[i].maxLength
  
-         else:
-           piece = ""
  
        self.inputDisplayLen[i] = len(piece)
!       rv += piece
  
!     return rv
  
  
    def _buildDate(self, value, mustValidate=0):
      date = GDateTime()
  
!     for i in range(len(self.inputHandlers)):
        if (self.inputMaskLen[i] or isinstance(self.inputHandlers[i],Literal)):
  #        if self.inputHandlers[i].isValidEntry(value[ self.inputMaskPos[i]: \
  #                   self.inputMaskPos[i] + self.inputMaskLen[i]]):
--- 168,188 ----
  
          # .. or if we have no data but are padding, pad appropriately
          elif len(padding):
!           pad = padding * self.inputHandlers[i].maxLength
  
  
        self.inputDisplayLen[i] = len(piece)
!       self.display += piece + pad
! 
!     print "inputDisplayLen=%s" % self.inputMaskLen
  
!     return self.display
  
  
    def _buildDate(self, value, mustValidate=0):
      date = GDateTime()
  
!     for i in range(self.inputCount):
        if (self.inputMaskLen[i] or isinstance(self.inputHandlers[i],Literal)):
  #        if self.inputHandlers[i].isValidEntry(value[ self.inputMaskPos[i]: \
  #                   self.inputMaskPos[i] + self.inputMaskLen[i]]):
***************
*** 210,215 ****
--- 214,235 ----
      pass
  
  
+ class _numberRangeSection (_baseDateSection):
+ 
+   minLength = 0
+   maxLength = 0
+   valueRange = (0,0)
+ 
+   def isValidEntry(self, value):
+     try:
+       v = int(value)
+       return (v >= self.valueRange[0] and v <= self.valueRange[1] \
+                                       and len(value) <= self.maxLength) or \
+              (v <= self.valueRange[1] and len(value) < self.maxLength)
+     except ValueError:
+       return 0
+ 
+ 
  class _aSection(_baseDateSection):
    def __init__(self):
      _baseDateSection.__init__(self)
***************
*** 247,258 ****
      pass
  
  
! class _BSection(_bSection): 
    def getFormattedValue(self, date):
      return monthNames[(date.month or 1) - 1]
  
  
! class _cSection(_baseDateSection): 
    def __init__(self):
      _baseDateSection.__init__(self)
      self.minLength = 1
--- 267,278 ----
      pass
  
  
! class _BSection(_bSection):
    def getFormattedValue(self, date):
      return monthNames[(date.month or 1) - 1]
  
  
! class _cSection(_baseDateSection):
    def __init__(self):
      _baseDateSection.__init__(self)
      self.minLength = 1
***************
*** 269,290 ****
      pass
  
  
! class _dSection(_baseDateSection):
    def __init__(self):
!     _baseDateSection.__init__(self)
      self.minLength = 1
      self.maxLength = 2
  
    def getFormattedValue(self, date):
      return "%02i" % date.day
  
-   def isValidEntry(self, value):
-     try:
-       v = int(value)
-       return (v >= 0 and v <= 31) or (v == 0 and len(value) == 1)
-     except ValueError:
-       return 0
- 
    def addSelfToDate(self, value, date):
      date.day = int(value or 1)
  
--- 289,304 ----
      pass
  
  
! class _dSection(_numberRangeSection):
    def __init__(self):
!     _numberRangeSection.__init__(self)
      self.minLength = 1
      self.maxLength = 2
+     self.valueRange = (0,31)
  
    def getFormattedValue(self, date):
      return "%02i" % date.day
  
    def addSelfToDate(self, value, date):
      date.day = int(value or 1)
  
***************
*** 294,304 ****
      return "%i" % date.day
  
  
! class _hSection(_baseDateSection):
!   def __init__(self): 
!     _baseDateSection.__init__(self)
      self.minLength = 1
      self.maxLength = 2
  
    def getFormattedValue(self, date):
      return "%02i" % date.hour
--- 308,319 ----
      return "%i" % date.day
  
  
! class _hSection(_numberRangeSection):
!   def __init__(self):
!     _numberRangeSection.__init__(self)
      self.minLength = 1
      self.maxLength = 2
+     self.valueRange = (0,24)
  
    def getFormattedValue(self, date):
      return "%02i" % date.hour
***************
*** 306,322 ****
    def isValidEntry(self, value):
      return 0
  
!   def addSelfToDate(self, value, date): 
      date.hour = int(value or 0)
  
  
  class _HSection(_hSection):
!   def getFormattedValue(self, date): 
      return "%i" % date.hour
  
  
! class _gSection(_baseDateSection): 
!   def __init__(self): 
      _baseDateSection.__init__(self)
      self.minLength = 1
      self.maxLength = 2
--- 321,337 ----
    def isValidEntry(self, value):
      return 0
  
!   def addSelfToDate(self, value, date):
      date.hour = int(value or 0)
  
  
  class _HSection(_hSection):
!   def getFormattedValue(self, date):
      return "%i" % date.hour
  
  
! class _gSection(_baseDateSection):
!   def __init__(self):
      _baseDateSection.__init__(self)
      self.minLength = 1
      self.maxLength = 2
***************
*** 328,379 ****
    def isValidEntry(self, value):
      return 0
  
!   def addSelfToDate(self, value, date): 
      pass
  
  
! class _GSection(_gSection): 
    def getFormattedValue(self, date):
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
  
  class _jSection(_baseDateSection):
!   def __init__(self): 
      _baseDateSection.__init__(self)
      self.minLength = 1
      self.maxLength = 2
  
!   def getFormattedValue(self, date): 
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
    def isValidEntry(self, value):
      return 0
  
!   def addSelfToDate(self, value, date): 
      pass
  
  
! class _JSection(_jSection): 
!   def getFormattedValue(self, date): 
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
  
! class _mSection(_baseDateSection): 
    def __init__(self):
!     _baseDateSection.__init__(self)
      self.minLength = 1
      self.maxLength = 2
  
!   def getFormattedValue(self, date): 
      return "%02i" % date.month
  
    def isValidEntry(self, value):
      try:
        v = int(value)
!       return (v >= 0 and v <= 12) or (v == 0 and len(value) == 1)
      except ValueError:
        return 0
  
--- 343,396 ----
    def isValidEntry(self, value):
      return 0
  
!   def addSelfToDate(self, value, date):
      pass
  
  
! class _GSection(_gSection):
    def getFormattedValue(self, date):
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
  
  class _jSection(_baseDateSection):
!   def __init__(self):
      _baseDateSection.__init__(self)
      self.minLength = 1
      self.maxLength = 2
  
!   def getFormattedValue(self, date):
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
    def isValidEntry(self, value):
      return 0
  
!   def addSelfToDate(self, value, date):
      pass
  
  
! class _JSection(_jSection):
!   def getFormattedValue(self, date):
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
  
! class _mSection(_numberRangeSection):
    def __init__(self):
!     _numberRangeSection.__init__(self)
      self.minLength = 1
      self.maxLength = 2
+     self.valueRange = (1,12)
  
!   def getFormattedValue(self, date):
      return "%02i" % date.month
  
    def isValidEntry(self, value):
      try:
        v = int(value)
!       return (v >= 0 and v <= 12 and len(value) <= 2) or \
!              (v == 0 and len(value) == 1)
      except ValueError:
        return 0
  
***************
*** 382,517 ****
  
  
  class _MSection(_baseDateSection):
!   def getFormattedValue(self, date): 
      return "%i" % date.month
  
  
! class _iSection(_baseDateSection): 
!   def __init__(self): 
!     _baseDateSection.__init__(self)
      self.minLength = 1
      self.maxLength = 2
  
!   def getFormattedValue(self, date): 
      return "%02i" % date.minute
  
-   def isValidEntry(self, value):
-     try:
-       v = int(value)
-       return (v >= 0 and v <= 59) or (v == 0 and len(value) == 1)
-     except ValueError: 
-       return 0
- 
    def addSelfToDate(self, value, date):
      date.minute = int(value)
  
  
! class _ISection(_iSection): 
!   def getFormattedValue(self, date): 
      return "%2i" % date.minute
  
  
! class _pSection(_baseDateSection): 
!   def __init__(self): 
      _baseDateSection.__init__(self)
      self.minLength = 1
      self.maxLength = 2
  
!   def getFormattedValue(self, date): 
!     # TODO: Implement this mask element
!     return "*" * self.maxLength
  
    def isValidEntry(self, value):
!     return 0
  
!   def addSelfToDate(self, value, date): 
      pass
  
  
! class _PSection(_pSection): 
    def getFormattedValue(self, date):
!     # TODO: Implement this mask element
!     return "*" * self.maxLength
  
  
! class _sSection(_baseDateSection):
!   def __init__(self): 
!     _baseDateSection.__init__(self)
      self.minLength = 1
      self.maxLength = 2
  
    def getFormattedValue(self, date):
      return "%02i" % date.second
  
!   def isValidEntry(self, value):
!     try: 
!       v = int(value)
!       return (v >= 0 and v <= 59) or (v == 0 and len(value) == 1)
!     except ValueError: 
!       return 0
! 
!   def addSelfToDate(self, value, date): 
      date.second = int(value)
  
  
! class _SSection(_sSection): 
!   def getFormattedValue(self, date): 
      return "%2i" % date.second
  
  
! class _uSection(_baseDateSection): 
!   def __init__(self): 
      _baseDateSection.__init__(self)
      self.minLength = 1
      self.maxLength = 2
  
!   def getFormattedValue(self, date): 
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
    def isValidEntry(self, value):
      return 0
  
!   def addSelfToDate(self, value, date): 
      pass
  
  
! class _USection(_uSection): 
    def getFormattedValue(self, date):
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
  
  class _vSection(_baseDateSection):
!   def __init__(self): 
      _baseDateSection.__init__(self)
      self.minLength = 1
      self.maxLength = 2
  
!   def getFormattedValue(self, date): 
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
    def isValidEntry(self, value):
      return 0
  
!   def addSelfToDate(self, value, date): 
      pass
  
  
! class _VSection(_vSection): 
    def getFormattedValue(self, date):
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
  
! class _wSection(_baseDateSection): 
    def __init__(self):
      _baseDateSection.__init__(self)
      self.minLength = 1
      self.maxLength = 2
  
!   def getFormattedValue(self, date): 
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
--- 399,521 ----
  
  
  class _MSection(_baseDateSection):
!   def getFormattedValue(self, date):
      return "%i" % date.month
  
  
! class _iSection(_numberRangeSection):
!   def __init__(self):
!     _numberRangeSection.__init__(self)
      self.minLength = 1
      self.maxLength = 2
+     self.valueRange = (0,59)
  
!   def getFormattedValue(self, date):
      return "%02i" % date.minute
  
    def addSelfToDate(self, value, date):
      date.minute = int(value)
  
  
! class _ISection(_iSection):
!   def getFormattedValue(self, date):
      return "%2i" % date.minute
  
  
! class _pSection(_baseDateSection):
!   def __init__(self):
      _baseDateSection.__init__(self)
      self.minLength = 1
      self.maxLength = 2
  
!   def getFormattedValue(self, date):
!     return date.hour >= 12 and 'pm' or 'am'
  
    def isValidEntry(self, value):
!     return string.upper(string.replace(string.replace(value,' ',''),'.','')) \
!              in ('A','AM','P','PM')
  
!   def addSelfToDate(self, value, date):
      pass
  
  
! class _PSection(_pSection):
    def getFormattedValue(self, date):
!     return date.hour >= 12 and 'PM' or 'AM'
  
  
! class _sSection(_numberRangeSection):
!   def __init__(self):
!     _numberRangeSection.__init__(self)
      self.minLength = 1
      self.maxLength = 2
+     self.valueRange = (0,59)
  
    def getFormattedValue(self, date):
      return "%02i" % date.second
  
!   def addSelfToDate(self, value, date):
      date.second = int(value)
  
  
! class _SSection(_sSection):
!   def getFormattedValue(self, date):
      return "%2i" % date.second
  
  
! class _uSection(_baseDateSection):
!   def __init__(self):
      _baseDateSection.__init__(self)
      self.minLength = 1
      self.maxLength = 2
  
!   def getFormattedValue(self, date):
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
    def isValidEntry(self, value):
      return 0
  
!   def addSelfToDate(self, value, date):
      pass
  
  
! class _USection(_uSection):
    def getFormattedValue(self, date):
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
  
  class _vSection(_baseDateSection):
!   def __init__(self):
      _baseDateSection.__init__(self)
      self.minLength = 1
      self.maxLength = 2
  
!   def getFormattedValue(self, date):
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
    def isValidEntry(self, value):
      return 0
  
!   def addSelfToDate(self, value, date):
      pass
  
  
! class _VSection(_vSection):
    def getFormattedValue(self, date):
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
  
! class _wSection(_baseDateSection):
    def __init__(self):
      _baseDateSection.__init__(self)
      self.minLength = 1
      self.maxLength = 2
  
!   def getFormattedValue(self, date):
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
***************
*** 522,566 ****
      pass
  
  
! class _xSection(_baseDateSection): 
    def __init__(self):
      _baseDateSection.__init__(self)
      self.minLength = 1
      self.maxLength = 2
  
!   def getFormattedValue(self, date): 
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
    def isValidEntry(self, value):
      return 0
  
!   def addSelfToDate(self, value, date): 
      pass
  
  
  class _XSection(_xSection):
!   def getFormattedValue(self, date): 
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
  
! class _ySection(_baseDateSection):
    def __init__(self):
!     _baseDateSection.__init__(self)
      self.minLength = 2
      self.maxLength = 2
  
    def getFormattedValue(self, date):
      return "%02i" % divmod(date.year, 100)[1]
  
-   def isValidEntry(self, value):
-     try:
-       v = int(value)
-       return (v >= 0) and (v <= 99)
-     except ValueError:
-       return 0
- 
    def addSelfToDate(self, value, date):
      # TODO: Temporary year hack!
      v = int(value)
--- 526,564 ----
      pass
  
  
! class _xSection(_baseDateSection):
    def __init__(self):
      _baseDateSection.__init__(self)
      self.minLength = 1
      self.maxLength = 2
  
!   def getFormattedValue(self, date):
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
    def isValidEntry(self, value):
      return 0
  
!   def addSelfToDate(self, value, date):
      pass
  
  
  class _XSection(_xSection):
!   def getFormattedValue(self, date):
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
  
! class _ySection(_numberRangeSection):
    def __init__(self):
!     _numberRangeSection.__init__(self)
      self.minLength = 2
      self.maxLength = 2
+     self.valueRange = (0,99)
  
    def getFormattedValue(self, date):
      return "%02i" % divmod(date.year, 100)[1]
  
    def addSelfToDate(self, value, date):
      # TODO: Temporary year hack!
      v = int(value)
***************
*** 570,590 ****
        date.year = 2000 + v
  
  
! class _YSection(_ySection):
    def __init__(self):
!     _baseDateSection.__init__(self)
      self.minLength = 2
      self.maxLength = 4
  
    def getFormattedValue(self, date):
      return "%04i" % date.year
- 
-   def isValidEntry(self, value):
-     try:
-       v = int(value)
-       return (v >= 1) and (v <= 9999)
-     except ValueError:
-       return 0
  
    def addSelfToDate(self, value, date):
      date.year = int(value)
--- 568,582 ----
        date.year = 2000 + v
  
  
! class _YSection(_numberRangeSection):
    def __init__(self):
!     _numberRangeSection.__init__(self)
      self.minLength = 2
      self.maxLength = 4
+     self.valueRange = (0,9999)
  
    def getFormattedValue(self, date):
      return "%04i" % date.year
  
    def addSelfToDate(self, value, date):
      date.year = int(value)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]