openlp/openlp/core/ui/starttimeform.py

98 lines
4.9 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 #
# --------------------------------------------------------------------------- #
2013-12-24 08:56:50 +00:00
# Copyright (c) 2008-2014 Raoul Snyman #
# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
2012-11-11 21:16:14 +00:00
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
2012-10-21 13:16:22 +00:00
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
# --------------------------------------------------------------------------- #
# 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 PyQt4 import QtGui
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
2014-03-16 21:25:23 +00:00
class StartTimeForm(QtGui.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
"""
2013-08-31 18:17:38 +00:00
super(StartTimeForm, self).__init__(Registry().get('main_window'))
self.setupUi(self)
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)
2013-08-31 18:17:38 +00:00
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)
self.hour_finish_label.setText('%s%s' % (str(hour), UiStrings().Hours))
self.minute_finish_label.setText('%s%s' % (str(minutes), UiStrings().Minutes))
self.second_finish_label.setText('%s%s' % (str(seconds), UiStrings().Seconds))
2011-03-19 11:23:45 +00:00
return QtGui.QDialog.exec_(self)
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
2011-03-19 11:23:45 +00:00
return QtGui.QDialog.accept(self)
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