Package dtk :: Package ui :: Module line

Source Code for Module dtk.ui.line

  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_hlinear, draw_vlinear 
 24  import gobject 
 25  import gtk 
 26   
27 -class HSeparator(gtk.Alignment):
28 ''' 29 Horizontal separator. 30 31 @undocumented: expose_hseparator 32 ''' 33
34 - def __init__(self, 35 color_infos, 36 padding_x=0, 37 padding_y=0):
38 '''Init horizontal separator. 39 40 @param color_infos: A list of color info, [(position, (hex_color, alpha_value))] 41 @param padding_x: Padding value in horizontally. 42 @param padding_y: Padding value in vertically. 43 ''' 44 # Init. 45 gtk.Alignment.__init__(self) 46 self.color_infos = color_infos 47 self.set(0.0, 0.0, 1.0, 0.0) 48 self.set_padding(padding_y, padding_y, padding_x, padding_x) 49 50 # Init separator. 51 self.separator = gtk.VBox() 52 self.separator.set_size_request(-1, 1) 53 self.separator.connect("expose-event", self.expose_hseparator) 54 self.add(self.separator) 55 56 # Show. 57 self.show_all()
58
59 - def expose_hseparator(self, widget, event):
60 ''' 61 Callback for `expose-event` signal. 62 63 @param widget: HSeparator instance. 64 @param event: Expose event. 65 @return: Return True. 66 ''' 67 # Init. 68 cr = widget.window.cairo_create() 69 rect = widget.allocation 70 71 # Draw. 72 start_x = rect.x 73 y = rect.y + rect.height / 2 74 draw_hlinear(cr, start_x, y, rect.width, 1, self.color_infos) 75 76 return True
77 78 gobject.type_register(HSeparator) 79
80 -class VSeparator(gtk.Alignment):
81 ''' 82 Vertically separator. 83 84 @undocumented: expose_vseparator 85 ''' 86
87 - def __init__(self, 88 color_infos, 89 padding_x=0, 90 padding_y=0):
91 '''Init vertically separator. 92 93 @param color_infos: A list of color info, [(position, (hex_color, alpha_value))] 94 @param padding_x: Padding value in horizontally. 95 @param padding_y: Padding value in vertically. 96 ''' 97 gtk.Alignment.__init__(self) 98 99 self.set(0.0, 0.0, 0.0, 1.0) 100 self.set_padding(padding_y, padding_y, padding_x, padding_x) 101 102 self.color_infos = color_infos 103 self.separator = gtk.VBox() 104 self.separator.set_size_request(1, -1) 105 self.separator.connect("expose-event", self.expose_vseparator) 106 self.add(self.separator) 107 self.show_all()
108
109 - def expose_vseparator(self, widget, event):
110 ''' 111 Callback for `expose-event` signal. 112 113 @param widget: HSeparator instance. 114 @param event: Expose event. 115 @return: Return True. 116 ''' 117 cr = widget.window.cairo_create() 118 rect = widget.allocation 119 120 start_x = rect.x + rect.width / 2 121 draw_vlinear(cr, start_x, rect.y, 1, rect.height, self.color_infos) 122 123 return True
124 125 gobject.type_register(VSeparator) 126