Development/Tutorials/SuperKaramba: Difference between revisions

    From KDE TechBase
    (Initial version)
     
    No edit summary
    Line 2: Line 2:


    [http://netdragon.sourceforge.net SuperKaramba] is a tool that allows one
    [http://netdragon.sourceforge.net SuperKaramba] is a tool that allows one
    to easily create functionality enhancement modules
    to easily create functionality enhancement modules on a [http://www.kde.org KDE desktop]. Such modules are interactive programs written in [http://www.python.org Python] or [http://www.ruby-lang.org/ Ruby] that are usually embedded directly into the background and do not disturb the normal view of the desktop.
    on a [http://www.kde.org KDE desktop]. Such modules are interactive programs
    written in [http://www.python.org Python] or [http://www.ruby-lang.org/ Ruby]
    that are usually embedded directly into the background and do not disturb the normal view
    of the desktop.


    * [http://netdragon.sourceforge.net Homepage]
    * [http://netdragon.sourceforge.net Homepage]
    Line 15: Line 11:
    ==Examples==
    ==Examples==


    SuperKaramba comes with a set of [http://websvn.kde.org/trunk/KDE/kdeutils/superkaramba/examples/ examples
    SuperKaramba comes with a set of [http://websvn.kde.org/trunk/KDE/kdeutils/superkaramba/examples/ examples].
    scripts].


    Let's take a look at one of them, the  
    Let's take a look at one of them, the  
    Line 40: Line 35:
    </pre>
    </pre>


    The initWidget method will be called once if the widget got initialized. Here we setup the RichText widget
    The initWidget method will be called once if the widget got initialized. Here we setup the RichText widget where we display the current time in. The widgetUpdated will be called each second once (the interval is defined in the [http://websvn.kde.org/trunk/KDE/kdeutils/superkaramba/examples/rubyclock/clock.theme?view=markup clock.theme] themefile) and just updates the text display in the RichText widget with the new time.
    where we display the current time in. The widgetUpdated will be called each second once (the interval is
    defined in the [http://websvn.kde.org/trunk/KDE/kdeutils/superkaramba/examples/rubyclock/clock.theme?view=markup clock.theme]
    themefile) and just updates the text display in the RichText widget with the new time.


    Let's take a look at another theme. The [http://websvn.kde.org/trunk/KDE/kdeutils/superkaramba/examples/text/text.py?view=markup text.py]
    Let's take a look at another theme. The [http://websvn.kde.org/trunk/KDE/kdeutils/superkaramba/examples/text/text.py?view=markup text.py] theme written in Python just displays some text widgets. We take this is example to create our own script, that does the same as the [http://websvn.kde.org/trunk/KDE/kdeutils/superkaramba/examples/rubyclock/clock.rb?view=markup clock.rb] above, that is to display the current time within a text widget.
    theme written in Python just displays some text widgets. We take this is example to create our own script, that does
    the same as the [http://websvn.kde.org/trunk/KDE/kdeutils/superkaramba/examples/rubyclock/clock.rb?view=markup clock.rb]
    above, that is to display the current time within a text widget.


    <pre>
    <pre>

    Revision as of 17:21, 21 April 2007

    SuperKaramba

    SuperKaramba is a tool that allows one to easily create functionality enhancement modules on a KDE desktop. Such modules are interactive programs written in Python or Ruby that are usually embedded directly into the background and do not disturb the normal view of the desktop.

    Examples

    SuperKaramba comes with a set of examples.

    Let's take a look at one of them, the clock.rb theme written in Ruby. The theme just displays the current time in a RichText widget.

    require 'karamba'
    
    def initWidget(widget)
        Karamba.resizeWidget(widget, 300, 120)
        @richtext = Karamba.createRichText(widget, Time.now.to_s)
        Karamba.moveRichText(widget, @richtext, 10, 10)
        Karamba.setRichTextWidth(widget, @richtext, 280)
        Karamba.redrawWidget(widget)
    end
    
    def widgetUpdated(widget)
        puts  >> widgetUpdated"
        Karamba.changeRichText(widget, @richtext, Time.now.to_s)
        Karamba.redrawWidget(widget)
    end
    

    The initWidget method will be called once if the widget got initialized. Here we setup the RichText widget where we display the current time in. The widgetUpdated will be called each second once (the interval is defined in the clock.theme themefile) and just updates the text display in the RichText widget with the new time.

    Let's take a look at another theme. The text.py theme written in Python just displays some text widgets. We take this is example to create our own script, that does the same as the clock.rb above, that is to display the current time within a text widget.

    import karamba, time
    
    text = nil
    
    def initWidget(widget):
        text = karamba.createText(widget, 0, 20, 200, 20, "Text meter")
    
    def widgetUpdated(widget):
        t = time.strftime("%Y-%M-%d %H:%M.%S")
        karamba.changeText(widget, text, t)
    

    In the initWidget method we create our text widget that is updated once per second (or per interval as defined in the matching theme file) at the widgetUpdated method to display the new current time.