Bug 4310: Ancestry>Pedigree View is largely broken with Gtk-OSX

Don't retain a reference to the CairoContext by setting self.context (or
self.cairocontext). That context is invalidated on the return from the 
handler anyway with a context.restore(), so there's no benefit to 
keeping it around.



svn: r20335
This commit is contained in:
John Ralls
2012-09-05 21:16:45 +00:00
parent 09806437b8
commit d8ccf0de9b

View File

@ -249,16 +249,15 @@ class PersonBoxWidgetCairo(_PersonWidgetBase):
0, alloc.height-5, 0, alloc.height-5,
0, alloc.height-8) 0, alloc.height-8)
context.close_path() context.close_path()
return self.context.copy_path() return context.copy_path()
# pylint: disable-msg=E1101 # pylint: disable-msg=E1101
minw = 120 minw = 120
minh = 25 minh = 25
alw = self.get_allocated_width() alw = self.get_allocated_width()
alh = self.get_allocated_height() alh = self.get_allocated_height()
self.context = context
if not self.textlayout: if not self.textlayout:
self.textlayout = PangoCairo.create_layout(self.context) self.textlayout = PangoCairo.create_layout(context)
self.textlayout.set_font_description(self.get_style().font_desc) self.textlayout.set_font_description(self.get_style().font_desc)
self.textlayout.set_markup(self.text, -1) self.textlayout.set_markup(self.text, -1)
size = self.textlayout.get_pixel_size() size = self.textlayout.get_pixel_size()
@ -275,67 +274,68 @@ class PersonBoxWidgetCairo(_PersonWidgetBase):
alh = self.get_allocated_height() alh = self.get_allocated_height()
# widget area for debugging # widget area for debugging
##self.context.rectangle(0, 0, alloc.width, alloc.height) ##context.rectangle(0, 0, alloc.width, alloc.height)
##self.context.set_source_rgb(1, 0, 1) ##context.set_source_rgb(1, 0, 1)
##self.context.fill_preserve() ##context.fill_preserve()
##self.context.stroke() ##context.stroke()
# Create box shape and store path # Create box shape and store path
self.context.save() context.save()
path = _boxpath(self.context, alloc) path = _boxpath(context, alloc)
# shadow # shadow
self.context.translate(3, 3) context.translate(3, 3)
self.context.new_path() context.new_path()
self.context.append_path(path) context.append_path(path)
self.context.set_source_rgba(*(self.bordercolor[:3] + (0.4,))) context.set_source_rgba(*(self.bordercolor[:3] + (0.4,)))
self.context.fill_preserve() context.fill_preserve()
self.context.set_line_width(0) context.set_line_width(0)
self.context.stroke() context.stroke()
self.context.restore() context.restore()
self.context.save() context.save()
# box shape used for clipping # box shape used for clipping
_boxpath(self.context, alloc) _boxpath(context, alloc)
self.context.clip() context.clip()
# background (while clipped) # background (while clipped)
_boxpath(self.context, alloc) _boxpath(context, alloc)
self.context.set_source_rgb(*self.bgcolor[:3]) context.set_source_rgb(*self.bgcolor[:3])
self.context.fill_preserve() context.fill_preserve()
self.context.stroke() context.stroke()
# image # image
if self.img_surf: if self.img_surf:
self.context.set_source_surface(self.img_surf, context.set_source_surface(self.img_surf,
alloc.width-4-self.img_surf.get_width(), 1) alloc.width-4-self.img_surf.get_width(), 1)
self.context.paint() context.paint()
# Mark deceased # Mark deceased
self.context.new_path() context.new_path()
if self.person and not self.alive: if self.person and not self.alive:
self.context.set_source_rgb(0, 0, 0) context.set_source_rgb(0, 0, 0)
self.context.set_line_width(2) context.set_line_width(2)
self.context.move_to(0, 10) context.move_to(0, 10)
self.context.line_to(10, 0) context.line_to(10, 0)
self.context.stroke() context.stroke()
#border #border
_boxpath(self.context, alloc) _boxpath(context, alloc)
if self.hightlight: if self.hightlight:
self.context.set_line_width(5) context.set_line_width(5)
else: else:
self.context.set_line_width(2) context.set_line_width(2)
self.context.set_source_rgb(*self.bordercolor[:3]) context.set_source_rgb(*self.bordercolor[:3])
self.context.stroke() context.stroke()
self.context.restore() context.restore()
self.context.save() context.save()
# text # text
self.context.move_to(5, 4) context.move_to(5, 4)
self.context.set_source_rgb(0, 0, 0) context.set_source_rgb(0, 0, 0)
PangoCairo.show_layout(self.context, self.textlayout) PangoCairo.show_layout(context, self.textlayout)
self.context.restore() context.restore()
context.get_target().flush()
class LineWidget(Gtk.DrawingArea): class LineWidget(Gtk.DrawingArea):
""" """
@ -357,9 +357,8 @@ class LineWidget(Gtk.DrawingArea):
""" """
Redraw the contents of the widget. Redraw the contents of the widget.
""" """
self.cairocontext = context
self.set_size_request(20, 20) self.set_size_request(20, 20)
self.cairocontext.set_source_rgb(0.,0.,0.) context.set_source_rgb(0.,0.,0.)
# pylint: disable-msg=E1101 # pylint: disable-msg=E1101
alloc = self.get_allocation() alloc = self.get_allocation()
child = self.child_box.get_allocation() child = self.child_box.get_allocation()
@ -393,42 +392,42 @@ class LineWidget(Gtk.DrawingArea):
parent_side = 0 parent_side = 0
if self.father_box: if self.father_box:
self.draw_link(parent_side, middle, child_side, centre, self.draw_link(context, parent_side, middle, child_side, centre,
father_side, self.mrel) father_side, self.mrel)
if self.mother_box: if self.mother_box:
self.draw_link(parent_side, middle, child_side, centre, self.draw_link(context, parent_side, middle, child_side, centre,
mother_side, self.frel) mother_side, self.frel)
def draw_link(self, parent_side, middle, child_side, centre, side, rela): def draw_link(self, cr, parent_side, middle, child_side, centre, side, rela):
""" """
Draw a link between parent and child. Draw a link between parent and child.
""" """
self.cairocontext.set_line_width(3) cr.set_line_width(3)
if rela: if rela:
self.cairocontext.set_dash([], 0) #SOLID cr.set_dash([], 0) #SOLID
else: else:
self.cairocontext.set_dash([9.], 1) #DASH cr.set_dash([9.], 1) #DASH
self.draw_line(parent_side, side, centre, side) self.draw_line(cr, parent_side, side, centre, side)
self.draw_line(centre, side, centre, middle, True) self.draw_line(cr, centre, side, centre, middle, True)
self.draw_line(centre, middle, child_side, middle, True) self.draw_line(cr, centre, middle, child_side, middle, True)
self.cairocontext.stroke() cr.stroke()
def draw_line(self, x_from, y_from, x_to, y_to, join=False): def draw_line(self, cr, x_from, y_from, x_to, y_to, join=False):
""" """
Draw a single line in a link. Draw a single line in a link.
""" """
# pylint: disable-msg=E1101 # pylint: disable-msg=E1101
if self.direction in [2, 3]: # horizontal if self.direction in [2, 3]: # horizontal
if not join: if not join:
self.cairocontext.move_to(x_from, y_from) cr.move_to(x_from, y_from)
self.cairocontext.line_to(x_to, y_to) cr.line_to(x_to, y_to)
else: else:
if not join: if not join:
self.cairocontext.move_to(y_from, x_from) cr.move_to(y_from, x_from)
self.cairocontext.line_to(y_to, x_to) cr.line_to(y_to, x_to)
class LineWidget2(Gtk.DrawingArea): class LineWidget2(Gtk.DrawingArea):
""" """
@ -447,9 +446,8 @@ class LineWidget2(Gtk.DrawingArea):
""" """
Redraw the contents of the widget. Redraw the contents of the widget.
""" """
self.cairocontext = context
self.set_size_request(20, -1) self.set_size_request(20, -1)
self.cairocontext.set_source_rgb(0.,0.,0.) context.set_source_rgb(0.,0.,0.)
# pylint: disable-msg=E1101 # pylint: disable-msg=E1101
alloc = self.get_allocation() alloc = self.get_allocation()
@ -468,11 +466,11 @@ class LineWidget2(Gtk.DrawingArea):
mid_y = alloc.width / 2 mid_y = alloc.width / 2
mid_x = alloc.height / 2 mid_x = alloc.height / 2
self.cairocontext.set_line_width(3) context.set_line_width(3)
if self.rela: if self.rela:
self.cairocontext.set_dash([], 0) #SOLID context.set_dash([], 0) #SOLID
else: else:
self.cairocontext.set_dash([9.], 1) #DASH context.set_dash([9.], 1) #DASH
if self.direction in [1, 3]: if self.direction in [1, 3]:
parent_x = 0 parent_x = 0
@ -480,22 +478,22 @@ class LineWidget2(Gtk.DrawingArea):
if not self.male: if not self.male:
child_y = 0 child_y = 0
self.draw_line(child_x, child_y, mid_x, mid_y) self.draw_line(context, child_x, child_y, mid_x, mid_y)
self.draw_line(mid_x, mid_y, parent_x, parent_y, True) self.draw_line(context, mid_x, mid_y, parent_x, parent_y, True)
def draw_line(self, x_from, y_from, x_to, y_to, join=False): def draw_line(self, cr, x_from, y_from, x_to, y_to, join=False):
""" """
Draw a single line in a link. Draw a single line in a link.
""" """
# pylint: disable-msg=E1101 # pylint: disable-msg=E1101
if self.direction in [2, 3]: # horizontal if self.direction in [2, 3]: # horizontal
if not join: if not join:
self.cairocontext.move_to(x_from, y_from) cr.move_to(x_from, y_from)
self.cairocontext.line_to(x_to, y_to) cr.line_to(x_to, y_to)
else: else:
if not join: if not join:
self.cairocontext.move_to(y_from, x_from) cr.move_to(y_from, x_from)
self.cairocontext.line_to(y_to, x_to) cr.line_to(y_to, x_to)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #