Measurements
The functions below are examples to calculate values into pixels and columns. These rouines can typically be put into a ./_py/include/defines.py file, so the constants and functions can be imported by all application files of a site. See Including modules for more information.Integer to pixels: px(n)
To convert integer values into pixel string, it is best to define a small function in the css.py file itself.def px(n): return str(n) + 'px'
self.style() self.css(ids='h2', fontsize=px(10)) self._style()
h2 {font-size:10px}
Integer to columns c(n) and cw(n)
To calculate from an integer column number to pixels we need two functions. The position of a column is different from the pixel width of a column.UNIT = 8 GUTTER = MARGIN = UNIT COLUMNWIDTH = 8 * UNIT def c(n): # Calculate column position to pixels return px(MARGIN + n * (COLUMNWIDTH + GUTTER)) def cw(n): # Calculate column width to pixels return px(n * COLUMNWIDTH + (n-1) * GUTTER)
self.css(ids='#content', position='absolute', x=c(1), width=cw(4))
Note that both c(n) and cw(n) are using px(n) to convert to a string including 'px'. It is important to add this, because some CSS measurements (like leading) do not behave as expected in certain browsers if only the value is defined.
