def cleanblock(self):
        """clean one block of a table"""

        blockaddr = self.block * self.dim * BSIZE
        if blockaddr >= self.numrows:    # done

            if self.hideN:
                self.rowl.HideLabelsWithDataAt(2, self.lastlbl)
            if self.hideinsig < 1.:
                self.rowl.HideLabelsWithDataAt(1, self.lastlbl)
            if self.hideL and hidelok:
                self.rowl.SetRowLabelWidthAt(1,self.lastlbl, 0)
                ###self.rowl.SetValueAt(1, self.lastlbl, " ")
            return False        

        for row in range(self.dim):
            rowaddr = blockaddr + row * BSIZE
            if self.lowertri:  # blank cells past dialgonal
                for c in range(row + 1, self.dim):
                    self.datacells.SetValueAt(rowaddr, c, " ")
                    self.datacells.HideFootnotesAt(rowaddr, c)
                    if not self.hideN:
                        self.datacells.SetValueAt(rowaddr+2, c, " ")
                    if not (self.hideinsig < 1.):
                        self.datacells.SetValueAt(rowaddr+1, c, " ")

            # blank insignificant cells (if requested) and highlight large corrs (if requested)
            for c in range(self.dim):   # column loop
                if self.lowertri and c > row:
                    continue
                skip = False
                if self.hideinsig < 1. or self.boldsig < 1.:  # blank insig
                    if c != row:
                        try:
                            sig = floatex(self.datacells.GetValueAt(rowaddr+1, c))
                        except:
                            sig = 1.  # hide if not a number
                        if sig > self.hideinsig:
                            self.datacells.SetValueAt(rowaddr, c, " ")
                            self.datacells.HideFootnotesAt(rowaddr, c)  # remove all footnotes
                            skip = True
                        elif sig <= self.boldsig:
                            self.datacells.SetTextStyleAt(rowaddr, c, 
                                SpssClient.SpssTextStyleTypes.SpssTSBold)
                corr = None
                if self.emphlarge < 1. and (not skip) and c != row:  # highlight large corrs unless failed sig test
                    try:
                        corr = floatex(self.datacells.GetValueAt(rowaddr, c))
                    except:
                        corr = 10.
                    if abs(corr) >= self.emphlarge:
                        self.datacells.SetTextStyleAt(rowaddr, c, style)
                        self.datacells.SetBackgroundColorAt(rowaddr, c, color)
                if (not self.decimals is None) and (not skip):
                    self.datacells.SetHDecDigitsAt(rowaddr, c, self.decimals)
        
        self.block += 1
Exemplo n.º 2
0
    def cleanblock(self):
        """clean one block of a table"""

        blockaddr = self.block * self.dim * BSIZE
        if blockaddr >= self.numrows:    # done

            if self.hideN:
                self.rowl.HideLabelsWithDataAt(2, self.lastlbl)
            if self.hideinsig < 1.:
                self.rowl.HideLabelsWithDataAt(1, self.lastlbl)
            if self.hideL and hidelok:
                self.rowl.SetRowLabelWidthAt(1,self.lastlbl, 0)
                ###self.rowl.SetValueAt(1, self.lastlbl, " ")
            return False        

        for row in range(self.dim):
            rowaddr = blockaddr + row * BSIZE
            if self.lowertri:  # blank cells past dialgonal
                for c in range(row + 1, self.dim):
                    self.datacells.SetValueAt(rowaddr, c, " ")
                    self.datacells.HideFootnotesAt(rowaddr, c)
                    if not self.hideN:
                        self.datacells.SetValueAt(rowaddr+2, c, " ")
                    if not (self.hideinsig < 1.):
                        self.datacells.SetValueAt(rowaddr+1, c, " ")

            # blank insignificant cells (if requested) and highlight large corrs (if requested)
            for c in range(self.dim):   # column loop
                if self.lowertri and c > row:
                    continue
                skip = False
                if self.hideinsig < 1. or self.boldsig < 1.:  # blank insig
                    if c != row:
                        try:
                            sig = floatex(self.datacells.GetValueAt(rowaddr+1, c))
                        except:
                            sig = 1.  # hide if not a number
                        if sig > self.hideinsig:
                            self.datacells.SetValueAt(rowaddr, c, " ")
                            self.datacells.HideFootnotesAt(rowaddr, c)  # remove all footnotes
                            skip = True
                        elif sig <= self.boldsig:
                            self.datacells.SetTextStyleAt(rowaddr, c, 
                                SpssClient.SpssTextStyleTypes.SpssTSBold)
                corr = None
                if self.emphlarge < 1. and (not skip) and c != row:  # highlight large corrs unless failed sig test
                    try:
                        corr = floatex(self.datacells.GetValueAt(rowaddr, c))
                    except:
                        corr = 10.
                    if abs(corr) >= self.emphlarge:
                        self.datacells.SetTextStyleAt(rowaddr, c, style)
                        self.datacells.SetBackgroundColorAt(rowaddr, c, color)
                if (not self.decimals is None) and (not skip):
                    self.datacells.SetHDecDigitsAt(rowaddr, c, self.decimals)
        
        self.block += 1
Exemplo n.º 3
0
    def datacellstyles(self, roworcol, expression):
        """Apply datacell styles looping over rows or columns

	roworcol is the row or column number to process.
	expression is True if an applyto expression exists."""

        coldim = self.dimension == "columns"
        if coldim:
            limit = self.numdatarows
        else:
            limit = self.numdatacols

        for i in range(limit):
            outcome = True
            if coldim:
                row, col = i, roworcol
            else:
                row,col = roworcol, i
            if expression:
                try:   # this api is new in V18 or 17.0.2
                    x = float(self.datacells.GetUnformattedValueAt(row, col))
                except AttributeError:
                    x = floatex(self.datacells.GetValueAt(row, col), self.datacells.GetNumericFormatAt(row, col))
                except ValueError:
                    x = self.datacells.GetValueAt(row, col)   # 2/19/2015
                try:
                    if outcome:
                        outcome = eval(self.applyto, {'x':x, "i":i, "ii": roworcol})
                except (NameError, SyntaxError), e:
                    if not isinstance(self.applyto, unicode):
                        self.applyto = unicode(self.applyto, self.encoding)
                    raise ValueError(_("APPLYTO expression is invalid: %s") % self.applyto)
                except:
                    outcome = False
def colorCrosstabResiduals(obj, i, j, numrows, numcols, section, more, custom):
    if section == "datacells":
        try:
            if abs(floatex(obj.GetValueAt(i, j))) >= custom.get("thresh", 2.0):
                for k in range(custom.get("number", 1) + 1):
                    obj.SetBackgroundColorAt(i - k, j, RGB((255, 0, 0)))
                obj.SetBackgroundColorAt(i - 1, j, RGB((255, 0, 0)))
        except:
            pass
def colorCrosstabResiduals(obj, i, j, numrows, numcols, section, more,custom):
    if section == "datacells":
        try:
            if abs(floatex(obj.GetValueAt(i,j))) >= custom.get("thresh", 2.0):
                for k in range(custom.get("number", 1) + 1):
                    obj.SetBackgroundColorAt(i - k, j, RGB((255,0,0)))
                obj.SetBackgroundColorAt(i-1, j, RGB((255,0,0))) 
        except:
            pass
	def crittest(value):
		"""return whether value meets the criterion test.

	    Tries to handle locale formatted and decorated strings via floatex function"""

		try:
			c = cmp(abs(floatex(value)), critvalue)
			return olist[c+1]
		except:
			return False
def makeSigCoefsBold(obj, i, j, numrows, numcols, section, more):
    """Working on the REGRESSION Coefficients table, make each coefficient
    that is significant at the 5% level bold.
    Coefficients are column 0, and significance is column 4"""
    
    # a little misuse protection
    if section != 'datacells':
        return
    sig = floatex(obj.GetValueAt(i, 4), obj.GetNumericFormatAt(i, 4))
    if sig <= 0.05:
        obj.SetTextStyleAt(i,0, SpssClient.SpssTextStyleTypes.SpssTSBold)
        more.rowlabelarray.SetTextStyleAt(i, 3, SpssClient.SpssTextStyleTypes.SpssTSBold)
def makeSigCoefsBold(obj, i, j, numrows, numcols, section, more):
    """Working on the REGRESSION Coefficients table, make each coefficient
    that is significant at the 5% level bold.
    Coefficients are column 0, and significance is column 4"""

    # a little misuse protection
    if section != 'datacells':
        return
    sig = floatex(obj.GetValueAt(i, 4), obj.GetNumericFormatAt(i, 4))
    if sig <= 0.05:
        obj.SetTextStyleAt(i, 0, SpssClient.SpssTextStyleTypes.SpssTSBold)
        more.rowlabelarray.SetTextStyleAt(
            i, 3, SpssClient.SpssTextStyleTypes.SpssTSBold)
    def datacellstyles(self, roworcol, expression):
        """Apply datacell styles looping over rows or columns

	roworcol is the row or column number to process.
	expression is True if an applyto expression exists."""

        coldim = self.dimension == "columns"
        if coldim:
            limit = self.numdatarows
        else:
            limit = self.numdatacols

        for i in range(limit):
            outcome = True
            if coldim:
                row, col = i, roworcol
            else:
                row,col = roworcol, i
            if expression:
                try:   # this api is new in V18 or 17.0.2
                    x = float(self.datacells.GetUnformattedValueAt(row, col))
                except AttributeError:
                    x = floatex(self.datacells.GetValueAt(row, col), self.datacells.GetNumericFormatAt(row, col))
                except ValueError:
                    x = self.datacells.GetValueAt(row, col)   # 2/19/2015
                try:
                    if outcome:
                        outcome = eval(self.applyto, {'x':x, "i":i, "ii": roworcol})
                except (NameError, SyntaxError) as e:
                    if not isinstance(self.applyto, str):
                        self.applyto = str(self.applyto, self.encoding)
                    raise ValueError(_("APPLYTO expression is invalid: %s") % self.applyto)
                except:
                    outcome = False

            if outcome:
                # checksigcells will return True if
                # - not doing significance formatting or
                # - doing significance formatting and it should be applied to this cell
                # Thus sig formatting can suppress formatting that would otherwise be applied
                if self.checksigcells(row, col):
                    for f in self.stylecalls:
                        rc = f(self.datacells, row, col, self.numdatarows, self.numdatacols, "datacells",  self)
                        if rc is False:
                            return rc