Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 08-22-2022, 03:57 AM   #1
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: 1,609
Karma: 7891011
Join Date: Sep 2020
Device: none
Emblem in Cover Grid not updating instantly like it used to

Hi,

I've been using successfully, for a long time now, a rule that sets an emblem in Cover Grid, as following:

"If the #lastopened column is set (single condition), add emblem X"

Issue is that, since Calibre 6, IIRC, the emblem will not display instantly after viewing any book (of any filetype).

The custom column #lastopened is updating instantly as it used to. I have it displayed on the details sidebar, so I can see it's working as usual.

Today I tried switching from this PI to use the Job Spy PI similar functionality, that updates the custom column, but the emblem still won't show up after opening/viewing the books, unless I restart Calibre.

(BTW, I'm not sure whether a PI is really necessary to get the #lastopened custom column updated.)

Anyway, problem is just that the emblem won't show up instantly as it used to. Thoughts?

I should clarify that I have many titles that were added to the Library, however haven't been viewed, hence I find that emblem kind of useful.


Update: today I tested again JS Plugin "Activate Last-viewed" option, and to my pleasant surprise, I had the emblem update instantly, after viewing any title even with external viewers.
(JS version 1.0.196)
Attached Thumbnails
Click image for larger version

Name:	MWSnap0633 2022-08-22, 04_26_41.png
Views:	148
Size:	24.0 KB
ID:	196025  

Last edited by Comfy.n; 12-07-2022 at 09:32 PM. Reason: update
Comfy.n is offline   Reply With Quote
Old 08-23-2022, 03:54 AM   #2
igorius
Zealot
igorius began at the beginning.
 
Posts: 123
Karma: 34
Join Date: Jun 2015
Device: ipad & inkpad X
I can confirm that certain rows dont get updated instantly (using external plugins), but normally if i do something in the library (open a book, add a new book or whatever), the affected rows get updated.
I dont use emblems, so this "problem" could be something different.
Maybe your row #lastopened is "malformed": Look inside the row settings, if that row only contains the date without hour, the row only gets updated once a day...
My setting is german view, set yours according your language
Attached Thumbnails
Click image for larger version

Name:	Bildschirmfoto 2022-08-23 um 09.58.23.jpg
Views:	95
Size:	27.0 KB
ID:	196039  

Last edited by igorius; 08-23-2022 at 03:59 AM.
igorius is offline   Reply With Quote
Advert
Old 08-23-2022, 05:04 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: 1,609
Karma: 7891011
Join Date: Sep 2020
Device: none
Quote:
Originally Posted by igorius View Post
I can confirm that certain rows dont get updated instantly (using external plugins), but normally if i do something in the library (open a book, add a new book or whatever), the affected rows get updated.
I dont use emblems, so this "problem" could be something different.
Maybe your row #lastopened is "malformed": Look inside the row settings, if that row only contains the date without hour, the row only gets updated once a day...
My setting is german view, set yours according your language
Thanks! My setting has always been hh:mm, and I remember clearly that same behaviour you described, starting from some version...

So I think I had three different behaviours happen as Calibre/QT versions would change:

1) All good, once I viewed any title, the emblem would show instantly;

2) The behaviour you described: while doing other things in the library, at some point the emblem would show up; and...

3) The current issue: emblem for that condition only shows up after restarting the program.

I just tried setting #lastopened to dd-MM-yyyy hh:mm:ss and still no good.

Comfy.n is offline   Reply With Quote
Old 08-23-2022, 01:55 PM   #4
igorius
Zealot
igorius began at the beginning.
 
Posts: 123
Karma: 34
Join Date: Jun 2015
Device: ipad & inkpad X
Ok, some silly question: What kind of value is your #lastopened? Is it of type date? Then your rule is wrong! is set expects a yes/no, but if its a date in this field, your rule has to fail! I tested this here.
When its date you should change to whatever has to do with date/time-settings. The only one which works is "not set". It applies when no date is set.
My faulty first answer, i should have looked better to your pic...
Sorry!
Hope that helps
igorius is offline   Reply With Quote
Old 08-23-2022, 02:29 PM   #5
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: 1,609
Karma: 7891011
Join Date: Sep 2020
Device: none
Quote:
Originally Posted by igorius View Post
Ok, some silly question: What kind of value is your #lastopened? Is it of type date? Then your rule is wrong! is set expects a yes/no, but if its a date in this field, your rule has to fail! I tested this here.
When its date you should change to whatever has to do with date/time-settings. The only one which works is "not set". It applies when no date is set.
My faulty first answer, i should have looked better to your pic...
Sorry!
Hope that helps
Rule is correct. As I said or perhaps implied, it's been working for years now.
When #lastopened has any stored value (which in this case is a Date), emblem should show up instantly, as it used to.

