Thursday, June 23, 2011

#! Crunchbang Statler - Enable Suspend Button on Exit

A few moons ago, I posted how to create a button for #! for suspend the computer on exit, but in those days, Crunchbang was based on Ubuntu, and the software worked diferent.

In the present time, Crunchbang is debian based, so things change a little

The "Exit" command on the openbox main menu opens several buttons so one can choose, those command are:

Cancel, Logout, Reboot and Shutdown

So suspend is out of the list.... those commands are all commands for gdm-control, but gdm-control for suspend is only possible after doing logout, but I wanted to suspend inside the session, so we have to do the trick in other way...

After taking a look at xfce-power-manager, it has suspend function, and after a litle dbus introspection, I found the correct message ( for dbus that does the trick once xfce-power-manager api supports freedesktop directives (I'm not an expert on any of these things, I just catched some lines here and there)


dbus-send \
--session \
--dest=org.freedesktop.PowerManagement \
--type=method_call \
--print-reply \
--reply-timeout=2000 \
/org/freedesktop/PowerManagement \

So, for our How-to....

1 - on a command line sudo gedit /usr/bin/openbox-logout

2 - Change the file where bold text is the new text to add


#!/usr/bin/env python


import pygtk


import gtk

import os


class DoTheLogOut:


    # Cancel/exit

    def delete_event(self, widget, event, data=None):


        return False


    # Logout

    def logout(self, widget):

        os.system("openbox --exit")


    # Reboot

    def reboot(self, widget):

        os.system("gdm-control --reboot && openbox --exit")


    # Shutdown

    def shutdown(self, widget):

        os.system("gdm-control --shutdown && openbox --exit")


    # Suspend

    def suspend(self, widget):

        os.system("dbus-send --session --dest=org.freedesktop.PowerManagement --type=method_call --print-reply --reply-timeout=2000 /org/freedesktop/PowerManagement org.freedesktop.PowerManagement.Suspend")


    def __init__(self):

        # Create a new window

        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)

        self.window.set_title("Exit? Choose an option:")



        self.window.connect("delete_event", self.delete_event)



        # Create a box to pack widgets into

        self.box1 = gtk.HBox(False, 0)



        # Create cancel button

        self.button1 = gtk.Button("_Cancel")


        self.button1.connect("clicked", self.delete_event, "Changed me mind :)")

        self.box1.pack_start(self.button1, True, True, 0)


        # Create logout button

        self.button2 = gtk.Button("_Log out")


        self.button2.connect("clicked", self.logout)

        self.box1.pack_start(self.button2, True, True, 0)


        # Create reboot button

        self.button3 = gtk.Button("_Reboot")


        self.button3.connect("clicked", self.reboot)

        self.box1.pack_start(self.button3, True, True, 0)


        # Create shutdown button

        self.button4 = gtk.Button("_Shutdown")


        self.button4.connect("clicked", self.shutdown)

        self.box1.pack_start(self.button4, True, True, 0)


        # Create suspend button

        self.button5 = gtk.Button("Sus_pend")


        self.button5.connect("clicked", self.suspend)

        self.box1.pack_start(self.button5, True, True, 0)




def main():



if __name__ == "__main__":

    gogogo = DoTheLogOut()


3 - Save the file, and there you go


Hope this is any good for anyone, as it is for me... You can always configure xfce-power-manager to suspend when you do some action, as "close lid" "press power button" etc, etc....

Friday, June 3, 2011

Treepad Alternative - Cherrytree

After a few months I'm back on my writings... My 7 months old daughter take my breath and my time away...

So today I'll be writing about a wonderful project from an Italian programmer, named Giuseppe (aka Giuspen).

As you may notice from the title, Cherrytree is a Treepad alternative, a hierarchical note taking application, and a very good one. It has a lot of advantages comparing to treepad:

1 - It's Open Source and Linux is supported natively
2 - It supports Images, tables and other rich text features
3 - Export to html
4 - Import from treepad and other alike
5 - Syntax highlighting
6 - Save all stuff in a single file

The project is supported by various translators (including me in Portuguese, not completed yet), and others are welcome.

The application runs real fast, can be docked to notification area, and it opens the last saved file. Recently it also allows multiple instances.

Giuspen, has a lot of ideas for making Cherrytree even better. If I could code as good as he, sure I'll give him a boost in Cherrytree, the program I use everyday for taking personal notes, and for work.

Finally one last taught about cherrytree.... What if Debian or Ubuntu packed it in repositories? I believe it would be great for most users that are not aware of this wonderful piece of software.
Made in Portugal