Added Sequencer and associated XML tags
authorandy_robinson
Mon, 12 Jun 2000 11:27:17 +0000
changeset 266 081154da1a78
parent 265 c03fcea1910d
child 267 52a348f6c4c3
Added Sequencer and associated XML tags
reportlab/lib/sequencer.py
reportlab/platypus/paraparser.py
--- a/reportlab/lib/sequencer.py	Mon Jun 12 11:26:34 2000 +0000
+++ b/reportlab/lib/sequencer.py	Mon Jun 12 11:27:17 2000 +0000
@@ -31,16 +31,19 @@
 #
 ###############################################################################
 #	$Log: sequencer.py,v $
+#	Revision 1.4  2000/06/12 11:27:17  andy_robinson
+#	Added Sequencer and associated XML tags
+#
 #	Revision 1.3  2000/06/11 21:34:01  andy_robinson
 #	Largely complete class for numbering lists, figures and chapters
-#
+#	
 #	Revision 1.2  2000/06/09 16:18:19  andy_robinson
 #	Doc strings, sequencer
 #	
 #	Revision 1.1  2000/06/01 15:23:06  rgbecker
 #	Platypus re-organisation
 #	
-__version__=''' $Id: sequencer.py,v 1.3 2000/06/11 21:34:01 andy_robinson Exp $ '''
+__version__=''' $Id: sequencer.py,v 1.4 2000/06/12 11:27:17 andy_robinson Exp $ '''
 """This module defines a single public class, Sequencer, which aids in
 numbering and formatting lists."""
 
@@ -66,7 +69,7 @@
 	def __init__(self):
 		self._base = 1
 		self._value = self._base
-		self._formatter = format_123
+		self._formatter = _format_123
 		self._resets = []
 
 	def setFormatter(self, formatFunc):
@@ -191,7 +194,7 @@
 	def reset(self, counter=None, base=1):
 		if not counter:
 			counter = self._defaultCounter
-		self._getCounter(counter).value = base
+		self._getCounter(counter)._value = base
 
 	def chain(self, parent, child):
 		p = self._getCounter(parent)
@@ -211,7 +214,15 @@
 	def format(self, template):
 		"""The crowning jewels - formats multi-level lists."""
 		return template % self
-	
+
+	def dump(self):
+		"""Write current state to stdout for diagnostics"""
+		counters = self._counters.items()
+		counters.sort()
+		print 'Sequencer dump:'
+		for (key, counter) in counters:
+			print '    %s: value = %d, base = %d, format example = %s' % (
+				key, counter.this(), counter._base, counter.thisf())
 def test():
 	s = Sequencer()
 	print 'Counting using default sequence: %d %d %d' % (s.next(),s.next(), s.next())
--- a/reportlab/platypus/paraparser.py	Mon Jun 12 11:26:34 2000 +0000
+++ b/reportlab/platypus/paraparser.py	Mon Jun 12 11:27:17 2000 +0000
@@ -31,9 +31,12 @@
 #
 ###############################################################################
 #	$Log: paraparser.py,v $
+#	Revision 1.22  2000/06/12 11:27:17  andy_robinson
+#	Added Sequencer and associated XML tags
+#
 #	Revision 1.21  2000/06/01 15:23:06  rgbecker
 #	Platypus re-organisation
-#
+#	
 #	Revision 1.20  2000/05/31 10:12:20  rgbecker
 #	<bullet> xml tag added
 #	
@@ -58,7 +61,7 @@
 #	Revision 1.13  2000/04/25 13:07:57  rgbecker
 #	Added license
 #	
-__version__=''' $Id: paraparser.py,v 1.21 2000/06/01 15:23:06 rgbecker Exp $ '''
+__version__=''' $Id: paraparser.py,v 1.22 2000/06/12 11:27:17 andy_robinson Exp $ '''
 import string
 import re
 from types import TupleType
@@ -80,7 +83,7 @@
 from reportlab.lib.colors import toColor, white, black, red, Color
 from reportlab.lib.fonts import tt2ps, ps2tt
 from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
-
+from reportlab.lib.sequencer import Sequencer
 _re_para = re.compile('^\\s*<\\s*para(\\s+|>)')
 
 sizeDelta = 2		# amount to reduce font size by for super and sub script
@@ -141,6 +144,7 @@
 				'fg': 	('textColor', toColor),
 				'color':('textColor', toColor)}
 
+
 def _addAttributeNames(m):
 	K = m.keys()
 	for k in K:
@@ -227,7 +231,7 @@
 #	   < super > < /super > - superscript
 #	   < sub > < /sub > - subscript
 #	   <font name=fontfamily/fontname color=colorname size=float>
-#
+#      < bullet > </bullet> - bullet text (at head of para only)
 #		The whole may be surrounded by <para> </para> tags
 #
 # It will also be able to handle any MathML specified Greek characters.
@@ -363,6 +367,59 @@
 	def end_bullet(self):
 		self._pop()
 
+
+
+	#---------------------------------------------------------------
+	def setSequencer(self, seq):
+		self._seq = seq
+
+	def getSequencer(self):
+		if self._seq is None:
+			self._seq = Sequencer()
+		return self._seq
+		
+	def start_seqdefault(self, attr):
+		try:
+			default = attr['id']
+		except KeyError:
+			default = None
+		self.getSequencer().setDefaultCounter(default)
+
+	def end_seqdefault(self):
+		pass
+	
+	def start_seqreset(self, attr):
+		try:
+			id = attr['id']
+		except KeyError:
+			id = None
+		try:
+			base = math.atoi(attr['base'])
+		except:
+			base=1
+		self.getSequencer().reset(id, base)
+
+	def end_seqreset(self):
+		pass
+	
+	def start_seq(self, attr):
+		#if it has a template, use that; otherwise try for id;
+		#otherwise take default sequence
+		if attr.has_key('template'):
+			templ = attr['template']
+			self.handle_data(templ % self.getSequencer())
+			return
+		elif attr.has_key('id'):
+			id = attr['id']
+		else: 
+			id = None
+		output = self.getSequencer().nextf(id)
+		self.handle_data(output)
+		
+	def end_seq(self):
+		pass
+
+	#---------------------------------------------------------------
 	def _push(self,**attr):
 		frag = copy.copy(self._stack[-1])
 		_applyAttributes(frag,attr)
@@ -393,6 +450,12 @@
 	#----------------------------------------------------------------
 
 	def __init__(self,verbose=0):
+		# the sequencing stuff presumes access to a sequencer.
+		# this may be set with setSequencer(); if a <seq> tag
+		# is encountered and it has not been set, a default
+		# sequencer will be provided.  
+		self._seq = None
+		
 		if _xmllib_newStyle:
 			xmllib.XMLParser.__init__(self,verbose=verbose)
 		else:
@@ -419,6 +482,8 @@
 			for item in greeks.keys():
 				self.entitydefs[item] = '<%s/>' % item
 
+		
+
 	def _iReset(self):
 		self.fragList = []
 		if hasattr(self, 'bFragList'): delattr(self,'bFragList')