Exemple #1
0
def clickPlayAudio(cmd):
    splitList = cmd.split(';')
    path = fetchAudioFromDict(splitList[1], splitList[2], int(splitList[3]))
    if path:
        path = join(addon_path, "user_files", 'accentAudio', path)
        if exists(path):
            sound.play(path)
def my_keyHandler(self, evt):
    #global messageBuff
    global audio_speed, audio_replay
    
    key = unicode(evt.text())

    if key == "0":
        audio_speed = 1.0
    elif key == "[":
        audio_speed = max(0.1, audio_speed - 0.1)
    elif key == "]":
        audio_speed = min(4.0, audio_speed + 0.1)
    
    if key in "0[]":    
        if audio_replay:
            play(audio_file)
        elif anki.sound.mplayerManager is not None:
            if anki.sound.mplayerManager.mplayer is not None: 
                anki.sound.mplayerManager.mplayer.stdin.write("af_add scaletempo=stride=10:overlap=0.8\n")
                anki.sound.mplayerManager.mplayer.stdin.write(("speed_set %f \n" % audio_speed))
    
    if key == "p":
        anki.sound.mplayerManager.mplayer.stdin.write("pause\n")
    elif key == "l":
        audio_replay = not audio_replay
        if audio_replay:
            showInfo("Auto Replay ON")
        else:
            showInfo("Auto Replay OFF")
    
    if key == "r":
        anki.sound.mplayerClear = True
Exemple #3
0
def my_keyHandler(self, evt):
    #global messageBuff
    global audio_speed, audio_replay

    key = unicode(evt.text())

    if key == "q":
        audio_speed = 1.0
    elif key == "[":
        audio_speed = max(0.1, audio_speed - 0.1)
    elif key == "]":
        audio_speed = min(4.0, audio_speed + 0.1)

    if key in "q[]":
        if audio_replay:
            play(audio_file)
        elif anki.sound.mplayerManager is not None:
            if anki.sound.mplayerManager.mplayer is not None:
                anki.sound.mplayerManager.mplayer.stdin.write(
                    "af_add scaletempo=stride=10:overlap=0.8\n")
                anki.sound.mplayerManager.mplayer.stdin.write(
                    ("speed_set %f \n" % audio_speed))

    if key == "p":
        anki.sound.mplayerManager.mplayer.stdin.write("pause\n")
    elif key == "`":
        audio_replay = not audio_replay
        if audio_replay:
            showInfo("Auto Replay ON")
        else:
            showInfo("Auto Replay OFF")

    if key == "r":
        anki.sound.mplayerClear = True
Exemple #4
0
 def _linkHandler(self, url):
     if url == "ans":
         self._showAnswer()
     elif url == "nxt":
         self.nextCard()
     elif url == "revFocused":
         self.mw.viewmanager.unhover()
     elif url == "showBottombar":
         self.mw.viewmanager.hoverBottom()
     elif url == "showMenubar":
         self.mw.viewmanager.hoverTop()
     elif url == "showCursor":
         self.mw.viewmanager.showCursor()
         self.mw.viewmanager.hideCursor()
     elif url == "ansHack":
         self.mw.progress.timer(100, self._showAnswerHack, False)
     elif url.startswith("ease"):
         self._answerCard(int(url[4:]))
     elif url == "edit":
         self.mw.onEditCurrent()
     elif url == "more":
         self.showContextMenu()
     elif url.startswith("typeans:"):
         (cmd, arg) = url.split(":", 1)
         self.typedAnswer = arg
     elif url.startswith("ankiplay:"):
         (cmd, arg) = url.split(":", 1)
         clearAudioQueue()
         play(arg)
     else:
         openLink(url)
def myPopUp(self, ease):
    cnt = self.mw.col.sched.answerButtons(self.card)
    popUp_Chance = config["Pop-Up Chance"]
    show_random = random.choice(range((101 - popUp_Chance)))
    if show_random == 0 and popUp_Chance != 0:
        play_audio = config["Play Audio"]
        if self.state == "answer":
            if cnt == 3:
                if ease == 1:
                    folder = 'again'
                elif ease == 2:
                    folder = 'good'
                else:
                    folder = 'easy'
            else:
                if ease == 1:
                    folder = 'again'
                elif ease == 2:
                    folder = 'hard'
                elif ease == 3:
                    folder = 'good'
                else:
                    folder = 'easy'
            audio_folder = join(addon_path, 'user_files/audio_video', folder)
            audioName_list = os.listdir(audio_folder)
            audio_name = '/{}'.format(random.choice(audioName_list))
            audio_path = audio_folder + audio_name
            if play_audio:
                AVPlayer.play_tags = _play_tags
                clearAudioQueue()
                play(audio_path)
            show_popUp(cnt, ease)
Exemple #6
0
def linkHandler(self, url, _old):
    if not url.startswith("spdf"):
        return _old(self, url)
    if not mw.col:
        # collection unloaded, e.g. when called during pre-exit sync
        return
    cmd, action = url.split(":")
    conf = mw.col.decks.confForDid(self.card.odid or self.card.did)

    if action == "typeans":
        suspendTimers()
    elif action == "alert":
        play(ALERT_PATH)
        timeout = conf.get('autoAlert', 0)
        tooltip("Wake up! You have been looking at <br>"
                "the question for <b>{}</b> seconds!".format(timeout),
                period=1000)
    elif action == "action":
        action = conf.get('autoAction', "again")

    if action == "again":
        if self.state == "question":
            self._showAnswer()
        self._answerCard(1)
    elif action == "good":
        if self.state == "question":
            self._showAnswer()
        self._answerCard(self._defaultEase())
    elif action == "bury":
        mw.reviewer.onBuryCard()
def showMsg():
    clearAudioQueue()
    m=random.choice(MELODY_LIST)
    m=os.path.join(SND_DIR,m)
    play(m)

    mw.requireReset(True)
    mw.bottomWeb.hide()
    mw.web.stdHtml(ASCII_ART, css=CSS)
    reset()
Exemple #8
0
def patched_play_from_text(text):
    matches = re.findall(sound_re, text)
    if not matches:
        # Avoid any problems with calling the programs with zero
        # files.
        return
    if command_list:
            play_with_mplayer(matches)
            return
    # Still here: no command list. I guess we didn't find
    # mplayer. Good luck playing it with play...
    for match in matches:
        play(match)
def patched_play_from_text(text):
    matches = re.findall(sound_re, text)
    if not matches:
        # Avoid any problems with calling the programs with zero
        # files.
        return
    if command_list:
            play_with_vlc(matches)
            return
    # Still here, neither all mp3 nor all playable with play. The
    # classical sound.play.
    for match in matches:
        play(match)
Exemple #10
0
 def linkHandler(self, url):
     """Executed when clicking on a card"""
     if url.startswith("focus"):
         # bring card into focus
         cid = int(url.split()[1])
         self.linkClicked = True
         self.b.focusCid(cid)
     elif url.startswith("ankiplay"):
         # support for 'Replay Buttons on Card' add-on
         clearAudioQueue()  # stop current playback
         play(url[8:])
     else:
         # handle regular links with the default link handler
         openLink(url)
Exemple #11
0
def patched_play_from_text(text):
    u"""Play the list of files directly without play queue."""
    matches = re.findall(sound_re, text)
    if not matches:
        # Avoid any problems with calling the programs with zero
        # files.
        return
    if command_list:
        play_with_mplayer(matches)
    else:
        # No command list. I guess we didn't find mplayer. Good luck
        # playing it with play...
        for match in matches:
            play(match)
Exemple #12
0
def patched_play_from_text(text):
    u"""Play the list of files directly without play queue."""
    matches = re.findall(sound_re, text)
    if not matches:
        # Avoid any problems with calling the programs with zero
        # files.
        return
    if command_list:
        play_with_mplayer(matches)
    else:
        # No command list. I guess we didn't find mplayer. Good luck
        # playing it with play...
        for match in matches:
            play(match)
def patched_play_from_text(text):
    matches = re.findall(sound_re, text)
    if not matches:
        # Avoid any problems with calling the programs with zero
        # files.
        return
    matches = [mtch.encode(fse) for mtch in matches]
    if command_list:
        play_with_mplayer(matches)
    else:
        # No command list. I guess we didn't find mplayer. Good luck
        # playing it with play...
        for match in matches:
            play(match)
Exemple #14
0
 def on_tomato(self, from_timer=True):
     self.db.end_session()
     if self.tm:
         self.tm.stop()
     self.pb_w.hide()
     self.pb.reset()
     if from_timer:
         mw.moveToState("overview")
         if not self.dlg_rest:
             self.dlg_rest = RestDialog(mw)
             self._set_style_sheet(self.dlg_rest)
             self.dlg_rest.accepted.connect(self.on_dlg_rest_accepted)
             self.dlg_rest.rejected.connect(self.on_dlg_rest_rejected)
         if UserConfig.PLAY_SOUNDS["break"]:
             play(BREAK)
         self.dlg_rest.exec_(self.dlg.min)
