1400_SpaceCat

dock.py

May 31st, 2016
132
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from gi.repository import Gtk as gtk
  2. from gi.repository import Gdk as gdk
  3. from gi.repository import GObject as gobject
  4. from gi.repository import Wnck as wnck
  5.  
  6. class App:
  7.     def __init__(self):
  8.         self.checker = wnck.Screen.get_default()
  9.         self.checker.connect("active-window-changed", self.RefreshItAgain)
  10.         self.checker.connect("active-workspace-changed", self.RefreshIt)
  11.         self.checker.connect("window-opened", self.RefreshIt)
  12.         self.checker.connect("window-closed", self.RefreshIt)
  13.          
  14.         self.checker.get_active_workspace()
  15.         self.checker.get_active_window()
  16.         self.checker.get_windows()
  17.         self.checker.get_workspaces()
  18.  
  19.         #create appbar box and window#
  20.         self.appbarHBox = gtk.HBox()
  21.         self.appbarHBox.set_name("appbarHBox")
  22.         self.appbarHBox.show()
  23.  
  24.         dockWindow = gtk.Window()
  25.         dockWindow.connect("destroy",lambda w: gtk.main_quit())
  26.         dockWindow.set_size_request(gdk.Screen.get_default().get_width(),0)
  27.         dockWindow.set_decorated(True)
  28.         dockWindow.set_keep_above(True)
  29.         dockWindow.set_decorated(False)
  30.         dockWindow.add(self.appbarHBox)
  31.         dockWindow.show_all()
  32.  
  33.         gobject.timeout_add(2,self.RefreshIt)
  34.  
  35.         dockWindow.show_all()
  36.         gtk.main()
  37.  
  38.     def Activate(self,checker,widnow):
  39.         widnow.activate(int(gobject.get_current_time()))
  40.  
  41.     def RefreshItAgain(self,checker,widnow):
  42.         try:
  43.             activeWindow = self.checker.get_active_window()
  44.             for b in self.appbarHBox.get_children():
  45.                 b.set_active(b.window == window)
  46.  
  47.         except Exception:
  48.             pass
  49.  
  50.     def RefreshIt(self,*args):
  51.         for b in self.appbarHBox.get_children():
  52.             self.appbarHBox.remove(b)
  53.  
  54.         activeWorkspace = self.checker.get_active_workspace()
  55.         activeWindow = self.checker.get_active_window()
  56.  
  57.         for w in self.checker.get_windows():
  58.             if w.get_workspace() == activeWorkspace:
  59.                 self.appButton = gtk.ToggleButton()
  60.                 self.appButton.set_relief(gtk.ReliefStyle.NONE)
  61.  
  62.                 self.appButton.w = w
  63.                 self.appButton.set_active(w == activeWindow)
  64.  
  65.                 self.appButtonIcon = w.get_icon()
  66.                 self.appButton.set_image(gtk.Image.new_from_pixbuf(self.appButtonIcon))
  67.                 self.appButton.set_tooltip_text(w.get_name())
  68.                 self.appButton.connect("clicked",self.Activate,w)
  69.                 self.appButton.show()
  70.                 self.appbarHBox.pack_start(self.appButton,False,False,0)
  71.  
  72. App()
RAW Paste Data