2
我是pygtk中的新手。我正在尋找一種方式如何創建使用父backgorund作爲自己的背景的自定義小部件 這樣的事情https://fbcdn-sphotos-e-a.akamaihd.net/hphotos-ak-prn1/31617_421363141269410_1875576801_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()
我想你應該可以設置背景透明的GTK3與CSS的幫助,但到底我又不是父母的信息需要當然。 – deinonychusaur