Guest User

Untitled

a guest
Feb 14th, 2014
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. #!/usr/bin/python2
  2. #based on: http://learngtk.org/pygtk-tutorial/statusicon.html
  3. #icons from https://launchpad.net/caffeine
  4. import gtk
  5. import os
  6.  
  7. EMPTY = "/usr/share/icons/hicolor/scalable/status/caffeine-cup-empty.svg"
  8. FULL = "/usr/share/icons/hicolor/scalable/status/caffeine-cup-full.svg"
  9. DPMS_ACTIVE = True
  10. DPMS_OFF = False
  11.  
  12. class StatusIcon:
  13.     def __init__(self):
  14.         self.statusicon = gtk.StatusIcon()
  15.         self.statusicon.set_from_file(EMPTY)
  16.         self.statusicon.connect("activate", self.left_click_event)
  17.         self.statusicon.set_tooltip("StatusIcon Example")
  18.         self.the_state = DPMS_ACTIVE
  19.         self.statusicon.connect("popup-menu", self.right_click_event)
  20.     def left_click_event(self, icon):
  21.         if self.the_state == DPMS_ACTIVE:
  22.             self.statusicon.set_from_file(FULL)
  23.             self.the_state = DPMS_OFF
  24.             os.system("xset dpms 0 0 0")
  25.         else:
  26.             self.statusicon.set_from_file(EMPTY)
  27.             self.the_state = not self.the_state
  28.             os.system("xset dpms 0 0 200")
  29.     def right_click_event(self, icon, button, time):
  30.         pass
  31. StatusIcon()
  32. gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment