2009-01-01 10:03:09 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2009-01-02 20:20:33 +00:00
|
|
|
|
2019-04-13 13:00:22 +00:00
|
|
|
##########################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# ---------------------------------------------------------------------- #
|
2020-12-30 21:42:49 +00:00
|
|
|
# Copyright (c) 2008-2021 OpenLP Developers #
|
2019-04-13 13:00:22 +00:00
|
|
|
# ---------------------------------------------------------------------- #
|
|
|
|
# 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, either version 3 of the License, or #
|
|
|
|
# (at your option) any later version. #
|
|
|
|
# #
|
|
|
|
# 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, see <https://www.gnu.org/licenses/>. #
|
|
|
|
##########################################################################
|
2009-01-02 20:20:33 +00:00
|
|
|
|
2015-12-30 15:03:35 +00:00
|
|
|
from PyQt5 import QtCore, QtWidgets
|
2009-10-24 16:40:36 +00:00
|
|
|
|
2017-10-07 07:05:07 +00:00
|
|
|
from openlp.core.common.i18n import translate
|
2011-02-02 23:12:31 +00:00
|
|
|
from openlp.core.lib.ui import critical_error_message_box
|
2010-06-06 10:07:48 +00:00
|
|
|
from openlp.plugins.songs.forms.authorsdialog import Ui_AuthorsDialog
|
|
|
|
|
2013-02-10 10:39:28 +00:00
|
|
|
|
2015-11-07 00:49:40 +00:00
|
|
|
class AuthorsForm(QtWidgets.QDialog, Ui_AuthorsDialog):
|
2009-01-01 10:03:09 +00:00
|
|
|
"""
|
2009-01-10 08:33:31 +00:00
|
|
|
Class to control the Maintenance of Authors Dialog
|
2009-01-01 10:03:09 +00:00
|
|
|
"""
|
2009-07-24 20:40:34 +00:00
|
|
|
def __init__(self, parent=None):
|
2009-01-01 10:03:09 +00:00
|
|
|
"""
|
2009-01-10 08:33:31 +00:00
|
|
|
Set up the screen and common data
|
2009-01-01 10:03:09 +00:00
|
|
|
"""
|
2017-06-04 12:14:23 +00:00
|
|
|
super(AuthorsForm, self).__init__(parent, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint |
|
|
|
|
QtCore.Qt.WindowCloseButtonHint)
|
2018-09-12 05:43:27 +00:00
|
|
|
self.setup_ui(self)
|
2013-02-10 10:39:28 +00:00
|
|
|
self.auto_display_name = False
|
|
|
|
self.first_name_edit.textEdited.connect(self.on_first_name_edited)
|
|
|
|
self.last_name_edit.textEdited.connect(self.on_last_name_edited)
|
2009-02-19 22:25:58 +00:00
|
|
|
|
2015-11-07 00:49:40 +00:00
|
|
|
def exec(self, clear=True):
|
2013-02-10 10:39:28 +00:00
|
|
|
"""
|
|
|
|
Execute the dialog.
|
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param clear: Clear the form fields before displaying the dialog.
|
2013-02-10 10:39:28 +00:00
|
|
|
"""
|
2009-07-24 20:40:34 +00:00
|
|
|
if clear:
|
2013-02-10 10:39:28 +00:00
|
|
|
self.first_name_edit.clear()
|
|
|
|
self.last_name_edit.clear()
|
|
|
|
self.display_edit.clear()
|
|
|
|
self.first_name_edit.setFocus()
|
2015-11-07 00:49:40 +00:00
|
|
|
return QtWidgets.QDialog.exec(self)
|
2009-06-03 16:14:56 +00:00
|
|
|
|
2013-02-10 10:39:28 +00:00
|
|
|
def on_first_name_edited(self, display_name):
|
|
|
|
"""
|
|
|
|
Slot for when the first name is edited.
|
|
|
|
|
|
|
|
When the first name is edited and the setting to automatically create a display name is True, then try to create
|
|
|
|
a display name from the first and last names.
|
2009-01-10 08:33:31 +00:00
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param display_name: The text from the first_name_edit widget.
|
2013-02-10 10:39:28 +00:00
|
|
|
"""
|
|
|
|
if not self.auto_display_name:
|
2009-07-24 20:40:34 +00:00
|
|
|
return
|
2013-02-10 10:39:28 +00:00
|
|
|
if self.last_name_edit.text():
|
2013-08-31 18:17:38 +00:00
|
|
|
display_name = display_name + ' ' + self.last_name_edit.text()
|
2013-02-10 10:39:28 +00:00
|
|
|
self.display_edit.setText(display_name)
|
2009-02-19 22:25:58 +00:00
|
|
|
|
2013-02-10 10:39:28 +00:00
|
|
|
def on_last_name_edited(self, display_name):
|
|
|
|
"""
|
|
|
|
Slot for when the last name is edited.
|
2009-02-19 22:25:58 +00:00
|
|
|
|
2013-02-10 10:39:28 +00:00
|
|
|
When the last name is edited and the setting to automatically create a display name is True, then try to create
|
|
|
|
a display name from the first and last names.
|
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param display_name: The text from the last_name_edit widget.
|
2013-02-10 10:39:28 +00:00
|
|
|
"""
|
|
|
|
if not self.auto_display_name:
|
|
|
|
return
|
|
|
|
if self.first_name_edit.text():
|
2013-08-31 18:17:38 +00:00
|
|
|
display_name = self.first_name_edit.text() + ' ' + display_name
|
2013-02-10 10:39:28 +00:00
|
|
|
self.display_edit.setText(display_name)
|
2009-02-19 22:25:58 +00:00
|
|
|
|
2009-07-25 22:07:59 +00:00
|
|
|
def accept(self):
|
2013-02-10 10:39:28 +00:00
|
|
|
"""
|
|
|
|
Override the QDialog's accept() method to do some validation before the dialog can be closed.
|
|
|
|
"""
|
|
|
|
if not self.first_name_edit.text():
|
2011-02-02 23:12:31 +00:00
|
|
|
critical_error_message_box(
|
2013-01-05 22:17:30 +00:00
|
|
|
message=translate('SongsPlugin.AuthorsForm', 'You need to type in the first name of the author.'))
|
2013-02-10 10:39:28 +00:00
|
|
|
self.first_name_edit.setFocus()
|
2009-07-25 22:07:59 +00:00
|
|
|
return False
|
2013-02-10 10:39:28 +00:00
|
|
|
elif not self.last_name_edit.text():
|
2011-02-02 23:12:31 +00:00
|
|
|
critical_error_message_box(
|
2013-01-05 22:17:30 +00:00
|
|
|
message=translate('SongsPlugin.AuthorsForm', 'You need to type in the last name of the author.'))
|
2013-02-10 10:39:28 +00:00
|
|
|
self.last_name_edit.setFocus()
|
2009-07-25 22:07:59 +00:00
|
|
|
return False
|
2013-02-10 10:39:28 +00:00
|
|
|
elif not self.display_edit.text():
|
2011-02-02 23:12:31 +00:00
|
|
|
if critical_error_message_box(
|
2011-01-15 19:24:50 +00:00
|
|
|
message=translate('SongsPlugin.AuthorsForm',
|
2014-03-04 18:49:30 +00:00
|
|
|
'You have not set a display name for the author, combine the first and last names?'),
|
2015-11-07 00:49:40 +00:00
|
|
|
parent=self, question=True) == QtWidgets.QMessageBox.Yes:
|
2013-08-31 18:17:38 +00:00
|
|
|
self.display_edit.setText(self.first_name_edit.text() + ' ' + self.last_name_edit.text())
|
2015-11-07 00:49:40 +00:00
|
|
|
return QtWidgets.QDialog.accept(self)
|
2009-07-22 06:14:34 +00:00
|
|
|
else:
|
2013-02-10 10:39:28 +00:00
|
|
|
self.display_edit.setFocus()
|
2009-07-26 10:02:18 +00:00
|
|
|
return False
|
2009-01-12 19:31:29 +00:00
|
|
|
else:
|
2015-11-07 00:49:40 +00:00
|
|
|
return QtWidgets.QDialog.accept(self)
|
2013-02-10 20:04:47 +00:00
|
|
|
|
|
|
|
def _get_first_name(self):
|
|
|
|
"""
|
|
|
|
Get the value of the first name from the UI widget.
|
|
|
|
"""
|
|
|
|
return self.first_name_edit.text()
|
|
|
|
|
|
|
|
def _set_first_name(self, value):
|
|
|
|
"""
|
|
|
|
Set the value of the first name in the UI widget.
|
|
|
|
"""
|
|
|
|
self.first_name_edit.setText(value)
|
|
|
|
|
|
|
|
first_name = property(_get_first_name, _set_first_name)
|
|
|
|
|
|
|
|
def _get_last_name(self):
|
|
|
|
"""
|
|
|
|
Get the value of the last name from the UI widget.
|
|
|
|
"""
|
|
|
|
return self.last_name_edit.text()
|
|
|
|
|
|
|
|
def _set_last_name(self, value):
|
|
|
|
"""
|
|
|
|
Set the value of the last name in the UI widget.
|
|
|
|
"""
|
|
|
|
self.last_name_edit.setText(value)
|
|
|
|
|
|
|
|
last_name = property(_get_last_name, _set_last_name)
|
|
|
|
|
|
|
|
def _get_display_name(self):
|
|
|
|
return self.display_edit.text()
|
|
|
|
|
|
|
|
def _set_display_name(self, value):
|
|
|
|
self.display_edit.setText(value)
|
|
|
|
|
|
|
|
display_name = property(_get_display_name, _set_display_name)
|