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 00:49:16 -0500

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    02/01/03 00:49:16

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.8&tr2=1.9&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/src/FormatMasks/DateMask.py.diff?cvsroot=OldCVS&tr1=1.12&tr2=1.13&r1=text&r2=text

Patches:
Index: gnue/common/src/FormatMasks/BaseMask.py
diff -c gnue/common/src/FormatMasks/BaseMask.py:1.8 
gnue/common/src/FormatMasks/BaseMask.py:1.9
*** gnue/common/src/FormatMasks/BaseMask.py:1.8 Wed Jan  2 18:23:05 2002
--- gnue/common/src/FormatMasks/BaseMask.py     Thu Jan  3 00:49:16 2002
***************
*** 70,78 ****
--- 70,80 ----
      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
***************
*** 120,149 ****
    def setText(self, text):
      self.input = text
      self.display = text
!     self.cursor = 0
!     self.index = 0
  
    def isValid(self):
      return 1
  
!   def addText(self, text, pos, replaces):
      pass
  
    def deleteText(self, text, pos, characters):
      pass
  
!   def cursorToIndex(self, val):
      return val
  
  
!   def indexToCursor(self, val):
      return val
  
  
    def moveCursor(self, relative):
  
!     # Direction will be either 1 or -1.
!     direction = relative = 0 or int(relative/abs(relative))
  
      self.cursor = self.cursor + relative
  
--- 122,152 ----
    def setText(self, text):
      self.input = text
      self.display = text
!     self.reset()
  
    def isValid(self):
      return 1
  
!   def addText(self, text, pos, replaces=0):
      pass
  
    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
  
***************
*** 154,163 ****
        self.cursor = len(self.display)
        self.direction = -1
  
      section = 0
      while section < len(self.inputMaskPos) and \
!           self.inputMaskPos[section] < pos:
        section += 1
  
      if section == len(self.inputMaskPos):
        self.cursor = len(self.display)
--- 157,169 ----
        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)
Index: gnue/common/src/FormatMasks/DateMask.py
diff -c gnue/common/src/FormatMasks/DateMask.py:1.12 
gnue/common/src/FormatMasks/DateMask.py:1.13
*** gnue/common/src/FormatMasks/DateMask.py:1.12        Wed Jan  2 18:23:05 2002
--- gnue/common/src/FormatMasks/DateMask.py     Thu Jan  3 00:49:16 2002
***************
*** 1,19 ****
  #
  # 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.
  #
  # Copyright 2001 Free Software Foundation
--- 1,19 ----
  #
  # 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.
  #
  # Copyright 2001 Free Software Foundation
***************
*** 50,55 ****
--- 50,56 ----
  #  m/y                        01/2001
  #  h:i p              12:29 pm
  #
+ #####################################################################
  
  from BaseMask import BaseMask, MaskSection, Literal
  from gnue.common import GDebug
***************
*** 79,84 ****
--- 80,86 ----
    def isValidEntry(self, value):
      return value == self.literal or len(value) == 1 and value in 
predefinedDateLiterals
  
+ 
  class DateMask (BaseMask):
    def __init__(self, outputMask, inputMask=None, outputMask2=None):
  
***************
*** 119,137 ****
  
  
    def getFormattedInput(self, value, padding=""):
      GDebug.printMesg(15,'getFormattedInput(%s,%s)' % (value,padding))
      rv = ""
      val = self._buildDate(value, 0)
  
      self.lastInputPos = 0
  
-     print
-     print value
-     print self.inputMaskLen
-     print self.inputMaskPos
-     print val
- 
- 
      lastElement = len(self.inputHandlers) - 1
  
      for i in range(lastElement+1):
--- 121,135 ----
  
  
    def getFormattedInput(self, value, padding=""):
+ 
      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):
***************
*** 143,150 ****
  
        # If this is a "literal" print it as is
        if isinstance(self.inputHandlers[i],Literal):
!         rv += self.inputHandlers[i].getFormattedValue(val)
!         print "#3 %s" % rv
        else:
  
          # If this is the very last (partial) section, add it unformatted
--- 141,148 ----
  
        # If this is a "literal" print it as is
        if isinstance(self.inputHandlers[i],Literal):
!         piece = self.inputHandlers[i].getFormattedValue(val)
! 
        else:
  
          # If this is the very last (partial) section, add it unformatted
***************
*** 153,178 ****
                ( ( i < lastElement) and self.inputMaskLen[i+1] ) ) :
  
  
