From ef8b57606d8f4d49354d5019317ecc649ecdf521 Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Thu, 05 Sep 2013 19:05:16 +0000 Subject: Don't crash if the book have bookmarks saved, but can't open the preview If the preview can't be opened or created, create a image with a number showing the page number. Signed-off-by: Gonzalo Odiard --- diff --git a/linkbutton.py b/linkbutton.py index 3fd4579..075fdb3 100644 --- a/linkbutton.py +++ b/linkbutton.py @@ -50,7 +50,11 @@ class LinkButton(TrayButton, GObject.GObject): # it as single byte string: if isinstance(color, unicode): color = str(color) - self.set_image(buf, color.split(',')[1], color.split(',')[0]) + if buf is not None: + self.set_image(buf, color.split(',')[1], color.split(',')[0]) + else: + self.set_empty_image(page, color.split(',')[1], + color.split(',')[0]) self.page = int(page) info = title + '\n' + owner @@ -87,6 +91,39 @@ class LinkButton(TrayButton, GObject.GObject): self.set_icon_widget(img) img.show() + def set_empty_image(self, page, fill='#0000ff', stroke='#4d4c4f'): + img = Gtk.Image() + + bg_width, bg_height = style.zoom(120), style.zoom(110) + bg_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, bg_width, + bg_height) + context = cairo.Context(bg_surface) + # draw a rectangle in the background with the selected colors + context.set_line_width(style.zoom(10)) + context.set_source_rgba(*style.Color(fill).get_rgba()) + context.rectangle(0, 0, bg_width, bg_height) + context.fill_preserve() + context.set_source_rgba(*style.Color(stroke).get_rgba()) + context.stroke() + + # add the page number + context.set_font_size(style.zoom(60)) + text = str(page) + x, y = bg_width / 2, bg_height / 2 + + xbearing, ybearing, width, height, xadvance, yadvance = \ + context.text_extents(text) + context.move_to(x - width / 2, y + height / 2) + context.show_text(text) + context.stroke() + + pixbuf_bg = Gdk.pixbuf_get_from_surface(bg_surface, 0, 0, + bg_width, bg_height) + + img.set_from_pixbuf(pixbuf_bg) + self.set_icon_widget(img) + img.show() + def setup_rollover_options(self, info): palette = Palette(info, text_maxlen=50) self.set_palette(palette) diff --git a/readactivity.py b/readactivity.py index 2714ccc..1aed546 100644 --- a/readactivity.py +++ b/readactivity.py @@ -1202,6 +1202,9 @@ class ReadActivity(activity.Activity): return None window = self.canvas.get_window() + if window is None: + return None + alloc = self.canvas.get_allocation() dummy_cr = Gdk.cairo_create(window) -- cgit v0.9.1