@@ -540,16 +540,28 @@ def _onTextEdited(self, text):
540540 #----------
541541
542542 def _playbackAudio (self , path ):
543+ self ._getAudioData (path , lambda data : self ._soundplayer .play (data ))
544+
545+ def _getAudioData (self , path , callback ):
543546 (archive , name ) = path .lstrip ('/' ).split ('/' , 1 )
544547 if archive in ('us_hwd_pron' , 'gb_hwd_pron' , 'exa_pron' , 'sfx' , 'sound' ):
545548 def finished ():
546549 if reply .error () == QNetworkReply .NoError :
547- self . _soundplayer . play (reply .readAll ())
550+ callback (reply .readAll ())
548551
549552 url = QUrl ('dict:///{0}/{1}' .format (archive , name ))
550553 reply = self ._networkAccessManager .get (QNetworkRequest (url ))
551554 reply .finished .connect (finished )
552555
556+ def downloadSelectedAudio (self ):
557+ path = self ._ui .webView .audioUrlToDownload .path ()
558+ def showSaveDialog (data ):
559+ filename = QFileDialog .getSaveFileName (self , u'Save mp3' , '' , u'MP3 Files (*.mp3)' )
560+ if filename != '' :
561+ file = open (filename , "w" )
562+ file .write (data )
563+ file .close ()
564+ self ._getAudioData (path , showSaveDialog )
553565
554566 def _onWebViewLinkClicked (self , url ):
555567 scheme = url .scheme ()
@@ -1126,6 +1138,7 @@ def act_conn(action, slot):
11261138 act_conn (ui .actionSearchDefinitions , self ._onSearchDefinitions )
11271139 act_conn (ui .actionAdvancedSearch , self ._onAdvancedSearch )
11281140 act_conn (wv .actionSearchText , self .searchSelectedText )
1141+ act_conn (wv .actionDownloadAudio , self .downloadSelectedAudio )
11291142 act_conn (ui .actionZoomIn , partial (self .setZoom , 1 , relative = True ))
11301143 act_conn (ui .actionZoomOut , partial (self .setZoom , - 1 , relative = True ))
11311144 act_conn (ui .actionNormalSize , partial (self .setZoom , 0 ))
0 commit comments