#!/usr/bin/env python #------------------------------------------------------------------------------ import sys import gtk import cairo if gtk.pygtk_version < (2,9,0): print "PyGtk 2.9.0 or later required" raise SystemExit #------------------------------------------------------------------------------ #------------------------------------------------------------------------------ class Dock(gtk.DrawingArea): def __init__(self): gtk.DrawingArea.__init__(self) # Override expose, called when we need to draw windows contents self.connect("expose_event", self.expose) def expose(self, widget, event): global alpha_support # Initialize our context self.context = widget.window.cairo_create() # Set a clip region for the expose event self.context.rectangle(event.area.x, event.area.y, event.area.width, event.area.height) self.context.clip() # Are we able to use alpha channels? if alpha_support: self.context.set_source_rgba(1.0, 1.0, 1.0, 0.0) # Transparent else: self.context.set_source_rgb(1.0, 1.0, 1.0) # Opaque white # Paint the background self.context.set_operator(cairo.OPERATOR_SOURCE) self.context.paint() # Now draw the rest... self.draw(self.context) return False def screen_changed(self, widget, old_screen=None): global alpha_support # To check if the display supports alpha channels, get the colormap screen = widget.get_screen() colormap = screen.get_rgba_colormap() if colormap == None: print 'WARNING: Alpha channel not supported!' colormap = screen.get_rgb_colormap() alpha_support = False else: alpha_support = True # Now we can set our colormap widget.set_colormap(colormap) return False def draw(self, context): # method to be overriden # get widget properties rect = self.get_allocation() # Draw a blue circle context.set_source_rgba(0.2, 0.2, 1.0, 0.6) radius = float((rect.width, rect.height)[rect.width>rect.height])/2 - 0.8 context.arc(float(rect.width)/2, float(rect.height)/2, radius, 0, 2.0*3.14) context.fill_preserve() # Black line border context.set_source_rgba(0.0, 0.0, 0.0, 1.0) context.stroke() def main(Widget): # Create our window and dock window = gtk.Window() window.connect("destroy", gtk.main_quit) # Tell GTK+ that we want to draw the windows background ourself. window.set_app_paintable(True) # Add the dock in there dock = Widget() window.set_default_size(300,400) window.add(dock) # Override default screen-changed Window function. window.connect("screen-changed", dock.screen_changed) dock.screen_changed(window) # Disable window frame window.set_decorated(False) window.set_position(1) # and finally show the window. window.show_all() gtk.main() if __name__ == "__main__": sys.exit(main(Dock))