summaryrefslogtreecommitdiffstats
path: root/shutdown.py
diff options
context:
space:
mode:
authorFlorian Pritz <f-p@gmx.at>2009-03-17 21:11:39 +0100
committerFlorian Pritz <f-p@gmx.at>2009-03-17 21:11:39 +0100
commit03a36673c7796a2df8c0752e1ae68dcf6d4d0ffd (patch)
treea0d993f192ae813ee9970e2b19e670424744ea99 /shutdown.py
parentf7cffeeff26d2f99803a1e8113c1874dc1186ff0 (diff)
downloadbin-03a36673c7796a2df8c0752e1ae68dcf6d4d0ffd.tar.gz
bin-03a36673c7796a2df8c0752e1ae68dcf6d4d0ffd.tar.xz
moved python scripts
Diffstat (limited to 'shutdown.py')
-rwxr-xr-xshutdown.py97
1 files changed, 97 insertions, 0 deletions
diff --git a/shutdown.py b/shutdown.py
new file mode 100755
index 0000000..6138a79
--- /dev/null
+++ b/shutdown.py
@@ -0,0 +1,97 @@
+#!/usr/bin/env python
+#----------------------------------------------------
+# Version: 0.1.1
+# Author: Florian "Bluewind" Pritz <f-p@gmx.at>
+#
+# Copyright (C) 2008-2009 Florian Pritz
+#
+# Licensed under GNU General Public License v3
+# (see COPYING for full license text)
+#
+#----------------------------------------------------
+# Display a small shutdown Dialog
+#----------------------------------------------------
+# NOTE:
+# Please change the image paths to mach your icons.
+# Otherwise the script will crash.
+
+
+import gtk
+import os
+
+def create_bbox(title=None, spacing=0, layout=gtk.BUTTONBOX_SPREAD):
+ bbox = gtk.VButtonBox()
+
+ bbox.set_spacing(spacing)
+
+ buttons = (('Cancel', 'gtk-cancel'),
+ ('Suspend', 'gnome-session-suspend'),
+ ('Reboot', 'gnome-session-reboot'),
+ ('Halt', 'gnome-session-halt')
+ )
+ for text, stock_id in buttons:
+ image = gtk.Image()
+ image.set_from_stock(stock_id, gtk.ICON_SIZE_LARGE_TOOLBAR)
+ b = gtk.Button(text)
+ b.set_image(image)
+ b.set_data("user_data", text)
+ b.connect("clicked", click, b)
+ b.set_size_request(100, -1)
+ b.set_alignment(0,1)
+ bbox.add(b)
+
+ return bbox
+
+def click(self, button):
+ ret = button.get_data("user_data")
+ self.hide()
+ self.destroy()
+ gtk.main_quit()
+
+ if ret == "Reboot":
+ os.system("sudo shutdown -r now")
+ if ret == "Suspend":
+ os.system("sudo pm-suspend")
+ if ret == "Halt":
+ os.system("sudo shutdown -h now")
+
+class ButtonBox(gtk.Window):
+ def __init__(self, parent=None):
+ # Create the toplevel window
+ gtk.Window.__init__(self)
+ try:
+ self.set_screen(parent.get_screen())
+ except AttributeError:
+ self.connect('destroy', lambda *w: gtk.main_quit())
+
+ self.set_title("Shutdown")
+ #self.set_decorated(False)
+ self.set_position(gtk.WIN_POS_CENTER)
+
+ hbox = gtk.HBox()
+ hbox.set_border_width(10)
+
+ self.add(hbox)
+ hbox.pack_start(create_bbox(None, 8, gtk.BUTTONBOX_START),
+ padding=0)
+
+ self.show_all()
+
+def register_iconsets(icon_info):
+ iconfactory = gtk.IconFactory()
+ stock_ids = gtk.stock_list_ids()
+ for stock_id, file in icon_info:
+ # only load image files when our stock_id is not present
+ if stock_id not in stock_ids:
+ pixbuf = gtk.gdk.pixbuf_new_from_file(file)
+ iconset = gtk.IconSet(pixbuf)
+ iconfactory.add(stock_id, iconset)
+ iconfactory.add_default()
+
+register_iconsets([('gnome-session-suspend', '/usr/share/icons/hydroxygen/128x128/apps/gnome-session-suspend.png'),
+ ('gnome-session-halt', '/usr/share/icons/hydroxygen/128x128/apps/gnome-session-halt.png'),
+ ('gnome-session-reboot', '/usr/share/icons/hydroxygen/128x128/apps/gnome-session-reboot.png')
+ ])
+
+ButtonBox()
+gtk.main()