Exemple #15
0
def myPopUp(self):
    SA_popUp_Chance = config["Show Answer Pop-Up Chance"]
    show_random = random.choice(range((101 - SA_popUp_Chance)))
    if show_random == 0 and SA_popUp_Chance != 0:
        play_audio = config["Play Audio"]
        # if self.state == "review":
        folder = 'show_answer'
        audio_folder = join(addon_path, 'user_files/audio_video', folder)
        audioName_list = os.listdir(audio_folder)
        audio_name = '/{}'.format(random.choice(audioName_list))
        audio_path = audio_folder + audio_name
        if play_audio:
            AVPlayer.play_tags=_play_tags
            clearAudioQueue()
            play(audio_path)
        show_popUp()
def my_keyHandler(key):
    global audio_speed, audio_replay

    if key == "p":
        audio_speed = 1.0
    elif key == "[":
        audio_speed = max(0.1, audio_speed - 0.1)
    elif key == "]":
        audio_speed = min(4.0, audio_speed + 0.1)

    if platform == "win32":
            # Windows
        if key in "p[]":
            if audio_replay:
                play(audio_file)

            elif anki.sound.mplayerManager is not None:
                if anki.sound.mplayerManager.mplayer is not None:
                    anki.sound.mplayerManager.mplayer.stdin.write(b"af_add scaletempo=stride=10:overlap=0.8\n")
                    anki.sound.mplayerManager.mplayer.stdin.write((b"speed_set %f \n" % audio_speed))
                    anki.sound.mplayerManager.mplayer.stdin.flush()
    else:
            # Mac and Linux
        mm = anki.sound.mpvManager
        if key in "[]" or key == "BS":
            if audio_replay:
                play(audio_file)

            elif mm is not None:
                if mm.command is not None:
                    mm.command ("keypress", key)
    # if key == "p":
    #     anki.sound.mplayerManager.mplayer.stdin.write(b"pause\n")
    # elif key == "l":
    #     audio_replay = not audio_replay
    #     if audio_replay:
    #         showInfo("Auto Replay ON")
    #     else:
    #         showInfo("Auto Replay OFF")

    if key == "r":
        anki.sound.mplayerClear = True
Exemple #17
0
def review_link_handler_wrapper(reviewer, url):
    """Play the sound or call the original link handler."""
    if url.startswith("urlplayhttp://") or url.startswith("urlplayhttps://"):
        if isWin:
            # download audio from url
            name = os.path.join(
                tmpdir(),
                hashlib.md5(url.encode(encoding="UTF-8")).hexdigest() + ".mp3")
            if not os.path.exists(name):
                f = open(name, "wb")
                f.write(requests.get(url[7:]).content)
                f.close()
            # it wants unix paths, too!
            path = name.replace("\\", "/")
            play(path)
        else:
            # use mpv directly
            mpvManager.command("loadfile", url[7:], "append-play")
    else:
        original_review_link_handler(reviewer, url)
    def maybeDownloadAudio(self, askForText=False):
        """Check whether we should download a pronunciation for this
        card and try to do so if that is the case. Then save add the
        pronunciation to the card"""

        # Check whether there is a place where we could put the audio
        if not self.cardCanUseAudio():
            noDownloadMessagePath = os.path.join(mw.config.configPath,
                                                 u'plugins', u'Japanese_audio',
                                                 noDownloadMessageFile)
            if not AUTO_DOWNLOAD_AUDIO:
                sound.play(noDownloadMessagePath)
            return

        # Check whether a number of further conditons are met
        if (not askForText) and (not self.shouldDownloadAudio()):
            noDownloadMessagePath = os.path.join(mw.config.configPath,
                                                 u'plugins', u'Japanese_audio',
                                                 noDownloadMessageFile)
            if not AUTO_DOWNLOAD_AUDIO:
                sound.play(noDownloadMessagePath)
            return
        self.createKanaKanjiStrings()
        if askForText:
            if not self.askForQueryStrings():
                # User clicked cancel
                return
        self.buildFileName()
        try:
            self.retrieveFile()
        except ValueError as ve:
            if str(ve).find('lacklist') > -1:
                # Clean up.
                os.remove(self.fileName)
            # An reraise.
            raise ve
        hashStoreFile = os.path.join(mw.config.configPath, u'plugins',
                                     u'Japanese_audio', hashStoreFileBasename)
        with open(hashStoreFile, 'a') as hashStore:
            hashStore.write(self.retrievedHash.hexdigest())
            hashStore.write(u'  ')
            hashStore.write(self.fileName.encode('utf-8'))
            hashStore.write(u'\n')
        self.processAudio()
        sound.play(self.fileName)
        storeFile = True
        if ALWAYS_ASK_BEFORE_SAVE:
            storeFile = self.askStoreFile()
        if storeFile:
            self.updateCard()
            self.createCards()
        else:
            os.remove(self.fileName)
    def maybeDownloadAudio(self, askForText=False):
        """Check whether we should download a pronunciation for this
        card and try to do so if that is the case. Then save add the
        pronunciation to the card"""

        # Check whether there is a place where we could put the audio
        if not self.cardCanUseAudio():
            noDownloadMessagePath = os.path.join(mw.config.configPath, u'plugins', u'Japanese_audio' ,noDownloadMessageFile)
            if not AUTO_DOWNLOAD_AUDIO:
                sound.play(noDownloadMessagePath)
            return

        # Check whether a number of further conditons are met
        if (not askForText) and (not self.shouldDownloadAudio()):
            noDownloadMessagePath = os.path.join(mw.config.configPath, u'plugins', u'Japanese_audio' ,noDownloadMessageFile)
            if not AUTO_DOWNLOAD_AUDIO:
                sound.play(noDownloadMessagePath)
            return
        self.createKanaKanjiStrings()
        if askForText:
            if not self.askForQueryStrings():
                # User clicked cancel
                return
        self.buildFileName()
        try:
            self.retrieveFile()
        except ValueError as ve:
            if str(ve).find('lacklist') > -1:
                # Clean up.
                os.remove(self.fileName)
            # An reraise.
            raise ve
        hashStoreFile = os.path.join(mw.config.configPath, u'plugins', u'Japanese_audio', hashStoreFileBasename)
        with open(hashStoreFile, 'a') as hashStore:
            hashStore.write(self.retrievedHash.hexdigest())
            hashStore.write(u'  ')
            hashStore.write(self.fileName.encode('utf-8'))
            hashStore.write(u'\n')
        self.processAudio()
        sound.play(self.fileName)
        storeFile = True
        if ALWAYS_ASK_BEFORE_SAVE:
            storeFile = self.askStoreFile()
        if storeFile:
            self.updateCard()
            self.createCards()
        else:
            os.remove(self.fileName)
