CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Classes | Public Member Functions | Public Attributes | Private Member Functions
svgfig.SVG Class Reference

Classes

class  SVGDepthIterator
 nested class More...
 

Public Member Functions

def __contains__
 
def __delitem__
 
def __eq__
 
def __getitem__
 
def __init__
 
def __iter__
 
def __ne__
 
def __repr__
 
def __setitem__
 
def __str__
 
def append
 
def breadth_first
 
def clone
 
def depth_first
 end nested class More...
 
def extend
 
def firefox
 
def inkscape
 
def inkview
 
def interpret_fileName
 
def items
 
def keys
 
def prepend
 
def save
 
def standalone_xml
 
def tree
 
def values
 
def xml
 

Public Attributes

 attr
 
 sub
 
 t
 

Private Member Functions

def __standalone_xml
 

Detailed Description

A tree representation of an SVG image or image fragment.

SVG(t, sub, sub, sub..., attribute=value)

t                       required             SVG type name
sub                     optional list        nested SVG elements or text/Unicode
attribute=value pairs   optional keywords    SVG attributes

In attribute names, "__" becomes ":" and "_" becomes "-".

SVG in XML

<g id="mygroup" fill="blue">
    <rect x="1" y="1" width="2" height="2" />
    <rect x="3" y="3" width="2" height="2" />
</g>

SVG in Python

>>> svg = SVG("g", SVG("rect", x=1, y=1, width=2, height=2), \ 
...                SVG("rect", x=3, y=3, width=2, height=2), \ 
...           id="mygroup", fill="blue")

Sub-elements and attributes may be accessed through tree-indexing:

>>> svg = SVG("text", SVG("tspan", "hello there"), stroke="none", fill="black")
>>> svg[0]
<tspan (1 sub) />
>>> svg[0, 0]
'hello there'
>>> svg["fill"]
'black'

Iteration is depth-first:

>>> svg = SVG("g", SVG("g", SVG("line", x1=0, y1=0, x2=1, y2=1)), \
...                SVG("text", SVG("tspan", "hello again")))
... 
>>> for ti, s in svg:
...     print ti, repr(s)
... 
(0,) <g (1 sub) />
(0, 0) <line x2=1 y1=0 x1=0 y2=1 />
(0, 0, 'x2') 1
(0, 0, 'y1') 0
(0, 0, 'x1') 0
(0, 0, 'y2') 1
(1,) <text (1 sub) />
(1, 0) <tspan (1 sub) />
(1, 0, 0) 'hello again'

Use "print" to navigate:

>>> print svg
None                 <g (2 sub) />
[0]                      <g (1 sub) />
[0, 0]                       <line x2=1 y1=0 x1=0 y2=1 />
[1]                      <text (1 sub) />
[1, 0]                       <tspan (1 sub) />

Definition at line 63 of file svgfig.py.

Constructor & Destructor Documentation

def svgfig.SVG.__init__ (   self,
  t_sub,
  attr 
)

Definition at line 124 of file svgfig.py.

125  def __init__(self, *t_sub, **attr):
126  if len(t_sub) == 0: raise TypeError("SVG element must have a t (SVG type)")
127 
128  # first argument is t (SVG type)
129  self.t = t_sub[0]
130  # the rest are sub-elements
131  self.sub = list(t_sub[1:])
132 
133  # keyword arguments are attributes
134  # need to preprocess to handle differences between SVG and Python syntax
135  self.attr = attr_preprocess(attr)
def __init__
Definition: svgfig.py:124
def attr_preprocess
Definition: svgfig.py:47

Member Function Documentation

def svgfig.SVG.__contains__ (   self,
  value 
)
x in svg == True iff x is an attribute in svg.

Definition at line 169 of file svgfig.py.

References svgfig.SVG.attr.

