03-05-2011, 04:56 AM | #1 |
Calibre Plugins Developer
Posts: 4,637
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Displaying arbitrary results in search screen from plugin
One of the plugin suggestions that came up was one that has the net effect of wanting to display rows in Calibre by some criteria that isn't handled by the search logic. Say for instance you wanted to find all books that had a cover smaller than certain dimensions/size.
So the plugin iterates through the data set and ends up with a bunch of calibre ids it wants to display in the library view. Is there a way to display these? It's a not dissimilar issue to the discussion we had on duplicate detection - except for that we think adding a custom column is appropriate in which case a normal search based on that column is possible. Is adding a custom column the only way to display arbitrary ids? |
03-05-2011, 06:16 AM | #2 |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
What should work today is library_view.select_rows(). This is not a search, but instead will highlight the rows in the view in the same fashion as search w/highlight search results. The user can use next and previous to move around in the highlighted set. This technique will not interfere with searching and restrictions.
'Searching' for a collection of arbitrary IDs would be more complicated. The problem is that searching is done by restricting the content of the cache (tied in with restrictions), which the GUI then treats as the library. Changing this processing is almost certainly not going to happen. I could imagine a special search syntax, something like 'ids:n,n,n,n,n,n,n,n,n', but this wouldn't be good if there are 1000s of them. |
Advert | |
|
03-05-2011, 10:33 AM | #3 |
Calibre Plugins Developer
Posts: 4,637
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Thanks Charles, I think it's time I tried that highlight feature you keep mentioning to see what it does for myself .
|
03-08-2011, 09:27 AM | #4 | |
Calibre Plugins Developer
Posts: 4,637
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Quote:
Code:
self.gui.search.clear() # As my code works across the whole library invalid_ids = [... build up my model ids...] self.gui.library_view.model().set_highlight_only(True) self.gui.library_view.select_rows(invalid_ids) Any suggestions as to what else I need to do? |
|
03-08-2011, 10:03 AM | #5 |
Calibre Plugins Developer
Posts: 4,637
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Ok, this is working, I am sure someone can slap me around if there is a better approach:
Code:
model = self.gui.library_view.model() model.ids_to_highlight = invalid_ids model.ids_to_highlight_set = set(invalid_ids) model.current_highlighted_idx = 0 self.gui.library_view.select_rows(invalid_ids[:1]) |
Advert | |
|
03-08-2011, 10:48 AM | #6 |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
I am not happy about you needing to reach inside the model like that. I can provide an API to do the 'right' way. However, before I do that, is the highlighting solution adequate?
|
03-08-2011, 10:57 AM | #7 |
Calibre Plugins Developer
Posts: 4,637
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Thought you might want to wrap it up
In a perfect world I think I would still prefer a way of limiting the view to just the invalid ids, but I can appreciate as per your initial response this isn't something easily possible currently. The disadvantage of the highlighting approach is that it requires leaving the view in "highlight mode" while the user works through those rows, and then they need to perform an action to get back out of it and return to normal searching. I've got a keyboard shortcut in my plugin to toggle turning highlight mode on/off. However there is no visible indication in the main gui as to whether you are in highlight mode or not (you have to drill into the search preferences dialog) so that is a little icky. I think as a user I might have preferred the checkbox (or a toggle button) on next to the search box as it used to be as it least you could see what "mode" you currently are in. With that all said, as you have the N/shift-N keyboard shortcuts to work through the results it functionally does the job. It just isn't quite as nice imho as limiting the set of rows to just the ones you are interested in rather than jumping all around the results, particularly since there is no way to sort to show the highlighted rows at the top. |
03-08-2011, 11:11 AM | #8 |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
I don't understand. I have a prototype in model() that sets the highlighted rows. They get highlighted. I am not required to turn highlight mode on or off. Are you sure that you need to change the toggle?
|
03-08-2011, 11:13 AM | #9 |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
How many rows are we talking about here? Tens, or tens of thousands?
|
03-08-2011, 11:22 AM | #10 |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
If you could try this before I submit to Kovid, that would be useful.
Add in gui2.library.models.py at line 280, just before 'search(...) Code:
def highlight_ids(self, ids_to_highlight): self.ids_to_highlight = ids_to_highlight self.ids_to_highlight_set = set(self.ids_to_highlight) if self.ids_to_highlight: self.current_highlighted_idx = 0 else: self.current_highlighted_idx = None self.reset() |
03-08-2011, 11:33 AM | #11 | |
Calibre Plugins Developer
Posts: 4,637
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Quote:
In terms of rows, it could be thousands, it could be a handful. Really depends on the state of the users library Perhaps it is possible to supply some custom sorting to the view with a delegate to display the highlighted rows at the top (in my case I just want to test for presence in the highlighted set)? |
|
03-08-2011, 11:39 AM | #12 | |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
It really sounds like you should create a (hidden?) custom column, fill that in how you want, then set a search restriction to select rows with appropriate values in the column. That would do everything you have described, including permitting sub-searching. |
|
03-08-2011, 11:53 AM | #13 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
It may be worth using the (currently unused) flags column for this kind of thing. We could provide an API to set the value for it and then have a true false search on it. That way every use would not require a separate custom column.
|
03-08-2011, 11:54 AM | #14 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
In fact there's no need to use the actual column, we could create a virtual column in meta2. This would not persist between calibre restarts, but I see that as a plus.
|
03-08-2011, 11:56 AM | #15 | |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
That should work easily enough. I will give it a try. What column name would you like to see in field_metadata? |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[GUI Plugin] Clipboard Search | kiwidude | Plugins | 29 | 04-02-2024 10:05 PM |
[GUI Plugin] Search the Internet | kiwidude | Plugins | 433 | 04-01-2024 05:48 PM |
Fictionwise Browser Search Plugin | Zero9 | Deals and Resources (No Self-Promotion or Affiliate Links) | 17 | 07-27-2009 03:15 PM |
eReader.com Browser Search Plugin | Zero9 | Deals and Resources (No Self-Promotion or Affiliate Links) | 0 | 07-24-2009 09:44 PM |
Snap.com - new search engine with sortable results | Colin Dunstan | Lounge | 1 | 10-06-2004 06:50 AM |