示例#1
0
    def get_thumbnail(self, page=None, width=128, height=128, create=False,
                      nowait=False):
        """Return a thumbnail pixbuf of <page> that fit in a box with
        dimensions <width>x<height>. Return a thumbnail for the current
        page if <page> is None.

        If <create> is True, and <width>x<height> <= 128x128, the
        thumbnail is also stored on disk.

        If <nowait> is True, don't wait for <page> to be available.
        """
        if not self._wait_on_page(page, check_only=nowait):
            # Page is not available!
            return None
        path = self.get_path_to_page(page)

        if path == None:
            return None

        try:
            thumbnailer = thumbnail_tools.Thumbnailer(store_on_disk=create,
                                                      size=(width, height))
            return thumbnailer.thumbnail(path)
        except Exception:
            log.debug("Failed to create thumbnail for image `%s':\n%s",
                      path, traceback.format_exc())
            return image_tools.MISSING_IMAGE_ICON
示例#2
0
    def get_thumbnail(self, page=None, width=128, height=128, create=False,
                      nowait=False):
        """Return a thumbnail pixbuf of <page> that fit in a box with
        dimensions <width>x<height>. Return a thumbnail for the current
        page if <page> is None.

        If <create> is True, and <width>x<height> <= 128x128, the
        thumbnail is also stored on disk.

        If <nowait> is True, don't wait for <page> to be available.
        """
        if page is None:
            page = self.get_current_page()
        if not self._wait_on_page(page, check_only=nowait):
            # Page is not available!
            return None
        path = self.get_path_to_page(page)

        if path == None:
            return None

        try:
            thumbnailer = thumbnail_tools.Thumbnailer()
            thumbnailer.set_store_on_disk(create)
            thumbnailer.set_size(width, height)
            return thumbnailer.thumbnail(path)
        except Exception:
            return constants.MISSING_IMAGE_ICON
示例#3
0
    def __init__(self, edit_dialog, window):
        super(_ImageArea, self).__init__()

        self._window = window
        self._edit_dialog = edit_dialog
        self.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)

        # The ListStore layout is (thumbnail, basename, full path, thumbnail status).
        # Basename is used as image tooltip.
        self._liststore = Gtk.ListStore(GdkPixbuf.Pixbuf, str, str, bool)
        self._iconview = thumbnail_view.ThumbnailIconView(
            self._liststore,
            2,  # UID
            0,  # pixbuf
            3,  # status
        )
        self._iconview.generate_thumbnail = self._generate_thumbnail
        self._iconview.set_tooltip_column(1)
        self._iconview.set_reorderable(True)
        self._iconview.set_selection_mode(Gtk.SelectionMode.MULTIPLE)
        self._iconview.connect('button_press_event', self._button_press)
        self._iconview.connect('key_press_event', self._key_press)
        self._iconview.connect_after('drag_begin', self._drag_begin)
        self.add(self._iconview)

        self._thumbnail_size = 128
        self._thumbnailer = thumbnail_tools.Thumbnailer(
            store_on_disk=False,
            size=(self._thumbnail_size, self._thumbnail_size))

        self._filler = GdkPixbuf.Pixbuf.new(
            colorspace=GdkPixbuf.Colorspace.RGB,
            has_alpha=True,
            bits_per_sample=8,
            width=self._thumbnail_size,
            height=self._thumbnail_size)
        # Make the pixbuf transparent.
        self._filler.fill(0)

        self._window.imagehandler.page_available += self._on_page_available

        self._ui_manager = Gtk.UIManager()
        ui_description = """
        <ui>
            <popup name="Popup">
                <menuitem action="remove" />
            </popup>
        </ui>
        """

        self._ui_manager.add_ui_from_string(ui_description)

        actiongroup = Gtk.ActionGroup(name='mcomix-edit-archive-image-area')
        actiongroup.add_actions([('remove', Gtk.STOCK_REMOVE,
                                  _('Remove from archive'), None, None,
                                  self._remove_pages)])
        self._ui_manager.insert_action_group(actiongroup, 0)
示例#4
0
文件: backend.py 项目: juracy/mcomix
 def remove_book(self, book):
     """Remove the <book> from the library."""
     path = self.get_book_path(book)
     if path is not None:
         thumbnailer = thumbnail_tools.Thumbnailer(
             dst_dir=constants.LIBRARY_COVERS_PATH)
         thumbnailer.delete(path)
     self._con.execute('delete from Book where id = ?', (book, ))
     self._con.execute('delete from Contain where book = ?', (book, ))
示例#5
0
    def add_extra_image(self, path):
        """Add an imported image (at <path>) to the end of the image list."""
        thumbnailer = thumbnail_tools.Thumbnailer()
        thumbnailer.set_store_on_disk(False)
        thumb = thumbnailer.thumbnail(path)

        if thumb is None:
            thumb = self.render_icon(gtk.STOCK_MISSING_IMAGE,
                                     gtk.ICON_SIZE_DIALOG)

        self._liststore.append([thumb, os.path.basename(path), path, -1, True])
    def _update_preview(self, *args):
        path = self.filechooser.get_preview_filename()

        if path and os.path.isfile(path):
            thumbnailer = thumbnail_tools.Thumbnailer(size=(128, 128),
                                                      archive_support=True)
            thumbnailer.thumbnail_finished += self._preview_thumbnail_finished
            thumbnailer.thumbnail(path, mt=True)
        else:
            self._preview_image.clear()
            self._namelabel.set_text('')
            self._sizelabel.set_text('')
示例#7
0
def main():
    parser = argparse.ArgumentParser(
        prog='comicthumb',
        description='Thumbnailer for comic book archives',
        epilog='Supported formats: ZIP, RAR and tar (.cbz, .cbr, .cbt)',
    )
    parser.add_argument('infile',
                        default=None,
                        metavar='INFILE',
                        help='input archive')
    parser.add_argument('outfile',
                        default=None,
                        metavar='OUTFILE',
                        help='output thumbnail')
    parser.add_argument(
        'size',
        nargs='?',
        default=THUMB_SIZE,
        metavar='SIZE',
        help='size of thumbnail (default: {})'.format(THUMB_SIZE))
    ns = parser.parse_args()
    in_path = abspath(ns.infile)
    out_path = abspath(ns.outfile)
    if in_path.startswith(URL_PREFIX):
        in_path = unquote(in_path[len(URL_PREFIX):])
    if not exists(in_path):
        print('not exists:', ns.infile)
        parser.print_usage()
        return 1
    try:
        size = int(ns.size)
    except ValueError:
        print('invalid SIZE:', ns.size)
        parser.print_usage()
        return 1

    thumbnailer = thumbnail_tools.Thumbnailer(force_recreation=True,
                                              archive_support=True,
                                              store_on_disk=False,
                                              size=(size, size))
    thumb = thumbnailer.thumbnail(in_path)
    if thumb:
        thumb.savev(out_path, 'png', [], [])
    else:
        print('unsupported file:', in_path)
        print(
            'please see https://github.com/multiSnow/mcomix3/blob/gtk3/README.rst'
        )
        print('for supported format and required library/tool.')
        return 1
    def _update_preview(self, *args):
        if self.filechooser.get_preview_filename():
            path = self.filechooser.get_preview_filename().decode('utf-8')
        else:
            path = None

        if path and os.path.isfile(path):
            thumbnailer = thumbnail_tools.Thumbnailer()
            thumbnailer.set_size(128, 128)
            thumbnailer.thumbnail_finished += self._preview_thumbnail_finished
            thumbnailer.thumbnail(path, async=True)
        else:
            self._preview_image.clear()
            self._namelabel.set_text('')
            self._sizelabel.set_text('')
示例#9
0
文件: backend.py 项目: juracy/mcomix
    def get_book_thumbnail(self, path):
        """ Returns a pixbuf with a thumbnail of the cover of the book at <path>,
        or None, if no thumbnail could be generated. """

        thumbnailer = thumbnail_tools.Thumbnailer(
            dst_dir=constants.LIBRARY_COVERS_PATH)
        thumbnailer.set_store_on_disk(True)
        # This is the maximum image size allowed by the library, so that thumbnails might be downscaled,
        # but never need to be upscaled (and look ugly)
        thumbnailer.set_size(constants.MAX_LIBRARY_COVER_SIZE,
                             constants.MAX_LIBRARY_COVER_SIZE)
        thumb = thumbnailer.thumbnail(path)

        if thumb is None:
            log.warning(_('! Could not get cover for book "%s"'), path)
        return thumb
示例#10
0
    def get_book_thumbnail(self, path):
        ''' Returns a pixbuf with a thumbnail of the cover of the book at <path>,
        or None, if no thumbnail could be generated. '''

        # Use the maximum image size allowed by the library, so that thumbnails
        # might be downscaled, but never need to be upscaled (and look ugly).
        thumbnailer = thumbnail_tools.Thumbnailer(
            dst_dir=constants.LIBRARY_COVERS_PATH,
            store_on_disk=True,
            archive_support=True,
            size=(constants.MAX_LIBRARY_COVER_SIZE,
                  constants.MAX_LIBRARY_COVER_SIZE))
        thumb = thumbnailer.thumbnail(path)

        if thumb is None:
            log.warning(_('! Could not get cover for book "%s"'), path)
        return thumb
示例#11
0
    def get_thumbnail(self, page=None, width=128, height=128, create=False):
        """Return a thumbnail pixbuf of <page> that fit in a box with
        dimensions <width>x<height>. Return a thumbnail for the current
        page if <page> is None.

        If <create> is True, and <width>x<height> <= 128x128, the
        thumbnail is also stored on disk.
        """
        self._wait_on_page(page)
        path = self.get_path_to_page(page)

        if path == None:
            return constants.MISSING_IMAGE_ICON

        try:
            thumbnailer = thumbnail_tools.Thumbnailer()
            thumbnailer.set_store_on_disk(create)
            thumbnailer.set_size(width, height)
            return thumbnailer.thumbnail(path)
        except Exception:
            return constants.MISSING_IMAGE_ICON
示例#12
0
from mcomix import portability

import sys
from urllib.parse import unquote

if __name__ == '__main__':
    argv = portability.get_commandline_args()
    try:
        in_path = argv[0]
        out_path = argv[1]
        if len(argv) == 3:
            size = int(argv[2])
        else:
            size = 128
    except:
        print(__doc__)
        sys.exit(1)

    if in_path.startswith('file://'):
        in_path = unquote(in_path[7:])

    thumbnailer = thumbnail_tools.Thumbnailer(force_recreation=True,
                                              archive_support=True,
                                              store_on_disk=False,
                                              size=(size, size))
    thumb = thumbnailer.thumbnail(in_path)
    thumb.savev(out_path, 'png', [], [])

    sys.exit(0)