Fwd: bug in python plasmoid tutorial

Jean Pierre Charalambos nakednous at gmail.com
Fri Sep 18 22:40:52 CEST 2009


On Friday 18 September 2009 02:41:08 pm Aaron J. Seigo wrote:
> On September 18, 2009, Matt Williams wrote:
> > http://osdir.com/ml/plasma-devel/2009-08/msg00220.html
> 
> the real problem there looks like:
> 
> charge = data[QString("Charge Percent")].toInt()[0]
> 
> is trying to treat toInt() as returning an array. i'm not a pythonista, but
> i'd expect the correct code to be:
> 
> charge = data[QString("Charge Percent")][0].toInt()

I tried it this, but actually data[QString("Charge Percent")] is returning an 
int, i.e.,

ERROR: syntax error
Traceback (most recent call last):
  File "/home/pierre/projects/plasmoids/python-battery/contents/code/main.py", 
line 36, in dataUpdated
    charge = data[QString("Charge Percent")][0].toInt()
TypeError: 'int' object is unsubscriptable

The workaround is to change the line to (as pointed elsewhere): charge = 
data[QString("Charge Percent")] and forget about the error messages. Really 
nice to seeing it working here :)

Anyway I'm not a pythonista either but I still don't get it: one expect data[] 
to be returning a QVariant: http://api.kde.org/4.3-api/kdelibs-
apidocs/plasma/html/classPlasma_1_1DataEngine.html#aee149bf52a3c74c29a04b0563a2be26f
Perhaps there's an error in the api docs? Once we clarify this I can update 
the tutorial text :)

Cheers,

Jean Pierre

-- 
A selection from the Taoist Writings:

"Lao-Tan asked Confucius: `What do you mean by benevolence and righteousness?'
 Confucius said:  `To be in one's inmost heart in kindly sympathy with all
 things; to love all men and allow no selfish thoughts: this is the nature
 of benevolence and righteousness.'"
		-- Kwang-tzu

> 
> > connecting to battery
> > /org/freedesktop/Hal/devices/computer_power_supply_battery_C1F3
> > Unrecognized character: /
> > Unrecognized character: /
> > ERROR: syntax error
> > Charge: 80%
> > Object::disconnect: No such slot
> > QObject::dataUpdated(QString,Plasma::DataEngine::Data)
> > Object::disconnect:  (sender name:
> > '/org/freedesktop/Hal/devices/computer_power_supply_battery_C1F3')
> 
> none of these are actually fatal or even errors afaik.
> 


More information about the Plasma-devel mailing list