Small fixes. Added checks of start/end times.

This commit is contained in:
Tomas Groth 2014-04-07 23:08:48 +02:00
parent bc2d45fc30
commit aefef04d97
3 changed files with 43 additions and 18 deletions

View File

@ -219,11 +219,35 @@ class MediaClipSelectorForm(QtGui.QDialog, Ui_MediaClipSelector):
time = QtCore.QTime()
new_pos_time = time.addMSecs(vlc_ms_pos)
self.end_timeedit.setTime(new_pos_time)
# If start time is after end time, update end time.
# If start time is after end time, update start time.
start_time = self.start_timeedit.time()
if start_time > new_pos_time:
self.start_timeedit.setTime(new_pos_time)
@QtCore.pyqtSlot(QtCore.QTime)
def on_start_timeedit_timeChanged(self, new_time):
"""
Called when start_timeedit is changed manually
:param new_time: The new time
"""
# If start time is after end time, update end time.
end_time = self.end_timeedit.time()
if end_time < new_time:
self.end_timeedit.setTime(new_time)
@QtCore.pyqtSlot(QtCore.QTime)
def on_end_timeedit_timeChanged(self, new_time):
"""
Called when end_timeedit is changed manually
:param new_time: The new time
"""
# If start time is after end time, update start time.
start_time = self.start_timeedit.time()
if start_time > new_time:
self.start_timeedit.setTime(new_time)
@QtCore.pyqtSlot(bool)
def on_jump_end_pushbutton_clicked(self, clicked):
"""
@ -288,12 +312,15 @@ class MediaClipSelectorForm(QtGui.QDialog, Ui_MediaClipSelector):
# Enable subtitle track combobox is anything in it
if len(subtitles_tracks) > 0:
self.subtitle_tracks_combobox.setDisabled(False)
# First track is "deactivated", so set to next if it exists
if len(subtitles_tracks) > 1:
self.subtitle_tracks_combobox.setCurrentIndex(1)
self.vlc_media_player.audio_set_mute(False)
self.playback_length = self.vlc_media_player.get_length()
self.position_horizontalslider.setMaximum(self.playback_length)
# setup start and end time
rounded_vlc_ms_length = int(round(self.playback_length / 100.0) * 100.0)
time = QtCore.QTime()
playback_length_time = time.addMSecs(rounded_vlc_ms_length)
self.start_timeedit.setMaximumTime(playback_length_time)
self.end_timeedit.setMaximumTime(playback_length_time)
# If a title or audio track is available the player is enabled
if self.title_combo_box.count() > 0 or len(audio_tracks) > 0:
self.toggle_disable_player(False)

View File

@ -125,8 +125,8 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties):
"""
Adds buttons to the start of the header bar.
"""
self.load_optical = self.toolbar.add_toolbar_action('load_optical', icon=OPTICAL_ICON, text='Load optical disc',
tooltip='Load optical disc', triggers=self.on_load_optical)
self.load_optical = self.toolbar.add_toolbar_action('load_optical', icon=OPTICAL_ICON, text='Load CD/DVD',
tooltip='Load CD/DVD', triggers=self.on_load_optical)
if not VLC_AVAILABLE:
self.load_optical.setDisabled(True)

View File

@ -88,9 +88,9 @@ class TestMediaClipSelectorForm(TestCase, TestMixin):
"""
# GIVEN: Mocked methods.
with patch('openlp.plugins.media.forms.mediaclipselectorform.critical_error_message_box') as \
mocked_critical_error_message_box,\
patch('openlp.plugins.media.forms.mediaclipselectorform.os.path.exists') as mocked_os_path_exists,\
patch('PyQt4.QtGui.QDialog.exec_') as mocked_exec:
mocked_critical_error_message_box,\
patch('openlp.plugins.media.forms.mediaclipselectorform.os.path.exists') as mocked_os_path_exists,\
patch('PyQt4.QtGui.QDialog.exec_') as mocked_exec:
self.form.exec_()
# WHEN: The load button is clicked with no path set
@ -101,10 +101,10 @@ class TestMediaClipSelectorForm(TestCase, TestMixin):
# WHEN: The load button is clicked with a non-existing path
mocked_os_path_exists.return_value = False
self.form.media_path_combobox.insertItem (0, '/non-existing/test-path.test')
self.form.media_path_combobox.insertItem(0, '/non-existing/test-path.test')
self.form.media_path_combobox.setCurrentIndex(0)
QtTest.QTest.mouseClick(self.form.load_disc_pushbutton, QtCore.Qt.LeftButton)
# THEN: we should get an error
assert self.form.media_path_combobox.currentText() == '/non-existing/test-path.test',\
'The media path should be the given one.'
@ -114,10 +114,10 @@ class TestMediaClipSelectorForm(TestCase, TestMixin):
mocked_os_path_exists.return_value = True
self.form.vlc_media_player = MagicMock()
self.form.vlc_media_player.play.return_value = -1
self.form.media_path_combobox.insertItem (0, '/existing/test-path.test')
self.form.media_path_combobox.insertItem(0, '/existing/test-path.test')
self.form.media_path_combobox.setCurrentIndex(0)
QtTest.QTest.mouseClick(self.form.load_disc_pushbutton, QtCore.Qt.LeftButton)
# THEN: we should get an error
assert self.form.media_path_combobox.currentText() == '/existing/test-path.test',\
'The media path should be the given one.'
@ -136,17 +136,15 @@ class TestMediaClipSelectorForm(TestCase, TestMixin):
self.form.subtitle_tracks_combobox.itemData.return_value = None
self.form.title_combo_box.insertItem(0, 'Test Title 0')
self.form.title_combo_box.insertItem(1, 'Test Title 1')
# WHEN: There exists audio and subtitle tracks and the index is updated.
self.form.vlc_media_player.audio_get_track_description.return_value = [(-1, b'Disabled'),
(0, b'Audio Track 1')]
self.form.vlc_media_player.audio_get_track_description.return_value = [(-1, b'Disabled'),
(0, b'Audio Track 1')]
self.form.vlc_media_player.video_get_spu_description.return_value = [(-1, b'Disabled'),
(0, b'Subtitle Track 1')]
(0, b'Subtitle Track 1')]
self.form.title_combo_box.setCurrentIndex(1)
# THEN: The subtitle and audio track comboboxes should be updated and get signals and call itemData.
self.form.audio_tracks_combobox.itemData.assert_any_call(0)
self.form.audio_tracks_combobox.itemData.assert_any_call(1)
self.form.subtitle_tracks_combobox.itemData.assert_any_call(0)