[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue gnue-common/src/FormatMasks/BaseMask.py gn...
From: |
Jason Cater |
Subject: |
gnue gnue-common/src/FormatMasks/BaseMask.py gn... |
Date: |
Thu, 11 Oct 2001 00:36:08 -0400 |
CVSROOT: /home/cvs
Module name: gnue
Changes by: Jason Cater <address@hidden> 01/10/11 00:36:08
Modified files:
gnue-common/src/FormatMasks: BaseMask.py DateMask.py
gnuef/src : GFForm.py UIbase.py UIcurses.py
gnuef/src/GFObjects: GFEntry.py
Log message:
synching machines (may be broken)
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/FormatMasks/BaseMask.py.diff?cvsroot=OldCVS&tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/FormatMasks/DateMask.py.diff?cvsroot=OldCVS&tr1=1.6&tr2=1.7&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnuef/src/GFForm.py.diff?cvsroot=OldCVS&tr1=1.123&tr2=1.124&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnuef/src/UIbase.py.diff?cvsroot=OldCVS&tr1=1.44&tr2=1.45&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnuef/src/UIcurses.py.diff?cvsroot=OldCVS&tr1=1.10&tr2=1.11&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnuef/src/GFObjects/GFEntry.py.diff?cvsroot=OldCVS&tr1=1.22&tr2=1.23&r1=text&r2=text
Patches:
Index: gnue/gnue-common/src/FormatMasks/BaseMask.py
diff -u gnue/gnue-common/src/FormatMasks/BaseMask.py:1.3
gnue/gnue-common/src/FormatMasks/BaseMask.py:1.4
--- gnue/gnue-common/src/FormatMasks/BaseMask.py:1.3 Wed Oct 10 19:24:50 2001
+++ gnue/gnue-common/src/FormatMasks/BaseMask.py Thu Oct 11 00:36:08 2001
@@ -41,7 +41,7 @@
def isValidEntry(self, value):
return value == self.literal
-class BaseMask:
+class BaseMask:
value = ""
maskMappings = {}
inputHandlers = []
@@ -54,38 +54,39 @@
def __init__(self, outputMask, inputMask=None, outputMask2=None):
self.outputHandlers = self.parseMask(outputMask)
- if inputMask != None:
+ if inputMask != None:
self.inputHandlers = self.parseMask(inputMask)
- if outputMask2 != None:
+ if outputMask2 != None:
self.output2Handlers = self.parseMask(outputMask2)
# Take a mask string and break it into its elements and map it to handlers
- def parseMask(self, mask):
+ def parseMask(self, mask):
+ GDebug.printMesg(15,'parseMask("%s")' % mask)
maskHandler = []
-
- # Load a predefined mask, if that's what user specified
+
+ # Load a predefined mask, if that's what user specified
# TODO: Should predefined masks be pulled from other than gnue.conf?
- if len(mask) > 1 and mask[0] == '&':
+ 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:
+ try:
mask = GConfig.get('%smask_%s' % (self.basetype, self.basetype))
- except KeyError:
+ except KeyError:
raise PredefinedMaskNotFound, \
'The requested format mask %s is not defined' % mask[1:]
# Process each character in mask at a time
isLiteral = 0
- for ch in mask:
- if ch == '\\':
+ for ch in mask:
+ if ch == '\\':
isLiteral = 1
- elif isLiteral or ch in self.predefinedLiterals:
+ elif isLiteral or ch in self.predefinedLiterals:
isLiteral = 0
maskHandler.append(self.literalClass(ch))
- elif self.maskMappings.has_key(ch):
+ elif self.maskMappings.has_key(ch):
maskHandler.append(self.maskMappings[ch]())
else:
raise InvalidCharInMask, 'Unexpected character "%s" in %s mask.' \
@@ -94,30 +95,30 @@
return maskHandler
# If secondary is true, then use secondary mask (outputMask2)
- def getFormattedOutput(self, secondary=0):
+ def getFormattedOutput(self, secondary=0):
pass
- def getFormattedInput(self):
+ def getFormattedInput(self):
pass
- def processEdit (self, str, pos=0, replaces=0):
+ def processEdit (self, str, pos=0, replaces=0):
pass
# This is a base class for mask elements
-class MaskSection:
- def __init__(self):
+class MaskSection:
+ def __init__(self):
self.minLength = 0
self.maxLength = 0
-
+
self.intersperse = 0
self.intersperseString = ","
self.intersperseRepeat = 1
- def getFormattedValue(self):
+ def getFormattedValue(self):
return self.value
- def isValidEntry(self, value):
+ def isValidEntry(self, value):
return 0
Index: gnue/gnue-common/src/FormatMasks/DateMask.py
diff -u gnue/gnue-common/src/FormatMasks/DateMask.py:1.6
gnue/gnue-common/src/FormatMasks/DateMask.py:1.7
--- gnue/gnue-common/src/FormatMasks/DateMask.py:1.6 Wed Oct 10 21:45:55 2001
+++ gnue/gnue-common/src/FormatMasks/DateMask.py Thu Oct 11 00:36:08 2001
@@ -72,12 +72,12 @@
predefinedDateLiterals = "-./: ,"
-class DateLiteral (Literal):
+class DateLiteral (Literal):
def addSelfToDate(self, value, date):
pass
- def isValidEntry(self, value):
- return value == self.literal or value in predefinedDateLiterals
+ 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):
@@ -120,6 +120,7 @@
def processEdit (self, value, str, pos=0, replaces=0):
+ GDebug.printMesg(15,'processEdit(%s,%s,%s,%s)' % (value,str,pos,replaces))
nv = value
if pos == len(nv):
nv += str
@@ -130,75 +131,77 @@
while section < len(self.inputMaskPos) and \
self.inputMaskPos[section] < pos:
section += 1
-
i = pos
while i < len(nv):
if not self.inputHandlers[section]\
.isValidEntry(nv[self.inputMaskPos[section]:i+1]):
if i == self.inputMaskPos[section] and \
- not isinstance(self.inputHandlers[section],Literal):
+ not isinstance(self.inputHandlers[section],Literal):
self.inputMaskLen[section] = i - self.inputMaskPos[section]
return nv
- else:
+ else:
self.inputMaskLen[section] = i - self.inputMaskPos[section]
- if section == len(self.inputHandlers) - 1:
+ if section == len(self.inputHandlers) - 1:
if i != len(nv)-1:
return nv
- else:
+ else:
section += 1
self.inputMaskPos[section] = i
self.inputMaskLen[section] = 0
- else:
+ else:
i += 1
self.inputMaskLen[section] = i - self.inputMaskPos[section]
- for i in range(section+1, len(self.inputHandlers)):
+ for i in range(section+1, len(self.inputHandlers)):
self.inputMaskLen[i] = 0
-
+ GDebug.printMesg(15,"<< %s" % nv)
return nv
- def getFormattedOutput(self, secondary=0):
+ def getFormattedOutput(self, value, secondary=0):
rv = ""
- value = self._buildDate(self.entry, 1)
- if secondary:
+ val = self._buildDate(value, 1)
+ if secondary:
handlers = self.output2Handlers
- else:
+ else:
handlers = self.outputHandlers
- try:
- for m in self.outputHandlers:
- rv += m.getFormattedValue(value)
+ try:
+ for m in self.outputHandlers:
+ rv += m.getFormattedValue(val)
return rv
except InvalidDate, msg:
raise InvalidEntry, msg
- def getFormattedInput(self, value, padding=""):
+ def getFormattedInput(self, value, padding=""):
+ GDebug.printMesg(15,'getFormattedInput(%s,%s)' % (value,padding))
rv = ""
- value = self._buildDate(self.entry, 0)
+ val = self._buildDate(value, 0)
+
+ print val
-# self.lastInputPos =
+# self.lastInputPos =
print self.inputMaskLen
for i in range(len(self.inputHandlers)):
- if self.inputMaskLen[i] or isinstance(self.inputHandlers[i],Literal):
- rv += self.inputHandlers[i].getFormattedValue(value)
- elif len(padding):
+ if self.inputMaskLen[i] or isinstance(self.inputHandlers[i],Literal):
+ rv += self.inputHandlers[i].getFormattedValue(val)
+ elif len(padding):
rv += padding * self.inputHandlers[i].maxLength
return rv
- def _buildDate(self, value, mustValidate=0):
+ 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.inputMaskLen[i] or isinstance(self.inputHandlers[i],Literal):
self.inputHandlers[i].addSelfToDate(
value[ self.inputMaskPos[i]: \
self.inputMaskPos[i] + self.inputMaskLen[i]], date )
@@ -220,29 +223,29 @@
pass
-class _aSection(_baseDateSection):
- def __init__(self):
+class _aSection(_baseDateSection):
+ def __init__(self):
_baseDateSection.__init__(self)
self.minLength = 1
self.maxLength = 2
- def getFormattedValue(self, date):
+ def getFormattedValue(self, date):
return weekdayAbbrevNames[date.getDayOfWeek()]
def isValidEntry(self, value):
return 0
- def addSelfToDate(self, value, date):
+ def addSelfToDate(self, value, date):
pass
-class _ASection(_aSection):
- def getFormattedValue(self, date):
+class _ASection(_aSection):
+ def getFormattedValue(self, date):
return weekdayNames[date.getDayOfWeek()]
-class _bSection(_baseDateSection):
- def __init__(self):
+class _bSection(_baseDateSection):
+ def __init__(self):
_baseDateSection.__init__(self)
self.minLength = 1
self.maxLength = 2
@@ -258,7 +261,7 @@
class _BSection(_bSection):
- def getFormattedValue(self, date):
+ def getFormattedValue(self, date):
return monthNames[(date.month or 1) - 1]
@@ -268,7 +271,7 @@
self.minLength = 1
self.maxLength = 2
- def getFormattedValue(self, date):
+ def getFormattedValue(self, date):
# TODO: Implement this mask element
return "*" * self.maxLength
@@ -310,7 +313,7 @@
self.minLength = 1
self.maxLength = 2
- def getFormattedValue(self, date):
+ def getFormattedValue(self, date):
return "%02i" % date.hour
def isValidEntry(self, value):
@@ -320,7 +323,7 @@
date.hour = int(value or 0)
-class _HSection(_hSection):
+class _HSection(_hSection):
def getFormattedValue(self, date):
return "%i" % date.hour
@@ -372,7 +375,7 @@
class _mSection(_baseDateSection):
- def __init__(self):
+ def __init__(self):
_baseDateSection.__init__(self)
self.minLength = 1
self.maxLength = 2
@@ -381,13 +384,13 @@
return "%02i" % date.month
def isValidEntry(self, value):
- try:
+ try:
v = int(value)
return (v >= 0 and v <= 12) or (v == 0 and len(value) == 1)
- except ValueError:
+ except ValueError:
return 0
- def addSelfToDate(self, value, date):
+ def addSelfToDate(self, value, date):
date.month = int(value or 1)
@@ -406,7 +409,7 @@
return "%02i" % date.minute
def isValidEntry(self, value):
- try:
+ try:
v = int(value)
return (v >= 0 and v <= 59) or (v == 0 and len(value) == 1)
except ValueError:
@@ -450,7 +453,7 @@
self.minLength = 1
self.maxLength = 2
- def getFormattedValue(self, date):
+ def getFormattedValue(self, date):
return "%02i" % date.second
def isValidEntry(self, value):
@@ -510,7 +513,7 @@
class _VSection(_vSection):
- def getFormattedValue(self, date):
+ def getFormattedValue(self, date):
# TODO: Implement this mask element
return "*" * self.maxLength
@@ -528,7 +531,7 @@
def isValidEntry(self, value):
return 0
- def addSelfToDate(self, value, date):
+ def addSelfToDate(self, value, date):
pass
@@ -549,7 +552,7 @@
pass
-class _XSection(_xSection):
+class _XSection(_xSection):
def getFormattedValue(self, date):
# TODO: Implement this mask element
return "*" * self.maxLength
@@ -561,51 +564,53 @@
self.minLength = 2
self.maxLength = 2
- def getFormattedValue(self, date):
+ def getFormattedValue(self, date):
return "%02i" % divmod(date.year, 100)[1]
def isValidEntry(self, value):
- try:
+ try:
v = int(value)
return (v >= 0) and (v <= 99)
- except ValueError:
+ except ValueError:
return 0
- def addSelfToDate(self, value, date):
+ def addSelfToDate(self, value, date):
# TODO: Temporary year hack!
v = int(value)
- if v >= 50:
+ if v >= 50:
date.year = 1900 + v
- else:
+ else:
date.year = 2000 + v
-class _YSection(_ySection):
- def __init__(self):
+class _YSection(_ySection):
+ def __init__(self):
_baseDateSection.__init__(self)
self.minLength = 2
self.maxLength = 4
- def getFormattedValue(self, date):
- return "%04i" % date.year
+ def getFormattedValue(self, date):
+ return "%04i" % date.year
def isValidEntry(self, value):
- try:
+ try:
v = int(value)
return (v >= 1) and (v <= 9999)
- except ValueError:
+ except ValueError:
return 0
- def addSelfToDate(self, value, date):
+ def addSelfToDate(self, value, date):
date.year = int(value)
-if __name__ == '__main__':
+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')
- print "processEdit1 <= %s" % dates.processEdit('071601')
- print dates.getFormattedInput("_")
- print dates.getFormattedOutput()
-# print "processEdit2 <= %s" %dates.processEdit('27',2,4)
- print dates.getFormattedInput("_")
- print dates.getFormattedOutput()
+ val = dates.processEdit(val, '07/1601')
+ print dates.getFormattedInput(val, "_")
+ print dates.getFormattedOutput(val)
+# print "processEdit2 <= %s" %dates.processEdit(val, '27',2,4)
+ print dates.getFormattedInput(val, "_")
+ print dates.getFormattedOutput(val)
Index: gnue/gnuef/src/GFForm.py
diff -u gnue/gnuef/src/GFForm.py:1.123 gnue/gnuef/src/GFForm.py:1.124
--- gnue/gnuef/src/GFForm.py:1.123 Wed Oct 10 19:24:50 2001
+++ gnue/gnuef/src/GFForm.py Thu Oct 11 00:36:08 2001
@@ -8,10 +8,10 @@
#
# 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
+# 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
+# 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.
@@ -97,7 +97,7 @@
i = i + 1
else:
i = i + 1
-
+
return GFObj._buildObject(self)
#
@@ -417,15 +417,15 @@
#
def moveCursor(self, position):
if position == 'end':
- self._currentEntry._cursorPosition = len(self._currentEntry.getValue())
+ self._currentEntry._cursorPosition = len(self._currentEntry.getDisplay())
elif position == 'home':
self._currentEntry._cursorPosition = 0
elif position == 'left' and self._currentEntry._cursorPosition > 0:
self._currentEntry._cursorPosition =
self._currentEntry._cursorPosition - 1
elif position == 'right':
- if self._currentEntry._cursorPosition <
len(self._currentEntry.getValue()):
+ if self._currentEntry._cursorPosition <
len(self._currentEntry.getDisplay()):
self._currentEntry._cursorPosition= self._currentEntry._cursorPosition
+ 1
-
+
def replaceValue(self,object, value):
replacement = ""
validValues = object.allowedValues()
Index: gnue/gnuef/src/GFObjects/GFEntry.py
diff -u gnue/gnuef/src/GFObjects/GFEntry.py:1.22
gnue/gnuef/src/GFObjects/GFEntry.py:1.23
--- gnue/gnuef/src/GFObjects/GFEntry.py:1.22 Wed Oct 10 19:24:51 2001
+++ gnue/gnuef/src/GFObjects/GFEntry.py Thu Oct 11 00:36:08 2001
@@ -90,7 +90,7 @@
del self.lowercase
self.case = 'lower'
- return GFValue._buildObject(self)
+ return GFValue._buildObject(self)
def initialize(self):
if self.typecast == 'number':
@@ -185,22 +185,22 @@
#
def getDisplay(self, hasFocus=0, value=None):
- if value == None:
+ if value == None:
v = self.getValue()
- else:
+ else:
v = value
- if v == None:
- v = ""
+ if v == None:
+ v = ""
- # TODO: How would format masks work w/styles other than default
+ # TODO: How would format masks work w/styles other than default
- if not self._maskHandler or self.style != 'default':
+ if not self._maskHandler or self.style != 'default' or v == "":
return str(v)
- else:
+ else:
if hasFocus:
return self._maskHandler.getFormattedInput(v)
- else:
+ else:
return self._maskHandler.getFormattedOutput(v, secondary=1)
@@ -219,10 +219,10 @@
# switchRecord
#
def switchRecord(self):
- value = self._block._resultSet.current.getField(self.field)
- if value == None:
+ value = self._block._resultSet.current.getField(self.field)
+ if value == None:
value = ''
- else:
+ else:
value = "%s" % value
self._cursorPosition = len(value)
Index: gnue/gnuef/src/UIbase.py
diff -u gnue/gnuef/src/UIbase.py:1.44 gnue/gnuef/src/UIbase.py:1.45
--- gnue/gnuef/src/UIbase.py:1.44 Sun Sep 16 17:16:24 2001
+++ gnue/gnuef/src/UIbase.py Thu Oct 11 00:36:08 2001
@@ -303,7 +303,7 @@
if style == 'dropdown':
value = event.data.allowedValues()["%s" % event.data.getValue()]
else:
- value = event.data.getValue()
+ value = event.data.getDisplay()
value = str(value) # Done to remove unicode types which wxpython doesn't
like
if style == 'checkbox':
Index: gnue/gnuef/src/UIcurses.py
diff -u gnue/gnuef/src/UIcurses.py:1.10 gnue/gnuef/src/UIcurses.py:1.11
--- gnue/gnuef/src/UIcurses.py:1.10 Tue Jul 31 19:22:30 2001
+++ gnue/gnuef/src/UIcurses.py Thu Oct 11 00:36:08 2001
@@ -7,7 +7,7 @@
# 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
+# 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.
#
@@ -335,7 +335,7 @@
if style == 'dropdown':
value = event.data.allowedValues()[event.data.getValue()]
else:
- value = event.data.getValue()
+ value = event.data.getDisplay()
ncfield = self._formToUI[event.data][0][index]
ncfield.setText(value)