Good evening, I would like to know if there is any way to show all of Anki’s widgets or webviews.
It could also be in the form of an addon, which would be used to show all of Anki’s widgets, whether on the main screen, in the editor, in the browser, etc. This would help in the development of addons.
I know that there is the ctrl shift ; command to open the debugging screen and also the element inspection addon 31746032, but in their case you have to search one by one until you find the one you want, so this may take a while depending on what the addon development wants to do.
I made the code below with the help of chatgpt for the Anki home screen, but it doesn’t work for this purpose, it shows few widgets.
from aqt import mw
from aqt.qt import QAction, QDialog, QVBoxLayout, QTextEdit, QPushButton
from PyQt6.QtCore import Qt, QObject
def print_widget_tree(widget, level=0):
"""Recursively print widget hierarchy."""
indent = " " * (level * 4)
result = f"{indent}Widget: {widget.objectName()} - {widget.__class__.__name__}\n"
for child in widget.findChildren(QObject):
result += print_widget_tree(child, level + 1)
return result
def show_widget_tree():
"""Show the widget tree in a dialog."""
widget_tree_text = print_widget_tree(mw.centralWidget())
dialog = QDialog(mw)
dialog.setWindowTitle("Lista de Widgets")
dialog.setGeometry(100, 100, 600, 400)
layout = QVBoxLayout()
text_edit = QTextEdit()
text_edit.setPlainText(widget_tree_text)
text_edit.setReadOnly(True)
close_button = QPushButton("Fechar")
close_button.clicked.connect(dialog.accept)
layout.addWidget(text_edit)
layout.addWidget(close_button)
dialog.setLayout(layout)
dialog.exec()
def add_custom_menu():
"""Add a custom menu to show widgets."""
menu = mw.form.menuTools.addMenu("Exibir Widgets")
show_widgets_action = QAction("Mostrar Todos os Widgets", mw)
show_widgets_action.triggered.connect(show_widget_tree)
menu.addAction(show_widgets_action)
# Add the custom menu to the Tools menu
add_custom_menu()
The result shown in the dialog box is the one below, very far from what was expected, as apparently the home screen does not use widgets, unlike the browser.
Widget: centralwidget - QWidget
Widget: - QVBoxLayout
Widget: - TopWebView
Widget: - QVBoxLayout
Widget: - QWidget
Widget: - QVBoxLayout
Widget: - QWidget
Widget: - MainWebView
Widget: - QVBoxLayout
Widget: - QWidget
Widget: - QVBoxLayout
Widget: - QWidget
Widget: - BottomWebView
Widget: - QVBoxLayout
Widget: - QWidget
Widget: - QVBoxLayout
Widget: - QWidget