[accerciser/pygi] Highlights using cairo. Deleted rsvg dependency
- From: Javier HernÃndez AntÃnez <jhernandez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [accerciser/pygi] Highlights using cairo. Deleted rsvg dependency
- Date: Mon, 29 Aug 2011 09:10:30 +0000 (UTC)
commit 7ca0eeaf3fc4183c1dbf7bf6d331dd9bc034faa8
Author: Javier HernÃndez <jhernandez emergya es>
Date: Mon Aug 29 11:12:19 2011 +0200
Highlights using cairo. Deleted rsvg dependency
src/lib/accerciser/node.py | 176 +++++++++++++++++++++++++++++++++-----------
1 files changed, 133 insertions(+), 43 deletions(-)
---
diff --git a/src/lib/accerciser/node.py b/src/lib/accerciser/node.py
index b829c0b..c1933bc 100644
--- a/src/lib/accerciser/node.py
+++ b/src/lib/accerciser/node.py
@@ -17,11 +17,10 @@ from gi.repository import Gtk as gtk
from gi.repository import Gdk as gdk
from gi.repository import GObject
from gi.repository import GConf as gconf
-
+#from gi.repository import cairo
+import cairo
import pyatspi
import string
-import rsvg
-import cairo
from tools import Tools, parseColorString
MAX_BLINKS = 6
@@ -180,24 +179,12 @@ class Node(GObject.GObject, Tools):
return False
return True
+
class _HighLight(gtk.Window):
'''
Highlight box class. Uses compositing when available. When not, it does
transparency client-side.
'''
- _svg = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<svg xmlns="http://www.w3.org/2000/svg">
- <rect
- style="fill:$fill;fill-opacity:$fill_opacity;fill-rule:evenodd;stroke:$stroke;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:$stroke_opacity"
- id="highlight"
- width="$width"
- height="$height"
- x="$x"
- y="$y"
- rx="2"
- ry="2" />
-</svg>
-"""
def __init__(self, x, y, w, h,
fill_color, fill_alpha,
stroke_color, stroke_alpha,
@@ -210,9 +197,10 @@ class _HighLight(gtk.Window):
# Normalize position for stroke and padding.
self.x, self.y = x - padding, y - padding
self.w, self.h = w + padding*2, h + padding*2
+ self.fill_color = fill_color
# Determine if we are compositing.
- self._composited = self.is_composited()
+ self._composited = True #self.is_composited()
if self._composited:
# Prepare window for transparency.
screen = self.get_screen()
@@ -222,6 +210,8 @@ class _HighLight(gtk.Window):
# Take a screenshot for compositing on the client side.
self.root = gdk.get_default_root_window().get_image(
self.x, self.y, self.w, self.h)
+ #self.root = gtk.Image(self.x, self.y, self.w, self.h)
+
# Place window, and resize it, and set proper properties.
self.set_app_paintable(True)
@@ -231,20 +221,24 @@ class _HighLight(gtk.Window):
self.resize(self.w, self.h)
self.set_accept_focus(False)
self.set_sensitive(False)
+ self.set_opacity(fill_alpha)
- # Create SVG with given parameters.
- offset = stroke_width/2.0
- self.svg = string.Template(self._svg).substitute(
- x=offset, y=offset,
- width=int(self.w - stroke_width), height=int(self.h - stroke_width),
- fill=fill_color,
- stroke_width=stroke_width,
- stroke=stroke_color,
- fill_opacity=fill_alpha,
- stroke_opacity=stroke_alpha)
+# # Create SVG with given parameters.
+# offset = stroke_width/2.0
+# self.svg = string.Template(self._svg).substitute(
+# x=offset, y=offset,
+# width=int(self.w - stroke_width), height=int(self.h - stroke_width),
+# fill=fill_color,
+# stroke_width=stroke_width,
+# stroke=stroke_color,
+# fill_opacity=fill_alpha,
+# stroke_opacity=stroke_alpha)
+ da = gtk.DrawingArea()
# Connect "draw"
- self.connect("draw", self._onExpose)
+ da.connect("draw", self._onExpose)
+ self.add(da)
+ self.show_all()
def highlight(self, duration=500):
if duration > 0:
@@ -254,16 +248,10 @@ class _HighLight(gtk.Window):
self.destroy()
def _onExpose(self, widget, event):
- svgh = rsvg.Handle()
- try:
- svgh.write(self.svg)
- except (GObject.GError, KeyError, ValueError), ex:
- print 'Error reading SVG for display: %s\r\n%s', ex, self.svg
- svgh.close()
- return
- svgh.close()
-
- if not self._composited:
+ window = widget.get_window()
+ cr = window.cairo_create()
+
+ if not self.is_composited():
# Draw the screengrab of the underlaying window, and set the drawing
# operator to OVER.
self.window.draw_image(self.style.black_gc, self.root,
@@ -273,14 +261,116 @@ class _HighLight(gtk.Window):
cairo_operator = cairo.OPERATOR_OVER
else:
cairo_operator = cairo.OPERATOR_SOURCE
- window = self.get_window()
- cr = window.cairo_create()
- cr.set_source_rgba(1.0, 1.0, 1.0, 0.0)
cr.set_operator(cairo_operator)
+
+ color = gdk.color_parse(self.fill_color)
+
+ #TODO: look for for set_source_rgb and Gdk.Color issues
+ cr.set_source_rgb(color.red, color.green, color.blue)
cr.paint()
- svgh.render_cairo( cr )
- del svgh
+
+#class _HighLight(gtk.Window):
+# '''
+# Highlight box class. Uses compositing when available. When not, it does
+# transparency client-side.
+# '''
+# _svg = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+#<svg xmlns="http://www.w3.org/2000/svg">
+# <rect
+# style="fill:$fill;fill-opacity:$fill_opacity;fill-rule:evenodd;stroke:$stroke;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:$stroke_opacity"
+# id="highlight"
+# width="$width"
+# height="$height"
+# x="$x"
+# y="$y"
+# rx="2"
+# ry="2" />
+#</svg>
+#"""
+# def __init__(self, x, y, w, h,
+# fill_color, fill_alpha,
+# stroke_color, stroke_alpha,
+# stroke_width, padding=0):
+#
+# # Initialize window.
+# #gtk.Window.__init__(self, gtk.WindowType.POPUP)
+# gtk.Window.__init__(self)
+#
+# # Normalize position for stroke and padding.
+# self.x, self.y = x - padding, y - padding
+# self.w, self.h = w + padding*2, h + padding*2
+#
+# # Determine if we are compositing.
+# self._composited = self.is_composited()
+# if self._composited:
+# # Prepare window for transparency.
+# screen = self.get_screen()
+# visual = screen.get_rgba_visual()
+# self.set_visual(visual)
+# else:
+# # Take a screenshot for compositing on the client side.
+# self.root = gdk.get_default_root_window().get_image(
+# self.x, self.y, self.w, self.h)
+#
+# # Place window, and resize it, and set proper properties.
+# self.set_app_paintable(True)
+# self.set_decorated(False)
+# self.set_keep_above(True)
+# self.move(self.x, self.y)
+# self.resize(self.w, self.h)
+# self.set_accept_focus(False)
+# self.set_sensitive(False)
+#
+# # Create SVG with given parameters.
+# offset = stroke_width/2.0
+# self.svg = string.Template(self._svg).substitute(
+# x=offset, y=offset,
+# width=int(self.w - stroke_width), height=int(self.h - stroke_width),
+# fill=fill_color,
+# stroke_width=stroke_width,
+# stroke=stroke_color,
+# fill_opacity=fill_alpha,
+# stroke_opacity=stroke_alpha)
+#
+# # Connect "draw"
+# self.connect("draw", self._onExpose)
+#
+# def highlight(self, duration=500):
+# if duration > 0:
+# GObject.timeout_add(duration, lambda w: w.destroy(), self)
+# self.show_all()
+# else:
+# self.destroy()
+#
+# def _onExpose(self, widget, event):
+# svgh = rsvg.Handle()
+# try:
+# svgh.write(self.svg)
+# except (GObject.GError, KeyError, ValueError), ex:
+# print 'Error reading SVG for display: %s\r\n%s', ex, self.svg
+# svgh.close()
+# return
+# svgh.close()
+#
+# if not self._composited:
+# # Draw the screengrab of the underlaying window, and set the drawing
+# # operator to OVER.
+# self.window.draw_image(self.style.black_gc, self.root,
+# event.area.x,event.area.y,
+# event.area.x, event.area.y,
+# event.area.width, event.area.height)
+# cairo_operator = cairo.OPERATOR_OVER
+# else:
+# cairo_operator = cairo.OPERATOR_SOURCE
+# window = self.get_window()
+# cr = window.cairo_create()
+# cr.set_source_rgba(1.0, 1.0, 1.0, 0.0)
+# cr.set_operator(cairo_operator)
+# cr.paint()
+#
+# svgh.render_cairo( cr )
+# del svgh
if __name__ == "__main__":
hl = _HighLight(200, 200, 200, 200, '#ff0000',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]