Exemple #1
0
 def row_style(self, row):
     if row['count'].value() <= row.form.query_fields.row['min_count'].value():
         return pp.Style(background='#fdd')
     elif row['marked'].value():
         return pp.Style(background='#ffd')
     else:
         return None
Exemple #2
0
 def _customize_fields(self, fields):
     fields.set_property('width', product_id=3, product=30, count=12, price=12, notes=50)
     fields.modify('product_id', column_width=6, fixed=True, editable=Editable.ALWAYS)
     fields.modify('product', style=lambda r: (pp.Style(overstrike=True)
                                               if r['count'].value() == 0
                                               else None))
     fields.modify('count', style=lambda r: (pp.Style(foreground='#f00')
                                             if r['count'].value() <= 5
                                             else None))
     fields.modify('price', type=pd.Monetary(not_null=True))
     fields.modify('since', descr=_("Date when the product was first included."),
                   default=pd.DateTime.datetime)
     fields.modify('notes', descr=_("Arbitrary internal notes about given product."),
                   height=3, text_format=pp.TextFormat.LCG)
Exemple #3
0
 def test_hash(self):
     cache = {
         pp.Style(): 'default',
         pp.Style(background='#ff4'): 'yellow bg',
         pp.Style(foreground='#f00', overstrike=True): 'red overstrike',
         pp.Style(foreground='#00f', slanted=True): 'blue slanted',
     }
     assert cache[pp.Style()] == 'default'
     assert cache[pp.Style(slanted=False)] == 'default'
     assert cache[pp.Style(slanted=False, overstrike=False)] == 'default'
     assert cache[pp.Style(background='#FF4')] == 'yellow bg'
     assert cache[pp.Style(foreground='#F00',
                           overstrike=True)] == 'red overstrike'
     assert cache[pp.Style(foreground='#00F',
                           slanted=True)] == 'blue slanted'
Exemple #4
0
 def _customize_fields(self, fields):
     fields.append(Field('price2', _("Price with VAT"), virtual=True,
                         type=pd.Float(precision=2),
                         computer=computer(lambda r, price: price and price * 1.21)))
     fields.set_property('width', product_id=3, product=30, count=12, price=12, price2=12,
                         notes=50)
     fields.modify('product_id', column_width=6, fixed=True)
     fields.modify('product', style=lambda r: (pp.Style(overstrike=True)
                                               if r['count'].value() == 0
                                               else None))
     fields.modify('count', style=lambda r: (pp.Style(foreground='#f00')
                                             if r['count'].value() <= 5
                                             else None))
     fields.modify('price', type=pd.Monetary(not_null=True))
     fields.modify('since', descr=_("Date when the product was first included."))
     fields.modify('notes', descr=_("Arbitrary internal notes about given product."),
                   height=3, text_format=pp.TextFormat.LCG)
Exemple #5
0
 def test_grid_performance(self, spec, data, benchmark):
     def rows(count):
         i = 0
         while i < count:
             i += 1
             yield (i, 'Row number %d' % i, 1.86 * i, i % 3 == 0)
     self.insert(data, rows(9500))
     t = self.grid_table(
         spec, data,
         sorting=(('name', pd.ASCENDENT),
                  ('flag', pd.ASCENDENT),
                  ('price', pd.ASCENDENT),),
         grouping=('name', 'flag'),
         row_style=lambda r: pp.Style(background='#ffa') if r['id'].value() % 2 else None,
         field_style={'price': lambda r: pp.Style(bold=True) if r['flag'].value() else None},
     )
     try:
         benchmark(self.emulate_real_grid, t)
     finally:
         data.close()