Exemple #20
0
 def _linkHandler(self, url):
     if url == "decks":
         if UserConfig.PLAY_SOUNDS["abort"]:
             play(ABORT)
         if askUser(_2("ABORT TOMATO"), mw):
             self.db.end_session()
             mw.toolbar._linkHandler("decks")
             mw.deckBrowser.refresh()
     elif url == "half_time":
         if UserConfig.PLAY_SOUNDS["half_way_limit"]:
             play(HALF_TIME)
     elif url == 'timeout':
         if UserConfig.PLAY_SOUNDS["timeout"]: play(TIMEOUT)
         if UserConfig.SHOW_ANSWER_ON_CARD_TIMEOUT:
             self._showAnswer()
     else:
         return super(anki_reviewer, self)._linkHandler(url)
Exemple #21
0
 def create_rows(self, layout, sarea):
     u"""Build the rows of the dialog box"""
     play_button_group = QButtonGroup(sarea)
     old_play_button_group = QButtonGroup(sarea)
     for num, entry in enumerate(self.entries_list, 2):
         tt_text = self.build_text_help_label(entry)
         ico_label = QLabel('', sarea)
         ico_label.setToolTip(tt_text)
         if entry.icon:
             ico_label.setPixmap(QPixmap.fromImage(entry.icon))
         layout.addWidget(ico_label, num, 0)
         tt_label = QLabel(entry.display_word, sarea)
         tt_label.setToolTip(tt_text)
         layout.addWidget(tt_label, num, 1)
         if self.hide_text:
             tt_label.hide()
         # Play button.
         t_play_button = QPushButton(sarea)
         play_button_group.addButton(t_play_button, num-2)
         t_play_button.setToolTip(self.play_help)
         t_play_button.setIcon(QIcon(os.path.join(icons_dir, 'play.png')))
         layout.addWidget(t_play_button, num, self.play_column)
         if self.note[entry.audio_field_name]:
             t_play_old_button = QPushButton(sarea)
             old_play_button_group.addButton(t_play_old_button, num-2)
             t_play_old_button.setIcon(
                 QIcon(os.path.join(icons_dir, 'play.png')))
             if not self.hide_text:
                 t_play_old_button.setToolTip(
                     self.note[entry.audio_field_name])
             else:
                 t_play_old_button.setToolTip(self.play_old_help_short)
             layout.addWidget(t_play_old_button, num, self.play_old_column)
         else:
             dummy_label = QLabel('', sarea)
             dummy_label.setToolTip(self.play_old_empty_line_help)
             layout.addWidget(dummy_label, num, self.play_old_column)
         # The group where we later look what to do:
         t_button_group = QButtonGroup(sarea)
         t_button_group.setExclusive(True)
         # Now the four buttons
         t_add_button = QPushButton(sarea)
         t_add_button.setCheckable(True)
         t_add_button.setFlat(True)
         t_add_button.setToolTip(self.add_help_text_short)
         t_add_button.setIcon(QIcon(os.path.join(icons_dir, 'add.png')))
         layout.addWidget(t_add_button, num, self.add_column)
         t_button_group.addButton(t_add_button, Action.Add)
         t_keep_button = QPushButton(sarea)
         t_keep_button.setCheckable(True)
         t_keep_button.setFlat(True)
         t_keep_button.setToolTip(self.keep_help_text_short)
         t_keep_button.setIcon(QIcon(os.path.join(icons_dir, 'keep.png')))
         layout.addWidget(t_keep_button, num, self.keep_column)
         t_button_group.addButton(t_keep_button, Action.Keep)
         t_delete_button = QPushButton(sarea)
         t_delete_button.setCheckable(True)
         t_delete_button.setFlat(True)
         t_delete_button.setToolTip(self.delete_help_text_short)
         t_delete_button.setIcon(
             QIcon(os.path.join(icons_dir, 'delete.png')))
         layout.addWidget(t_delete_button, num, self.delete_column)
         t_button_group.addButton(t_delete_button,  Action.Delete)
         t_blacklist_button = QPushButton(sarea)
         t_blacklist_button.setCheckable(True)
         t_blacklist_button.setFlat(True)
         t_blacklist_button.setToolTip(self.blacklist_help_text_short)
         t_blacklist_button.setIcon(
             QIcon(os.path.join(icons_dir, 'blacklist.png')))
         if entry.entry_hash:
             layout.addWidget(
                 t_blacklist_button, num, self.blacklist_column)
         else:
             t_blacklist_button.hide()
             dummy_label_bl = QLabel('', sarea)
             dummy_label_bl.setToolTip(self.blacklist_empty_line_help)
             layout.addWidget(dummy_label_bl, num, self.blacklist_column)
         t_button_group.button(entry.action).setChecked(True)
         # New: check a button based on how good the downloader is.
         t_button_group.addButton(t_blacklist_button, Action.Blacklist)
         self.buttons_groups.append(t_button_group)
     play_button_group.buttonClicked.connect(
         lambda button: play(
             self.entries_list[play_button_group.id(button)].file_path))
     # N.B.: anki.sound.play() plays files from anywhere, not just
     # from the colection.media folder. We should be good,
     # here. (This behaviour may be a security risk, idk.)
     old_play_button_group.buttonClicked.connect(
         lambda button: playFromText(
             self.note[
                 self.entries_list[
                     old_play_button_group.id(button)].audio_field_name]))