The last field in this kind of rule is greyed out (disabled), meaning "there's no value to assign, since this rule will just see if there's any date stored in database for that custom column".

BTW, yesterday I found a workaround to have the emblem show up lol

It goes like this:

1) View any book (emblem still won't show up, right?)
2) Click the EDIT METADATA button, for any title in the library. Don't change anything after the dialog box comes up. Just click OK. (Boom, emblem in that previously viewed book now SHOWS UP)

Last edited by Comfy.n; 08-24-2022 at 01:08 AM.
Comfy.n is offline   Reply With Quote
Advert
Old 08-23-2022, 07:57 PM   #6
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,707
Karma: 29711016
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Quote:
Originally Posted by Comfy.n View Post
BTW, yesterday I found a workaround to have the emblem show up lol

It goes like this:

1) View any book (emblem still won't show up, right?)
2) Click the EDIT METADATA button, for any title in the library. Don't change anything after the dialog box comes up. Just click OK. (Boom, emblem in that previously viewed book now SHOWS UP)
Try pressing the Focus the book list shortcut. On Windows you may have to set it to something other than the default… Ctrl+Esc… which pops the Start Menu. It's in the Miscellaneous shortcut group.

BR
BetterRed is offline   Reply With Quote
Old 08-23-2022, 08:26 PM   #7
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: 1,609
Karma: 7891011
Join Date: Sep 2020
Device: none
Quote:
Originally Posted by BetterRed View Post
Try pressing the Focus the book list shortcut. On Windows you may have to set it to something other than the default… Ctrl+Esc… which pops the Start Menu. It's in the Miscellaneous shortcut group.

BR
default was shift+esc. tried it, nothing happened
..changed it to ctrl-alt-J, no good either

anyway, I guess this is a highly irrelevant issue
Comfy.n is offline   Reply With Quote
Old 08-23-2022, 10:45 PM   #8
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,318
Karma: 27111242
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Is this happening only when the value is changed using a plugin or when using the edit metadata dialog as well? If its the former, its a bug in the plugin, the plugin must call refresh_ids() after making a change to ensure things are updated.
kovidgoyal is offline   Reply With Quote
Old 08-24-2022, 12:44 AM   #9
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: 1,609
Karma: 7891011
Join Date: Sep 2020
Device: none
Quote:
Originally Posted by kovidgoyal View Post
Is this happening only when the value is changed using a plugin or when using the edit metadata dialog as well? If its the former, its a bug in the plugin, the plugin must call refresh_ids() after making a change to ensure things are updated.
Hi, Kovid, thanks again for all your work!

Well... I just tested that here, by changing the custom column #lastopened on the Edit Metadata dialog to "today" and the emblem showed up instantly! (I have attached a screenshot)

That indeed indicates a bug in the plugins. I'm using this one, called Auto Datestamp and View. Is there some quick fix I can apply to it? I'm no coder, but sometimes I customise plugins and browser extensions for personal use.

Here is the code of Auto Datestamp and View:
Code:
#!/usr/bin/env python2
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai

__license__   = 'GPL v3'
__copyright__ = '2019, Paul'
__docformat__ = 'restructuredtext en'

from calibre.gui2.actions import InterfaceAction
from calibre.customize import InterfaceActionBase
from calibre.gui2 import error_dialog
from calibre.utils.date import format_date
import datetime

class InterfacePluginBase(InterfaceActionBase):
    name                = 'Auto Datestamp and View'
    description         = 'Add a date stamp and view current book'
    supported_platforms = ['windows', 'osx', 'linux']
    author              = 'Paul'
    version             = (0, 0, 9)
    minimum_calibre_version = (0, 7, 53)
    actual_plugin = 'calibre_plugins.auto_datestamp_and_view:AutoDatestampAndView'

class AutoDatestampAndView(InterfaceAction):
    name = 'Auto Datestamp and View'
    action_spec = (_('Date and view book'), None, None, None)
    action_type = 'current'
    
    def genesis(self):
        self.qaction.triggered.connect(self.gui.iactions['View']._view_calibre_books)
        orig_func = self.gui.iactions['View']._view_calibre_books

        def datestamp_and_view(book_ids):
            # View the book(s)
            orig_func(book_ids)
            # Then update the date stamp
            db = self.gui.library_view.model().db
            dateformat = 'iso'
            date_column = '#lastopened'
            custom_columns = db.custom_field_keys()
            # Make sure column exists
            if date_column not in custom_columns: 
                return error_dialog(self.gui, 'Before running this plugin', 
                        'You need to create a custom Date column called %s '%date_column, show=True)
            label = db.field_metadata.key_to_label(date_column)
            # Stamp each one by one
            for book_id in book_ids:
                now = datetime.datetime.now()
                viewdate = format_date(now, dateformat, assume_utc=False, as_utc=False)
                db.set_custom(book_id, viewdate, label=label, commit=True)
        # thanks to Kovid Goyal for the following line, also for Calibre in general
        self.gui.iactions['View']._view_calibre_books = datestamp_and_view
BTW, I tried Job Spy Plugin similar functionality, but the emblem would not update either.
Attached Thumbnails
Click image for larger version

Name:	MWSnap0623 2022-08-24, 01_26_07.png
Views:	113
Size:	596.7 KB
ID:	196049  
Comfy.n is offline   Reply With Quote
Old 08-24-2022, 01:27 AM   #10
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,318
Karma: 27111242
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
self.gui.library_view.model().refresh_ids(book_ids )
kovidgoyal is offline   Reply With Quote
Old 08-24-2022, 02:48 AM   #11
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: 1,609
Karma: 7891011
Join Date: Sep 2020
Device: none
Thumbs up

Quote:
Originally Posted by kovidgoyal View Post
self.gui.library_view.model().refresh_ids(book_ids )
Wheeeeeeeeeeee !!

That works lol!! NOW THE EMBLEM SHOWS UP INSTANTLY! (for any filetype)


I just added that line here:
Code:
   for book_id in book_ids:
                now = datetime.datetime.now()
                viewdate = format_date(now, dateformat, assume_utc=False, as_utc=False)
                db.set_custom(book_id, viewdate, label=label, commit=True)
                self.gui.library_view.model().refresh_ids(book_ids)
Comfy.n is offline   Reply With Quote
Old 08-24-2022, 06:45 AM   #12
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,415
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Comfy.n View Post
Wheeeeeeeeeeee !!

That works lol!! NOW THE EMBLEM SHOWS UP INSTANTLY! (for any filetype)


I just added that line here:
Code:
   for book_id in book_ids:
                now = datetime.datetime.now()
                viewdate = format_date(now, dateformat, assume_utc=False, as_utc=False)
                db.set_custom(book_id, viewdate, label=label, commit=True)
                self.gui.library_view.model().refresh_ids(book_ids)
FWIW: the refresh_ids should be after the loop, not in the loop. As it is the code is refreshing all books for every book, which could create a performance problem. I suggest
Code:
    for book_id in book_ids:
        now = datetime.datetime.now()
        viewdate = format_date(now, dateformat, assume_utc=False, as_utc=False)
        db.set_custom(book_id, viewdate, label=label, commit=True)
    if book_ids:
        self.gui.library_view.model().refresh_ids(book_ids)
chaley is offline   Reply With Quote
Old 08-24-2022, 06:05 PM   #13
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: 1,609
Karma: 7891011
Join Date: Sep 2020
Device: none
Quote:
Originally Posted by chaley View Post
FWIW: the refresh_ids should be after the loop, not in the loop. As it is the code is refreshing all books for every book, which could create a performance problem. I suggest
Code:
    for book_id in book_ids:
        now = datetime.datetime.now()
        viewdate = format_date(now, dateformat, assume_utc=False, as_utc=False)
        db.set_custom(book_id, viewdate, label=label, commit=True)
    if book_ids:
        self.gui.library_view.model().refresh_ids(book_ids)
Hi Chaley, I used your suggestion, but it gave me an error when installing the plugin, as following:

Code:
ERROR: Unhandled exception: <b>NameError</b>:name 'book_ids' is not defined
[...]
Traceback (most recent call last):
  File "calibre\gui2\preferences\plugins.py", line 325, in add_plugin
  File "calibre\customize\ui.py", line 479, in add_plugin
  File "calibre\customize\ui.py", line 64, in load_plugin
  File "calibre\customize\zipplugin.py", line 307, in load
  File "polyglot\builtins.py", line 123, in reload
  File "importlib\__init__.py", line 169, in reload
  File "<frozen importlib._bootstrap>", line 619, in _exec
  File "calibre\customize\zipplugin.py", line 208, in exec_module
  File "calibre_plugins.auto_datestamp_and_view.__init__", line 23, in <module>
  File "calibre_plugins.auto_datestamp_and_view.__init__", line 46, in AutoDatestampAndView
NameError: name 'book_ids' is not defined
I have attached a zip archive containing the code alternatives, perhaps all it needs is some syntax correction?
Attached Files
File Type: zip code placement question.zip (2.4 KB, 82 views)
Comfy.n is offline   Reply With Quote
Old 08-24-2022, 06:21 PM   #14
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 45,947
Karma: 168961900
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Looking at the code, chaley posted:

Code:
    if book_ids:
        self.gui.library_view.model().refresh_ids(book_ids)
Looking at the after the loop in the zip archive:

Code:
    if book_id:
        self.gui.library_view.model().refresh_ids(book_ids)
It seems as if you are missing an s in the if line.

Edit: Tried changing book_id to book_ids and got a BOOL error on install.

Last edited by DNSB; 08-24-2022 at 06:43 PM.
DNSB is offline   Reply With Quote
Old 08-24-2022, 06:40 PM   #15
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,415
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by DNSB View Post
Looking at the code, chaley posted:

Code:
    if book_ids:
        self.gui.library_view.model().refresh_ids(book_ids)
Looking at the after the loop in the zip archive:

Code:
    if book_id:
        self.gui.library_view.model().refresh_ids(book_ids)
It seems as if you are missing an s in the if line.
Yes, this is part of the problem. However, the main problem is that the indentation isn't right. I think the file should look like
Code:
#!/usr/bin/env python2
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai

__license__   = 'GPL v3'
__copyright__ = '2019, Paul'
__docformat__ = 'restructuredtext en'

from calibre.gui2.actions import InterfaceAction
from calibre.customize import InterfaceActionBase
from calibre.gui2 import error_dialog
from calibre.utils.date import format_date
import datetime

class InterfacePluginBase(InterfaceActionBase):
    name                = 'Auto Datestamp and View'
    description         = 'Add a date stamp and view current book'
    supported_platforms = ['windows', 'osx', 'linux']
    author              = 'Paul'
    version             = (0, 0, 9)
    minimum_calibre_version = (0, 7, 53)
    actual_plugin = 'calibre_plugins.auto_datestamp_and_view:AutoDatestampAndView'

class AutoDatestampAndView(InterfaceAction):
    name = 'Auto Datestamp and View'
    action_spec = (_('Date and view book'), None, None, None)
    action_type = 'current'
    
    def genesis(self):
        self.qaction.triggered.connect(self.gui.iactions['View']._view_calibre_books)
        orig_func = self.gui.iactions['View']._view_calibre_books

        def datestamp_and_view(book_ids):
            # View the book(s)
            orig_func(book_ids)
            # Then update the date stamp
            db = self.gui.library_view.model().db
            dateformat = 'iso'
            date_column = '#lastopened'
            custom_columns = db.custom_field_keys()
            # Make sure column exists
            if date_column not in custom_columns: 
                return error_dialog(self.gui, 'Before running this plugin', 
                        'You need to create a custom Date column called %s '%date_column, show=True)
            label = db.field_metadata.key_to_label(date_column)
            # Stamp each one by one
            for book_id in book_ids:
                now = datetime.datetime.now()
                viewdate = format_date(now, dateformat, assume_utc=False, as_utc=False)
                db.set_custom(book_id, viewdate, label=label, commit=True)
            if book_ids:
                self.gui.library_view.model().refresh_ids(book_ids)
            # thanks to Kovid Goyal for the following line, also for Calibre in general
            self.gui.iactions['View']._view_calibre_books = datestamp_and_view
TBH I don't know why the last 2 lines are in this file, but I'm not going to go deep into development.
chaley is offline   Reply With Quote
Reply

Tags
cover grid, emblems


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cover grid tooltip ownedbycats Library Management 1 02-04-2022 09:33 AM
Cover grid of Caliber Laval Calibre 2 03-07-2019 07:21 PM
Can't show the emblem in grid view Ansem_93 Library Management 2 04-24-2017 05:21 PM
Cover grid not updating in large window Snorkledorf Calibre 2 07-30-2014 03:33 AM
Cover Grid Ignoring Tweaks? danwdoo Calibre 1 09-16-2013 09:32 AM


All times are GMT -4. The time now is 11:54 AM.


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