![]() |
#316 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,385
Karma: 27756918
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
In Qt applications you cannot use GUI objects in threads other than the main thread. You can use the Dispatcher helper class in calibre.gui2 to ensure that a python function call happens in the main thread.
|
![]() |
![]() |
![]() |
#317 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 24,905
Karma: 47303824
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
Bug with "Move to list"
I keep meaning to report a bug. Whenever I do a "Move to list", I get an error. The details are:
Code:
calibre, version 0.8.33 ERROR: Unhandled exception: <b>NameError</b>:global name 'previous' is not defined Traceback (most recent call last): File "calibre_plugins.reading_list.action", line 273, in _move_selected_to_list File "calibre_plugins.reading_list.action", line 449, in move_books_to_list NameError: global name 'previous' is not defined After looking at the code, I fixed it by copying Code:
previous = self.gui.library_view.currentIndex() |
![]() |
![]() |
![]() |
#318 |
Calibre Plugins Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,731
Karma: 2197770
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
@davidfor - thanks for that, try the attached version. Probably something I broke when refactoring for this API stuff.
@JimmXinu - try the attached version. The relevant methods now have a display_warnings parameter which you can set to False. Bearing in mind that these methods should still be called from a GUI thread and not a background thread, because adding/removing from a list can result in changes to the database if the user has rules setup to modify tags/custom columns based on list add/remove. Any database updates need to be done on the UI thread to be sure there is no conflict with the user currently editing data manually etc. So hence why plugins like metadata downloads force the operation back onto the GUI thread by prompting with a dialog after the background work is done. I suggest you follow the same pattern if the rest of your plugin is doing background work stuff. I have also exposed for your convenience: get_book_list(list_name) get_list_names(exclude_auto=True) Let me know if I broke anything else, I have only given this a quick test. Last edited by kiwidude; 01-12-2012 at 05:06 PM. Reason: Removed attachment as latest version officially released |
![]() |
![]() |
![]() |
#319 | |
Plugin Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,987
Karma: 4604635
Join Date: Dec 2011
Location: Midwest USA
Device: Kobo Clara Colour running KOReader
|
Quote:
@kiwidude-Thanks. But you forgot the self parameter on get_book_list & get_list_names. |
|
![]() |
![]() |
![]() |
#320 |
Calibre Plugins Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,731
Karma: 2197770
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
@JimmXinu - I've uploaded a new version of the zip with the self parameter on the previous post.
As for the background stuff, it depends on how you do it. Basically it depends on whether you want to do it in-process (faster execution for small jobs) or out of process (the latter being a "job" the gets put in the calibre jobs queue, like downloading metadata or send to device). Count Pages (& Modify ePub) use the job queue (out of process) approach, which is the most common way of doing it. Effectively it is scheduling an executable process to be launched for each "job". This has the additional advantage that if the code being called has memory leaks (which anything related to book conversions does for instance) you are not going to crash the main calibre process. Extract ISBN has both the in-process and out of process approaches. If the user selects a very small number of books (can't remember the threshold I put in, might may be something like 2 or less), then it uses the in-process approach. More than that, it uses out of process (for memory leak prevention reasons). |
![]() |
![]() |
![]() |
#321 |
Member
![]() Posts: 17
Karma: 10
Join Date: Sep 2009
Device: PRS 300
|
Kiwidude,
Thank you for developing this plugin. Either I am missing something or I have a feature request. Is there a way for the sorted list to be exported as a file so (i.e. like a catalog)? The Kindle Fire doesn't seem to support collections nor does it display the books in the same order as the list. Having the list exported (which Calibre could then upload to the KF) would allow me to access the list and see the order I want to read books. If this already exists please point me in the direction. If not, can it be implemented? Thank you, Kurt |
![]() |
![]() |
![]() |
#322 |
Calibre Plugins Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,731
Karma: 2197770
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
@weirichk - no it isn't something you are failing to find. It's an idea that has been tossed around a couple of times in this thread (mainly by me) but no real clamouring of demand to justify the effort.
You could perhaps view the list in Calibre and then produce a catalog using the existing catalog feature, though I haven't tried it. My guess would be that it might lose the reading list sort order. I agree that ultimately it would be nice for the plugin to have an option for a list that when synced it sends a special book to your device which contains the equivalent of a catalog but in reading list order. Maybe I'll get to it one day... I don't know enough about the catalog code in Calibre at the moment though to know what if any I could reuse. And last time this idea got thrown around someone started talking about how they wanted the ability to customise the output etc - it all starts becoming a bit of a beast. |
![]() |
![]() |
![]() |
#323 | |
Plugin Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,987
Karma: 4604635
Join Date: Dec 2011
Location: Midwest USA
Device: Kobo Clara Colour running KOReader
|
Quote:
But I took a break to test all the RL methods you've exposed for me. So far I've found everything works as I expected except:
Thanks again, Jim |
|
![]() |
![]() |
![]() |
#324 |
Calibre Plugins Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,731
Karma: 2197770
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Hi Jim,
Remove from all lists works fine for me? I have two lists, I add a book to one or both of them, then I choose Remove from All lists and the lists are now empty (if that book was the only one on it) or reduced otherwise? If you are seeing something else can you give me some steps to replicate it? The move books to list thing, yeah I was a bit conflicted about what to do with that. As depending on what you are doing it might be you want to see the source list, the dest list, or not have any change at all. I have removed that view_list line from what I will officially release. The edit_list thing doesn't bother me, I wouldn't seriously expect anyone to invoke that method externally, and if they did it is a simple matter of making sure your list is valid. My menus get rebuilt every time they are displayed so it can't really happen in normal plugin usage. |
![]() |
![]() |
![]() |
#325 |
Plugin Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,987
Karma: 4604635
Join Date: Dec 2011
Location: Midwest USA
Device: Kobo Clara Colour running KOReader
|
kiwidude,
I have a test library with 11 books in it. I have three lists, including Default. To start, all three lists are empty. I select all 11 books, do 'Add to all lists'. Each list has 11 entries. With all 11 still selected (or reselected), I do 'Remove from all lists', now each list has 5 entries--the same five in each list. I haven't analyzed the remove_books_from_all_lists() in depth, but using book_ids as a parameter and assigning to it in the for...list_names loop looks suspicious to me. Jim |
![]() |
![]() |
![]() |
#326 |
Calibre Plugins Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,731
Karma: 2197770
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Hmmm, I havent tried replicating it again but looking at the code after what you described I can see the issue. Copy/paste wrong when I refactored stuff for you, darn it. New version attached above, thanks for finding it. Havent looked at why I couldnt replicate it, dumb luck I guess.
|
![]() |
![]() |
![]() |
#327 |
Plugin Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,987
Karma: 4604635
Join Date: Dec 2011
Location: Midwest USA
Device: Kobo Clara Colour running KOReader
|
It's working now. That was the last issue I had.
Many thanks for adding this API for me. Jim |
![]() |
![]() |
![]() |
#328 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 24,905
Karma: 47303824
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
Quote:
The displayed list isn't being refreshed to show the changes. Looking at the code, the old version has "self.view_list(source_list_name)" at the end of the "if removed_ids:" block. The new version doesn't have this or anything similar in the equivalent block. I also noticed that the remove is not updating the list either. So, this might be deliberate. But, it can lead to a problem. If I try to remove or move the same book from the list, I get an error that the book isn't in the list. Also, when testing the remove from list, I noticed there isn't a message put into the status area when a remove is done. The tags in the book details aren't being updated either. The same goes when adding a book to a list. The issue is in "_add_selected_to_list" and "_remove_selected_from_list". Both of these have "refresh_screen=True" as an argument. But, refresh_screen seems to be set to False. I can see where the menu items are created and I would think that what you have done is correct. Adding "True" as an extra parameter to the call to "partial" here fixes the problem. It appears the partial object created by this method is not respecting the default parameter values for the method when called. From the documentation, I can't decide if this is deliberate or a bug. In any case, I suggest removing the "refresh_screen" from arguments of these methods. The methods are designed to be used only from the menus. As such, a value like this can be hard-coded or taken from a property for the instance. This is the sort of thing I define as a property of the instance so that I can easily turn it on or off for everywhere during my testing. When debugging, I might also add it to a menu or on the settings dialog so that I can easily toggle the value without rebuilding the code. |
|
![]() |
![]() |
![]() |
#329 |
Calibre Plugins Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,731
Karma: 2197770
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
@davidfor - see post #323/#324 above for the discussion on move to list and why I removed the view_list line. You obviously use the move to list functionality yourself (unlike me), and as I don't believe it is an API call that Jim needs to use I'm open to suggestions if you want the previous behavior restored.
I'll take a look at the refresh_screen stuff tonight. I tried to make the changes for Jim around midnight that night just to get something out for him, and clearly didn't give it my normal TLC. |
![]() |
![]() |
![]() |
#330 | ||
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 24,905
Karma: 47303824
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
Quote:
Quote:
- Separate the database and GUI updates. This will help with exposing methods as part of the API as it means that no unexpected side-effects will happen. And, looking at it, the remove and add methods, probably shouldn't be interacting with the GUI in any way. - For errors in the database/API methods, raise exceptions for the errors. These can be caught and handled by the calling code. - Refactor the code that does the GUI updates. You can easily move this this to a separate method to be called from a lot of places. I would use the code from the bottom of "remove_books_from_list". - Where do the GUI updates get done? In this, case, I would probably do them from the methods the menu call. These would check the input was OK, call the database updates, display any messages and update the GUI. But, I might also leave the input checking there and move the rest of it to another method. I would have to look at the code reuse scenarios properly to decide. Those are my quick thoughts on this. On the other side of this, I do like your code. It is well laid out, easy to read, method and variable names are obvious and I can easily understand it. |
||
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
[GUI Plugin] Extract ISBN | kiwidude | Plugins | 548 | 03-04-2025 10:43 PM |
[GUI Plugin] Open With | kiwidude | Plugins | 404 | 02-21-2025 05:42 AM |
[GUI Plugin] Manage Sony x50 Reader Book List | kpw | Plugins | 170 | 10-02-2014 08:23 PM |
[GUI Plugin] Temp Marker | kiwidude | Plugins | 41 | 10-14-2013 12:25 AM |
[GUI Plugin] Plugin Updater **Deprecated** | kiwidude | Plugins | 159 | 06-19-2011 12:27 PM |