170  def __contains__(self, value):
171  """x in svg == True iff x is an attribute in svg."""
172  return value in self.attr
def __contains__
Definition: svgfig.py:169
def svgfig.SVG.__delitem__ (   self,
  ti 
)
Index is a list that descends tree, returning a sub-element if
it ends with a number and an attribute if it ends with a string.

Definition at line 158 of file svgfig.py.

159  def __delitem__(self, ti):
160  """Index is a list that descends tree, returning a sub-element if
161  it ends with a number and an attribute if it ends with a string."""
162  obj = self
163  if isinstance(ti, (list, tuple)):
164  for i in ti[:-1]: obj = obj[i]
165  ti = ti[-1]
166 
167  if isinstance(ti, (int, long, slice)): del obj.sub[ti]
168  else: del obj.attr[ti]
def __delitem__
Definition: svgfig.py:158
def svgfig.SVG.__eq__ (   self,
  other 
)
x == y iff x represents the same SVG as y.

Definition at line 173 of file svgfig.py.

References svgfig.SVG.attr, gpuClustering.id, svgfig.SVG.sub, svgfig.SVG.t, and AlignmentMonitorMuonSystemMap1D::MyCSCDetId.t.

Referenced by SequenceTypes._UnarySequenceOperator.__ne__().

174  def __eq__(self, other):
175  """x == y iff x represents the same SVG as y."""
176  if id(self) == id(other): return True
177  return isinstance(other, SVG) and self.t == other.t and self.sub == other.sub and self.attr == other.attr
def __eq__
Definition: svgfig.py:173
uint16_t *__restrict__ id
def svgfig.SVG.__getitem__ (   self,
  ti 
)
Index is a list that descends tree, returning a sub-element if
it ends with a number and an attribute if it ends with a string.

Definition at line 136 of file svgfig.py.

137  def __getitem__(self, ti):
138  """Index is a list that descends tree, returning a sub-element if
139  it ends with a number and an attribute if it ends with a string."""
140  obj = self
141  if isinstance(ti, (list, tuple)):
142  for i in ti[:-1]: obj = obj[i]
143  ti = ti[-1]
144 
145  if isinstance(ti, (int, long, slice)): return obj.sub[ti]
146  else: return obj.attr[ti]
def __getitem__
Definition: svgfig.py:136
def svgfig.SVG.__iter__ (   self)

Definition at line 247 of file svgfig.py.

References svgfig.SVG.depth_first().

248  def __iter__(self): return self.depth_first()
def depth_first
end nested class
Definition: svgfig.py:235
def __iter__
Definition: svgfig.py:247
def svgfig.SVG.__ne__ (   self,
  other 
)
x != y iff x does not represent the same SVG as y.

Definition at line 178 of file svgfig.py.

179  def __ne__(self, other):
180  """x != y iff x does not represent the same SVG as y."""
181  return not (self == other)
def __ne__
Definition: svgfig.py:178
def svgfig.SVG.__repr__ (   self)

Definition at line 285 of file svgfig.py.

References svgfig.SVG.xml().

Referenced by data_sources.json_file.__str__().

286  def __repr__(self): return self.xml(depth_limit=0)
def __repr__
Definition: svgfig.py:285
def xml
Definition: svgfig.py:320
def svgfig.SVG.__setitem__ (   self,
  ti,
  value 
)
Index is a list that descends tree, returning a sub-element if
it ends with a number and an attribute if it ends with a string.

Definition at line 147 of file svgfig.py.

148  def __setitem__(self, ti, value):
149  """Index is a list that descends tree, returning a sub-element if
150  it ends with a number and an attribute if it ends with a string."""
151  obj = self
152  if isinstance(ti, (list, tuple)):
153  for i in ti[:-1]: obj = obj[i]
154  ti = ti[-1]
155 
156  if isinstance(ti, (int, long, slice)): obj.sub[ti] = value
157  else: obj.attr[ti] = value
def __setitem__
Definition: svgfig.py:147
def svgfig.SVG.__standalone_xml (   self,
  indent,
  newl 
)
private

Definition at line 373 of file svgfig.py.

