3

I wish to implement this unanswered idea of reverse cloze cards in Anki 2.1.x, i.e. (since I do not think that there is a builtin that does this) I want to write an add-on in Python 3.x and PyQt 5, which are the versions Anki 2.1.x uses. Basically, what I want this to do is that if I have the following card

This is {{c1::clozed::card type}}.

It will create two cards, akin to how you can reverse FrontSide and BackSide in regular Anki cards. I.e. I want to have two cards displaying

This is [card type]. --> This is clozed.

and the other

This is [clozed]. --> This is card type.

respectively. Here are my problems with this:

  • The cloze card type is a special one and the only way to get cloze cards is by copying this card type. The problem is this card type does not even allow the adding of multiple card types.

    My first thought was to have it as for regular cards, in which one has one card with Front -> Back and the other card Back -> Front. I would like to have this Hint -> Cloze and Cloze -> Hint.

    Just adding {{cloze:fieldname}} to templates of normal cards does not seem to work correctly either (it stops working when studying the cards, because in the preview it works fine). So one would first have to solve the issue of creating two cards from one entered card.

  • I first thought of somehow rewriting the code in this answer, but I am not sure how to do this, since I have not been able to get that code running. I thought that maybe one could exchange the hint and the cloze field for a second card and then have that card added.

I have not been able to find anything on this on the internet. I am not asking for completely functioning code (though of course that would be the easiest for me). As I am more or less able to program in Python, an explanation of how Anki would allow me to implement this with a link to documentation or source code (ideally Anki 2.1 code, i.e. code from the github), maybe even with small code snippets, would be tremendously helpful.

I just have the small doubt that this is not even possible, and if it is I have no clue how to start tackling this issue since documentation is scarce. If I end up writing my own implementation, I will make sure to share it here as well.

Yannick
  • 153
  • 8
  • 1
    I don't think you need the [tag:add-on] tag; anything with the tags [tag:anki] and [tag:python] / [tag:python-3.x] is about an add-on. – wizzwizz4 Mar 03 '18 at 14:19
  • 1
    By the way, the reason it works in the preview is due to [this code](https://github.com/dae/anki/blob/d96517710a967102be46c6e7f78c2e4ee061b3c6/aqt/models.py#L125-L136) assuming that everything containing `{{cloze:Text}}` is a cloze when creating the temporary notes. – wizzwizz4 Mar 03 '18 at 14:24
  • 1
    In fact, the cloze handling system is very badly designed. I mean, it works, but that's not the point. You have [this](https://github.com/dae/anki/blob/e8cc960da36ad7dd97f93af4cfb70eeb527fdbd5/aqt/addcards.py#L167-L172) sort of thing a lot; keep this in mind. It should probably check `.model()['type'] == MODEL_CLOZE` instead, which sometimes happens, but I don't know; there must be some sort of reason for it. – wizzwizz4 Mar 03 '18 at 14:28
  • 1
    [This](https://github.com/dae/anki/blob/ee940cfa854a8c7fe125c9fecb6ca7985023d622/anki/media.py#L214-L230) might be a good starting point. – wizzwizz4 Mar 03 '18 at 14:34
  • Sorry for not seeing this quicker, somehow I am not getting emails for comments on my own posts (gotta change settings). From your posts it certainly does not seem to be the most flexible piece of coding. But I think you're right, that will be a good starting point. I'll have to look into that part of the source once I find the time – Yannick May 19 '18 at 13:22
  • Also that bit with it working in the preview is interesting, albeit confusing if one does not know. – Yannick May 19 '18 at 13:23
  • Have you had the time yet? I'm trying to implement something similar, and rediscovered this question through a web search... Frustrating. – wizzwizz4 Nov 17 '18 at 17:15
  • I am currently setting aside time to start working on this. I asked on Anki support whether there would be interest in including this in the app or whether it should be an addon and Damien Elmes essentially discouraged me from trying to implement this stating it might not be too straightforward (see https://anki.tenderapp.com/discussions/ankidesktop/37930-feature-suggestion-reverse-cloze). I'll continue looking at addons treating cloze cards but not sure how to continue. – Yannick Jan 14 '20 at 11:02
  • At some point, I was working on an add-on to create generic custom note types. I've got a magic number stored on my desktop that I made sure nothing else was using – it would then start numbering the "reverse" cloze cards at `0x1001` or something. I'm not sure how AnkiWeb would deal with that, though, and I've mostly forgotten the details of how it was going to work, and I don't really have the time to make it any more. – wizzwizz4 Jan 14 '20 at 11:06
  • I'm starting to remember. Basically, genericising cloze cards, so that "normal" cards would be numbered normally, but cloze cards would be numbered as `0xaaaabbbb` where `aaaa` is the cloze card type and `bbbb` is the deletion. Trouble is, this effectively square-roots the available IDs (from 32-bit to 16-bit) – but that isn't all that much of a limitation. Then you'd be able to edit cloze cards as normal, but the cloze deletion system would automagically cope, a bit like the current automagic but two-dimensional instead of one-dimensional. – wizzwizz4 Jan 14 '20 at 12:58

0 Answers0