Exemple #22
0
 def replay(self):
     au = self.getAudio()
     if au:
         self.clear()
         play(au)
def play_sound():
    """ Plays a short sound effect if the add-on is not muted """
    if not MUTED:
        play(slow_down_sound)
Exemple #24
0
 def exec_(self):
     if not self.updater.isRunning():
         self.updater.start()
     if UserConfig.PLAY_SOUNDS["start"]:
         play(START)
     return super(OneClock, self).exec_()
Exemple #25
0
 def playMajorEventSound(self):
     if self.ae.getOptions().getOption('soundEnabled'):
         sound.play(getMajorEventSound())
Exemple #26
0
 def playMajorEventSound(self):
     if self.ae.getOptions().getOption('soundEnabled'):
         sound.play(getMajorEventSound())
Exemple #27
0
def simple_link_handler(url):
    u"""Play the file."""
    if url.startswith("ankiplay"):
        play(url[8:])
    else:
        QDesktopServices.openUrl(QUrl(url))
Exemple #28
0
def review_link_handler_wrapper(reviewer, url):
    u"""Play the sound or call the original link handler."""
    if url.startswith("ankiplay"):
        play(url[8:])
    else:
        original_review_link_handler(reviewer, url)
Exemple #29
0
def playMusic(filePath):
    play(filePath)
Exemple #30
0
def simple_link_handler(url):
    u"""Play the file."""
    if url.startswith("ankiplay"):
        play(url[8:])
    else:
        QDesktopServices.openUrl(QUrl(url))
Exemple #31
0
def play( sPath ):
   path = basePath + os.sep + sPath
   path = path.replace( os.sep, os.sep*2 ) # fix for windows
   print 'playing:', path
   sound.play( path )
Exemple #32
0
 def create_rows(self, layout):
     """Build one row of the dialog box"""
     play_button_group = QButtonGroup(self)
     old_play_button_group = QButtonGroup(self)
     for num, (source, dest, text, dl_fname, dl_hash, extras, icon)\
             in enumerate(self.list, 3):
         tt_text = self.build_text_help_label(text, source, extras)
         ico_label = QLabel('', self)
         ico_label.setToolTip(tt_text)
         if icon:
             ico_label.setPixmap(QPixmap.fromImage(icon))
         layout.addWidget(ico_label, num, 0)
         tt_label = QLabel(text, self)
         tt_label.setToolTip(tt_text)
         layout.addWidget(tt_label, num, 1)
         if self.hide_text:
             tt_label.hide()
         # Play button.
         t_play_button = QPushButton(self)
         play_button_group.addButton(t_play_button, num - 3)
         t_play_button.setToolTip(self.play_help)
         t_play_button.setIcon(QIcon(os.path.join(icons_dir, 'play.png')))
         layout.addWidget(t_play_button, num, self.play_column)
         if self.note[dest]:
             t_play_old_button = QPushButton(self)
             old_play_button_group.addButton(t_play_old_button, num - 3)
             t_play_old_button.setIcon(
                 QIcon(os.path.join(icons_dir, 'play.png')))
             if not self.hide_text:
                 t_play_old_button.setToolTip(self.note[dest])
             else:
                 t_play_old_button.setToolTip(self.play_old_help_short)
             layout.addWidget(t_play_old_button, num, self.play_old_column)
         else:
             dummy_label = QLabel('', self)
             dummy_label.setToolTip(self.play_old_empty_line_help)
             layout.addWidget(dummy_label, num, self.play_old_column)
         # The group where we later look what to do:
         t_button_group = QButtonGroup(self)
         t_button_group.setExclusive(True)
         # Now the four buttons
         t_add_button = QPushButton(self)
         t_add_button.setCheckable(True)
         t_add_button.setChecked(True)
         t_add_button.setFlat(True)
         t_add_button.setToolTip(self.add_help_text_short)
         t_add_button.setIcon(QIcon(os.path.join(icons_dir, 'add.png')))
         layout.addWidget(t_add_button, num, self.add_column)
         t_button_group.addButton(t_add_button, action['add'])
         t_keep_button = QPushButton(self)
         t_keep_button.setCheckable(True)
         t_keep_button.setFlat(True)
         t_keep_button.setToolTip(self.keep_help_text_short)
         t_keep_button.setIcon(QIcon(os.path.join(icons_dir, 'keep.png')))
         layout.addWidget(t_keep_button, num, self.keep_column)
         t_button_group.addButton(t_keep_button,  action['keep'])
         t_delete_button = QPushButton(self)
         t_delete_button.setCheckable(True)
         t_delete_button.setFlat(True)
         t_delete_button.setToolTip(self.delete_help_text_short)
         t_delete_button.setIcon(QIcon(os.path.join(icons_dir,
                                                    'delete.png')))
         layout.addWidget(t_delete_button, num, self.delete_column)
         t_button_group.addButton(t_delete_button,  action['delete'])
         t_blacklist_button = QPushButton(self)
         t_blacklist_button.setCheckable(True)
         t_blacklist_button.setFlat(True)
         t_blacklist_button.setToolTip(self.blacklist_help_text_short)
         t_blacklist_button.setIcon(QIcon(os.path.join(icons_dir,
                                                       'blacklist.png')))
         if self.show_skull_and_bones:
             layout.addWidget(
                 t_blacklist_button, num, self.blacklist_column)
         else:
             t_blacklist_button.hide()
         t_button_group.addButton(t_blacklist_button,  action['blacklist'])
         self.buttons_groups.append(t_button_group)
     play_button_group.buttonClicked.connect(
         lambda button: play(self.list[play_button_group.id(button)][3]))
     old_play_button_group.buttonClicked.connect(
         lambda button: playFromText(
             self.note[self.list[old_play_button_group.id(button)][1]]))
Exemple #33
0
 def create_rows(self, layout):
     u"""Build the rows of the dialog box"""
     play_button_group = QButtonGroup(self)
     old_play_button_group = QButtonGroup(self)
     for num, entry in enumerate(self.entries_list, 3):
         tt_text = self.build_text_help_label(entry)
         ico_label = QLabel('', self)
         ico_label.setToolTip(tt_text)
         if entry.icon:
             ico_label.setPixmap(QPixmap.fromImage(entry.icon))
         layout.addWidget(ico_label, num, 0)
         tt_label = QLabel(entry.display_word, self)
         tt_label.setToolTip(tt_text)
         layout.addWidget(tt_label, num, 1)
         if self.hide_text:
             tt_label.hide()
         # Play button.
         t_play_button = QPushButton(self)
         play_button_group.addButton(t_play_button, num - 3)
         t_play_button.setToolTip(self.play_help)
         t_play_button.setIcon(QIcon(os.path.join(icons_dir, 'play.png')))
         layout.addWidget(t_play_button, num, self.play_column)
         if self.note[entry.audio_field_name]:
             t_play_old_button = QPushButton(self)
             old_play_button_group.addButton(t_play_old_button, num - 3)
             t_play_old_button.setIcon(
                 QIcon(os.path.join(icons_dir, 'play.png')))
             if not self.hide_text:
                 t_play_old_button.setToolTip(
                     self.note[entry.audio_field_name])
             else:
                 t_play_old_button.setToolTip(self.play_old_help_short)
             layout.addWidget(t_play_old_button, num, self.play_old_column)
         else:
             dummy_label = QLabel('', self)
             dummy_label.setToolTip(self.play_old_empty_line_help)
             layout.addWidget(dummy_label, num, self.play_old_column)
         # The group where we later look what to do:
         t_button_group = QButtonGroup(self)
         t_button_group.setExclusive(True)
         # Now the four buttons
         t_add_button = QPushButton(self)
         t_add_button.setCheckable(True)
         t_add_button.setFlat(True)
         t_add_button.setToolTip(self.add_help_text_short)
         t_add_button.setIcon(QIcon(os.path.join(icons_dir, 'add.png')))
         layout.addWidget(t_add_button, num, self.add_column)
         t_button_group.addButton(t_add_button, Action.Add)
         t_keep_button = QPushButton(self)
         t_keep_button.setCheckable(True)
         t_keep_button.setFlat(True)
         t_keep_button.setToolTip(self.keep_help_text_short)
         t_keep_button.setIcon(QIcon(os.path.join(icons_dir, 'keep.png')))
         layout.addWidget(t_keep_button, num, self.keep_column)
         t_button_group.addButton(t_keep_button, Action.Keep)
         t_delete_button = QPushButton(self)
         t_delete_button.setCheckable(True)
         t_delete_button.setFlat(True)
         t_delete_button.setToolTip(self.delete_help_text_short)
         t_delete_button.setIcon(
             QIcon(os.path.join(icons_dir, 'delete.png')))
         layout.addWidget(t_delete_button, num, self.delete_column)
         t_button_group.addButton(t_delete_button,  Action.Delete)
         t_blacklist_button = QPushButton(self)
         t_blacklist_button.setCheckable(True)
         t_blacklist_button.setFlat(True)
         t_blacklist_button.setToolTip(self.blacklist_help_text_short)
         t_blacklist_button.setIcon(
             QIcon(os.path.join(icons_dir, 'blacklist.png')))
         if entry.entry_hash:
             layout.addWidget(
                 t_blacklist_button, num, self.blacklist_column)
         else:
             t_blacklist_button.hide()
             dummy_label_bl = QLabel('', self)
             dummy_label_bl.setToolTip(self.blacklist_empty_line_help)
             layout.addWidget(dummy_label_bl, num, self.blacklist_column)
         t_button_group.button(entry.action).setChecked(True)
         # New: check a button based on how good the downloader is.
         t_button_group.addButton(t_blacklist_button, Action.Blacklist)
         self.buttons_groups.append(t_button_group)
     play_button_group.buttonClicked.connect(
         lambda button: play(
             self.entries_list[play_button_group.id(button)].file_path))
     # N.B.: anki.sound.play() plays files from anywhere, not just
     # from the colection.media folder. We should be good,
     # here. (This behaviour may be a security risk, idk.)
     old_play_button_group.buttonClicked.connect(
         lambda button: playFromText(
             self.note[
                 self.entries_list[
                     old_play_button_group.id(button)].audio_field_name]))
Exemple #34
0
def playSoundEaseAnswer(self, card, ease):
    play(os.path.join(path, soundEase[ease]))
Exemple #35
0
 def onReplayRecorded(self):
     if not self._recordedAudio:
         return tooltip(_("You haven't recorded your voice yet."))
     clearAudioQueue()
     play(self._recordedAudio)
