This forum has been archived. All content is frozen. Please use KDE Discuss instead.

[SOLVED] Battery Charge Plotting at set intervals

Tags: None
(comma "," separated)
screamnAbdab
Registered Member
Posts
5
Karma
0
(Newbie alert!!!)
I would like to create a battery charge charting plasmoid that updates the plotter at set intervals.

I currently have a plotter working but, from what I can tell, the data engine only calls "dataUpdated" when the charge changes. This makes for a rather linear graph which does not indicate change in charge over time. From what I can tell, this is to be expected since the documentation for dataEngine states the following concerning the pollingInterval:
"If the data has not changed, no update will be sent. "

So, I'm hoping someone could give me some guidance on how to capture and plot change of charge over time.

By the way, I am building on the plasmoid from "getting started with python plasma tutorial". The following is some simple code illustrating how I currently am using the dataengine:

def connectToEngine(self):
self.engine = self.dataEngine('soliddevice')
battery = self.engine.query('IS Battery').values()[0].toString()
print "Connecting to battery %s"%battery
self.engine.connectSource(battery, self)

@pyqtSignature("dataUpdated(const QString &, const Plasma::DataEngine::Data &)")
def dataUpdated(self, sourceName, data):
charge = data[QString("Charge Percent")].toInt()[0]
print "Charge: %s%%"%charge
samples = [charge,]
self.chart.addSample(samples)


Thanks for any help!
Ben
screamnAbdab
Registered Member
Posts
5
Karma
0
screamnAbdab wrote:(Newbie alert!!!)
I would like to create a battery charge charting plasmoid that updates the plotter at set intervals.

I currently have a plotter working but, from what I can tell, the data engine only calls "dataUpdated" when the charge changes. This makes for a rather linear graph which does not indicate change in charge over time. From what I can tell, this is to be expected since the documentation for dataEngine states the following concerning the pollingInterval:
"If the data has not changed, no update will be sent. "

So, I'm hoping someone could give me some guidance on how to capture and plot change of charge over time.

By the way, I am building on the plasmoid from "getting started with python plasma tutorial". The following is some simple code illustrating how I currently am using the dataengine:

def connectToEngine(self):
self.engine = self.dataEngine('soliddevice')
battery = self.engine.query('IS Battery').values()[0].toString()
print "Connecting to battery %s"%battery
self.engine.connectSource(battery, self)

@pyqtSignature("dataUpdated(const QString &, const Plasma::DataEngine::Data &)")
def dataUpdated(self, sourceName, data):
charge = data[QString("Charge Percent")].toInt()[0]
print "Charge: %s%%"%charge
samples = [charge,]
self.chart.addSample(samples)


Thanks for any help!
Ben


Well, it looks like I implemented this easy enough... Just used a "time" dataEngine source to manage the plotter update at set intervals. The battery datasource just updates the charge value to be used when plotting.

Out of curiosity now... is there a better way to do it?

Thanks again!
Ben
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Other than using the time dataengine, you could have used a QTimer which actvated every x seconds / minutes.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]


Bookmarks



Who is online

Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]