示例#1
0
    def _drag_begin(self, iconview, context):
        """Create a cursor image for drag-n-drop from the library.

        This method relies on implementation details regarding PIL's
        drawing functions and default font to produce good looking results.
        If those are changed in a future release of PIL, this method might
        produce bad looking output (e.g. non-centered text).

        It's also used with connect_after() to overwrite the cursor
        automatically created when using enable_model_drag_source(), so in
        essence it's a hack, but at least it works.
        """
        icon_path = iconview.get_cursor()[0]
        num_books = len(iconview.get_selected_items())
        book = self.get_book_at_path(icon_path)

        cover = self._library.backend.get_book_cover(book)
        if cover is None:
            cover = self._library.render_icon(gtk.STOCK_MISSING_IMAGE,
                                              gtk.ICON_SIZE_DIALOG)
        cover = cover.scale_simple(max(0, cover.get_width() // 2),
                                   max(0, cover.get_height() // 2), gtk.gdk.INTERP_TILES)
        cover = image.add_border(cover, 1, 0xFFFFFFFF)
        cover = image.add_border(cover, 1)

        if num_books > 1:
            cover_width = cover.get_width()
            cover_height = cover.get_height()
            pointer = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8,
                                     max(30, cover_width + 15), max(30, cover_height + 10))
            pointer.fill(0x00000000)
            cover.composite(pointer, 0, 0, cover_width, cover_height, 0, 0,
                            1, 1, gtk.gdk.INTERP_TILES, 255)
            im = Image.new('RGBA', (30, 30), 0x00000000)
            draw = ImageDraw.Draw(im)
            draw.polygon(
                    (8, 0, 20, 0, 28, 8, 28, 20, 20, 28, 8, 28, 0, 20, 0, 8),
                    fill=(0, 0, 0), outline=(0, 0, 0))
            draw.polygon(
                    (8, 1, 20, 1, 27, 8, 27, 20, 20, 27, 8, 27, 1, 20, 1, 8),
                    fill=(128, 0, 0), outline=(255, 255, 255))
            text = str(num_books)
            draw.text((15 - (6 * len(text) // 2), 9), text,
                      fill=(255, 255, 255))
            circle = image.pil_to_pixbuf(im)
            circle.composite(pointer, max(0, cover_width - 15),
                             max(0, cover_height - 20), 30, 30, max(0, cover_width - 15),
                             max(0, cover_height - 20), 1, 1, gtk.gdk.INTERP_TILES, 255)
        else:
            pointer = cover

        context.set_icon_pixbuf(pointer, -5, -5)
示例#2
0
文件: lens.py 项目: yamaka67/Comix
 def _get_lens_pixbuf(self, x, y):
     """Get a pixbuf containing the appropiate image data for the lens
     where <x> and <y> are the positions of the cursor.
     """
     canvas = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8,
                             prefs['lens size'], prefs['lens size'])
     canvas.fill(0x000000bb)
     if self._window.displayed_double():
         if self._window.is_manga_mode:
             r_source_pixbuf, l_source_pixbuf = \
                 self._window.file_handler.get_pixbufs()
         else:
             l_source_pixbuf, r_source_pixbuf = \
                 self._window.file_handler.get_pixbufs()
         l_image_size = self._window.left_image.size_request()
         r_image_size = self._window.right_image.size_request()
         self._add_subpixbuf(canvas, x, y, l_image_size, l_source_pixbuf,
                             r_image_size[0], left=True)
         self._add_subpixbuf(canvas, x, y, r_image_size, r_source_pixbuf,
                             l_image_size[0], left=False)
     else:
         source_pixbuf = self._window.file_handler.get_pixbufs()
         image_size = self._window.left_image.size_request()
         self._add_subpixbuf(canvas, x, y, image_size, source_pixbuf)
     return image.add_border(canvas, 1)
示例#3
0
文件: edit.py 项目: HoverHell/Comix
 def add_extra_image(self, path):
     """Add an imported image (at <path>) to the end of the image list."""
     thumb = thumbnail.get_thumbnail(path, create=False)
     if thumb is None:
         thumb = self.render_icon(gtk.STOCK_MISSING_IMAGE,
                                  gtk.ICON_SIZE_DIALOG)
     thumb = image.fit_in_rectangle(thumb, 67, 100)
     thumb = image.add_border(thumb, 1, 0x555555FF)
     self._liststore.append([thumb, os.path.basename(path), path])
示例#4
0
文件: edit.py 项目: yamaka67/Comix
 def add_extra_image(self, path):
     """Add an imported image (at <path>) to the end of the image list."""
     thumb = thumbnail.get_thumbnail(path, create=False)
     if thumb is None:
         thumb = self.render_icon(gtk.STOCK_MISSING_IMAGE,
                                  gtk.ICON_SIZE_DIALOG)
     thumb = image.fit_in_rectangle(thumb, 67, 100)
     thumb = image.add_border(thumb, 1, 0x555555FF)
     self._liststore.append([thumb, os.path.basename(path), path])
示例#5
0
 def _add_book(self, book):
     """Add the <book> to the ListStore (and thus to the _BookArea)."""
     pixbuf = self._library.backend.get_book_cover(book)
     if pixbuf is None:
         pixbuf = self._library.render_icon(gtk.STOCK_MISSING_IMAGE,
                                            gtk.ICON_SIZE_DIALOG)
     # The ratio (0.67) is just above the normal aspect ratio for books.
     pixbuf = image.fit_in_rectangle(
         pixbuf, int(0.67 * prefs['library cover size']),
         prefs['library cover size'])
     pixbuf = image.add_border(pixbuf, 1, 0xFFFFFFFF)
     self._liststore.append([pixbuf, book])
示例#6
0
 def _add_book(self, book):
     """Add the <book> to the ListStore (and thus to the _BookArea)."""
     pixbuf = self._library.backend.get_book_cover(book)
     if pixbuf is None:
         pixbuf = self._library.render_icon(gtk.STOCK_MISSING_IMAGE,
                                            gtk.ICON_SIZE_DIALOG)
     # The ratio (0.67) is just above the normal aspect ratio for books.
     pixbuf = image.fit_in_rectangle(pixbuf,
                                     int(0.67 * prefs['library cover size']),
                                     prefs['library cover size'])
     pixbuf = image.add_border(pixbuf, 1, 0xFFFFFFFF)
     self._liststore.append([pixbuf, book])
示例#7
0
文件: edit.py 项目: HoverHell/Comix
 def fetch_images(self):
     """Load all the images in the archive or directory."""
     for page in range(1, self._edit_dialog.file_handler.get_number_of_pages() + 1):
         thumb = self._edit_dialog.file_handler.get_thumbnail(
                 page, 67, 100, create=False)
         thumb = image.add_border(thumb, 1, 0x555555FF)
         path = self._edit_dialog.file_handler.get_path_to_page(page)
         self._liststore.append([thumb,
                                 encoding.to_unicode(os.path.basename(path)), path])
         if page % 10 == 0:
             while gtk.events_pending():
                 gtk.main_iteration(False)
             if self._edit_dialog.kill:
                 return
示例#8
0
 def _update_preview(self, *args):
     path = self.filechooser.get_preview_filename()
     if path and os.path.isfile(path):
         pixbuf = thumbnail.get_thumbnail(path, prefs['create thumbnails'])
         if pixbuf is None:
             self._preview_image.clear()
             self._namelabel.set_text('')
             self._sizelabel.set_text('')
         else:
             pixbuf = image.add_border(pixbuf, 1)
             self._preview_image.set_from_pixbuf(pixbuf)
             self._namelabel.set_text(encoding.to_unicode(
                     os.path.basename(path)))
             self._sizelabel.set_text(
                     '{:.1f} KiB'.format(os.stat(path).st_size / 1024.0))
     else:
         self._preview_image.clear()
         self._namelabel.set_text('')
         self._sizelabel.set_text('')
示例#9
0
文件: edit.py 项目: yamaka67/Comix
 def fetch_images(self):
     """Load all the images in the archive or directory."""
     for page in range(
             1,
             self._edit_dialog.file_handler.get_number_of_pages() + 1):
         thumb = self._edit_dialog.file_handler.get_thumbnail(page,
                                                              67,
                                                              100,
                                                              create=False)
         thumb = image.add_border(thumb, 1, 0x555555FF)
         path = self._edit_dialog.file_handler.get_path_to_page(page)
         self._liststore.append(
             [thumb,
              encoding.to_unicode(os.path.basename(path)), path])
         if page % 10 == 0:
             while gtk.events_pending():
                 gtk.main_iteration(False)
             if self._edit_dialog.kill:
                 return
示例#10
0
 def _update_preview(self, *args):
     path = self.filechooser.get_preview_filename()
     if path and os.path.isfile(path):
         pixbuf = thumbnail.get_thumbnail(path, prefs['create thumbnails'])
         if pixbuf is None:
             self._preview_image.clear()
             self._namelabel.set_text('')
             self._sizelabel.set_text('')
         else:
             pixbuf = image.add_border(pixbuf, 1)
             self._preview_image.set_from_pixbuf(pixbuf)
             self._namelabel.set_text(
                 encoding.to_unicode(os.path.basename(path)))
             self._sizelabel.set_text('%.1f KiB' %
                                      (os.stat(path).st_size / 1024.0))
     else:
         self._preview_image.clear()
         self._namelabel.set_text('')
         self._sizelabel.set_text('')
示例#11
0
 def _load(self):
     if self._window.file_handler.archive_type is not None:
         create = False
     else:
         create = prefs['create thumbnails']
     self._stop_update = False
     for i in range(1, self._window.file_handler.get_number_of_pages() + 1):
         pixbuf = self._window.file_handler.get_thumbnail(
             i, prefs['thumbnail size'], prefs['thumbnail size'], create)
         if prefs['show page numbers on thumbnails']:
             _add_page_number(pixbuf, i)
         pixbuf = image.add_border(pixbuf, 1)
         self._liststore.append([pixbuf])
         while gtk.events_pending():
             gtk.main_iteration(False)
         if self._stop_update:
             return
         self._height += self._treeview.get_background_area(
             i - 1, self._column).height
         self._layout.set_size(0, self._height)
     self._stop_update = True
     self.update_select()
示例#12
0
 def _load(self):
     if self._window.file_handler.archive_type is not None:
         create = False
     else:
         create = prefs['create thumbnails']
     self._stop_update = False
     for i in range(1, self._window.file_handler.get_number_of_pages() + 1):
         pixbuf = self._window.file_handler.get_thumbnail(i,
                                                          prefs['thumbnail size'], prefs['thumbnail size'], create)
         if prefs['show page numbers on thumbnails']:
             _add_page_number(pixbuf, i)
         pixbuf = image.add_border(pixbuf, 1)
         self._liststore.append([pixbuf])
         while gtk.events_pending():
             gtk.main_iteration(False)
         if self._stop_update:
             return
         self._height += self._treeview.get_background_area(i - 1,
                                                            self._column).height
         self._layout.set_size(0, self._height)
     self._stop_update = True
     self.update_select()
示例#13
0
    def _drag_begin(self, iconview, context):
        """Create a cursor image for drag-n-drop from the library.

        This method relies on implementation details regarding PIL's
        drawing functions and default font to produce good looking results.
        If those are changed in a future release of PIL, this method might
        produce bad looking output (e.g. non-centered text).

        It's also used with connect_after() to overwrite the cursor
        automatically created when using enable_model_drag_source(), so in
        essence it's a hack, but at least it works.
        """
        icon_path = iconview.get_cursor()[0]
        num_books = len(iconview.get_selected_items())
        book = self.get_book_at_path(icon_path)

        cover = self._library.backend.get_book_cover(book)
        if cover is None:
            cover = self._library.render_icon(gtk.STOCK_MISSING_IMAGE,
                                              gtk.ICON_SIZE_DIALOG)
        cover = cover.scale_simple(max(0,
                                       cover.get_width() // 2),
                                   max(0,
                                       cover.get_height() // 2),
                                   gtk.gdk.INTERP_TILES)
        cover = image.add_border(cover, 1, 0xFFFFFFFF)
        cover = image.add_border(cover, 1)

        if num_books > 1:
            cover_width = cover.get_width()
            cover_height = cover.get_height()
            pointer = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8,
                                     max(30, cover_width + 15),
                                     max(30, cover_height + 10))
            pointer.fill(0x00000000)
            cover.composite(pointer, 0, 0, cover_width, cover_height, 0, 0, 1,
                            1, gtk.gdk.INTERP_TILES, 255)
            im = Image.new('RGBA', (30, 30), 0x00000000)
            draw = ImageDraw.Draw(im)
            draw.polygon(
                (8, 0, 20, 0, 28, 8, 28, 20, 20, 28, 8, 28, 0, 20, 0, 8),
                fill=(0, 0, 0),
                outline=(0, 0, 0))
            draw.polygon(
                (8, 1, 20, 1, 27, 8, 27, 20, 20, 27, 8, 27, 1, 20, 1, 8),
                fill=(128, 0, 0),
                outline=(255, 255, 255))
            text = str(num_books)
            draw.text((15 - (6 * len(text) // 2), 9),
                      text,
                      fill=(255, 255, 255))
            circle = image.pil_to_pixbuf(im)
            circle.composite(pointer, max(0, cover_width - 15),
                             max(0, cover_height - 20), 30, 30,
                             max(0,
                                 cover_width - 15), max(0, cover_height - 20),
                             1, 1, gtk.gdk.INTERP_TILES, 255)
        else:
            pointer = cover

        context.set_icon_pixbuf(pointer, -5, -5)
示例#14
0
 def set_thumbnail(self, pixbuf):
     pixbuf = image.add_border(pixbuf, 1)
     self._thumb.set_from_pixbuf(pixbuf)
示例#15
0
 def set_thumbnail(self, pixbuf):
     pixbuf = image.add_border(pixbuf, 1)
     self._thumb.set_from_pixbuf(pixbuf)