So I am trying to create a non modal dialog box (or window) supposed to show the content of certain fields from the card I just answered to. I want this window to mimic the main window of the Anki App so that the Yomilens addon which reacts when text is selected on the main one would react the same way when selecting text on this one as well.
import sys
from PyQt6.QtWidgets import*
from PyQt6.QtCore import *
from PyQt6.QtGui import *
class FieldsDialog(QWidget):
def __init__(self):
super().__init__()
self.title = "Fields"
self.setGeometry(400, 100, 300, 200)
self.left = 1367 # for it to be on the very left of my right monitor (a tablet)
self.top = 30 #otherwise the upper part is hidden
self.right = 504
self.width = 800
self.height = 1
self.icon = "?"
# self._help_dialog = None
# self._other_dialog = None
self.createUI()
def createUI(self):
self.setGeometry(self.left,self.top,self.right,self.width)
self.setWindowTitle(self.title)
self.setWindowIcon(QIcon(self.icon))
self.setStyleSheet("""
background: black;
""")
self.grid = QGridLayout()
self.setLayout(self.grid)
def on_show_fields():
if __name__ == '__main__':
app = QApplication(sys.argv)
fields_win = FieldsDialog()
fields_win.show()
sys.exit(app.exec())import sys
1 - The window shows while on pycharm (yay) but not in anki. Maybe the type of dialog is not adapted but for now it's been the only thing that worked)
2 - Since there was progress on that part, I was trying to see if my function supposed to get the text for the dialog actually worked
def _get_previous_fields(self, card) -> str | None:
if not card: return
note = card.note()
r = self.mw.reviewer
# current_id = r.card.id if r.card else "null"
previous = r.lastCard()
Front_value = mw.reviewer.card.note()['Front'] if FIELD_FRONT in note else ""
Back_value = mw.reviewer.card.note()['Back'] if FIELD_BACK in note else ""
previous_korean = Front_value.previous if previous else "null"
previous_english = Back_value.previous if previous else "null"
_queue_toast(f"{previous_korean}+\n+{previous_english}")
return "{previous_korean}+\n+{previous_english}"
but I keep getting errors like that :
lambda cid=card.id, e=ease, skip=skip_interval_checks: _post_answer_processing(cid, e, skip)
~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
TypeError: _post_answer_processing() missing 1 required positional argument: 'self'
I tried calling in on my on_show_answer
HOOK_ANSWER = reviewer_did_answer_card
if HOOK_ANSWER:
HOOK_ANSWER.append(on_answer)
But i'm told it (on_show_answer) is missing the self argument so I add it :
File "D:\a\anki\anki\out\installer\build\anki\windows\app\src\app_packages_aqt\hooks.py", line 4390, in __call__
TypeError: on_answer() missing 1 required positional argument: 'self' File "D:\a\anki\anki\out\installer\build\anki\windows\app\src\app_packages_aqt\hooks.py", line 4390, in __call__
TypeError: on_answer() missing 1 required positional argument: 'self'
I tried using hooks instead
if HOOK_SHOW:
HOOK_SHOW.append(on_show_question)
if HOOK_ANSWER:
HOOK_ANSWER.append(on_answer)
HOOK_ANSWER.append(_get_previous_fields) #here
if HOOK_SUSPEND:
HOOK_SUSPEND.append(on_reviewer_suspend)
and I get :
Traceback (most recent call last):
File "D:\a\anki\anki\out\installer\build\anki\windows\app\src\app_packages\aqt\taskman.py", line 152, in raise_exception
File "D:\a\anki\anki\out\installer\build\anki\windows\app\src\app_packages\aqt\taskman.py", line 148, in _on_closures_pending
File "D:\a\anki\anki\out\installer\build\anki\windows\app\src\app_packages\aqt\taskman.py", line 88, in <lambda>
File "D:\a\anki\anki\out\installer\build\anki\windows\app\src\app_packages\aqt\taskman.py", line 111, in wrapped_done
File "D:\a\anki\anki\out\installer\build\anki\windows\app\src\app_packages\aqt\operations__init__.py", line 128, in wrapped_done
File "D:\a\anki\anki\out\installer\build\anki\windows\app\src\app_packages\aqt\reviewer.py", line 556, in after_answer
File "D:\a\anki\anki\out\installer\build\anki\windows\app\src\app_packages\aqt\reviewer.py", line 566, in _after_answering
File "D:\a\anki\anki\out\installer\build\anki\windows\app\src\app_packages_aqt\hooks.py", line 4390, in __call__
TypeError: _get_previous_fields() takes 2 positional arguments but 3 were given
Do you happen to know what the issue is ?