(self, e)
return D
This method factors out what is essentially grid printing.
This method factors out what is essentially grid printing.
This method factors out what is essentially grid printing .
def _print_matrix_contents(self, e):
        """
        This method factors out what is essentially grid printing.
        """
        M = e   # matrix
        Ms = {}  # i,j -> pretty(M[i,j])
        for i in range(M.rows):
            for j in range(M.cols):
                Ms[i, j] = self._print(M[i, j])

        # h- and v- spacers
        hsep = 2
        vsep = 1

        # max width for columns
        maxw = [-1] * M.cols

        for j in range(M.cols):
            maxw[j] = max([Ms[i, j].width() for i in range(M.rows)] or [0])

        # drawing result
        D = None

        for i in range(M.rows):

            D_row = None
            for j in range(M.cols):
                s = Ms[i, j]

                # reshape s to maxw
                # XXX this should be generalized, and go to stringPict.reshape ?
                assert s.width() <= maxw[j]

                # hcenter it, +0.5 to the right                        2
                # ( it's better to align formula starts for say 0 and r )
                # XXX this is not good in all cases -- maybe introduce vbaseline?
                wdelta = maxw[j] - s.width()
                wleft = wdelta // 2
                wright = wdelta - wleft

                s = prettyForm(*s.right(' '*wright))
                s = prettyForm(*s.left(' '*wleft))

                # we don't need vcenter cells -- this is automatically done in
                # a pretty way because when their baselines are taking into
                # account in .right()

                if D_row is None:
                    D_row = s   # first box in a row
                    continue

                D_row = prettyForm(*D_row.right(' '*hsep))  # h-spacer
                D_row = prettyForm(*D_row.right(s))

            if D is None:
                D = D_row       # first row in a picture
                continue

            # v-spacer
            for _ in range(vsep):
                D = prettyForm(*D.below(' '))

            D = prettyForm(*D.below(D_row))

        if D is None:
            D = prettyForm('')  # Empty Matrix

        return D
def _print_matrix_contents ( self , e ) : M = e # matrix Ms = { } # i,j -> pretty(M[i,j]) for i in range ( M . rows ) : for j in range ( M . cols ) : Ms [ i , j ] = self . _print ( M [ i , j ] ) # h- and v- spacers hsep = 2 vsep = 1 # max width for columns maxw = [ - 1 ] * M . cols for j in range ( M . cols ) : maxw [ j ] = max ( [ Ms [ i , j ] . width ( ) for i in range ( M . rows ) ] or [ 0 ] ) # drawing result D = None for i in range ( M . rows ) : D_row = None for j in range ( M . cols ) : s = Ms [ i , j ] # reshape s to maxw # XXX this should be generalized, and go to stringPict.reshape ? assert s . width ( ) <= maxw [ j ] # hcenter it, +0.5 to the right                        2 # ( it's better to align formula starts for say 0 and r ) # XXX this is not good in all cases -- maybe introduce vbaseline? wdelta = maxw [ j ] - s . width ( ) wleft = wdelta // 2 wright = wdelta - wleft s = prettyForm ( * s . right ( ' ' * wright ) ) s = prettyForm ( * s . left ( ' ' * wleft ) ) # we don't need vcenter cells -- this is automatically done in # a pretty way because when their baselines are taking into # account in .right() if D_row is None : D_row = s # first box in a row continue D_row = prettyForm ( * D_row . right ( ' ' * hsep ) ) # h-spacer D_row = prettyForm ( * D_row . right ( s ) ) if D is None : D = D_row # first row in a picture continue # v-spacer for _ in range ( vsep ) : D = prettyForm ( * D . below ( ' ' ) ) D = prettyForm ( * D . below ( D_row ) ) if D is None : D = prettyForm ( '' ) # Empty Matrix return D