References join(), svgfig.SVG.sub, svgfig.SVG.t, AlignmentMonitorMuonSystemMap1D::MyCSCDetId.t, and betterConfigParser.unicode.

374  def __standalone_xml(self, indent, newl):
375  output = [u"<%s" % self.t]
376 
377  for n, v in self.attr.items():
378  if isinstance(v, dict):
379  v = "; ".join(["%s:%s" % (ni, vi) for ni, vi in v.items()])
380  elif isinstance(v, (list, tuple)):
381  v = ", ".join(v)
382  output.append(u" %s=\"%s\"" % (n, v))
383 
384  if len(self.sub) == 0:
385  output.append(u" />%s%s" % (newl, newl))
386  return output
387 
388  elif self.t == "text" or self.t == "tspan" or self.t == "style":
389  output.append(u">")
390 
391  else:
392  output.append(u">%s%s" % (newl, newl))
393 
394  for s in self.sub:
395  if isinstance(s, SVG): output.extend(s.__standalone_xml(indent, newl))
396  else: output.append(unicode(s))
397 
398  if self.t == "tspan": output.append(u"</%s>" % self.t)
399  else: output.append(u"</%s>%s%s" % (self.t, newl, newl))
400 
401  return output
def __standalone_xml
Definition: svgfig.py:373
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
def svgfig.SVG.__str__ (   self)
Print (actually, return a string of) the tree in a form useful for browsing.

Definition at line 287 of file svgfig.py.

References tree.Tree.tree, HIPMonitorVariables.tree, SimpleTreeProducer.SimpleTreeProducer.tree, eventstfile.Events.tree, CSCTFAnalyzer.tree, CSCTFanalyzer.tree, core.TreeAnalyzerNumpy.TreeAnalyzerNumpy.tree, TreeWriterForEcalCorrection.tree, AlignmentIORootBase.tree, TkOfflineVariables.tree, HIPTwoBodyDecayAnalyzer.tree, EcalPerEvtMatacqAnalyzer.tree, HcalIsoTrackAnalyzer.tree, CheckSecondary.tree, KVFTest.tree, EcalMatacqAnalyzer.tree, BPHHistoSpecificDecay.tree, PhysicsTools::TreeReader.tree, KinematicVertex.tree, IsoTrackCalibration.tree, IsoTrackCalib.tree, KinematicParticle.tree, TkAlMap.TkAlMap.tree, HcalIsoTrkSimAnalyzer.tree, HcalIsoTrkAnalyzer.tree, and svgfig.SVG.tree().

Referenced by edmStreamStallGrapher.Point.__repr__(), BeautifulSoup.Tag.__repr__(), BeautifulSoup.Tag.__unicode__(), and BeautifulSoup.Tag.prettify().

288  def __str__(self):
289  """Print (actually, return a string of) the tree in a form useful for browsing."""
290  return self.tree(sub=True, attr=False, text=False)
def __str__
Definition: svgfig.py:287
def tree
Definition: svgfig.py:291
def svgfig.SVG.append (   self,
  x 
)
Appends x to the list of sub-elements (drawn last, overlaps
other primatives).

Definition at line 182 of file svgfig.py.

Referenced by diclist.diclist.add(), and BeautifulSoup.Tag.setString().

183  def append(self, x):
184  """Appends x to the list of sub-elements (drawn last, overlaps
185  other primatives)."""
186  self.sub.append(x)
def append
Definition: svgfig.py:182
def svgfig.SVG.breadth_first (   self,
  depth_limit = None 
)
Not implemented yet.  Any ideas on how to do it?

Returns a breadth-first generator over the SVG.  If depth_limit
is a number, stop recursion at that depth.

Definition at line 240 of file svgfig.py.

241  def breadth_first(self, depth_limit=None):
242  """Not implemented yet. Any ideas on how to do it?
243 
244  Returns a breadth-first generator over the SVG. If depth_limit
245  is a number, stop recursion at that depth."""
246  raise NotImplementedError("Got an algorithm for breadth-first searching a tree without effectively copying the tree?")
def breadth_first
Definition: svgfig.py:240
def svgfig.SVG.clone (   self,
  shallow = False 
)
Deep copy of SVG tree.  Set shallow=True for a shallow copy.

Definition at line 196 of file svgfig.py.

197  def clone(self, shallow=False):
198  """Deep copy of SVG tree. Set shallow=True for a shallow copy."""
199  if shallow:
200  return copy.copy(self)
201  else:
202  return copy.deepcopy(self)
def clone
Definition: svgfig.py:196
def svgfig.SVG.depth_first (   self,
  depth_limit = None 
)

end nested class

Returns a depth-first generator over the SVG.  If depth_limit
is a number, stop recursion at that depth.

Definition at line 235 of file svgfig.py.

Referenced by svgfig.SVG.__iter__(), and svgfig.SVG.tree().

236  def depth_first(self, depth_limit=None):
237  """Returns a depth-first generator over the SVG. If depth_limit
238  is a number, stop recursion at that depth."""
239  return self.SVGDepthIterator(self, (), depth_limit)
def depth_first
end nested class
Definition: svgfig.py:235
def svgfig.SVG.extend (   self,
  x 
)
Extends list of sub-elements by a list x.

Definition at line 192 of file svgfig.py.

Referenced by MatrixUtil.WF.__init__(), Config.Process.extend(), Config.Process.load(), and Mixins._ValidatingParameterListBase.setValue().

193  def extend(self, x):
194  """Extends list of sub-elements by a list x."""
195  self.sub.extend(x)
def extend
Definition: svgfig.py:192
def svgfig.SVG.firefox (   self,
  fileName = None,
  encoding = "utf-8" 
)
View in "firefox", assuming that program is available on your system.

fileName        default=None            note that any file named _default_fileName will be
                                    overwritten if no fileName is specified. If the extension
                                    is ".svgz" or ".gz", the output will be gzipped
encoding        default="utf-8"       file encoding (default is Unicode)

Definition at line 462 of file svgfig.py.

References svgfig.SVG.interpret_fileName(), and svgfig.SVG.save().

463  def firefox(self, fileName=None, encoding="utf-8"):
464  """View in "firefox", assuming that program is available on your system.
465 
466  fileName default=None note that any file named _default_fileName will be
467  overwritten if no fileName is specified. If the extension
468  is ".svgz" or ".gz", the output will be gzipped
469  encoding default="utf-8" file encoding (default is Unicode)
470  """
471  fileName = self.interpret_fileName(fileName)
472  self.save(fileName, encoding)
473  os.spawnvp(os.P_NOWAIT, "firefox", ("firefox", fileName))
def interpret_fileName
Definition: svgfig.py:402
def firefox
Definition: svgfig.py:462
def save
Definition: svgfig.py:409
def svgfig.SVG.inkscape (   self,
  fileName = None,
  encoding = "utf-8" 
)
View in "inkscape", assuming that program is available on your system.

fileName        default=None            note that any file named _default_fileName will be
                                    overwritten if no fileName is specified. If the extension
                                    is ".svgz" or ".gz", the output will be gzipped
encoding        default="utf-8"       file encoding (default is Unicode)

Definition at line 450 of file svgfig.py.

References svgfig.SVG.interpret_fileName(), and svgfig.SVG.save().

451  def inkscape(self, fileName=None, encoding="utf-8"):
452  """View in "inkscape", assuming that program is available on your system.
453 
454  fileName default=None note that any file named _default_fileName will be
455  overwritten if no fileName is specified. If the extension
456  is ".svgz" or ".gz", the output will be gzipped
457  encoding default="utf-8" file encoding (default is Unicode)
458  """
459  fileName = self.interpret_fileName(fileName)
460  self.save(fileName, encoding)
461  os.spawnvp(os.P_NOWAIT, "inkscape", ("inkscape", fileName))
def inkscape
Definition: svgfig.py:450
def interpret_fileName
Definition: svgfig.py:402
def save
Definition: svgfig.py:409
def svgfig.SVG.inkview (   self,
  fileName = None,
  encoding = "utf-8" 
)
View in "inkview", assuming that program is available on your system.

fileName        default=None            note that any file named _default_fileName will be
                                    overwritten if no fileName is specified. If the extension
                                    is ".svgz" or ".gz", the output will be gzipped
encoding        default="utf-8"       file encoding (default is Unicode)

Definition at line 438 of file svgfig.py.

References svgfig.SVG.interpret_fileName(), and svgfig.SVG.save().

439  def inkview(self, fileName=None, encoding="utf-8"):
440  """View in "inkview", assuming that program is available on your system.
441 
442  fileName default=None note that any file named _default_fileName will be
443  overwritten if no fileName is specified. If the extension
444  is ".svgz" or ".gz", the output will be gzipped
445  encoding default="utf-8" file encoding (default is Unicode)
446  """
447  fileName = self.interpret_fileName(fileName)
448  self.save(fileName, encoding)
449  os.spawnvp(os.P_NOWAIT, "inkview", ("inkview", fileName))
def interpret_fileName
Definition: svgfig.py:402
def inkview
Definition: svgfig.py:438
def save
Definition: svgfig.py:409
def svgfig.SVG.interpret_fileName (   self,
  fileName = None 
)

Definition at line 402 of file svgfig.py.

Referenced by svgfig.SVG.firefox(), svgfig.SVG.inkscape(), svgfig.SVG.inkview(), and svgfig.SVG.save().

403  def interpret_fileName(self, fileName=None):
404  if fileName == None:
405  fileName = _default_fileName
406  if re.search("windows", platform.system(), re.I) and not os.path.isabs(fileName):
407  fileName = _default_directory + os.sep + fileName
408  return fileName
def interpret_fileName
Definition: svgfig.py:402
def svgfig.SVG.items (   self,
  sub = True,
  attr = True,
  text = True 
)
Get a recursively-generated list of tree-index, sub-element/attribute pairs.

If sub == False, do not show sub-elements.
If attr == False, do not show attributes.
If text == False, do not show text/Unicode sub-elements.

Definition at line 249 of file svgfig.py.

Referenced by DictTypes.SortedKeysDict.__repr__(), event.Event.__str__(), config.CFG.__str__(), generateEDF.LumiInfoCont.__str__(), generateEDF.LumiInfoCont._integrateContainer(), betterConfigParser.BetterConfigParser.exists(), submitPVValidationJobs.BetterConfigParser.exists(), crabConfigParser.CrabConfigParser.getSectionLines(), svgfig.SVG.keys(), python.rootplot.core.Options.kwarg_list(), and svgfig.SVG.values().

250  def items(self, sub=True, attr=True, text=True):
251  """Get a recursively-generated list of tree-index, sub-element/attribute pairs.
252 
253  If sub == False, do not show sub-elements.
254  If attr == False, do not show attributes.
255  If text == False, do not show text/Unicode sub-elements.
256  """
257  output = []
258  for ti, s in self:
259  show = False
260  if isinstance(ti[-1], (int, long)):
261  if isinstance(s, str): show = text
262  else: show = sub
263  else: show = attr
264 
265  if show: output.append((ti, s))
266  return output
def items
Definition: svgfig.py:249
def svgfig.SVG.keys (   self,
  sub = True,
  attr = True,
  text = True 
)
Get a recursively-generated list of tree-indexes.

If sub == False, do not show sub-elements.
If attr == False, do not show attributes.
If text == False, do not show text/Unicode sub-elements.

Definition at line 267 of file svgfig.py.

References PixelDCSObject< class >.items, and svgfig.SVG.items().

Referenced by psClasses.queueList.__init__(), psClasses.queueList.smallestQueue(), and psClasses.queueList.thinerQueue().

