Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- import pygtk
- pygtk.require('2.0')
- import gtk, cairo
- from sys import argv,exit
- from math import pi
- from glib import timeout_add
- class Icon(object):
- def __init__(self, cr, width, height,alpha,png_file):
- img = cairo.ImageSurface.create_from_png(png_file)
- img_width=img.get_width()
- img_height=img.get_height()
- self.alpha = alpha
- scalew=0.8*width/img_width
- scaleh=0.8*height/img_height
- size=min(scalew,scaleh)
- cr.scale(size,size)
- cr.set_source_rgba(0.07,0.07,0.07,self.alpha)
- self.draw_rounded_rectangle(cr, 0, 0, width/(size*10.0), width/size,height/size)
- cr.fill()
- cr.set_source_surface(img,0.1*width/size+0.5*(0.8*width/size-img_width),0.1*height/size+0.5*(0.8*height/size-img_height))
- cr.paint()
- def draw_rounded_rectangle (self, cr, x, y, radius, width, height):
- cr.move_to(x + radius, y)
- cr.line_to(x + width - radius,y)
- cr.arc (x + width - radius, y + radius,radius,-90.0 * pi / 180.0,0.0 * pi / 180.0)
- cr.line_to(x + width, y + height - radius)
- cr.arc (x + width - radius,y + height - radius,radius,0.0 * pi / 180.0,90.0 * pi / 180.0)
- cr.line_to(x + radius,y + height)
- cr.arc (x + radius,y + height - radius,radius,90.0 * pi / 180.0, 180.0 * pi / 180.0)
- cr.line_to(x,y + radius)
- cr.arc (x + radius,y + radius,radius,180.0 * pi / 180.0,270.0 * pi / 180.0)
- cr.close_path()
- class RunOsd(gtk.Window):
- def __init__(self,png_file):
- super(RunOsd, self).__init__()
- self.png_file=png_file
- monitorw=gtk.gdk.screen_width()
- monitorh=gtk.gdk.screen_height()
- scalew=monitorw/640.0
- scaleh=monitorh/480.0
- scale = min(scalew, scaleh)
- self.size=int(130.0*max(1,scale))
- self.alpha=1
- self.set_decorated(False)
- self.set_resizable(False)
- self.set_keep_above(True)
- self.set_skip_taskbar_hint(True)
- self.set_size_request(self.size,self.size)
- self.set_uposition(int((monitorw-self.size)*0.5),int(monitorh-self.size*1.43))
- rgba = gtk.gdk.Screen.get_rgba_colormap(self.get_screen())
- self.set_colormap(rgba)
- self.set_opacity(self.alpha)
- pm = gtk.gdk.Pixmap(None, self.get_size()[0],self.get_size()[1], 1)
- pmcr = pm.cairo_create()
- pmcr.rectangle(0,0,1,1)
- pmcr.fill()
- self.input_shape_combine_mask(pm, 0, 0)
- self.darea = gtk.DrawingArea()
- self.darea.connect("expose-event", self.expose)
- self.darea.connect("button_press_event",self.button_press_cb)
- self.darea.set_events(gtk.gdk.EXPOSURE_MASK | gtk.gdk.BUTTON_PRESS_MASK)
- self.add(self.darea)
- self.connect("destroy", lambda w: gtk.main_quit())
- self.show_all()
- self.stick()
- timeout_add(3000,self.osd_fade_start)
- def expose(self,widget,event):
- self.cr = widget.window.cairo_create()
- self.cr.set_operator(cairo.OPERATOR_CLEAR)
- self.cr.rectangle(0.0, 0.0, self.size,self.size)
- self.cr.fill()
- self.cr.set_operator(cairo.OPERATOR_OVER)
- Icon(self.cr, self.size, self.size,0.75,self.png_file)
- def button_press_cb(self,widget,event):
- self.osd_fade_start()
- def osd_fade_start(self):
- timeout_add(25,self.osd_fade)
- return False
- def osd_fade(self):
- self.alpha = self.alpha - 0.15
- self.set_opacity(self.alpha)
- if self.alpha > 0:
- return True
- if self.alpha <= 0:
- gtk.main_quit()
- return False
- if __name__ == "__main__":
- if len(argv) < 2:
- print "need png!"
- exit(1)
- window = RunOsd(argv[1])
- gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement