Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old Yesterday, 05:51 PM   #1
cgrapski
Enthusiast
cgrapski began at the beginning.
 
Posts: 42
Karma: 10
Join Date: Dec 2016
Device: Kindle
Plugin : Help needed

I created a plugin to put cover image data in columns. It loads and is enabled - but I don't get a choice to add it to a toolbar.

I created a ui.py file - this is it:
Code:
from calibre.customize import InterfaceActionBase
from calibre.gui2.actions import InterfaceAction
from calibre.gui2 import info_dialog
from calibre.utils.magick import Image
import os


class CoverSizeChecker(InterfaceActionBase):
    name = 'Cover Size Checker'
    description = 'Scan cover sizes and update #cover_width, #cover_height, and #cover_small.'
    supported_platforms = ['windows', 'osx', 'linux']
    author = 'Charlie'
    version = (1, 0, 0)
    minimum_calibre_version = (6, 0, 0)
    actual_plugin = 'calibre_plugins.CoverSizeChecker:CoverSizeCheckerAction'


class CoverSizeCheckerAction(InterfaceAction):
    name = 'Cover Size Checker'

    def genesis(self):
        self.qaction.triggered.connect(self.run)

    def run(self):
        gui = self.gui
        db = gui.current_db
        updated = 0
        small = []

        for book_id in db.all_book_ids():
            mi = db.get_metadata(book_id, index_is_id=True)
            cover = db.cover(book_id)

            if not cover or not os.path.exists(cover):
                continue

            try:
                img = Image()
                img.load(cover)
                w, h = img.width, img.height
            except Exception:
                continue

            mi.set('#cover_width', str(w))
            mi.set('#cover_height', str(h))

            if w < 450:
                mi.set('#cover_small', 'yes')
                small.append(f'{mi.title} — {w}x{h}')
            else:
                mi.set('#cover_small', 'no')

            db.set_metadata(book_id, mi)
            updated += 1

        msg = f'Updated {updated} books.\n\n'
        if small:
            msg += 'Small covers (

Last edited by PeterT; Yesterday at 09:33 PM.
cgrapski is offline   Reply With Quote
Old Today, 02:10 AM   #2
Comfy.n
want to learn what I want
Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.
 
Posts: 2,283
Karma: 7971785
Join Date: Sep 2020
Device: Libra Colour
Here's a working version, based on the action chain posted by @ownedbycats in this thread:

https://www.mobileread.com/forums/sh....php?p=4474488
Attached Files
File Type: zip CoverSizeChecker.zip (2.0 KB, 4 views)
Comfy.n is offline   Reply With Quote
Advert
Old Today, 02:16 AM   #3
Comfy.n
want to learn what I want
Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.
 
Posts: 2,283
Karma: 7971785
Join Date: Sep 2020
Device: Libra Colour
Column definitions used:
PHP Code:
Column headerCover Width
Lookup name
#cover_width
Typeint
Description
Cover Size Checkercover image width in pixels.
Is CompositeNo
Display settings
:
{
  
"description""Cover Size Checker: cover image width in pixels.",
  
"number_format""{0:,d}"

PHP Code:
Column headerCover Height
Lookup name
#cover_height
Typeint
Description
Cover Size Checkercover image height in pixels.
Is CompositeNo
Display settings
:
{
  
"description""Cover Size Checker: cover image height in pixels.",
  
"number_format""{0:,d}"

PHP Code:
Column headerCover Small
Lookup name
#cover_small
Typebool
Description
Cover Size Checkerflagged Yes when cover width is below 450 px.
Is CompositeNo
Display settings
:
{
  
"bools_show_icons"true,
  
"bools_show_text"false,
  
"description""Cover Size Checker: flagged Yes when cover width is below 450 px."

Comfy.n is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Testers needed for Reading Tracker plugin varia Plugins 69 04-26-2026 03:56 PM
Metadata Source Plugin, advice needed Boilerplate4U Development 19 04-03-2021 03:41 AM
Help needed to create a plugin to add more shortcuts celiapgt Plugins 11 06-28-2018 10:17 PM
An idea for a plugin - your opinions and help very welcome and needed! TAtanasoska Plugins 1 11-15-2014 10:49 PM
New MOBI output plugin, testing needed kovidgoyal Conversion 30 11-19-2011 04:52 PM


All times are GMT -4. The time now is 11:33 PM.


MobileRead.com is a privately owned, operated and funded community.