I use a flashcard program called Anki, which is written in Python. I want to write my first add-on. I'm new to Python. I'm not a techie, but I have a few years experience of jumping around inside other people's code in Java, C++, C#, and so on.
The flash card shows a question, for example "Capital of France?". When the "Show Answer" button is pressed, Anki displays the answer "Paris".
I want to grab this text "Paris", before it's shown.
I've arrived at this point in the Anki code. At this instant, the card shows "Capital of France?". The answer is still blank. I think I want to be able to grab "val" (which I think is "Paris") and use it in my add-on.
def _getTypedAnswer(self):
self.web.evalWithCallback("typeans ? typeans.value : null", self._onTypedAnswer)
def _onTypedAnswer(self, val):
self.typedAnswer = val
self._showAnswer()
I've been googling to try to find the meaning of this:
("typeans ? typeans.value : null", self._onTypedAnswer)
I have access to all the code, and I can provide any code that might be useful to responders.
Thanks.
Added: after questions from responders.
Anki can be run on a computer or on the internet. All the results of studying cards are synced, so there's no difference between one method or the other as far as the end user is concerned.
From the "webview" class:
def evalWithCallback(self, js, cb):
self.page().runJavaScript(js, cb)
The "reviewer" class shows the questions and answers. The reviewer window is "mw" (for "main window")
Here's the init statement for class "reviewer"
def __init__(self, mw):
self.mw = mw
self.web = mw.web