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 12-11-2020, 12:15 PM   #1
DaltonST
Deviser
DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.
 
DaltonST's Avatar
 
Posts: 2,265
Karma: 2090983
Join Date: Aug 2013
Location: Texas
Device: none
calibre.utils.ipc RC Removed in 5.7? Replacement?

Code:
from calibre.utils.ipc import RC 

...
...


t = RC(print_error=False, socket_address=self.gui_socket_address) 
t.start()  
t.join(3)
if t.done:
msg = 'refreshdb:   '
t.conn.send(msg)
t.conn.close()
My MFI Media File Importer plugin has used RC() for years to properly "notify" the GUI that it should be refreshed so that newly added books will appear in the GUI without having to restart Calibre.

In Calibre 5.7, MFI fails at Calibre startup because RC no longer exists to be imported from calibre.utils.ipc .

Would there be a replacement for RC that can be used to perform the identical function in Calibre 5.7?



Thanks.


DaltonST
DaltonST is offline   Reply With Quote
Old 12-11-2020, 09:24 PM   #2
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,322
Karma: 27111242
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
See calibre.gui2.listener
kovidgoyal is offline   Reply With Quote
Advert
Old 12-12-2020, 04:15 PM   #3
DaltonST
Deviser
DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.
 
DaltonST's Avatar
 
Posts: 2,265
Karma: 2090983
Join Date: Aug 2013
Location: Texas
Device: none
IPC message 'refreshdb:' no longer exists in Calibre 5.7

Unfortunately, the message 'refreshdb: ' no longer exists in Calibre 5.7.

Is there a way to get the same result as in Calibre 5.6?


DaltonST
DaltonST is offline   Reply With Quote
Old 12-12-2020, 08:35 PM   #4
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,322
Karma: 27111242
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
No, since you are not allowed to open a calibre database in multiple programs simultaneously, there is no longer any need for that function.
kovidgoyal is offline   Reply With Quote
Old 12-12-2020, 11:01 PM   #5
DaltonST
Deviser
DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.
 
DaltonST's Avatar
 
Posts: 2,265
Karma: 2090983
Join Date: Aug 2013
Location: Texas
Device: none
So if a GUI plugin exrcutes a db.add_book() many times quickly, how does it now (5.7) notify Calibre to update the Cache from the physical DB so that the library_view can be subsequently updated from the refreshed Cache? That is the very real problem. 5.6 could do that. 5.7 now requires a Calibre restart to show the new books, which is unacceptable.

I tried using the "bookedit:" message in a loop for each new book_id, but the Listener refuses the connection because it sources from an unknown server.

Is a GUI plugin now considered a different program?
DaltonST is offline   Reply With Quote
Advert
Old 12-12-2020, 11:05 PM   #6
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,322
Karma: 27111242
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
If you want to refresh the book list from a GUI plugin, you dont need to use IPC. Refreshing the book list is trivial to do, look at any number of plugins that do it or look at for instance how the builtin edit metadata action does it.

I have no clue why you were using IPC to refresh the GUI in your GUI plugin. GUI plugins run the in the same process as the rest of the GUI and should ever need to use IPC to communicate with it.
kovidgoyal is offline   Reply With Quote
Old 12-13-2020, 11:26 AM   #7
DaltonST
Deviser
DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.
 
DaltonST's Avatar
 
Posts: 2,265
Karma: 2090983
Join Date: Aug 2013
Location: Texas
Device: none
You misunderstand.

It is trivial to refresh the Library View from the Cache, but only if the Cache itself has just been refreshed from metadata.db.

I was reloading the book ids from the physical SQLite database into the Cache by using the "refreshdb:" IPC message that no longer exists in Calibre 5.7.

Hard-drive to Cache, not Cache to GUI Library View.


Added: History: I began to use IPC to refresh the Cache after you deprecated using "calibredb --add-books" while the current Calibre Library GUI was running. It was so easy with "calibredb --add-books".





I will try this next:

Code:
class ResultCache(SearchQueryParser):

    def refresh_ids(self, db, ids):
        '''
        Refresh the data in the cache for books identified by ids.
        Returns a list of affected rows or None if the rows are filtered.
        '''
        for id in ids:
            try:
                self._data[id] = CacheRow(db, self.composites, self.datetimes,
                        db.conn.get('SELECT * from meta2 WHERE id=?', (id,))[0],
                        self.series_col, self.series_sort_col)
                self._data[id].append(db.book_on_device_string(id))
                self._data[id].append(self.marked_ids_dict.get(id, None))
                self._data[id].append(None)
                self._uuid_map[self._data[id][self._uuid_column_index]] = id
            except IndexError:
                return None
        try:
            return list(map(self.row, ids))
        except ValueError:
            pass
        return None

Last edited by DaltonST; 12-13-2020 at 11:39 AM. Reason: History: calibredb --add-books
DaltonST is offline   Reply With Quote
Old 12-13-2020, 11:46 AM   #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,322
Karma: 27111242
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Let me repeat, you are not supposed to be accessing the database in ANYTHING other than the calibre process, using the calibre database API. If you do so, you will break things, and you are on your own. Good luck. If you think you are going to be able to manipulate the database out from under calibre and then somehow successfully refresh the in-memory view of the database that calibre has, I'm afraid you have another think coming.
kovidgoyal is offline   Reply With Quote
Old 12-13-2020, 11:48 AM   #9
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,322
Karma: 27111242
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
And although I remember you ignored me the first time around as well, let me link to you teh CORRECT way to add books, if only for the sake of the poor users whose databases you are going to end up breaking.

https://manual.calibre-ebook.com/db_...ache.add_books
kovidgoyal is offline   Reply With Quote
Old 12-13-2020, 12:33 PM   #10
DaltonST
Deviser
DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.
 
DaltonST's Avatar
 
Posts: 2,265
Karma: 2090983
Join Date: Aug 2013
Location: Texas
Device: none
Kovid, Let me remind you of my previous post above:


Quote:
So if a GUI plugin exrcutes a db.add_book() many times quickly, how does it now (5.7) notify Calibre to update the Cache from the physical DB so that the library_view can be subsequently updated from the refreshed Cache? That is the very real problem. 5.6 could do that. 5.7 now requires a Calibre restart to show the new books, which is unacceptable.
I have been using db.add_book() for years, along with the IPC call plus self.maingui.library_view.model().refresh_ids(ids)


I am now using self.maingui.library_view.model().refresh(), instead of .refresh_ids(ids), which solves my problem of not using IPC any longer. Works fine.



Quote:
Let me repeat, you are not supposed to be accessing the database in ANYTHING other than the calibre process, using the calibre database API. If you do so, you will break things, and you are on your own. Good luck.
You have me confused with someone else. I have no clue what you are talking about, or why you are saying this to me.


Quote:
If you think you are going to be able to manipulate the database out from under calibre and then somehow successfully refresh the in-memory view of the database that calibre has, I'm afraid you have another think coming.
Ditto.


Thank you for your kind advice, although it clearly was meant for someone other than me.


DaltonST

Last edited by DaltonST; 12-16-2020 at 11:16 AM. Reason: Clarification
DaltonST is offline   Reply With Quote
Old 12-15-2020, 07:50 AM   #11
thiago.eec
Wizard
thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.
 
Posts: 1,208
Karma: 1419583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite, Kindle Oasis
Quote:
Originally Posted by DaltonST View Post
I have been using db.add_book() for years, along with the IPC call plus self.maingui.library_view.model().refresh_ids(ids)


I am now using self.maingui.library_view.model().refresh(), instead of .refresh_ids(ids), which solves my problem of not using IPC any longer. Works fine.



Thank you for your kind advice.




DaltonST

I have a GUI plugin that uses refresh_ids(ids), but I also use another parameter to refresh the Book Details Panel for the currently selected book:

Code:
self.gui.library_view.model().refresh_ids(ids, current_row=self.gui.library_view.currentIndex().row())
Without this, when the books are added, the book list is refreshed, but not the Book Details Panel (it will keep showing the last selected book before adding the new books).
thiago.eec is offline   Reply With Quote
Old 12-15-2020, 08:24 AM   #12
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,322
Karma: 27111242
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
The canonical way to refresh the GUI after adding books, is the way calibre does it itself, which is:

Code:
self.gui.iactions['Add Books'].refresh_gui(num_of_books_added)
kovidgoyal is offline   Reply With Quote
Old 12-15-2020, 08:50 AM   #13
thiago.eec
Wizard
thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.
 
Posts: 1,208
Karma: 1419583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite, Kindle Oasis
Quote:
Originally Posted by kovidgoyal View Post
The canonical way to refresh the GUI after adding books, is the way calibre does it itself, which is:

Code:
self.gui.iactions['Add Books'].refresh_gui(num_of_books_added)
Thanks!

But this raised another question for me. When I use the refresh_ids method (with current_row argument), the last added book gets selected and everything is refreshed for that book (including Quick View, by using qv.refresh_quickview(current)).

But when I use the canonical way, after all books are added, the current book is still the same as before the adding action. Also, Quick View does not update*, even if a new book that affects it was added).

* To refresh it, I have to click on another book and then go back to the previously selected book.
thiago.eec is offline   Reply With Quote
Old 12-15-2020, 11:37 AM   #14
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,322
Karma: 27111242
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
If you want the last added book to be selected, pass set_current_row=row_number to that function.
kovidgoyal is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Kobo Utils and new Calibre Stevex Kobo Reader 4 09-03-2020 02:19 PM
IPC between plugin and interface Sytten Development 5 05-10-2020 11:56 PM
PBTouchLux3: Series removed in Calibre, still on reader bluesorella PocketBook 1 09-03-2016 12:07 PM
linux-utils (k3 and beyond) twobob Kindle Developer's Corner 4 11-19-2013 10:26 AM
xdg-utils should be listed as a debian build-dep? twobob Calibre 4 10-16-2013 04:16 AM


All times are GMT -4. The time now is 02:41 AM.


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