New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QtMultimedia availability check added #1203
Conversation
But what if there will be another exception type? I don't know entrails of pyqt. Maybe it can raise another exception type. |
from PyQt5 import QtMultimedia | ||
except Exception as e: | ||
qt_multimedia_available = False | ||
log.warning("{} - Internal player disabled".format(e.msg)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to pre-format with log.warning()
and we usually place the detailed reason after the main message.
Also import
will raise ImportError
try:
from PyQt5 import QtMultimedia
except ImportError as e:
qt_multimedia_available = False
log.warning('Internal player disabled: %s', e.msg)
else:
qt_multimedia_available = True
@@ -113,8 +121,9 @@ def __init__(self, parent=None): | |||
self.selected_objects = [] | |||
self.ignore_selection_changes = False | |||
self.toolbar = None | |||
self.player = QtMultimedia.QMediaPlayer(self) | |||
self.player.error.connect(self._on_player_error) | |||
if qt_multimedia_available: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also try to import directly here and only set player property if a player is actually available.
self.player = None
try:
from PyQt5 import QtMultimedia
player = QtMultimedia.QMediaPlayer(self)
if player.availability() != QtMultimedia.QMultimedia.ServiceMissing:
self.player = player
self.player.error.connect(self._on_player_error)
except ImportError as e:
log.warning('Internal player disabled: %s', e.msg)
It would simplify tests:
if self.player:
do_something_with(self.player)
And ensure an exception is raised if self.player
is used without being really available (like using self.player.volume()
).
@timur-enikeev @phw : what do you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not a big fan of importing inline, I think this is clearer if done at the top. Apart from that I agree, so I would change your example to:
self.player = None
player = QtMultimedia.QMediaPlayer(self)
if qt_multimedia_available and player.availability() != QtMultimedia.QMultimedia.ServiceMissing:
self.player = player
self.player.error.connect(self._on_player_error)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I implemented this, with extra error logging in #1207
If another exception is raised, then it shouldn't be converted to a warning, because it'd be unexpected. But testing lack of exception on module import isn't sufficient to ensure the player is available, see #1203 (comment) We have 3 cases:
|
Closing this pull request as #1207 includes it. |
Summary
Problem
After internal music player has been added, picard crashes if PyQt5.QtMultimedia module is not available. I have added availability check for QtMultimedia module.
Solution
I have added handling of ImportError exception when we try to import PyQt5.QtMultimedia. If the import fails, qt_multimedia_available variable will be False. If the import was successful, this variable will be True.
Action