Exemple #36
0
 def create_rows(self, layout):
     play_button_group = QButtonGroup(self)
     old_play_button_group = QButtonGroup(self)
     for num, (source, dest, text, dl_fname, dl_hash, extras, icon)\
             in enumerate(self.list, 3):
         tt_text = self.build_text_help_label(text, source, extras)
         ico_label = QLabel('', self)
         ico_label.setToolTip(tt_text)
         if icon:
             ico_label.setPixmap(QPixmap.fromImage(icon))
         layout.addWidget(ico_label, num, 0)
         tt_label = QLabel(text, self)
         tt_label.setToolTip(tt_text)
         layout.addWidget(tt_label, num, 1)
         if self.hide_text:
             tt_label.hide()
         # Play button.
         t_play_button = QPushButton(self)
         play_button_group.addButton(t_play_button, num - 3)
         t_play_button.setToolTip(self.play_help)
         t_play_button.setIcon(QIcon(os.path.join(icons_dir, 'play.png')))
         layout.addWidget(t_play_button, num, self.play_column)
         if self.note[dest]:
             t_play_old_button = QPushButton(self)
             old_play_button_group.addButton(t_play_old_button, num - 3)
             t_play_old_button.setIcon(
                 QIcon(os.path.join(icons_dir, 'play.png')))
             if not self.hide_text:
                 t_play_old_button.setToolTip(self.note[dest])
             else:
                 t_play_old_button.setToolTip(self.play_old_help_short)
             layout.addWidget(t_play_old_button, num, self.play_old_column)
         else:
             dummy_label = QLabel('', self)
             dummy_label.setToolTip(self.play_old_empty_line_help)
             layout.addWidget(dummy_label, num, self.play_old_column)
         # The group where we later look what to do:
         t_button_group = QButtonGroup(self)
         t_button_group.setExclusive(True)
         # Now the four buttons
         t_add_button = QPushButton(self)
         t_add_button.setCheckable(True)
         t_add_button.setChecked(True)
         t_add_button.setFlat(True)
         t_add_button.setToolTip(self.add_help_text_short)
         t_add_button.setIcon(QIcon(os.path.join(icons_dir, 'add.png')))
         layout.addWidget(t_add_button, num, self.add_column)
         t_button_group.addButton(t_add_button, action['add'])
         t_keep_button = QPushButton(self)
         t_keep_button.setCheckable(True)
         t_keep_button.setFlat(True)
         t_keep_button.setToolTip(self.keep_help_text_short)
         t_keep_button.setIcon(QIcon(os.path.join(icons_dir, 'keep.png')))
         layout.addWidget(t_keep_button, num, self.keep_column)
         t_button_group.addButton(t_keep_button,  action['keep'])
         t_delete_button = QPushButton(self)
         t_delete_button.setCheckable(True)
         t_delete_button.setFlat(True)
         t_delete_button.setToolTip(self.delete_help_text_short)
         t_delete_button.setIcon(QIcon(os.path.join(icons_dir,
                                                    'delete.png')))
         layout.addWidget(t_delete_button, num, self.delete_column)
         t_button_group.addButton(t_delete_button,  action['delete'])
         t_blacklist_button = QPushButton(self)
         t_blacklist_button.setCheckable(True)
         t_blacklist_button.setFlat(True)
         t_blacklist_button.setToolTip(self.blacklist_help_text_short)
         t_blacklist_button.setIcon(QIcon(os.path.join(icons_dir,
                                                       'blacklist.png')))
         if self.show_skull_and_bones:
             layout.addWidget(
                 t_blacklist_button, num, self.blacklist_column)
         else:
             t_blacklist_button.hide()
         t_button_group.addButton(t_blacklist_button,  action['blacklist'])
         self.buttons_groups.append(t_button_group)
     play_button_group.buttonClicked.connect(
         lambda button: play(self.list[play_button_group.id(button)][3]))
     old_play_button_group.buttonClicked.connect(
         lambda button: playFromText(
             self.note[self.list[old_play_button_group.id(button)][1]]))
Exemple #37
0
def review_link_handler_wrapper(reviewer, url):
    u"""Play the sound or call the original link handler."""
    if url.startswith("ankiplay"):
        play(url[8:])
    else:
        original_review_link_handler(reviewer, url)
Exemple #38
0
 def play(self):
     filename = download_pronunciation(self.pron)
     sound.clearAudioQueue()
     sound.play(filename)
Exemple #39
0
 def onReplayRecorded(self):
     if not self._recordedAudio:
         return tooltip(_("You haven't recorded your voice yet."))
     clearAudioQueue()
     play(self._recordedAudio)
Exemple #40
0
 def save_audio_selection(self, event, source_object=None):
     source_object.toggle()
     self.selected_audio = str(source_object.abs_audio_path)
     play(str(source_object.abs_audio_path))