SAlut , Voila .; je vous partage un remix ( un tout petit !!)
POMPé Basé 😃 sur les travaux et divers scripts de iggkoopa, adcomp, et nick_doof
Je l'ai simplifié, il ne sert qu'a quitter openbox, redémarrer ou éteindre votre ordinateur.
Il peut utiliser consolekit ou hal via dbus ( si le paquet python-dbus est présent), ou-bien les commandes /sbin/** ( nécessite les droits d'administration , à moins d'avoir modifier votre fichiers sudoers ou d' être root )
Il devrait fonctionner tels quel dans la plupart des cas .;
#!/usr/bin/python
# -*- coding: utf-8 -*-
##
# Script to Exit , logout , reboot [ openbox ]
# Basé sur:
# http://crunchbanglinux.org/forums/topic/295/updated-openboxlogout-script/
# ADcomp - http://www.ad-comp.be/
# Et le paquet OBLOGOUT:
# https://launchpad.net/oblogout/
# Edit 12/10/2010 UUBBUU_user
import gtk
import os, subprocess, sys
import commands
try:
from PIL import Image, ImageFilter
except:
print "PIL missing, install python-imaging"
sys.exit()
UsingDbus = True
try:
import dbus
except:
print "Python DBUS modules missing, please install python-dbus"
answer = raw_input('Usings Defaults (authentication required) ?? (y/n/?) ')
if answer == y :
UsingDbus = False
else :
sys.exit()
## True / False ( only for debbuging )
DEBUG=False
def LogInfo(msg):
if DEBUG:
print( "***** %s" % (msg))
def CheckPkg(pkg):
# checking package on distro
devnull = open(os.devnull,"w")
IsPackage = subprocess.call(["dpkg","-s",pkg],stdout=devnull,stderr=subprocess.STDOUT)
if IsPackage != 0:
return False
else:
return True
devnull.close()
def CheckDaemon(daemon):
devnull = open(os.devnull,"w")
demonIsRunning = subprocess.call(["ps","-ef","|","grep",daemon],stdout=devnull,stderr=subprocess.STDOUT)
if demonIsRunning != 0:
return False
else:
return True
devnull.close()
def checkForCommand(pkg,daemon):
isinstalled = CheckPkg(pkg)
isrunning = CheckDaemon(daemon)
if isinstalled and isrunning:
return True
else:
return False
ICON_LIST = [
("logout", "Quitter la session"),
("restart","Redemarer l'ordinateur"),
("shutdwn","Eteindre l'ordinateur"),
("cancel","Quitter le Menu"),
]
#UserDir = os.getenv('HOME')
#~ Repertoire du script
IconDir = os.path.abspath( os.path.dirname( __file__))
LogInfo(" le repertoire du script est : %s " %(IconDir))
#~ Repertoire du dossier img ( iconnes )
# les iconnes doivent se trouver dans un dossier "img" dans le pwd du script
# Pour simplifier .. les icônes portent le nom de du titre du bouton ( logout, shutdwn, restart, cancel )
IconDir = IconDir + "/img/"
LogInfo(" le repertoire des iconnes est : %s " %(IconDir))
if UsingDbus:
#~ Checking wich daemon to discuss with if dbus-python is ok
#~ consolekit, hal or back to /sbin/**** with sudoers or not
UsingConsoleKit = checkForCommand("consolekit","[c]onsole-kit-daemon")
if not UsingConsoleKit:
UsingHAL = checkForCommand("hal","[h]ald")
if not UsingHAL:
UsingDbus = False
class ObLogOut():
def __init__(self):
# if using dbus connect to interface
if UsingDbus:
bus = dbus.SystemBus()
# if using upower specification
if UsingConsoleKit:
dbus_proxy = bus.get_object('org.freedesktop.ConsoleKit','/org/freedesktop/ConsoleKit/Manager')
self.dbus_powermanagement = dbus.Interface(dbus_proxy, "org.freedesktop.ConsoleKit.Manager")
LogInfo("using ConsoleKit")
# if use Hal specification
else:
dbus_proxy = bus.get_object("org.freedesktop.Hal", "/org/freedesktop/Hal/devices/computer")
self.dbus_powermanagement = dbus.Interface(dbus_proxy, "org.freedesktop.Hal.Device.SystemPowerManagement")
LogInfo("using Hal")
else:
LogInfo("using default command /sbin/***")
self.screen_x , self.screen_y = gtk.gdk.screen_width(), gtk.gdk.screen_height()
self.NumbIcon = len(ICON_LIST)
LogInfo(" %s iconnes" % self.NumbIcon)
self.init_window()
self.set_background()
def init_window(self):
self.window = gtk.Window()
# set title
self.window.set_title("Log Out ..")
# connect evenement to window
self.window.connect("destroy", self.doquit)
self.window.connect("key-press-event", self.onkeypress)
# run undecorated
self.window.set_decorated(False)
# create Panel For Button bouton box
self.mainpanel = gtk.Fixed()
# connect panel to gtk.Window()
self.window.add(self.mainpanel)
self.init_bouton()
def init_bouton(self):
# finding the best place for the box depends on icon nbs max
# espace entre debut x de l'icone 120
# selnumbicon x 120 = 480 diviser en deux =240
# un icone fait 70 donc une moitier d'icone =-35
# ce qui nous donne moitier ecran - 205 vers la gauche
# axe horizontal ( depuis la gauche )
x = ( self.screen_x / 2 ) - ( self.NumbIcon * int(51.25))
# axe vertical ( depuis le haut )
y = ( self.screen_y / 2 )
for ico in ICON_LIST:
name , tooltips = ico
self.add_bouton(name,tooltips,x,y)
x = x+120
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 du filtre du fond de la fenetre sur le bureau ( 0 pour transparence )
alpha = 0.6
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()
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, name, info,x,y):
box = gtk.VBox()
bouton = gtk.Button(label=None, stock=None, use_underline=None)
bouton.set_relief(gtk.RELIEF_NONE)
bouton.set_focus_on_click(False)
bouton.set_border_width(0)
image = gtk.Image()
image.set_from_file(IconDir + name + ".png")
bouton.set_image(image)
bouton.set_tooltip_text(str(info))
box.pack_start(gtk.VBox())
box.pack_start(bouton, False, False)
box.pack_start(gtk.VBox())
label = gtk.Label(name)
label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse("white"))
box.pack_end(label, False, False)
bouton.connect("clicked", self.clic_bouton,name)
self.mainpanel.put(box,int(x),int(y))
bouton.show()
box.show()
def clic_bouton(self, widget, data):
if (data == 'cancel'):
self.doquit()
elif (data == 'logout'):
# probleme conky reste allumer
os.system('openbox --exit')
elif (data == 'restart'):
if UsingDbus:
if UsingConsoleKit:
self.dbus_powermanagement.Restart()
else:
self.dbus_powermanagement.Reboot()
else:
os.system('x-terminal-emulator -e sudo /sbin/reboot')
elif (data == 'shutdown'):
if UsingDbus:
if UsingConsoleKit:
self.dbus_powermanagement.Stop()
else:
self.dbus_powermanagement.Shutdown()
else:
os.system('x-terminal-emulator -e sudo /sbin/shutdown')
self.doquit()
def onkeypress(self, widget=None, event=None, data=None):
if event.keyval == gtk.keysyms.Escape:
self.doquit()
LogInfo("ESC has Been Press .. EXiting ")
def doquit(self, widget=None, data=None):
gtk.main_quit()
def run(self):
self.window.show_all()
gtk.main()
#-------------------------
if __name__ == "__main__":
#-------------------------
app = ObLogOut()
app.run()
ps: n'hésitais pas a faire toute remarque ..