Package dtk :: Package ui :: Module box

Source Code for Module dtk.ui.box

  1  #! /usr/bin/env python 
  2  # -*- coding: utf-8 -*- 
  3   
  4  # Copyright (C) 2011 ~ 2012 Deepin, Inc. 
  5  #               2011 ~ 2012 Wang Yong 
  6  #  
  7  # Author:     Wang Yong <lazycat.manatee@gmail.com> 
  8  # Maintainer: Wang Yong <lazycat.manatee@gmail.com> 
  9  #  
 10  # This program is free software: you can redistribute it and/or modify 
 11  # it under the terms of the GNU General Public License as published by 
 12  # the Free Software Foundation, either version 3 of the License, or 
 13  # any later version. 
 14  #  
 15  # This program is distributed in the hope that it will be useful, 
 16  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 17  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 18  # GNU General Public License for more details. 
 19  #  
 20  # You should have received a copy of the GNU General Public License 
 21  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 22   
 23  from draw import draw_pixbuf, propagate_expose, draw_vlinear, cairo_state 
 24  from skin_config import skin_config 
 25  from utils import get_window_shadow_size 
 26  import gobject 
 27  import gtk 
 28   
29 -class EventBox(gtk.EventBox):
30 ''' 31 Event box, not like Gtk.EventBox, it don't show visible window default. 32 ''' 33
34 - def __init__(self):
35 ''' 36 Initialize the EventBox class. 37 ''' 38 gtk.EventBox.__init__(self) 39 self.set_visible_window(False)
40
41 -class ImageBox(gtk.EventBox):
42 ''' 43 ImageBox. 44 45 @undocumented: expose_image_box 46 ''' 47
48 - def __init__(self, image_dpixbuf):
49 ''' 50 Initialize the ImageBox class. 51 52 @param image_dpixbuf: Image dynamic pixbuf. 53 ''' 54 # Init. 55 gtk.EventBox.__init__(self) 56 self.set_visible_window(False) 57 self.image_dpixbuf = image_dpixbuf 58 59 # Set size. 60 pixbuf = self.image_dpixbuf.get_pixbuf() 61 self.set_size_request(pixbuf.get_width(), pixbuf.get_height()) 62 63 # Connect expose signal. 64 self.connect("expose-event", self.expose_image_box)
65
66 - def expose_image_box(self, widget, event):
67 ''' 68 Callback for `expose-event` signal. 69 70 @param widget: Gtk.Widget instance. 71 @param event: Expose event. 72 ''' 73 # Init. 74 cr = widget.window.cairo_create() 75 rect = widget.allocation 76 pixbuf = self.image_dpixbuf.get_pixbuf() 77 78 # Draw. 79 draw_pixbuf(cr, pixbuf, rect.x, rect.y) 80 81 # Propagate expose. 82 propagate_expose(widget, event) 83 84 return True
85 86 gobject.type_register(ImageBox) 87
88 -class BackgroundBox(gtk.VBox):
89 ''' 90 BackgroundBox is container for clip background. 91 92 @undocumented: expose_background_box 93 ''' 94
95 - def __init__(self):
96 ''' 97 Initialize the BackgroundBox class. 98 ''' 99 # Init. 100 gtk.VBox.__init__(self) 101 self.set_can_focus(True) 102 103 self.connect("expose-event", self.expose_background_box)
104
105 - def draw_mask(self, cr, x, y, w, h):
106 ''' 107 Mask render function. 108 109 @param cr: Cairo context. 110 @param x: X coordinate of draw area. 111 @param y: Y coordinate of draw area. 112 @param w: Width of draw area. 113 @param h: Height of draw area. 114 ''' 115 draw_vlinear(cr, x, y, w, h, 116 [(0, ("#FF0000", 1)), 117 (1, ("#FF0000", 1))] 118 )
119
120 - def expose_background_box(self, widget, event):
121 ''' 122 Callback for `expose-event` signal. 123 124 @param widget: BackgroundBox self. 125 @param event: Expose event. 126 @return: Always return False. 127 ''' 128 cr = widget.window.cairo_create() 129 rect = widget.allocation 130 toplevel = widget.get_toplevel() 131 coordinate = widget.translate_coordinates(toplevel, rect.x, rect.y) 132 (offset_x, offset_y) = coordinate 133 134 with cairo_state(cr): 135 cr.rectangle(rect.x, rect.y, rect.width, rect.height) 136 cr.clip() 137 138 (shadow_x, shadow_y) = get_window_shadow_size(toplevel) 139 skin_config.render_background(cr, widget, shadow_x, shadow_y) 140 141 self.draw_mask(cr, rect.x, rect.y, rect.width, rect.height) 142 143 return False
144 145 gobject.type_register(BackgroundBox) 146