removido
(usa Nenhuma)
Enviado em 20/04/2012 - 21:01h
#!/usr/bin/env python
##
# Script to Exit , logout , reboot , suspend [ gdm / openbox ]
#
#
http://crunchbanglinux.org/forums/topic/295/updated-openboxlogout-script/
# ADcomp -
http://www.ad-comp.be/
##
#~ CMD_LOGOUT = 'openbox --exit'
#~ CMD_REBOOT = 'sudo shutdown -r now'
#~ CMD_SHUTDOWN = 'sudo shutdown -h now'
#~ CMD_SUSPEND = 'echo "pas de commande"'
#~ CMD_HIBERNATE = 'echo "pas de commande"'
CMD_LOGOUT = 'openbox --exit'
CMD_REBOOT = 'dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart'
CMD_SHUTDOWN = 'dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop'
CMD_SUSPEND = 'echo "pas de commande"'
CMD_HIBERNATE = 'echo "pas de commande"'
import gtk
import os
import pwd
from PIL import Image, ImageFilter
class MyApp():
def __init__(self):
self.window = gtk.Window()
self.window.set_title("Log Out ..")
self.window.connect("destroy", self.doquit)
self.window.connect("key-press-event", self.onkeypress)
self.window.set_decorated(False)
self.mainpanel = gtk.Fixed()
self.window.add(self.mainpanel)
self.screen_x , self.screen_y = gtk.gdk.screen_width(), gtk.gdk.screen_height()
x = ( self.screen_x / 2 ) - ( 140 * 4 / 2 ) - 30
y = ( self.screen_y / 2 ) - 100
self.bt_tab = []
## 1st Line
self.add_bouton("application-exit", x+30, y+30, "Cancel")
self.add_bouton("system-log-out", x+170, y+30, "Logout")
self.add_bouton("system-restart", x+310, y+30, "Reboot")
self.add_bouton("system-shutdown", x+450, y+30, "Shutdown")
## 2nd Line
#~ self.add_bouton("application-exit", x+30, y+200, "Cancel")
#~ self.add_bouton("system-suspend", x+170, y+200, "Suspend")
#~ self.add_bouton("system-suspend-hibernate", x+310, y+200, "Hibernate")
self.set_background()
self.bt_tab[3].grab_focus()
def set_background(self):
img_file = "/tmp/root_window.jpg"
w = gtk.gdk.get_default_root_window()
sz = w.get_size()
pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1])
pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1])
if (pb != None):
pb.save(img_file,"jpeg")
image = Image.open(img_file)
color = 'black'
alpha = 0.8
mask = Image.new("RGB", image.size, color)
image = Image.blend(image, mask, alpha)
image.save(img_file,"jpeg")
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(img_file, self.screen_x, self.screen_y)
pixmap, mask = pixbuf.render_pixmap_and_mask()
# width, height = pixmap.get_size()
self.window.set_app_paintable(True)
self.window.resize(self.screen_x, self.screen_y)
self.window.realize()
self.window.window.set_back_pixmap(pixmap, False)
self.window.move(0,0)
del pixbuf
del pixmap
def add_bouton(self, icon, x, y, info):
image = gtk.Image()
image.set_from_file("img/" + icon + ".png")
image.show()
bouton = gtk.Button()
bouton.set_relief(gtk.RELIEF_NONE)
bouton.set_focus_on_click(False)
bouton.set_border_width(0)
#~ bouton.set_property('can-focus', False)
bouton.add(image)
#~ tooltips = gtk.Tooltips()
#~ tooltips.set_tip(bouton, str(info))
bouton.show()
self.mainpanel.put(bouton, x,y)
bouton.connect("clicked", self.clic_bouton, icon)
self.bt_tab.append(bouton)
# Cette fonction est invoquee quand on clique sur un bouton.
def clic_bouton(self, widget, data=None):
if (data=='system-log-out'):
os.system(CMD_LOGOUT)
elif (data=='system-restart'):
os.system(CMD_REBOOT)
elif (data=='system-shutdown'):
os.system(CMD_SHUTDOWN)
elif (data=='suspend'):
os.system(CMD_SUSPEND)
elif (data=='hibernate'):
os.system(CMD_HIBERNATE)
self.doquit()
def onkeypress(self, widget=None, event=None, data=None):
if event.keyval == gtk.keysyms.Escape:
self.doquit()
def doquit(self, widget=None, data=None):
gtk.main_quit()
def run(self):
self.window.show_all()
gtk.main()
#-------------------------
if __name__ == "__main__":
#-------------------------
## need to change directory
SRC_PATH = os.path.dirname( os.path.realpath( __file__ ) )
os.chdir(SRC_PATH)
app = MyApp()
app.run()