On Tuesday 04 November 2008 11:58:54 am Paul McNett wrote:
> johnf wrote:
> > On Tuesday 04 November 2008 11:38:25 am Paul McNett wrote:
> >> johnf wrote:
> >>> It took a long time to figure out find the root cause. Even now I'm
> >>> unsure that we are going about this correctly. But this function is
> >>> required - somehow we need to be able to change the screen view from
> >>> pounds to kilos.
> >>
> >> In my app the user can choose millimeters or inches for unit_of_measure.
> >> They make the choice from a dropdown list, and immediately all
> >> length/width fields recalculate and update. I don't recall this being
> >> difficult, so if you are still struggling getting this updating to
> >> happen, perhaps you should post some code to show us what you've tried?
> >>
> >> The biggest issue for me is the rounding errors that occur when
> >> converting from 1-31/32 to millimeters, when they only want millimeters
> >> to the tenth place. Converting back to inches can make it round to 2 or
> >> 1-15/16. But I don't have any screen update issues like you seem to be
> >> struggling with.
> >>
> >> Paul
> >
> > The math is not even an issue. That is always right. It's the display
> > that is causing us grief. Could you post your code that changes the
> > screen. Our code is this long winded thing. I should tell you that our
> > code actually does three things.
> >
> > 1. displays pounds and oz in two text boxes one for pounds and one for oz
> > 2. displays kilos if greater than 1000g
> > 3. displays grams if not a kilo.
> >
> > Maybe not the code but the approach?
>
> Here's the relevant code:
> {{{
> 62 class DrpUOM(dabo.ui.dDropdownList):
> 63 def initProperties(self):
> 64 self.ValueMode = "Key"
> 65 self.Choices = ['Inches', 'Millimeters']
> 66 self.Keys = {"inches":0, "millimeters":1}
> 67
> 68 def onHit(self, evt):
> 69 biz = self.Form.Bizobj
> 70 uom_opening = biz.Record.unit_of_measure
> 71 if self.Value == uom_opening:
> 72 return
> 73
> 74 def okay(first, second):
> 75 return dabo.ui.areYouSure("You need to review the opening
> carefully after converting the unit "
> 76 "of measure. Are you sure you want to convert this
> opening from %s to %s at this time?"
> 77 % (first, second), cancelButton=False)
> 78
> 79 if self.Value == "inches" and uom_opening == "millimeters":
> 80 convert_from, convert_to = "millimeters", "inches"
> 81 elif self.Value == "millimeters" and uom_opening in ("inches",
> ""): 82 convert_from, convert_to = "inches", "millimeters"
> 83
> 84 if okay(convert_from, convert_to):
> 85 biz.convert_uom(convert_to)
> 86 self.Form.update_sizes()
> 87 self.Form.setUnitOfMeasure()
>
> 477 def update_sizes(self):
> 478 biz = self.Bizobj
> 479 if not getattr(self, "txtWidth", None) or not biz or
> biz.RowCount < 1: 480 return
> 481
> 482 self.txtWidth.update()
> 483 self.txtHeight.update()
> 484
> 485 biz.updateNetSize()
> 486 self.update_calculator()
>
> Paul
Immediately I see a major difference in the approach. Larry is setting a
dynamic property to trigger the changes. DynamicSelectedPageNumber is
setting what is visible on the screen.
def afterInit(self):
self.Sizer = hs = dabo.ui.dSizer("v")
pageFrame = pgf =
RAConvpgf(self,DynamicSelectedPageNumber=self.GetDisplayMode,RegID=self.PgfID)
pgf.appendPage(pgCls=RAKiloPanel)
pgf.appendPage(pgCls=RAGramPanel)
pgf.appendPage(pgCls=RALbsPanel)
pgf.appendPage(pgCls=RACntPanel)
hs.append(pgf, 1,"x")
def GetDisplayMode(self):
if self.RegID=='test':
pass
#try:
if self.TrackbyBizObj is None:
o=self.Form.PrimaryBizobj
else:
o=self.TrackbyBizObj
try:
ntrackby=o.getFieldVal('ntrackby')
except:
ntrackby=-1
if ntrackby>=0:
if ntrackby == 0: #weight
#ConvDisplayPage
#0=Kilos
#1=Grams
#2=Pounds
#3=Count
if self.RAConvpgf.BaseValue is None:
self.RAConvpgf.BaseValue=0
if self.Nolbs or (self.Application.WtDisplayMode == 1 or
(self.RAConvpgf.BaseValue >0 and self.RAConvpgf.BaseValue < 29)): #0=Pounds
1=Kilos
if abs(self.RAConvpgf.BaseValue)<1000 and not
self.Nograms:
nPage=1 #grams
else:
nPage=0 #kg
else:
nPage=2 #lbs
else:
nPage=3 #seed cnt
self.update()
else:
nPage=2
return(nPage)
--
John Fabiani
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/[EMAIL PROTECTED]