i’m attempting to make an addon for the first time (just a basic one that changes the images of different anki icons) and i’ve looked at how some simple addons work and came up with this (all i’m doing is (theoretically) copying a function from the deckbrowser.py file, changing the filepath within that function, then overwriting the original function in deckbrowser.py):
from aqt.deckbrowser import DeckTreeNode, RenderDeckNodeContext, DeckBrowser
import os
addon_path = os.path.dirname(__file__)
addonfoldername = os.path.basename(addon_path)
def _render_deck_node(self, node: DeckTreeNode, ctx: RenderDeckNodeContext) -> str:
if node.collapsed:
prefix = "+"
else:
prefix = "-"
due = node.review_count + node.learn_count
def indent() -> str:
return " " * 6 * (node.level - 1)
if node.deck_id == ctx.current_deck_id:
klass = "deck current"
else:
klass = "deck"
buf = "<tr class='%s' id='%d'>" % (klass, node.deck_id)
# deck link
if node.children:
collapse = (
"<a class=collapse href=# onclick='return pycmd(\"collapse:%d\")'>%s</a>"
% (node.deck_id, prefix)
)
else:
collapse = "<span class=collapse></span>"
if node.filtered:
extraclass = "filtered"
else:
extraclass = ""
buf += """
<td class=decktd colspan=5>%s%s<a class="deck %s"
href=# onclick="return pycmd('open:%d')">%s</a></td>""" % (
indent(),
collapse,
extraclass,
node.deck_id,
node.name,
)
# due counts
def nonzeroColour(cnt: int, klass: str) -> str:
if not cnt:
klass = "zero-count"
return f'<span class="{klass}">{cnt}</span>'
buf += "<td align=right>%s</td><td align=right>%s</td>" % (
nonzeroColour(due, "review-count"),
nonzeroColour(node.new_count, "new-count"),
)
# options
buf += (
"<td align=center class=opts><a onclick='return pycmd(\"opts:%d\");'>"
f"<img src='/_addons/{addonfoldername}/files/gears.svg' class=gears></a></td></tr>" % node.deck_id
)
# children
if not node.collapsed:
for child in node.children:
buf += self._render_deck_node(child, ctx)
return buf
DeckBrowser._render_deck_node = _render_deck_node
instead of replacing the gear icon with the one in the addon folder, the gear icon just disappears. i’ve used webinspector to check if the filepath is correct, and it seems to be fine (i’ve tried using the full filepath rather than starting from "/_addons/“, but the image still doesn’t show up)
any thoughts as to why it doesnt work?
update: other icons such as the bold text icon dont seem to work either (image disappears rather than changes to the new image)