SuperKaramba and Plasma, Part 2

After providing last time a screenshot and a screencast (2.4MB, mpeg4) of SuperKaramba in action running the Aero AIO theme, here we go with a more concrete sample that connects SuperKaramba and Plasma together.

This Python sample script does use the Plasma TimeEngine to display the current local time - such kind of clock-examples will never end I guess :)

# Import the needed modules.
import karamba, PlasmaApplet
# Fetch the TimeEngine Plasma::DataEngine object.
engine = PlasmaApplet.dataEngine("time")

# We like to update it each second.
engine.setProperty("reportSeconds", True)
# Connect with the TimeEngine's "Local" source.
# This is the richedit widget we use to display something.
text = None
# This method just returns some text to display.
def getText():
    return "%s\n%s" % (PlasmaApplet.name(),engine.query("Local"))
# This method got called by SuperKaramba on initialization.
def initWidget(widget):
    global text
    karamba.resizeWidget(widget, 400, 400)
    text = karamba.createText(widget, 10, 10, 380, 380, getText())
# This method got called by SuperKaramba on update.
def widgetUpdated(widget):
    global text
    karamba.changeText(widget, text, getText())


Wow! You had me at

import PlasmaApplet
engine = PlasmaApplet.dataEngine("time")

I wonder if it's possible to establish signal-slot relationship between time engine changing the second/minute and widgetNotify().

That way I could just use the callbacks to update the clock, instead of waking up all the time and checking the time.

By suslik at Sat, 07/28/2007 - 23:34

Plasma::Applet::dataEngine(const QString&) really makes it easy to access data, that's for sure. it even takes care of ref'ing/deref'ing the engine behind the scenes so the engine gets memory managed properly even thought shared.

as for signal/slot between the engine and the display ... that's the whole point of the updated slot in all the Plasma::Widgets. see my comment above.

By Aaron J. Seigo at Sat, 07/28/2007 - 23:43

probably something like this;

import karamba, PlasmaApplet
def sourceUpdated(source,data):
    karamba.changeText(karamba, text, data["Time"])
engine.connect("sourceUpdated(QString,QVariantMap)", sourceUpdated)

can do the job already. But I'll look more detailed at it within next days, maybe just a compatible updated() functionality for SK ;)

By Sebastian Sauer at Sun, 07/29/2007 - 02:29

Done with commit r694880, see the second sample at the tutorial :)

By Sebastian Sauer at Wed, 08/01/2007 - 02:09

some thoughts:

why not connect the Local source from the time engine to the text edit directly? and then you don't need to do the DataEngine::query (which means hitting the data twice in a row), the getText() method or widgetUpdated for that matter.

if you use a Plasma::LineEdit or Plasma::Label in there, you get this all for free to boot. and if you use a layout (e.g. VBoxLayout) you get nice management of the widget geometry.

you'll also save on the redrawWidget calls as those also happen for free. should cut your example down to .. (*counts*) .. 6 lines of code, 7 if you include the import line. that's less than half of the 15 lines in the example =)

so .. it would look something like:

engine = PlasmaApplet.dataEngine("time")
engine.setProperty("reportSeconds", True)
text = PlasmaLabel(this)
engine.connectSource("Local", text)
layout = PlasmaVBoxLayout(this)

By Aaron J. Seigo at Sat, 07/28/2007 - 23:40

This would need either to turn all the methods Plasma::Widget, Plasma::Label, etc. are providing into Q_PROPERTY/Q_SLOTS/Q_INVOKABLE or to write adaptors for all of them. My personal preference would be the first since it would save code duplications.

or shouldn't scripts be able to manipulate such widgets?

By Sebastian Sauer at Sun, 07/29/2007 - 00:37

Done with commit r693790, following works now too (5 lines of code btw);

import PlasmaApplet
engine = PlasmaApplet.dataEngine("time")
engine.setProperty("reportSeconds", True)
widget = PlasmaApplet.widget("LineEdit")
engine.connectSource("Local", widget)

By Sebastian Sauer at Sun, 07/29/2007 - 02:04