catch media adding errors

This commit is contained in:
Damien Elmes 2010-04-06 19:15:30 +09:00
parent 4928c21914
commit 7698d36f84

View file

@ -894,10 +894,17 @@ class FactEditor(object):
w = widget w = widget
else: else:
w = self.focusedEdit() w = self.focusedEdit()
path = self.deck.addMedia(file) path = self._addMedia(file)
self.maybeDelete(path, file) self.maybeDelete(path, file)
w.insertHtml('<img src="%s">' % path) w.insertHtml('<img src="%s">' % path)
def _addMedia(self, file):
try:
self.deck.addMedia(file)
except (IOError, OSError), e:
ui.utils.showWarning(_("Unable to add media: %s") % unicode(e),
parent=self.parent)
def onAddSound(self): def onAddSound(self):
# get this before we open the dialog # get this before we open the dialog
w = self.focusedEdit() w = self.focusedEdit()
@ -915,7 +922,7 @@ class FactEditor(object):
w = widget w = widget
else: else:
w = self.focusedEdit() w = self.focusedEdit()
path = self.deck.addMedia(file) path = self._addMedia(file)
self.maybeDelete(path, file) self.maybeDelete(path, file)
anki.sound.play(path) anki.sound.play(path)
w.insertHtml('[sound:%s]' % path) w.insertHtml('[sound:%s]' % path)