Asset Manager [Official support]

The add-on author author could take a look at Porting tips for Anki 23.10 - Add-ons - Anki Forums

Modules under QtCore, QtGui and QtWidgets can be imported from aqt.qt instead, to remove old PyQt5 dependencies.

Hey
I tried installing the asset manager add-on but Anki seems to be unable to install or “use” the package.
I just keep getting a error message and having to delete the add on.

Anki ⁨24.04.1 (ccd9ca1a)⁩

Thanks for helping

[asset manager][Anki 25.09.2] works, then crashes later?
PyQt5→PyQt6, 
from aqt.qt import (QRegExp→from aqt.qt import (QRegularExpression as QRegExp,
QtCore.Qt.WindowModal→QtCore.Qt.WindowModality.WindowModal, 
QtWidgets.QSizePolicy.Fixed→QtWidgets.QSizePolicy.Policy.Fixed, 
QtCore.Qt.Horizontal→QtCore.Qt.Orientation.Horizontal
QtWidgets.QDialogButtonBox.Ok→QtWidgets.QDialogButtonBox.StandardButton.Ok, 
QtWidgets.QDialogButtonBox.Cancel→QtWidgets.QDialogButtonBox.StandardButton.Cancel, 
QtWidgets.QFrame.HLine→QtWidgets.QFrame.Shape.HLine, 
QtWidgets.QFrame.Sunken→QtWidgets.QFrame.Shadow.Sunken, 
QLayout.SetFixedSize→QLayout.SizeConstraint.SetFixedSize, 
exec_()→exec(), 
QtWidgets.QSizePolicy.Expanding→QtWidgets.QSizePolicy.Policy.Expanding, 
QtWidgets.QSizePolicy.Minimum→QtWidgets.QSizePolicy.Policy.Minimum, 
QtWidgets.QAbstractItemView.NoEditTriggers→QtWidgets.QAbstractItemView.EditTrigger.NoEditTriggers, 
QtWidgets.QAbstractItemView.SingleSelection→QtWidgets.QAbstractItemView.SelectionMode.SingleSelection, 
QtWidgets.QAbstractItemView.SelectRows→QtWidgets.QAbstractItemView.SelectionBehavior.SelectRows, 
#self.scriptsTable.setGridStyle(QtCore.Qt.DashLine), 
Qt.AlignCenter→Qt.AlignmentFlag.AlignCenter, 
QFont.Monospace→QFont.StyleHint.Monospace, 
QFont.Medium→QFont.Weight.Medium, 
QFont.Bold→QFont.Weight.Bold, 
Qt.GlobalColor.cyan blue magenta darkMagenta red darkRed yellow darkYellow green darkGreen lightGray gray, 
reducer=lambda lst: "\n\n".join(lst),→reducer=lambda lst: "\n\n".join(x[0] if isinstance(x, tuple) else str(x) for x in lst), #chatgpt
    def highlightBlock(self, text): #chatgpt
        # --- Handle normal syntax rules ---
        for pattern, format in self.highlightingRules:
            expression = QRegularExpression(pattern)
            match_iterator = expression.globalMatch(text)
            while match_iterator.hasNext():
                match = match_iterator.next()
                index = match.capturedStart()
                length = match.capturedLength()
                self.setFormat(index, length, format)
    
        self.setCurrentBlockState(0)
    
        # --- Handle multi-line comments ---
        startIndex = 0
        if self.previousBlockState() != 1:
            start_match = self.commentStartExpression.match(text)
            startIndex = start_match.capturedStart() if start_match.hasMatch() else -1
    
        while startIndex >= 0:
            end_match = self.commentEndExpression.match(text, startIndex)
            if end_match.hasMatch():
                endIndex = end_match.capturedStart()
                commentLength = endIndex - startIndex + end_match.capturedLength()
                self.setCurrentBlockState(0)
            else:
                self.setCurrentBlockState(1)
                commentLength = len(text) - startIndex
    
            self.setFormat(startIndex, commentLength, self.multiLineCommentFormat)
    
            # Look for next comment start
            next_match = self.commentStartExpression.match(text, startIndex + commentLength)
            startIndex = next_match.capturedStart() if next_match.hasMatch() else -1

Replaced all entries - now, just nothing happens. All that’s working is “Asset Manager Settings” window. The rest is nowhere to be found.

So, there is also “Assetts…” button in Tools→’Manage Note Types’ menu, which isn’t described anywhere in the addon docs smh.

To make everything work you need to replace the following in every file in addon’s code (where it presented):

  1. self.scriptsTable.setGridStyle(QtCore.Qt.PenStyle.DashLine)self.scriptsTable.setGridStyle(QtCore.Qt.DashLine)
  2. QSizePolicy.PreferredQSizePolicy.Policy.Preferred
    1. Note these color usings:
      1. Qt.cyan,
        Qt.blue,
        Qt.red,
        Qt.darkRed,
        Qt.yellow,
        Qt.darkYellow,
        Qt.green,
        Qt.darkGreen,
        Qt.magenta,
        Qt.darkMagenta,
        Qt.gray,
        Qt.lightGray
    2. Change Qt to Qt.GlobalColor in all of these. For example: Qt.manentato Qt.GlobalColor.magenta, Qt.red to Qt.GlobalColor.red.
    3. Also, after that, wrap all expressions with changed color usings in QColor(). For example Qt.GlobalColor.cyan if is_night_mode else Qt.GlobalColor.blue to QColor(Qt.GlobalColor.cyan if is_night_mode else Qt.GlobalColor.blue)
    4. from aqt import QDialog, QLayout, QKeySequencefrom aqt.qt import QDialog, QLayout, QKeySequence

Next, I’ll take the post with the code above, which it is strangely formatted, and translate it to you:

  1. Make all substitutions specified in that post (but don’t add # to the line starting with self.scriptsTable). Substitutions are pairs of the source and target strings, divided by “→”.
  2. Keep in mind, that substitutions there start with PyQt5PyQt6
  3. The source string in the second substitution is actually 2 strings in the corresponding source file (there is only one place and one file related to that source string).
  4. Skip a line in that post starting with Qt.GlobalColor.cyan, since we already did corresponding substitution in step 3.
  5. Small substitutions end before the line “#chatgpt”.
  6. You need to replace the whole function highlightBlock which text goes to the end of the post.
  7. highlightBlock function is located in highliighter.py.