dcorking / google-wave-resources

Automatically exported from code.google.com/p/google-wave-resources
0 stars 0 forks source link

blip.elements documentation is incorrect #731

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I have a robot written in the v2 Python API that listens to the 
GadgetStateChanged event. I access 
the gadget element in the event handler like this:

def on_gadget_state_changed(event, wavelet):
  gadget_index = event.index
  gadget = event.blip.elements[gadget_index]
  ...

If the gadget is inserted in any blip other than the root (top) blip, 
everything works fine. However, 
if I insert the gadget in the first top blip of the wavelet, I get an 
"IndexError: list index out of 
range" when accessing the event.blip.elements list. 

The appengine debug log shows that the following was transmitted to the robot:

Incoming: 
{"events":[{"type":"GADGET_STATE_CHANGED","modifiedBy":"kreichgauer@wavesandbox.
com","tim
estamp":1271257193486,"properties":{"blipId":"b+smWwhR4eB","index":17,"oldState"
:{}}}],"wavele
t":  . . . 

"index":17 is, what event.index is initialized with in the GadgetStateChanged 
event constructor. If 
I print the event.blip.elements list, its length is only 5 and the gadget's 
index is 1:

 [<waveapi.element.Line object at 0x865f4d449f02d180>, <waveapi.element.Gadget object at 
0x865f4d449f02d780>, <waveapi.element.Line object at 0x865f4d449f02d640>, 
<waveapi.element.Line object at 0x865f4d449f02d7c0>, <waveapi.element.Line 
object at 
0x865f4d449f02d600>]

I assume this is an issue with the wave server, transmitting an incorrect index 
in this case.

Original issue reported on code.google.com by Kreichga...@gmail.com on 14 Apr 2010 at 3:20

GoogleCodeExporter commented 9 years ago
I believe this is due to our mis-documentation of blip.elements().

Per: http://code.google.com/p/wave-robot-python-
client/source/browse/trunk/src/waveapi/blip.py
elements() actually returns the values() of an index->Element dictionary, so it 
returns the list of Element's only.
If you want to access via index, you should try using 
blip._elements[gadget_index].

Please try that out and report back if it doesn't work.

We will fix up the docs.

Original comment by pamela.fox on 22 Apr 2010 at 12:48