Exemple #6
0
 def test_cell_style(self, spec, data):
     self.insert(data, (
         (1, 'Apple', 12.3, False),
         (2, 'Banana', 23.4, True),
         (3, 'Strawberry', 2.34, True),
         (4, 'Orange', None, True),
     ))
     t = self.grid_table(
         spec, data,
         row_style=lambda r: pp.Style(background='#ffa') if r['id'].value() % 2 else None,
         field_style={'price': lambda r: pp.Style(bold=True) if r['flag'].value() else None},
     )
     try:
         assert t.cell_style(4, 1) is None
         assert t.cell_style(3, 4) is None
         assert t.cell_style(0, 2) == pp.Style(background='#ffa')
         assert t.cell_style(1, 3) == pp.Style()
         assert t.cell_style(1, 2) == pp.Style(bold=True)
         assert t.cell_style(2, 2) == pp.Style(bold=True, background='#ffa')
     finally:
         data.close()
Exemple #7
0
 def test_add(self):
     assert pp.Style() == pp.Style() + pp.Style()
     assert pp.Style() == pp.Style() + None
     assert pp.Style() == (None + pp.Style())
     assert pp.Style(bold=True) == (None + pp.Style(bold=True))
     assert (pp.Style(slanted=True, overstrike=True,
                      foreground='#F00') == pp.Style(slanted=True) +
             pp.Style(overstrike=True, foreground='#F00'))
     assert pp.Style(
         slanted=True) == pp.Style(slanted=True) + pp.Style(slanted=False)
     assert pp.Style(
         slanted=False) == pp.Style(slanted=False) + pp.Style(slanted=True)
     assert (pp.Style(overstrike=True,
                      foreground='#000') == pp.Style(foreground='#000') +
             pp.Style(overstrike=True, foreground='#F00'))
Exemple #8
0
 def test_equality(self):
     assert pp.Style() == pp.Style()
     assert pp.Style(slanted=True) == pp.Style(slanted=True)
     assert (pp.Style(slanted=True,
                      foreground='#fff') == pp.Style(slanted=True,
                                                     foreground='#FFF'))
     assert pp.Style(slanted=False) == pp.Style()
     assert pp.Style() != pp.Orientation()
     assert pp.Orientation() != pp.Style()
     assert pp.Style(slanted=True) != pp.Style(foreground='#fff')
Exemple #9
0
 def test_colors(self):
     with pytest.raises(TypeError):
         pp.Style(background=20)
     with pytest.raises(TypeError):
         pp.Style(background={})
     with pytest.raises(TypeError):
         pp.Style(background=('a', 10, 20))
     with pytest.raises(ValueError):
         pp.Style(background='#1g2h3i')
     with pytest.raises(ValueError):
         pp.Style(background='fff')
     with pytest.raises(ValueError):
         pp.Style(background=(300, 10, 20))
     assert pp.Style(background='#fff') == pp.Style(background='#FFFFFF')
     assert pp.Style(background='#fff') == pp.Style(background=(255, 255,
                                                                255))
     assert pp.Style(background='#fff') == pp.Style(
         background=pp.Color.WHITE)
     assert pp.Style(background='#002e6a') == pp.Style(
         background=[0, 46, 106])
     assert pp.Style(background='#e00020') == pp.Style(background=(0xe0,
                                                                   0x00,
                                                                   0x20))
Exemple #10
0
 def row_style(self, row):
     if row['success'].value():
         return None
     else:
         return pp.Style(foreground='#f00')
Exemple #11
0
 def row_style(self, record):
     if not record['mod_id'].value():
         return None
     else:
         return pp.Style(background='#ffd')
Exemple #12
0
 def row_style(self, record):
     if not record['published'].value():
         return pp.Style(foreground='#777', background='#eee')
     else:
         return None
Exemple #13
0
 def row_style(self, row):
     return not row['changed'].value() and pp.Style(background='#ffd') or None
Exemple #14
0
 def row_style(self, row):
     return (row['id'].value() ^ 3) % 2 and pp.Style(background='#ffd') or None
Exemple #15
0
 def _customize_fields(self, fields):
     fields.modify('value', style=lambda r: (pp.Style(overstrike=True)
                                             if (r['id'].value() ^ 4) % 2 == 0
                                             else None))