openlp/openlp/core/ui/starttimeform.py

94 lines
4.7 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2012-12-29 15:25:29 +00:00
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2015-12-31 22:46:06 +00:00
# Copyright (c) 2008-2016 OpenLP Developers #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
2013-02-01 21:34:23 +00:00
"""
The actual start time form.
"""
from PyQt5 import QtCore, QtWidgets
2013-08-31 18:17:38 +00:00
from .starttimedialog import Ui_StartTimeDialog
2011-03-19 11:50:48 +00:00
2014-03-16 21:25:23 +00:00
from openlp.core.common import Registry, RegistryProperties, UiStrings, translate
from openlp.core.lib.ui import critical_error_message_box
2013-02-01 21:34:23 +00:00
2015-11-07 00:49:40 +00:00
class StartTimeForm(QtWidgets.QDialog, Ui_StartTimeDialog, RegistryProperties):
"""
2013-02-01 21:34:23 +00:00
The start time dialog
"""
2013-01-27 07:36:04 +00:00
def __init__(self):
2013-02-01 21:34:23 +00:00
"""
Constructor
"""
super(StartTimeForm, self).__init__(Registry().get('main_window'),
2016-01-09 16:26:14 +00:00
QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint)
self.setupUi(self)
2015-11-07 00:49:40 +00:00
def exec(self):
"""
Run the Dialog with correct heading.
"""
2013-08-31 18:17:38 +00:00
hour, minutes, seconds = self._time_split(self.item['service_item'].start_time)
2013-12-24 15:55:01 +00:00
self.hour_spin_box.setValue(hour)
self.minute_spin_box.setValue(minutes)
self.second_spin_box.setValue(seconds)
hours, minutes, seconds = self._time_split(self.item['service_item'].end_time)
if hours == 0 and minutes == 0 and seconds == 0:
hours, minutes, seconds = self._time_split(self.item['service_item'].media_length)
2013-12-24 15:55:01 +00:00
self.hour_finish_spin_box.setValue(hours)
self.minute_finish_spin_box.setValue(minutes)
self.second_finish_spin_box.setValue(seconds)
2016-05-20 16:22:06 +00:00
self.hour_finish_label.setText('{val:d}{text}'.format(val=hour, text=UiStrings().Hours))
self.minute_finish_label.setText('{val:d}{text}'.format(val=minutes, text=UiStrings().Minutes))
self.second_finish_label.setText('{val:d}{text}'.format(val=seconds, text=UiStrings().Seconds))
2015-11-07 00:49:40 +00:00
return QtWidgets.QDialog.exec(self)
2011-03-19 11:23:45 +00:00
def accept(self):
2013-02-01 21:34:23 +00:00
"""
When the dialog succeeds, this is run
"""
2013-12-24 15:55:01 +00:00
start = self.hour_spin_box.value() * 3600 + self.minute_spin_box.value() * 60 + self.second_spin_box.value()
end = self.hour_finish_spin_box.value() * 3600 + \
self.minute_finish_spin_box.value() * 60 + self.second_finish_spin_box.value()
2013-08-31 18:17:38 +00:00
if end > self.item['service_item'].media_length:
2013-12-24 15:55:01 +00:00
critical_error_message_box(title=translate('OpenLP.StartTime_form', 'Time Validation Error'),
2014-03-20 19:10:31 +00:00
message=translate('OpenLP.StartTime_form',
2013-12-24 15:55:01 +00:00
'Finish time is set after the end of the media item'))
2011-03-19 11:50:48 +00:00
return
elif start > end:
2013-12-24 15:55:01 +00:00
critical_error_message_box(title=translate('OpenLP.StartTime_form', 'Time Validation Error'),
2014-03-20 19:10:31 +00:00
message=translate('OpenLP.StartTime_form',
2013-12-24 15:55:01 +00:00
'Start time is after the finish time of the media item'))
2011-03-19 11:50:48 +00:00
return
2013-08-31 18:17:38 +00:00
self.item['service_item'].start_time = start
self.item['service_item'].end_time = end
2015-11-07 00:49:40 +00:00
return QtWidgets.QDialog.accept(self)
2011-03-19 11:23:45 +00:00
def _time_split(self, seconds):
2013-02-01 21:34:23 +00:00
"""
2014-03-16 21:25:23 +00:00
Split time up into hours minutes and seconds from seconds
2013-02-01 21:34:23 +00:00
"""
hours = seconds // 3600
2011-02-13 13:11:15 +00:00
seconds -= 3600 * hours
minutes = seconds // 60
2011-02-13 13:11:15 +00:00
seconds -= 60 * minutes
2014-03-20 19:10:31 +00:00
return hours, minutes, seconds