#!/usr/bin/env python
#
# $Id: shuttdown.py,v 1.1 2009/01/11 08:01:57 guru Exp $

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

class XsetBlank:

    # Our callback for Yes, reboot
    #
    def callback(self, widget, data=None):
        os.system("/sbin/reboot")
        gtk.main_quit()

    # another callback, for No. exit
    def delete_event(self, widget, event, data=None):
        gtk.main_quit()
        return False

    def __init__(self):
        # Create a new window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)

        # set the title
        #
        self.window.set_title("/sbin/reboot")

        # Here we just set a handler for delete_event that immediately
        # exits GTK.
        #
        self.window.connect("delete_event", self.delete_event)

        # Sets the border width of the window.
        #
        self.window.set_border_width(20)

        # We create a Vbox to pack two Hbox into.
        #
        self.vbox1 = gtk.VBox(homogeneous=False, spacing=5)

        # Put the Vbox into the main window.
        #
        self.window.add(self.vbox1)

        # create 2 HBox and put it into the VBox
        self.hbox0 = gtk.HBox(homogeneous=False, spacing=15)
        self.hbox1 = gtk.HBox(homogeneous=False, spacing=15)
        self.vbox1.pack_start(self.hbox0)
        self.vbox1.pack_start(self.hbox1)

        # Add a Image                                      
        # 
        # self.stat_image = gtk.Image()                               
        # self.stat_image.set_from_file("/usr/share/pixmaps/SandClock200.png")
        # self.hbox0.pack_start(self.stat_image)
        # self.stat_image.show()   


        # Add a label                                                   
        self.instrucction_label = gtk.Label("The proc events/0 run away and\nthe CPU will drain the battery.\n\nReboot now?")
        self.hbox0.pack_start(self.instrucction_label)                              
        self.instrucction_label.show()                                         


        # Creates a new button with the label "Button 1".
        self.button1 = gtk.Button("Yes")

        # Now when the button is clicked, we call the "callback" method
        # with a pointer to "button 1" as its argument
        self.button1.connect("clicked", self.callback, "")

        # Instead of add(), we pack this button into the invisible
        # box, which has been packed into the window.
        self.hbox1.pack_start(self.button1, True, True, 0)

        # Always remember this step, this tells GTK that our preparation for
        # this button is complete, and it can now be displayed.
        self.button1.show()

        # Do these same steps again to create a second button
        self.button2 = gtk.Button("No")

        # Call the same callback method with a different argument,
        # passing a pointer to "button 2" instead.
        self.button2.connect("clicked", self.delete_event, "")

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

        # The order in which we show the buttons is not really important, but I
        # recommend showing the window last, so it all pops up at once.
        self.button2.show()
        self.hbox0.show()
        self.hbox1.show()
        self.vbox1.show()
        self.window.show()

def main():
    gtk.main()

if __name__ == "__main__":
    xset = XsetBlank()
    main()
