CrunchBang Linux Pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

CrunchBang Linux Pastebin

Posted by iggykoopa on Sun 11th Jan 19:28 (modification of post by iggykoopa view diff)
diff | download | new post

  1. #!/usr/bin/env python2.5
  2.  
  3. ##
  4. #   Script to Exit , logout , reboot , suspend  [ gdm / openbox ]
  5. #
  6. #   http://crunchbanglinux.org/forums/topic/295/updated-openboxlogout-script/
  7. ##
  8.  
  9. import gtk
  10. import os
  11. import pwd
  12. from PIL import Image, ImageFilter
  13.  
  14. class MyApp():
  15.     def __init__(self):
  16.  
  17.         self.window = gtk.Window()
  18.         self.window.set_title("Log Out ..")
  19.         self.window.connect("destroy", self.doquit)
  20.         self.window.connect("key-press-event", self.onkeypress)
  21.         self.window.set_decorated(False)
  22.  
  23.         self.mainpanel = gtk.Fixed()
  24.         self.window.add(self.mainpanel)
  25.  
  26.         self.screen_x , self.screen_y = gtk.gdk.screen_width(), gtk.gdk.screen_height()
  27.  
  28.         x = ( self.screen_x / 2 ) - ( 140 * 3 / 2 ) - 30
  29.         y = ( self.screen_y / 2 ) - 200
  30.  
  31.         ## 1st Line
  32.         self.add_bouton("system-log-out",x+30,y+30)
  33.         self.add_bouton("system-restart",x+170,y+30)
  34.         self.add_bouton("system-shutdown",x+310,y+30)
  35.         ## 2nd Line
  36.         self.add_bouton("application-exit",x+30,y+200)
  37.         self.add_bouton("system-suspend",x+170,y+200)
  38.         self.add_bouton("system-suspend-hibernate",x+310,y+200)
  39.  
  40.         ## 1st Line
  41.         self.add_label("Logout",x+70, y+170)
  42.         self.add_label("Reboot",x+210, y+170)
  43.         self.add_label("Shutdown",x+350, y+170)
  44.         ## 2nd Line
  45.         self.add_label("Cancel",x+70, y+340)
  46.         self.add_label("Suspend",x+210, y+340)
  47.         self.add_label("Hibernate",x+350, y+340)
  48.  
  49.         self.set_background()
  50.  
  51.     def set_background(self):
  52.         img_file = "/tmp/root_window.jpg"
  53.         w = gtk.gdk.get_default_root_window()
  54.         sz = w.get_size()
  55.         pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1])
  56.         pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1])
  57.         if (pb != None):
  58.             pb.save(img_file,"jpeg")
  59.             image = Image.open(img_file)
  60.             color = 'black'
  61.             alpha = 0.5
  62.             mask = Image.new("RGB", image.size, color)
  63.             image = Image.blend(image, mask, alpha)
  64.             image.save(img_file,"jpeg")
  65.  
  66.         pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(img_file, self.screen_x, self.screen_y)
  67.         pixmap, mask = pixbuf.render_pixmap_and_mask()
  68.         # width, height = pixmap.get_size()
  69.         self.window.set_app_paintable(True)
  70.         self.window.resize(self.screen_x, self.screen_y)
  71.         self.window.realize()
  72.         self.window.window.set_back_pixmap(pixmap, False)
  73.         self.window.move(0,0)
  74.         del pixbuf
  75.         del pixmap
  76.  
  77.  
  78.  
  79.     def add_bouton(self, name, x, y):
  80.         image = gtk.Image()
  81.         image.set_from_file("img/" + name + ".png")
  82.         image.show()
  83.         # un bouton pour contenir le widget image
  84.         bouton = gtk.Button()
  85.         bouton.set_relief(gtk.RELIEF_NONE)
  86.         bouton.set_focus_on_click(False)
  87.         bouton.set_border_width(0)
  88.         bouton.set_property('can-focus', False)
  89.         bouton.add(image)
  90.         bouton.show()
  91.         self.mainpanel.put(bouton, x,y)
  92.         bouton.connect("clicked", self.clic_bouton, name)
  93.  
  94.     def add_label(self, name, x, y):
  95.         label = gtk.Label(name)
  96.         label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse("white"))
  97.         self.mainpanel.put(label, x, y)
  98.  
  99.     # Cette fonction est invoquee quand on clique sur un bouton.
  100.     def clic_bouton(self, widget, data=None):
  101.  
  102.         if (data=='application-exit'):
  103.             self.doquit()
  104.  
  105.         elif (data=='system-log-out'):
  106.             os.system('openbox --exit')
  107.  
  108.         elif (data=='system-restart'):
  109.             os.system('gdm-control --reboot && openbox --exit')
  110.  
  111.         elif (data=='system-shutdown'):
  112.             os.system('gdm-control --shutdown && openbox --exit')
  113.  
  114.         elif (data=='system-suspend'):
  115.             pid = os.getpid()
  116.             os.system("(sleep 1s && gnome-power-cmd.sh suspend) && kill " + str(pid))
  117.  
  118.         elif (data=='system-suspend-hibernate'):
  119.             pid = os.getpid()
  120.             os.system("(sleep 1s && gnome-power-cmd.sh hibernate) && kill " + str(pid))
  121.  
  122.     def onkeypress(self, widget=None, event=None, data=None):
  123.         if event.keyval == gtk.keysyms.Escape:
  124.             self.doquit()
  125.  
  126.     def doquit(self, widget=None, data=None):
  127.         gtk.main_quit()
  128.  
  129.     def run(self):
  130.         self.window.show_all()
  131.         gtk.main()
  132.  
  133. #-------------------------
  134. if __name__ == "__main__":
  135. #-------------------------
  136.     ## need to change directory
  137.     SRC_PATH = os.path.dirname( os.path.realpath( __file__ ) )
  138.     os.chdir(SRC_PATH)
  139.     app = MyApp()
  140.     app.run()

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me