SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2011-03-08 18:27:50

ali
#! Die Hard
Registered: 2010-05-31
Posts: 1,035

openbox-logout exit on escape

here's a small tweak for the openbox-logout script

to exit the openbox-logout script when pressing 'escape' add these lines outside of the DoTheLogout class

def capture_key(dialog, event):
    if event.keyval == gtk.keysyms.Escape:
        gtk.main_quit()

and this one anywhere after the gtk.Window was created

        self.window.connect("key-press-event", capture_key)

here's the whole script

#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk
import os

class DoTheLogOut:

    # Cancel/exit
    def delete_event(self, widget, event, data=None):
        gtk.main_quit()
        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")

    def __init__(self):
        # Create a new window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_title("Exit? Choose an option:")
        self.window.set_resizable(False)
        self.window.set_position(1)
        self.window.connect("delete_event", self.delete_event)
        self.window.set_border_width(20)
        self.window.connect("key-press-event", capture_key)

        # Create a box to pack widgets into
        self.box1 = gtk.HBox(False, 0)
        self.window.add(self.box1)

        # Create cancel button
        self.button1 = gtk.Button("_Cancel")
        self.button1.set_border_width(10)
        self.button1.connect("clicked", self.delete_event, "Changed me mind :)")
        self.box1.pack_start(self.button1, True, True, 0)
        self.button1.show()

        # Create logout button
        self.button2 = gtk.Button("_Log out")
        self.button2.set_border_width(10)
        self.button2.connect("clicked", self.logout)
        self.box1.pack_start(self.button2, True, True, 0)
        self.button2.show()

        # Create reboot button
        self.button3 = gtk.Button("_Reboot")
        self.button3.set_border_width(10)
        self.button3.connect("clicked", self.reboot)
        self.box1.pack_start(self.button3, True, True, 0)
        self.button3.show()

        # Create shutdown button
        self.button4 = gtk.Button("_Shutdown")
        self.button4.set_border_width(10)
        self.button4.connect("clicked", self.shutdown)
        self.box1.pack_start(self.button4, True, True, 0)
        self.button4.show()

        self.box1.show()
        self.window.show()

def capture_key(dialog, event):
    if event.keyval == gtk.keysyms.Escape:
        gtk.main_quit()
        
def main():
    gtk.main()

if __name__ == "__main__":
    gogogo = DoTheLogOut()
    main()

Last edited by ali (2011-03-08 18:31:12)

Offline

Help fund CrunchBang, donate to the project!

#2 2011-03-08 18:49:03

Tunafish
#! Die Hard
From: the Netherlands
Registered: 2010-03-07
Posts: 1,204

Re: openbox-logout exit on escape

Nice! Works great!


sed 's/stress/relaxation/g'
Privacy & Security on #!

Offline

#3 2011-03-08 18:52:53

ali
#! Die Hard
Registered: 2010-05-31
Posts: 1,035

Re: openbox-logout exit on escape

glad to know i'm not the only one enjoying this new feature

Offline

#4 2011-08-29 19:45:03

bldninja
New Member
Registered: 2011-08-26
Posts: 5

Re: openbox-logout exit on escape

hm, wrong post

Last edited by bldninja (2011-08-29 19:47:51)


- bldninja ----------------------------------------------------------------
Asus-Eee-901-Linux-White%&/(¤%&/¤%&/)(//#¤%&#¤&§¤%&//#¤
Kingston 2GB RAM+Runcore 32GB SDD+ASUS-PHISON 16GB SDD

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo