<?xml version="1.0"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
   <channel>
      <pubDate>Fri, 29 Aug 2008 22:06:05 GMT</pubDate>
      <lastBuildDate>Fri, 29 Aug 2008 22:06:05 GMT</lastBuildDate>
      <language>en</language>
      <docs>http://www.rssboard.org/rss-specification</docs>
      <title>CrunchBang ~ python</title>
      <link>http://crunchbang.org/tags/python/</link>
      <description>Code, Design &amp; GNU/Linux</description>

<item>
    <title>Openbox Logout, Reboot &amp; Shutdown Script</title>
    <link>http://crunchbang.org/archives/2008/04/01/openbox-logout-reboot-and-shutdown-script/</link>
    <pubDate>Tue, 01 Apr 2008 19:23:34 GMT</pubDate>
    <dc:creator>Philip Newborough</dc:creator>
    <guid>http://crunchbang.org/archives/2008/04/01/openbox-logout-reboot-and-shutdown-script/</guid>
    <description><![CDATA[
    <p>I have been using the latest <a href="http://icculus.org/openbox/index.php/Main_Page " title="Openbox - A standards compliant light-weight extensible window manager.">Openbox</a> release [<em>3.4.7-pre2</em>] for the last few weeks and so far I have been impressed. One of the new features from the latest release is a <a href="http://www.gnome.org/projects/gdm/ " title="GDM - The GNOME Display Manager">GDM</a> control script. The script basically allows for a user to send reboot and shutdown signals to GDM from within the Openbox environment. This provides a means to reboot/shutdown an Openbox system in a clean and efficient manner.</p>

<p><img alt="Screenshot of Openbox logout, reboot, shutdown script." src="http://crunchbang.org/uploads/040108135523-openbox-logout-reboot-shutdown.png" /></p>

<p>I have written the following <a href="http://www.pygtk.org/ " title="PyGTK: GTK+ for Python">PyGTK</a> script to take advantage of the new GDM control. Python is not currently a language that I am too familiar with, so please feel free to <strike>rip the script to bits</strike> improve as you see fit.</p>

<pre><code>#!/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 &amp;&amp; openbox --exit")

    # Shutdown
    def shutdown(self, widget):
        os.system("gdm-control --shutdown &amp;&amp; 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)

        # 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 main():
    gtk.main()

if __name__ == "__main__":
    gogogo = DoTheLogOut()
    main()
</code></pre>

    <p style="font-size:smaller;">Tags: <a href="http://crunchbang.org/tags/code/" title="Browse all posts tagged with &#8220;code&#8221;">code</a>, <a href="http://crunchbang.org/tags/crunchbanglinux/" title="Browse all posts tagged with &#8220;crunchbanglinux&#8221;">crunchbanglinux</a>, <a href="http://crunchbang.org/tags/openbox/" title="Browse all posts tagged with &#8220;openbox&#8221;">openbox</a>, <a href="http://crunchbang.org/tags/python/" title="Browse all posts tagged with &#8220;python&#8221;">python</a></p>
    ]]></description>
</item>

 </channel>
</rss>