On Tue, Dec 17, 2013 at 1:09 PM, Qas K <[email protected]> wrote:
> Thanks for you help, that did solve the problem.
>
> I looked at the code to see if there was any difference between *value *and
> *_value*. I don't understand why *value* is a simple wrapper around
> *_value*; I don't see the reason for the existence of *_value*. Does
> anyone know why this is the case?
>
I guess _value , as a list of characters, simplifies the on_key_press
handler.
It is an implementation detail.
A second look at the EntryMenuItem code suggest that instead of
1. Change the_entry_menu_item._value
2. call the_entry_menu_item._calculate_value()
it would be more correct to
1. Change the_entry_menu_item.value
2. call the_entry_menu_item._calculate_value()
Here the property .value would care to modify ._value
>
> I have also made a minor alteration to show how to do this in the
> documentation. I'm unfamiliar with how to submit this as a patch so I'll
> just post it here:
>
For small patches like this the easy way is:
1. checkout the svn repo
2. modify as desired
3. from the top dir of your checkout do a
svn diff -u >recognizable_name.patch
4. attach that file in a mail or an issue.
>
> *cocos/menu.py, line 629:*
>
>> class EntryMenuItem(MenuItem):
>> """A menu item for entering a value.
>>
>> When selected, ``self.value`` is toggled, the callback function is
>> called with ``self.value`` as argument.
>>
>> To alter the value in the callback function, do the following:
>> 1. Alter _value (which is a list) to what you want, eg.
>> menu_item._value = list("New")
>> 2. Call menu_item._calculate_value()"""
>>
>
>
>
I'm not sure this will work in the general case: the callback is called
from _calculate_value, so you risk to enter an endless loop.
To avoid that, we can change to:
def _calculate_value(self, use_callback=True):
...
if use_callback:
self.callback_func(self.value)
Then, if you want to change value in the callback, you do and call
._update_value with use_callback=False
The docstring then could hint at this usage.
A more clean option would be to move the call to callback to the top:
def _calculate_value( self ):
self.callback_func(self.value)
new_text = u"%s %s" % (self._label, self.value)
self.item.text = new_text
self.item_selected.text = new_text
This way is unnecessary to call _calculate_value from the callback.
I would like to commit the later, any one has a use case that will break ?
--
You received this message because you are subscribed to the Google Groups
"cocos2d discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cocos-discuss.
For more options, visit https://groups.google.com/groups/opt_out.