1 2import cairo 3 4from .__init__ import NORTH, EAST, SOUTH, WEST, CENTER 5from .OverlayWindow import OverlayWindow 6 7from math import ceil as fceil 8 9# ceil = lambda f: int(fceil(f)) 10 11 12def ceil(f): 13 return int(fceil(f)) 14 15 16class HighlightArea(OverlayWindow): 17 """ An entirely blue widget """ 18 19 def __init__(self, parent): 20 OverlayWindow.__init__(self, parent) 21 self.cid = self.connect_after("draw", self.__onExpose) 22 23 def showAt(self, position): 24 alloc = self.myparent.get_allocation() 25 if position == NORTH: 26 x_loc, y_loc = 0, 0 27 width, height = alloc.width, alloc.height * 0.381966011 28 elif position == EAST: 29 x_loc, y_loc = alloc.width * 0.618033989, 0 30 width, height = alloc.width * 0.381966011, alloc.height 31 elif position == SOUTH: 32 x_loc, y_loc = 0, alloc.height * 0.618033989 33 width, height = alloc.width, alloc.height * 0.381966011 34 elif position == WEST: 35 x_loc, y_loc = 0, 0 36 width, height = alloc.width * 0.381966011, alloc.height 37 elif position == CENTER: 38 x_loc, y_loc = 0, 0 39 width, height = alloc.width, alloc.height 40 41 try: 42 x_loc, y_loc = self.translateCoords(int(x_loc), int(y_loc)) 43 self.move(x_loc, y_loc) 44 except ValueError: 45 pass 46 # Can't move to x,y, because top level parent has no window. 47 48 self.resize(ceil(width), ceil(height)) 49 self.show() 50 51 def __onExpose(self, self_, ctx): 52 context = self.get_window().cairo_create() 53 a = self_.get_allocation() 54 context.rectangle(a.x, a.y, a.width, a.height) 55 sc = self.get_style_context() 56 found, color = sc.lookup_color('p_light_selected') 57 if self.is_composited(): 58 context.set_operator(cairo.OPERATOR_CLEAR) 59 context.set_source_rgba(0, 0, 0, 0.0) 60 context.fill_preserve() 61 context.set_operator(cairo.OPERATOR_OVER) 62 context.set_source_rgba(color.red, color.green, color.blue, 0.5) 63 context.fill() 64 else: 65 context.set_source_rgba(color.red, color.green, color.blue) 66 context.set_operator(cairo.OPERATOR_OVER) 67 context.fill() 68