Classes | Public Member Functions | Public Attributes | List of all members
SortModuleTimes.TabularAlignmentClass Class Reference

Classes

class  CatchAllLines
 
class  FormatNotSupported
 
class  LineIdentifierClass
 
class  LineNo
 

Public Member Functions

def __init__ (self, specs=[None)
 
def ParseFormatSpec (self, spec)
 
def SetRowFormats (self, rowSelector, specs)
 
def SetDefaultFormats (self, specs)
 
def AddData (self, data)
 
def AddRow (self, row_data)
 
def SelectFormat (self, iLine)
 
def FormatTable (self)
 
def ToStrings (self, separator=" ")
 
def Print (self, stream=sys.stdout)
 

Public Attributes

 tabledata
 
 formats
 

Detailed Description

Formats list of data in a table

Definition at line 691 of file SortModuleTimes.py.

Constructor & Destructor Documentation

def SortModuleTimes.TabularAlignmentClass.__init__ (   self,
  specs = [ None 
)
Each format specification applies to one item in each row.
If no format specification is supplied for an item, the last used format
is applied. By default, that is a plain conversion to string.

Definition at line 693 of file SortModuleTimes.py.

693  def __init__(self, specs = [ None, ]):
694  """
695  Each format specification applies to one item in each row.
696  If no format specification is supplied for an item, the last used format
697  is applied. By default, that is a plain conversion to string.
698  """
699  self.tabledata = []
700  self.formats = {}
701  if specs: self.SetDefaultFormats(specs)

Member Function Documentation

def SortModuleTimes.TabularAlignmentClass.AddData (   self,
  data 
)

Definition at line 765 of file SortModuleTimes.py.

765  def AddData(self, data): self.tabledata.extend(data)
def SortModuleTimes.TabularAlignmentClass.AddRow (   self,
  row_data 
)

Definition at line 766 of file SortModuleTimes.py.

766  def AddRow(self, *row_data): self.tabledata.append(row_data)
767 
768 
def SortModuleTimes.TabularAlignmentClass.FormatTable (   self)

Definition at line 783 of file SortModuleTimes.py.

783  def FormatTable(self):
784  # select the formats for all lines
785  AllFormats \
786  = [ self.SelectFormat(iRow) for iRow in xrange(len(self.tabledata)) ]
787 
788  # format all the items
789  ItemLengths = MaxItemLengthsClass()
790  TableContent = []
791  for iRow, rowdata in enumerate(self.tabledata):
792  RowFormats = AllFormats[iRow]
793  LineContent = []
794  LastSpec = None
795  for iItem, itemdata in enumerate(rowdata):
796  try:
797  Spec = RowFormats[iItem]
798  LastSpec = Spec
799  except IndexError: Spec = LastSpec
800 
801  Formatter = Spec['format']
802  if isinstance(Formatter, basestring):
803  ItemContent = Formatter % itemdata
804  elif callable(Formatter):
805  ItemContent = Formatter(itemdata)
806  else:
807  raise RuntimeError("Formatter %r (#%d) not supported."
808  % (Formatter, iItem))
809  # if ... else
810  LineContent.append(ItemContent)
811  # for items
812  ItemLengths.add(LineContent)
813  TableContent.append(LineContent)
814  # for rows
815 
816  # pad the objects
817  for iRow, rowdata in enumerate(TableContent):
818  RowFormats = AllFormats[iRow]
819  Spec = AllFormats[iRow]
820  for iItem, item in enumerate(rowdata):
821  try:
822  Spec = RowFormats[iItem]
823  LastSpec = Spec
824  except IndexError: Spec = LastSpec
825 
826  fieldWidth = ItemLengths[iItem]
827  alignment = Spec.get('align', 'left')
828  if alignment == 'right':
829  alignedItem = RightString(item, fieldWidth)
830  elif alignment == 'justified':
831  alignedItem = JustifyString(item, fieldWidth)
832  elif alignment == 'center':
833  alignedItem = CenterString(item, fieldWidth)
834  else: # if alignment == 'left':
835  alignedItem = LeftString(item, fieldWidth)
836  if Spec.get('truncate', True): alignedItem = alignedItem[:fieldWidth]
837 
838  rowdata[iItem] = alignedItem
839  # for items
840  # for rows
841  return TableContent
def RightString(s, w, f=' ')
def CenterString(s, w, f=' ')
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
def LeftString(s, w, f=' ')
def JustifyString(s, w, f=' ')
def SortModuleTimes.TabularAlignmentClass.ParseFormatSpec (   self,
  spec 
)

Definition at line 738 of file SortModuleTimes.py.

738  def ParseFormatSpec(self, spec):
739  SpecData = {}
740  if spec is None: SpecData['format'] = str
741  elif isinstance(spec, basestring): SpecData['format'] = spec
742  elif isinstance(spec, dict):
743  SpecData = spec
744  SpecData.setdefault('format', str)
746  return SpecData
def SortModuleTimes.TabularAlignmentClass.Print (   self,
  stream = sys.stdout 
)

Definition at line 847 of file SortModuleTimes.py.

847  def Print(self, stream = sys.stdout):
848  print "\n".join(self.ToStrings())
849 
850 # class TabularAlignmentClass
851 
852 
def ToStrings(self, separator=" ")
def Print(self, stream=sys.stdout)
def SortModuleTimes.TabularAlignmentClass.SelectFormat (   self,
  iLine 
)

Definition at line 769 of file SortModuleTimes.py.

769  def SelectFormat(self, iLine):
770  rowdata = self.tabledata[iLine]
771  success = None
772  bestFormat = None
773  for lineMatcher, format_ in self.formats.items():
774  match_success = lineMatcher(iLine, self.tabledata)
775  if match_success <= success: continue
776  bestFormat = format_
777  success = match_success
778  # for
779  return bestFormat
def SortModuleTimes.TabularAlignmentClass.SetDefaultFormats (   self,
  specs 
)
def SortModuleTimes.TabularAlignmentClass.SetRowFormats (   self,
  rowSelector,
  specs 
)

Definition at line 749 of file SortModuleTimes.py.

749  def SetRowFormats(self, rowSelector, specs):
750  # parse the format specifications
751  formats = []
752  for iSpec, spec in enumerate(specs):
753  try:
754  formats.append(self.ParseFormatSpec(spec))
756  raise RuntimeError("Format specification %r (#%d) not supported."
757  % (str(e), iSpec))
758  # for specifications
759  self.formats[rowSelector] = formats
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
def SetRowFormats(self, rowSelector, specs)
static QCString str
def SortModuleTimes.TabularAlignmentClass.ToStrings (   self,
  separator = " " 
)

Definition at line 844 of file SortModuleTimes.py.

844  def ToStrings(self, separator = " "):
845  return [ separator.join(RowContent) for RowContent in self.FormatTable() ]
846 
def ToStrings(self, separator=" ")

Member Data Documentation

SortModuleTimes.TabularAlignmentClass.formats

Definition at line 700 of file SortModuleTimes.py.

SortModuleTimes.TabularAlignmentClass.tabledata

Definition at line 699 of file SortModuleTimes.py.


The documentation for this class was generated from the following file: