Please Help to build an addon for Anki

Mahesh Chiramure mchirmure at
Mon Apr 20 10:53:12 CEST 2015


I liked the addon "Picture-flasher" written for anki very much
and I was wondering if the same thing could be done with mp3 and/or
flac files. Means I am looking for an addon that chooses a random mp3
and/or flac file from a directory provided by me (to the addon as we
have to provide in "Picture-flasher") and plays it on successful
reviewing of a certain number of cards (as does the addon
"Picture-flasher"). As a music lover, I feel that this addon can
motivate a whole lot of music lovers out there to pay a visit to Anki
on their PC and review to listen to their favorite mp3 and/or flac
files as a reward.

I am not a programmer yet, please guide.

Hoping for a quick response.

Mahesh Chirmure
-------------- next part --------------
# -*- coding: utf-8 -*-
# Picture-Flasher (a plugin for Anki)
# Authors:
#   Emanuel Rylke, ema-fox at
#   D_Malik, malik6174 at
# Version 2
# License: GNU GPL, version 3 or later;

A simple plugin that flashes pictures on-screen to reinforce reviews.

Before using:
- Get pictures from someplace. I downloaded pictures off reddit using the script at
- Change all lines (in the plugin source) marked with "CHANGEME" according to your preferences.

For more details, see the post at For more details, see the post at

from anki.hooks import addHook
from aqt import mw
from random import random, choice
from aqt.qt import QSplashScreen, QPixmap, QTimer
from os import listdir

#------ begin configuration ------#
pictureDirectory = "E://Family stuff//22 Feb//Personal//College//A J//" #CHANGEME to the directory where you're storing your pictures. NB: This MUST end with a trailing slash e.g. D://Family stuff//19 Jan//Imgs//Wallys//, D://Family stuff//22 Feb//Imgs//Windows 7//.

flashTime = 3000 #CHANGEME to change how long pictures stay on the screen. The number is time in milliseconds.

#flashPosition = [20, 1050] #CHANGEME if you want the picture to be shown at a specific location. The numbers are x- and y-coordinates.

    #CHANGEME: The next lines are a python dictionary associating deck names with probabilities of pictures being shown.
    #Eg, when using the deck "brainscience", you will get a picture after 30% of cards. When using a deck without a listed name, "other" is used.
    #Change this according to your decks. Decks with shorter, easier cards need lower probabilities.
deckPicsProbabilities = {
    "rocketsurgery"    :   0.3,
    "brainscience"     :   0.5,
    "other"            :   0.1,
#------- end configuration -------#

pics = listdir(pictureDirectory)

def showPics():
    if mw.col.decks.current()['name'] in deckPicsProbabilities:
        picsProbability = deckPicsProbabilities[mw.col.decks.current()['name']]
        picsProbability = deckPicsProbabilities["other"]
    if random() < picsProbability:
        mw.splash = QSplashScreen(QPixmap(pictureDirectory + choice(pics)))
            mw.splash.move(flashPosition[0], flashPosition[1])
        except NameError:
        QTimer.singleShot(flashTime, mw.splash.close)

addHook("showQuestion", showPics)

More information about the Python-list mailing list