Register Guidelines E-Books Search Today's Posts Mark Forums Read

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

Notices

Reply
 
Thread Tools Search this Thread
Old 03-05-2011, 04:56 AM   #1
kiwidude
Calibre Plugins Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,636
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?
kiwidude is offline   Reply With Quote
Old 03-05-2011, 06:16 AM   #2
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: 11,733
Karma: 6690881
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.
chaley is offline   Reply With Quote
Advert
Old 03-05-2011, 10:33 AM   #3
kiwidude
Calibre Plugins Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,636
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 .
kiwidude is offline   Reply With Quote
Old 03-08-2011, 09:27 AM   #4
kiwidude
Calibre Plugins Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,636
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
Quote:
Originally Posted by chaley View Post
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.
So I decided to give this approach a go. I have built up a list of ids I want to highlight, and have code something like this:
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)
However all that does is select the rows, it won't actually color them. The highlighting code seems to take place in the search code in BooksModel, where it sets those "ids_to_highlight" etc.

Any suggestions as to what else I need to do?
kiwidude is offline   Reply With Quote
Old 03-08-2011, 10:03 AM   #5
kiwidude
Calibre Plugins Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,636
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])
kiwidude is offline   Reply With Quote
Advert
Old 03-08-2011, 10:48 AM   #6
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: 11,733
Karma: 6690881
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?
chaley is offline   Reply With Quote
Old 03-08-2011, 10:57 AM   #7
kiwidude
Calibre Plugins Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,636
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.
kiwidude is offline   Reply With Quote
Old 03-08-2011, 11:11 AM   #8
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: 11,733
Karma: 6690881
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by kiwidude View Post
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 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?
chaley is offline   Reply With Quote
Old 03-08-2011, 11:13 AM   #9
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: 11,733
Karma: 6690881
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
How many rows are we talking about here? Tens, or tens of thousands?
chaley is offline   Reply With Quote
Old 03-08-2011, 11:22 AM   #10
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: 11,733
Karma: 6690881
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()
chaley is offline   Reply With Quote
Old 03-08-2011, 11:33 AM   #11
kiwidude
Calibre Plugins Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,636
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
Quote:
Originally Posted by chaley View Post
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?
I didn't realise it was possible to highlight the rows without switching the highlight mode. I've just tried your code now and that works well - I just hit esc and my highlight mode state is preserved whether it was on or off.

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)?
kiwidude is offline   Reply With Quote
Old 03-08-2011, 11:39 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: 11,733
Karma: 6690881
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by kiwidude View Post
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)?
This has a problem similar to search -- the model.py must be asked to do the work, somehow cause cache.py to order the records in the cache (using data in the cache), then redisplay the reordered cache.

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.
chaley is offline   Reply With Quote
Old 03-08-2011, 11:53 AM   #13
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: 43,838
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.
kovidgoyal is online now   Reply With Quote
Old 03-08-2011, 11:54 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: 43,838
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.
kovidgoyal is online now   Reply With Quote
Old 03-08-2011, 11:56 AM   #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: 11,733
Karma: 6690881
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by kovidgoyal View Post
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.
Hmmm...

That should work easily enough. I will give it a try. What column name would you like to see in field_metadata?
chaley is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

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


All times are GMT -4. The time now is 10:56 AM.


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