268  def keys(self, sub=True, attr=True, text=True):
269  """Get a recursively-generated list of tree-indexes.
270 
271  If sub == False, do not show sub-elements.
272  If attr == False, do not show attributes.
273  If text == False, do not show text/Unicode sub-elements.
274  """
275  return [ti for ti, s in self.items(sub, attr, text)]
def items
Definition: svgfig.py:249
def keys
Definition: svgfig.py:267
def svgfig.SVG.prepend (   self,
  x 
)
Prepends x to the list of sub-elements (drawn first may be
overlapped by other primatives).

Definition at line 187 of file svgfig.py.

References svgfig.SVG.sub.

188  def prepend(self, x):
189  """Prepends x to the list of sub-elements (drawn first may be
190  overlapped by other primatives)."""
191  self.sub[0:0] = [x]
def prepend
Definition: svgfig.py:187
def svgfig.SVG.save (   self,
  fileName = None,
  encoding = "utf-8",
  compresslevel = None 
)
Save to a file for viewing.  Note that svg.save() overwrites the file named _default_fileName.

fileName        default=None            note that _default_fileName will be overwritten if
                                    no fileName is specified. If the extension
                                    is ".svgz" or ".gz", the output will be gzipped
encoding        default="utf-8"       file encoding (default is Unicode)
compresslevel   default=None            if a number, the output will be gzipped with that
                                    compression level (1-9, 1 being fastest and 9 most
                                    thorough)

Definition at line 409 of file svgfig.py.

References svgfig.SVG.interpret_fileName(), and svgfig.SVG.standalone_xml().

Referenced by svgfig.SVG.firefox(), svgfig.SVG.inkscape(), svgfig.SVG.inkview(), and SpecificationBuilder_cfi.Specification.saveAll().

410  def save(self, fileName=None, encoding="utf-8", compresslevel=None):
411  """Save to a file for viewing. Note that svg.save() overwrites the file named _default_fileName.
412 
413  fileName default=None note that _default_fileName will be overwritten if
414  no fileName is specified. If the extension
415  is ".svgz" or ".gz", the output will be gzipped
416  encoding default="utf-8" file encoding (default is Unicode)
417  compresslevel default=None if a number, the output will be gzipped with that
418  compression level (1-9, 1 being fastest and 9 most
419  thorough)
420  """
421  fileName = self.interpret_fileName(fileName)
422 
423  if compresslevel != None or re.search("\.svgz$", fileName, re.I) or re.search("\.gz$", fileName, re.I):
424  import gzip
425  if compresslevel == None:
426  f = gzip.GzipFile(fileName, "w")
427  else:
428  f = gzip.GzipFile(fileName, "w", compresslevel)
429 
430  f = codecs.EncodedFile(f, "utf-8", encoding)
431  f.write(self.standalone_xml())
432  f.close()
433 
434  else:
435  f = codecs.open(fileName, "w", encoding=encoding)
436  f.write(self.standalone_xml())
437  f.close()
def interpret_fileName
Definition: svgfig.py:402
def save
Definition: svgfig.py:409
def standalone_xml
Definition: svgfig.py:358
def svgfig.SVG.standalone_xml (   self,
  indent = "    ",
  newl = "\n" 
)
Get an XML representation of the SVG that can be saved/rendered.

indent      string used for indenting
newl        string used for newlines

Definition at line 358 of file svgfig.py.

References svgfig.canvas(), join(), svgfig.SVG.t, and AlignmentMonitorMuonSystemMap1D::MyCSCDetId.t.

Referenced by svgfig.SVG.save().

