![]() |
#1 |
Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 36
Karma: 2062
Join Date: Oct 2021
Device: Kobo Libra 2
|
Is there a way to patch a plugin?
Specifically the vocabbuilder.koplugin.
i want to close the dictionary lookup popup when a word is added to the Vocabulary Builder database. i am assuming the close needs be added to VocabBuilder:onDictButtonsReady function. Saves just one button press action on the dictionary lookup.. but curious if this can be achieved. Last edited by sdothum; 02-02-2025 at 10:58 AM. |
![]() |
![]() |
![]() |
#2 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,179
Karma: 3592925
Join Date: Sep 2014
Location: Ukraine
Device: Kindle
|
Example of patching a plugin
https://github.com/koreader/koreader...ent-2393154113 |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 36
Karma: 2062
Join Date: Oct 2021
Device: Kobo Libra 2
|
Thank you for the plugin patch example.
i've managed to override the VocabBuilder: onDictButtonsReady function but am stumped at what i was expecting to be the easiest part -- closing the DictQuickLookup window. More needs be done than simply calling DictQuickLookup: onClose() after the button tap. Any ideas? before i create another thread post? Last edited by sdothum; 02-11-2025 at 05:18 AM. |
![]() |
![]() |
![]() |
#4 |
Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 36
Karma: 2062
Join Date: Oct 2021
Device: Kobo Libra 2
|
Found the answer.. at least what appears to work. Instead of using DictQuickLookup:onClose..
UIManager:sendEvent(Event:new("Close")) |
![]() |
![]() |
![]() |
#5 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,751
Karma: 730681
Join Date: Oct 2014
Location: Antwerp
Device: Kobo Aura H2O
|
It's probably more proper to do UIManager:close(the_widget_in_question)
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 36
Karma: 2062
Join Date: Oct 2021
Device: Kobo Libra 2
|
|
![]() |
![]() |
![]() |
#7 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,179
Karma: 3592925
Join Date: Sep 2014
Location: Ukraine
Device: Kindle
|
It is dict_popup.
|
![]() |
![]() |
![]() |
#8 |
Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 36
Karma: 2062
Join Date: Oct 2021
Device: Kobo Libra 2
|
The UIManager:close(dict_popup) does close the widget..
BUT this action also appears to bypass the widget's DictQuickLookup: onClose() function -- at least, the scheduled highlight clear is not triggered after the widget is closed (i do patch that to lengthen its duration before clearing). The UIManager:sendEvent() close appears to be a more graceful action in this regard, clearing the highlight afterwards. Last edited by sdothum; 02-11-2025 at 05:20 AM. |
![]() |
![]() |
![]() |
#9 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,179
Karma: 3592925
Join Date: Sep 2014
Location: Ukraine
Device: Kindle
|
Code:
dict_popup:onClose() |
![]() |
![]() |
![]() |
#10 |
Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 36
Karma: 2062
Join Date: Oct 2021
Device: Kobo Libra 2
|
Thank you! Adding that direct call works.
A question: - the UIManager:close() plus dict_popup: onClose() are two statements versus the single UIManager:sendEvent() statement -- with the proposed changes more widget explicit. Is there a reason to discourage the sendEvent() usage (which has not presented any issues for this usecase)? i'm guessing the above is more immune to future coding changes or are there other possible semantic reasons? Last edited by sdothum; 02-11-2025 at 11:07 AM. |
![]() |
![]() |
![]() |
#11 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,179
Karma: 3592925
Join Date: Sep 2014
Location: Ukraine
Device: Kindle
|
Direct calls are cheaper than events.
Events can be handled by many listeners, for example, renaming a book title and resetting some caches here and there. |
![]() |
![]() |
![]() |
#12 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,179
Karma: 3592925
Join Date: Sep 2014
Location: Ukraine
Device: Kindle
|
|
![]() |
![]() |
![]() |
#13 |
Plugin Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,969
Karma: 4604635
Join Date: Dec 2011
Location: Midwest USA
Device: Kobo Clara Colour running KOReader
|
A similar question if I may:
Is there a way to patch something in a plugin that's not in the main plugin object? I'm trying to patch in a replacement for CalibreSearch.switchResults() in calibre.koplugin/search.lua. I'm trying to replace the sort with one that does lower() before compare so lower case Calibre titles, tags, etc aren't after all the upper case ones. (I suspect patching sort.natsort_cmp would be easier, but it's also used by other things.) |
![]() |
![]() |
![]() |
#14 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,179
Karma: 3592925
Join Date: Sep 2014
Location: Ukraine
Device: Kindle
|
CalibreSearch can be found as an upvalue in some of the main module methods.
Look for example at https://github.com/koreader/koreader...ent-2871327027 |
![]() |
![]() |
![]() |
#15 | |
Plugin Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,969
Karma: 4604635
Join Date: Dec 2011
Location: Midwest USA
Device: Kobo Clara Colour running KOReader
|
Quote:
I have: Code:
local userpatch = require("userpatch") userpatch.registerPatchPluginFunc("calibre", function(Calibre) local CalibreSearch, up_idx = userpatch.getUpValue(Calibre.onCalibreSearch, "CalibreSearch") print("\ncalibre patch CalibreSearch:") print(CalibreSearch) end) Code:
function Calibre:onCalibreSearch() CalibreSearch:ShowSearch() return true end ADDENDUM Of all the Calibre methods that reference CalibreSearch, getSearchMenuTable is the only one that gives me that reference from getUpValue: Code:
userpatch.registerPatchPluginFunc("calibre", function(Calibre) local CalibreSearch, up_idx = userpatch. getUpValue(Calibre.getSearchMenuTable, "CalibreSearch") print("\ncalibre patch CalibreSearch:") print(CalibreSearch) end) ![]() Last edited by JimmXinu; 06-20-2025 at 02:29 PM. Reason: Addendum |
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Plugin] LOI-Generator - edit] plugin to generate a List of Illustrations | KevinH | Plugins | 1 | 01-19-2023 04:31 PM |
Updating plugin fails because plugin file is in use by Calibre? | ownedbycats | Calibre | 1 | 12-03-2022 08:34 PM |
[Metadata Source Plugin] Empty Plugin? (Fake Identifier) | mneimeyer | Plugins | 3 | 11-11-2019 08:07 PM |
[Plugin] QuickPrefsEdit - Edit plugin prefs json files. | slowsmile | Plugins | 3 | 07-25-2018 08:14 PM |
Goodread Perception Expander plugin not shown on plugin list (kobo h2o) | www | KOReader | 4 | 09-28-2017 10:34 AM |