[buug] Homemade shutdown widget
Ian Zimmerman
itz at buug.org
Thu Apr 16 22:25:51 PDT 2009
Someone asked about this tonight.
$ cat /usr/local/sbin/shutdown.glade
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.5 on Sat Dec 27 22:37:28 2008 -->
<glade-interface>
<widget class="GtkDialog" id="top_dialog">
<property name="border_width">5</property>
<property name="title" translatable="yes">Shutdown</property>
<property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<signal name="destroy" handler="on_top_dialog_destroy"/>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="spacing">2</property>
<child>
<widget class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="label" translatable="yes">Push the appropriate button to shut down.</property>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="single_user_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="label" translatable="yes">_Single User</property>
<property name="use_underline">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_single_user_button_clicked"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="reboot_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="label" translatable="yes">_Reboot</property>
<property name="use_underline">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_reboot_button_clicked"/>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="halt_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="label" translatable="yes">_Halt</property>
<property name="use_underline">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_halt_button_clicked"/>
</widget>
<packing>
<property name="position">2</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>
$ cat /usr/local/sbin/shutdown.py
#! /usr/bin/env python
import gtk
import gtk.glade
import os
class ShutdownReactor(object):
def on_halt_button_clicked(self, b):
os.system('shutdown -h now')
def on_reboot_button_clicked(self, b):
os.system('shutdown -r now')
def on_single_user_button_clicked(self, b):
os.system('telinit 1')
def on_top_dialog_destroy(self, d):
gtk.main_quit()
if __name__ == '__main__':
xml = gtk.glade.XML('/usr/local/sbin/shutdown.glade')
xml.signal_autoconnect(ShutdownReactor())
w = xml.get_widget('top_dialog')
w.show_all()
gtk.main()
$ cat /etc/X11/xdm/Xsetup
#!/bin/sh
#
# $Id$
#
# This script is run as root before showing login widget.
#xsetroot -solid rgb:8/8/8
hsetroot -tile /usr/local/share/sky-1280x1024.jpg
xconsole -geometry +0-0 &
/usr/local/sbin/shutdown.py &
echo "$!" > /var/run/shutdown.py.pid
(I actually only want this with the login dialog, so I kill it
in /etc/X11/xdm/Xstartup ; that's why I save the pid. But you
don't have to do that, and it will persist into your session.)
hth
--
Ian Zimmerman <itz at buug.org>
gpg public key: 1024D/C6FF61AD
fingerprint: 66DC D68F 5C1B 4D71 2EE5 BD03 8A00 786C C6FF 61AD
Ham is for reading, not for eating.
More information about the buug
mailing list