Ocean Mist

28 Mar 2009

Python Suspend Applet

Posted by astromme

Yesterday Sebas blogged about his desire for a small plasmoid that would allow him to suspend his computer when the screen is locked.

Since I already wanted an excuse to play around with a Python plasmoid, I decided this would be a cool little applet to code. Turns out that there is a (pending) freedesktop.org interface to power management and PowerDevil implements the important parts of this.

I started out with the great Python+Plasma tutorial and the second one on using the Plasma::Widgets that we know and love from C++. Couple that with the python bindings for dbus, and you’ve got yourself a little applet that suspends your computer at the press of a button.

You can find the applet on kde-look, and it should be present in GHNS as well. (working on this point… for some reason it’s not showing up for me).
Edit: Ok, now it’s showing up. I guess it just took some time.

Subscribe to Comments

8 Responses to “Python Suspend Applet”

  1. Yay! Looks pretty much exactly how I want it, and as a bonus, it has DPMS support :-)

    Now I’ve got an excuse to compile the python plasma bindings, I guess



  2. Cool stuff, thanks ;)
    Just as a suggestion for the next version, center the icons vertically in the buttons, this looks even cooler than aligning at the top



  3. @sebas

    Glad to help =). KDE technologies can be quite easy to work with.

    I think that’s a byproduct of my theme. I didn’t touch anything with icon alignment (And I don’t think Plasma::PushButton has that capability anyways)

    hmm… it actually seems to go away if I resize the applet a bit. I wonder if some layout thing is getting in the way. Wouldn’t be the first time.



  4. nice :)

    one little nitpick: why is “turn display off” in hte middle? I would’ve expected it to be at the top, since it has the smallest effect, with hibernate (the “biggest” change) at the bottom.



  5. No particular reason at all, just the way it was coded. They’re flipped now, you’re right it makes more sense.



  6. It gives me a warm and fuzzy feeling to hear that people are enjoying and producing useful things with the Python support in Plasma. (especially after the turd-sandwich of an email some frustrated user sent me this morning. :-( )

    A small request: Perhaps you could make a small tutorial on techbase explaining the code you use to talk to DBus. That would be handy and I think quite a few people would be interested in it. thanks.


    Simon Edwards

  7. I’ve started a PyKDE4 DBus tutorial here:


    It’s a work in progress for now



  8. Thank you very much for this useful widget!
    I would like to ask you if there is a way to remove some buttons. I want to remove “turn display off” and “hibernate”.
    It would be useful a “settings” button for that.
    Well, I came to your site because I’m not able to use my old desktop icon I made for suspend: a simple widget icon with this command on press : # qdbus org.kde.kded /modules/powerdevil suspend 2
    Since I upgraded to KDE 4.6 that don’t work anymore (this is the error message: Cannot find ‘.suspend’ in object /modules/powerdevil at org.kde.kded.
    Your applet works for me in 4.6.
    Please, can you tell me what command I must use to suspend as user? I very like a very very clean desktop and a simple transparent icon with just a dot as “title” is what I used before and what I want to use..
    Thank you very much for patience! Hope this wasn’t a to long post :)


    Daniel Chiriac

Leave a Reply