359  def standalone_xml(self, indent=" ", newl="\n"):
360  """Get an XML representation of the SVG that can be saved/rendered.
361 
362  indent string used for indenting
363  newl string used for newlines
364  """
365 
366  if self.t == "svg": top = self
367  else: top = canvas(self)
368  return """\
369 <?xml version="1.0" standalone="no"?>
370 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
371 
372 """ + ("".join(top.__standalone_xml(indent, newl))) # end of return statement
def canvas
Definition: svgfig.py:482
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
def standalone_xml
Definition: svgfig.py:358
def svgfig.SVG.tree (   self,
  depth_limit = None,
  sub = True,
  attr = True,
  text = True,
  tree_width = 20,
  obj_width = 80 
)
Print (actually, return a string of) the tree in a form useful for browsing.

If depth_limit == a number, stop recursion at that depth.
If sub == False, do not show sub-elements.
If attr == False, do not show attributes.
If text == False, do not show text/Unicode sub-elements.
tree_width is the number of characters reserved for printing tree indexes.
obj_width is the number of characters reserved for printing sub-elements/attributes.

Definition at line 291 of file svgfig.py.

References svgfig.SVG.depth_first(), and join().

Referenced by svgfig.SVG.__str__(), ZJetsTreeAnalyzer.ZJetsTreeAnalyzer.beginLoop(), MetTreeProducer.MetTreeProducer.declareVariables(), core.AutoFillTreeProducer.AutoFillTreeProducer.declareVariables(), core.AutoFillTreeProducer.AutoFillTreeProducer.fillTree(), ZJetsTreeAnalyzer.ZJetsTreeAnalyzer.process(), MetTreeProducer.MetTreeProducer.process(), and python.cmstools.EventTree.SetAlias().

292  def tree(self, depth_limit=None, sub=True, attr=True, text=True, tree_width=20, obj_width=80):
293  """Print (actually, return a string of) the tree in a form useful for browsing.
294 
295  If depth_limit == a number, stop recursion at that depth.
296  If sub == False, do not show sub-elements.
297  If attr == False, do not show attributes.
298  If text == False, do not show text/Unicode sub-elements.
299  tree_width is the number of characters reserved for printing tree indexes.
300  obj_width is the number of characters reserved for printing sub-elements/attributes.
301  """
302 
303  output = []
304 
305  line = "%s %s" % (("%%-%ds" % tree_width) % repr(None), ("%%-%ds" % obj_width) % (repr(self))[0:obj_width])
306  output.append(line)
307 
308  for ti, s in self.depth_first(depth_limit):
309  show = False
310  if isinstance(ti[-1], (int, long)):
311  if isinstance(s, str): show = text
312  else: show = sub
313  else: show = attr
314 
315  if show:
316  line = "%s %s" % (("%%-%ds" % tree_width) % repr(list(ti)), ("%%-%ds" % obj_width) % (" "*len(ti) + repr(s))[0:obj_width])
317  output.append(line)
318 
319  return "\n".join(output)
def depth_first
end nested class
Definition: svgfig.py:235
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
def tree
Definition: svgfig.py:291
def svgfig.SVG.values (   self,
  sub = True,
  attr = True,
  text = True 
)
Get a recursively-generated list of sub-elements and attributes.

If sub == False, do not show sub-elements.
If attr == False, do not show attributes.
If text == False, do not show text/Unicode sub-elements.

Definition at line 276 of file svgfig.py.

References PixelDCSObject< class >.items, and svgfig.SVG.items().

Referenced by genericValidation.ValidationWithPlotsSummaryBase.SummaryItem.value().

277  def values(self, sub=True, attr=True, text=True):
278  """Get a recursively-generated list of sub-elements and attributes.
279 
280  If sub == False, do not show sub-elements.
281  If attr == False, do not show attributes.
282  If text == False, do not show text/Unicode sub-elements.
283  """
284  return [s for ti, s in self.items(sub, attr, text)]
def items
Definition: svgfig.py:249
def values
Definition: svgfig.py:276
def svgfig.SVG.xml (   self,
  indent = "    ",
  newl = "\n",
  depth_limit = None,
  depth = 0 
)
Get an XML representation of the SVG.

indent      string used for indenting
newl        string used for newlines
If depth_limit == a number, stop recursion at that depth.
depth       starting depth (not useful for users)

