Advertisement
cesarzeta

Archlinux. Cierre de sesión

Mar 13th, 2013
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.44 KB | None | 0 0
  1. #! /usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. # Importamos lo módulos necesarios
  4. import os
  5. import sys
  6. from tkinter import *
  7. # Obtenemos el usuario logueado y creamos las funciones que van a ser comandos de los botones.
  8. usuario = os.getlogin()
  9. def reiniciar():
  10.     os.system("/usr/bin/systemctl reboot")
  11. def apagar():
  12.     os.system("/usr/bin/systemctl poweroff")
  13. def salir():
  14.     os.system("sudo /usr/bin/loginctl terminate-seat seat0")
  15. def suspender():
  16.     os.system("/usr/bin/systemctl suspend")
  17. def hibernar():
  18.     os.system("/usr/bin/systemctl hibernate")
  19. def bloquear():
  20.     os.system("/usr/bin/xflock4")
  21. # Creamos la clase que incluye la ventana sin decoración , etiqueta para el título, los botones para las acciones y la configuración de cada elemento.
  22. class closingDialog:
  23.     def __init__(self):
  24.         self.v0 = Tk ()
  25.         w = 235
  26.         h = 215
  27.         sw=self.v0.winfo_screenwidth()
  28.         sh = self.v0.winfo_screenheight()
  29.         x = (sw - w)/2
  30.         y = (sh - h)/2
  31.         self.v0.geometry('%dx%d+%d+%d' % (w, h, x, y))
  32.         self.v0.overrideredirect(1)
  33.         self.v0.config(bg="black")
  34.         photo0=PhotoImage(file="/home/" + usuario + "/.icons/logout.png")
  35.         photo1=PhotoImage(file="/home/" + usuario + "/.icons/reboot.png")
  36.         photo2=PhotoImage(file="/home/" + usuario + "/.icons/shutdown.png")
  37.         photo3=PhotoImage(file="/home/" + usuario + "/.icons/hibernate.png")
  38.         photo4=PhotoImage(file="/home/" + usuario + "/.icons/suspend.png")
  39.         photo5=PhotoImage(file="/home/" + usuario + "/.icons/lock-screen.png")
  40.         photo6=PhotoImage(file="/home/" + usuario + "/.icons/cancel.png")
  41.         self.label1=Label(self.v0,height=2,width=25,bg="#606060",fg="cyan",font=("Arial", 12, "bold"),text = "Cerrar sesión de " + usuario).grid(row=0,column=0,sticky=W+E+N+S,columnspan=3,pady=2)
  42.         self.b1=Button(self.v0,height=48,width=48,relief=FLAT,fg="blue",font=("Arial", 9, "bold"),text="Salir",image=photo0,compound=TOP,command=lambda: salir()).grid(row=1,column=0,padx=1, pady=1)
  43.         self.b2=Button(self.v0,height=48,width=48,relief=FLAT,fg="brown",font=("Arial", 9, "bold"),text="Reiniciar",image=photo1,compound=TOP,command=lambda: reiniciar()).grid(row=1,column=1,padx=1, pady=1)
  44.         self.b3=Button(self.v0,height=48,width=48,relief=FLAT,fg="red",font=("Arial", 9, "bold"),text="Apagar",image=photo2,compound=TOP,command=lambda: apagar()).grid(row=1,column=2,padx=1,pady=1)
  45.         self.b4=Button(self.v0,height=48,width=48,relief=FLAT,fg="#483D8B",font=("Arial", 9, "bold"),text="Hibernar",image=photo3,compound=TOP,command=lambda: hibernar()).grid(row=2,column=0,padx=1,pady=1)
  46.         self.b5=Button(self.v0,height=48,width=48,relief=FLAT,fg="#3672B4",font=("Arial", 9, "bold"),text="Suspender",image=photo4,compound=TOP,command=lambda: suspender()).grid(row=2,column=1,padx=1,pady=1)
  47.         self.b6=Button(self.v0,height=48,width=48,relief=FLAT,fg="magenta",font=("Arial", 9, "bold"),text="Bloquear",image=photo5,compound=TOP,command=lambda: bloquear()).grid(row=2,column=2,padx=1,pady=1)
  48.         self.b7=Button(self.v0,height=26,width=48,relief=FLAT,fg="black",font=("Arial", 10, "bold"),text="Cancelar",image=photo6,compound=LEFT,command=self.v0.quit).grid(row=3,column=0,columnspan=3,sticky=W+E+N+S, padx=1,pady=1)
  49.         self.v0.mainloop()
  50. # Cuando el script inicia, "closingDialog" instancia "app" es creada y su función  "__init__"es ejecutada. La ventana principal v0, label, y botones son creados . Finalmente se ejecuta la mainloop de "v0" y la aplicación queda a la espera de eventos (como clicks del mouse)
  51. if __name__ == "__main__":
  52.        app = closingDialog()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement