On Jan 1, 2013, at 2:29 PM, Carey Gagnon <[email protected]> wrote:

> Ok...I finally got it:
> 
> def setDynBackColor(self):
>    red = (255, 0, 0)
>    green = (0, 255, 0)
>    biz = self.getBizobj("dbo.Companies")
>    ds = biz.getDataSet()
>    if len(ds) == 0:
>        pass
>    else:
>        testval = biz.getFieldVal("InactiveCompany")
>        if testval == 0:
>            print "0"
>            dabo.ui.setAfter(self.tbInactiveCompany, "BackColor", red)
>        else:
>            print "1"
>            dabo.ui.setAfter(self.tbInactiveCompany, "BackColor", green)

        Almost!

        You don't set the color (or whatever dynamic prop you are determining) 
in the dynamic function; you simply return the value. Here's how to write the 
method above:

def setDynBackColor(self):
   biz = self.getBizobj("dbo.Companies")
   ds = biz.getDataSet()
   if not biz.RowCount:
        return "white"
   testval = biz.getFieldVal("InactiveCompany")
   if testval:
      return "green"
   else:
      return "red"

        A few general notes:
1) you don't need to get the entire data set of the bizobj in order to check if 
there are records. Instead, just use the bizobj's RowCount property.

2) In Python, testing for empty lists (or tuples, or dicts, or strings) by 
comparing their length to zero is not needed, and is frowned upon. Instead, 
take advantage of the fact that empty lists evaluate to boolean False. In other 
words, these two statements are equivalent, but the second is more Pythonic:
        if len(somelist) == 0:
        # and
        if not somelist:

3) Dabo understands colors! No need to create RGB tuples or HTML hash values; 
if what you need is one of the 150 colors that have standard HTML names, just 
use the name. Check out http://wiki.dabodev.com/ColorExamples for examples of 
all the color names Dabo understands.


-- Ed Leafe

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: 
http://leafe.com/archives/byMID/[email protected]

Reply via email to