# This file is part of emesene.## Eval plugin is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## Eval plugin is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with emesene; if not, write to the Free Software# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA#version 0.0.1 - h4x0r3d by C10uD <c10ud.dev@gmail.com>#special thanks to teh internetsimport mathimport pangoimport pygtkimport gtkfrom gtk import gdkimport cairofrom emesenelib.common import escapefrom Plugin import Pluginsupports_alpha = Falsedef screen_changed(widget, old_screen=None): global supports_alpha screen = widget.get_screen() colormap = screen.get_rgba_colormap() if colormap == None: print 'Your screen does not support alpha channels!' colormap = screen.get_rgb_colormap() supports_alpha = False else: print 'Your screen supports alpha channels!' supports_alpha = True widget.set_colormap(colormap)class AlphaOSD: def __init__(self): self.win = gtk.Window() self.win.set_default_size(800,200) self.win.set_border_width(10) self.win.set_title('emesene OSD') self.win.set_app_paintable(True) (self.width, self.height) = self.win.get_size() self.padding = 5 #increase the first value to get moar roundness!! self.rounded = (10 / 100.0) * min(self.width, self.height) / 2 - self.padding self.lab = gtk.Label("JEJEJEJEJEJJEJEJEJEJJEJEJEJEJJEJEJEJJEJEJEJJEJEJEJJE") self.lab.set_use_markup(True) self.lab.set_justify(gtk.JUSTIFY_LEFT) self.lab.set_ellipsize(pango.ELLIPSIZE_END) self.win.add(self.lab) self.win.connect('expose-event', self.expose) self.win.connect('screen-changed', screen_changed) self.win.set_decorated(False) self.win.add_events(gdk.BUTTON_PRESS_MASK) self.win.connect('button-press-event', self.clicked) screen_changed(self.win) self.win.show_all() def clicked(self, widget, event): widget.set_decorated(not widget.get_decorated()) #This is called when we need to draw the windows contents def expose(self, widget, event): global supports_alpha cr = widget.window.cairo_create() if supports_alpha == True: cr.set_source_rgba(1.0, 1.0, 1.0, 0.0) # Transparent else: cr.set_source_rgb(1.0, 1.0, 1.0) # Opaque white # Draw the background cr.set_operator(cairo.OPERATOR_SOURCE) cr.paint() padding=self.padding rounded=self.rounded #draw a nice rounded rectangle (w, h) = widget.get_size() w = float(w) h = float(h) cr.set_source_rgba(0.2, 0.2, 0.2, 0.6) cr.move_to(0+padding+rounded, 0+padding) cr.line_to(w-padding-rounded, 0+padding) cr.arc(w-padding-rounded, 0+padding+rounded, rounded, math.pi/2, 0) cr.line_to(w-padding, h-padding-rounded) cr.arc(w-padding-rounded, h-padding-rounded, rounded, 0, math.pi/2) cr.line_to(0+padding+rounded, h-padding) cr.arc(0+padding+rounded, h-padding-rounded, rounded, math.pi+math.pi/2, math.pi) cr.line_to(0+padding, 0+padding+rounded) cr.arc(0+padding+rounded, 0+padding+rounded, rounded, math.pi/2, 0) cr.fill() cr.stroke() children = self.win.get_children() for c in children: self.win.propagate_expose(c, event) def add_text(self, text): self.lab.set_text(text)class MainClass(Plugin): def __init__(self, controller, msn): Plugin.__init__(self, controller, msn) self.description = _('emesene OSD message viewer') self.authors = {'C10uD': 'c10ud.dev@gmail.com'} self.website = 'http://emesene.org' self.displayName = _('OSD') self.name = 'OSD' self.enabled = False self.osd = AlphaOSD() def start(self): self.enabled = True self.newMsgId = self.controller.conversationManager.connect( 'receive-message', self.newMsg ) def stop(self): self.enabled = False self.disconnect( self.newMsgId ) def check(self): return (True, 'Ok') def newMsg(self, switchboard, conversation, mail, nick, message, format, charset): '''called when someone send a message''' self.osd.add_text(message)