我是 pygtk 的新手。我正在寻找一种方法来创建使用父背景作为自己的背景的自定义小部件,例如https://fbcdn-sphotos-ea.akamaihd.net/hphotos-ak-prn1/31617_421363141269410_1875576 801_n.jpg
如何获取父位图并将其用作自己的位图?
class RoundRectPanel(gtk.DrawingArea, PanelBase):
"""
Panel That represents
"""
def __init__(self):
super(ProximityPanel, self).__init__()
def initialize(self):
super(RoundRectPanel, self).initialize()
self.set_size_request(340, 300)
self.connect('expose-event', self.expose)
def terminate(self):
pass
def rounded_rectangle(self, cr, x, y, w, h, r=20):
# A****BQ
# H C
# * *
# G D
# F****E
cr.move_to(x+r,y) # Move to A
cr.line_to(x+w-r,y) # Straight line to B
cr.curve_to(x+w,y,x+w,y,x+w,y+r) # Curve to C, Control points are both at Q
cr.line_to(x+w,y+h-r) # Move to D
cr.curve_to(x+w,y+h,x+w,y+h,x+w-r,y+h) # Curve to E
cr.line_to(x+r,y+h) # Line to F
cr.curve_to(x,y+h,x,y+h,x,y+h-r) # Curve to G
cr.line_to(x,y+r) # Line to H
cr.curve_to(x,y,x,y,x+r,y) # Curve to A
def expose(self, canvas, event):
# Create cairo context
cr = canvas.window.cairo_create()
# TODO: 1. GET PARENT background
# 2. set it as canvas background
# 3. draw on it
self.rounded_rectangle(cr, 0, 0, 340, 300)
cr.stroke_preserve()
cr.set_source_rgba(1.0, 1.0, 1.0, 0.5)
cr.fill()