print svg.xml()

Definition at line 320 of file svgfig.py.

References join(), svgfig.SVG.sub, svgfig.SVG.t, and AlignmentMonitorMuonSystemMap1D::MyCSCDetId.t.

Referenced by svgfig.SVG.__repr__().

321  def xml(self, indent=" ", newl="\n", depth_limit=None, depth=0):
322  """Get an XML representation of the SVG.
323 
324  indent string used for indenting
325  newl string used for newlines
326  If depth_limit == a number, stop recursion at that depth.
327  depth starting depth (not useful for users)
328 
329  print svg.xml()
330  """
331 
332  attrstr = []
333  for n, v in self.attr.items():
334  if isinstance(v, dict):
335  v = "; ".join(["%s:%s" % (ni, vi) for ni, vi in v.items()])
336  elif isinstance(v, (list, tuple)):
337  v = ", ".join(v)
338  attrstr.append(" %s=%s" % (n, repr(v)))
339  attrstr = "".join(attrstr)
340 
341  if len(self.sub) == 0: return "%s<%s%s />" % (indent * depth, self.t, attrstr)
342 
343  if depth_limit == None or depth_limit > depth:
344  substr = []
345  for s in self.sub:
346  if isinstance(s, SVG):
347  substr.append(s.xml(indent, newl, depth_limit, depth + 1) + newl)
348  elif isinstance(s, str):
349  substr.append("%s%s%s" % (indent * (depth + 1), s, newl))
350  else:
351  substr.append("%s%s%s" % (indent * (depth + 1), repr(s), newl))
352  substr = "".join(substr)
353 
354  return "%s<%s%s>%s%s%s</%s>" % (indent * depth, self.t, attrstr, newl, substr, indent * depth, self.t)
355 
356  else:
357  return "%s<%s (%d sub)%s />" % (indent * depth, self.t, len(self.sub), attrstr)
def xml
Definition: svgfig.py:320
static std::string join(char **cmd)
Definition: RemoteFile.cc:19

Member Data Documentation

svgfig.SVG.attr

Definition at line 134 of file svgfig.py.

Referenced by svgfig.SVG.__contains__(), svgfig.SVG.__eq__(), svgfig.Path.__repr__(), svgfig.Curve.__repr__(), svgfig.Poly.__repr__(), svgfig.Text.__repr__(), svgfig.TextGlobal.__repr__(), svgfig.Dots.__repr__(), svgfig.Line.__repr__(), svgfig.LineGlobal.__repr__(), svgfig.VLine.__repr__(), svgfig.HLine.__repr__(), svgfig.Rect.__repr__(), svgfig.Ellipse.__repr__(), svgfig.Ticks.__repr__(), svgfig.CurveAxis.__repr__(), svgfig.LineAxis.__repr__(), svgfig.XAxis.__repr__(), svgfig.YAxis.__repr__(), svgfig.Axes.__repr__(), svgfig.HGrid.__repr__(), svgfig.VGrid.__repr__(), svgfig.Grid.__repr__(), svgfig.Curve.Path(), svgfig.Poly.Path(), svgfig.Rect.Path(), svgfig.Path.SVG(), svgfig.Text.SVG(), svgfig.TextGlobal.SVG(), svgfig.LineGlobal.SVG(), svgfig.Axes.SVG(), svgfig.XErrorBars.SVG(), and svgfig.YErrorBars.SVG().

svgfig.SVG.sub

Definition at line 130 of file svgfig.py.

Referenced by svgfig.SVG.__eq__(), svgfig.SVG.__standalone_xml(), svgfig.SVG.prepend(), and svgfig.SVG.xml().

svgfig.SVG.t

Definition at line 128 of file svgfig.py.

Referenced by svgfig.SVG.__eq__(), svgfig.Curve.Sample.__repr__(), svgfig.SVG.__standalone_xml(), svgfig.SVG.standalone_xml(), and svgfig.SVG.xml().