Miguel Lopes wrote:
> On Mon, Jul 27, 2009 at 2:05 PM, Paul McNett<[email protected]> wrote:
>> Miguel Lopes wrote:
>>> This case maybe special because the form is loaded from a cdxml file.
>>> Note that properties are not being set in the class designer (as per
>>> my email above).
>>>
>>> In this case dropdownList properties are being set in the afterInitAll
>>> cdxml form method. The code is:
>>>
>>> def afterInitAll(self):
>>>       _valueListProvider = self.Application.getAppInfo('valueListProvider')
>>>       vlKeys, vlChoices = 
>>> _valueListProvider.getKeysAndChoices('contact_title')
>>>       dropDown = self.getObjectByRegID("dlTitle")
>>>       dropDown.DataSource="contact"
>>>       dropDown.DataField="title_id"
>>>       dropDown.Keys = vlKeys
>>>       dropDown.Choices = vlChoices
>>>       dropDown.ValueMode="Key"      # if both commented runs ok - but not
>>> in 'key' valueMode
>>>       dropDown.Value = vlKeys[0]       # if both commented runs ok - but
>>> not in 'key' valueMode
>> What happens with:
>>
>> def afterInitAll(self):
>>        ...
>>        dropDown.Keys = vlKeys
>>        dropDown.Choices = vlChoices
>>        dropDown.ValueMode = "key"
>>        print self.getBizobj("contact")
>>        dropDown.DataSource = "contact"
>>        dropDown.DataField = "title_id"
>>        print "choices", dropDown.Choices
>>        print "keys", dropDown.Keys
>>
>>
>> After typing the above I just re-read your original post, and see that
>> the offending line is where you set dropDown.Value = vlKeys[0]. You
>> generally don't want to do that, because the Value is coming from the
>> bizobj and you are setting it to an arbitrary value which would get
>> saved to the bizobj.
> 
> The dropDown.ValueMode = "key" has also been an offending line from
> the beginning.
> 
>> However, you should be able to do that if you really want to, if the key
>> is present in the choices. Otherwise, you'll get the error you
>> originally reported. So, please still run with the above changes and
>> let's see what the choices and keys are.
>>
>> Paul
>>
> 
> The print is:
> <biz.ContactBizobj.ContactBizobj (baseclass dabo.biz.dBizobj, id:439330288)>
> choices [u'Sr.', u'Sr.\xaa', u'Arq.', u'Arq.\xaa', u'Eng.',
> u'Eng.\xaa', u'Dr.', u'Dr.\xaa']
> keys [25, 24, 23, 22, 21, 20, 19, 18]
> 
> The traceback is the same as before:
> Traceback (most recent call last):
>   File 
> "//usr/local/lib/wxPython-unicode-2.8.9.2/lib/python2.5/site-packages/wx-2.8-mac-unicode/wx/_misc.py",
> line 1342, in Notify
>     self.notify()
>   File 
> "//usr/local/lib/wxPython-unicode-2.8.9.2/lib/python2.5/site-packages/wx-2.8-mac-unicode/wx/_core.py",
> line 14676, in Notify
>     self.result = self.callable(*self.args, **self.kwargs)
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/dabo/ui/uiwx/dForm.py",
> line 123, in __update
>     super(BaseForm, self).update()
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/dabo/ui/uiwx/dPemMixin.py",
> line 1244, in update
>     self.raiseEvent(dEvents.Update)
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/dabo/ui/uiwx/dPemMixin.py",
> line 949, in raiseEvent
>     super(dPemMixin, self).raiseEvent(eventClass, nativeEvent, *args, 
> **kwargs)
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/dabo/lib/eventMixin.py",
> line 93, in raiseEvent
>     bindingFunction(event)
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/dabo/ui/uiwx/dPemMixin.py",
> line 1225, in __onUpdate
>     self.update()
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/dabo/ui/uiwx/dPemMixin.py",
> line 1244, in update
>     self.raiseEvent(dEvents.Update)
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/dabo/ui/uiwx/dPemMixin.py",
> line 949, in raiseEvent
>     super(dPemMixin, self).raiseEvent(eventClass, nativeEvent, *args, 
> **kwargs)
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/dabo/lib/eventMixin.py",
> line 93, in raiseEvent
>     bindingFunction(event)
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/dabo/ui/uiwx/dPemMixin.py",
> line 1225, in __onUpdate
>     self.update()
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/dabo/ui/dDataControlMixinBase.py",
> line 97, in update
>     self.__dataUpdate()
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/dabo/ui/dDataControlMixinBase.py",
> line 114, in __dataUpdate
>     self.Value = src.getFieldVal(self.DataField)
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/dabo/ui/uiwx/dControlItemMixin.py",
> line 380, in _setValue
>     self.KeyValue = value
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/dabo/ui/uiwx/dControlItemMixin.py",
> line 239, in _setKeyValue
>     raise ValueError(_("Trying to set %s.Value to these invalid
> selections: %s") % (self.Name, invalidSelections))
> ValueError: Trying to set dDropdownList1.Value to these invalid selections: 
> [0]
> 
> If we run your code without the line:
> dropDown.ValueMode = "key"
> 
> Then there is no exception raise. But, as expected, the value of the
> "title_id" field does not get recorded to the db, because it is a
> string, not an integer. So there is something wrong with setting
> ValueMode.

The offending line(s) aren't directly causing the traceback. The problem 
appears to be that the bizobj reports that the value of contact.title_id 
is 0.

Do a:

dropDown.Choices.append("---None---")
dropDown.Keys.append(0)

and you should see the traceback disappear.

You probably need to set a sensible default value for title_id in your 
bizobj (one that is one of the choices presented in the list).

Paul



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://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