!           out = value[self.inputMaskPos[i]: \
!                       self.inputMaskPos[i]+self.inputMaskLen[i]]
! 
!           rv += out
  
            # Pad any extra space in this section
            if len(padding):
!             rv += padding * (self.inputHandlers[i].maxLength - len(out))
! 
!           print "#1 %s" % rv
  
          # .. or if we have data to output, format it appropriately
          elif self.inputMaskLen[i]:
!           rv += self.inputHandlers[i].getFormattedValue(val)
!           print "#2a %s" % rv
  
          # .. or if we have no data but are padding, pad appropriately
          elif len(padding):
!           rv += padding * self.inputHandlers[i].maxLength
!           print "#2b %s" % rv
  
      return rv
  
--- 151,176 ----
                ( ( i < lastElement) and self.inputMaskLen[i+1] ) ) :
  
  
!           piece = value[self.inputMaskPos[i]: \
!                         self.inputMaskPos[i]+self.inputMaskLen[i]]
  
            # 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]:
!           piece = self.inputHandlers[i].getFormattedValue(val)
  
          # .. 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
  
***************
*** 199,204 ****
--- 197,203 ----
  #
  # Mask elements
  #
+ #####################################################################
  
  class _baseDateSection (MaskSection):
    def __init__(self):
***************
*** 238,244 ****
      self.minLength = 1
      self.maxLength = 2
  
!   def getFormattedValue(self, date): 
      return monthAbbrevNames[(date.month or 1) - 1]
  
    def isValidEntry(self, value):
--- 237,243 ----
      self.minLength = 1
      self.maxLength = 2
  
!   def getFormattedValue(self, date):
      return monthAbbrevNames[(date.month or 1) - 1]
  
    def isValidEntry(self, value):
***************
*** 334,340 ****
  
  
  class _GSection(_gSection): 
!   def getFormattedValue(self, date): 
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
--- 333,339 ----
  
  
  class _GSection(_gSection): 
!   def getFormattedValue(self, date):
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
***************
*** 382,388 ****
      date.month = int(value or 1)
  
  
! class _MSection(_baseDateSection): 
    def getFormattedValue(self, date): 
      return "%i" % date.month
  
--- 381,387 ----
      date.month = int(value or 1)
  
  
! class _MSection(_baseDateSection):
    def getFormattedValue(self, date): 
      return "%i" % date.month
  
***************
*** 430,436 ****
  
  
  class _PSection(_pSection): 
!   def getFormattedValue(self, date): 
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
--- 429,435 ----
  
  
  class _PSection(_pSection): 
!   def getFormattedValue(self, date):
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
***************
*** 478,484 ****
  
  
  class _USection(_uSection): 
!   def getFormattedValue(self, date): 
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
--- 477,483 ----
  
  
  class _USection(_uSection): 
!   def getFormattedValue(self, date):
      # TODO: Implement this mask element
      return "*" * self.maxLength
  
***************
*** 596,601 ****
--- 595,602 ----
  #
  # Mask mappings
  #
+ #####################################################################
+ 
  
  # Map the mask characters to their corresponding classes...
  # Since these can be reused, we will create one instance at
***************
*** 628,640 ****
  #
  # Debugging stuff
  #
  
  if __name__ == '__main__':
    GDebug.setDebug(20)
    val = ""
    dates = DateMask(r'\D\a\t\e: A, B d, Y  \T\i\m\e: h:i:s','m.d.y')
! #  input = dates.createInputHandler('07/16/01')
! #  val = dates.processEdit(val, '07/1601')
  #  print dates.getFormattedInput(val, "_")
  
    val = dates.processEdit(val, '1',0,0)
--- 629,643 ----
  #
  # Debugging stuff
  #
+ #####################################################################
  
  if __name__ == '__main__':
    GDebug.setDebug(20)
    val = ""
    dates = DateMask(r'\D\a\t\e: A, B d, Y  \T\i\m\e: h:i:s','m.d.y')
! 
! #  val = dates.processEdit(val, '07/161',0,0)
! #  print "processEdit <= %s" % val
  #  print dates.getFormattedInput(val, "_")
  
    val = dates.processEdit(val, '1',0,0)
***************
*** 646,651 ****
--- 649,658 ----
    print dates.getFormattedInput(val, "_")
  
    val = dates.processEdit(val, '091',1,1)
+   print "processEdit <= %s" % val
+   print dates.getFormattedInput(val, "_")
+ 
+   val = dates.processEdit(val, '',1,1)
    print "processEdit <= %s" % val
    print dates.getFormattedInput(val, "_")
  



reply via email to

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