######################################################################################################################
# Copyright (C) 2017-2021 Spine project consortium
# This file is part of Spine Toolbox.
# Spine Toolbox is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser 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 Lesser General
# Public License for more details. You should have received a copy of the GNU Lesser General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
######################################################################################################################
"""
Classes for custom QDialogs to add edit and remove database items.
:author: M. Marin (KTH)
:date: 13.5.2018
"""
from PySide2.QtWidgets import QDialog, QVBoxLayout, QPlainTextEdit, QDialogButtonBox, QAction, QApplication
from PySide2.QtCore import Slot, Qt
[docs]class CommitDialog(QDialog):
"""A dialog to query user's preferences for new commit.
"""
def __init__(self, parent, *db_names):
"""Initialize class.
Args:
parent (QWidget): the parent widget
db_names (str): database names
"""
super().__init__(parent)
self.setWindowModality(Qt.ApplicationModal)
self.commit_msg = None
self.setWindowTitle('Commit changes to {}'.format(",".join(db_names)))
form = QVBoxLayout(self)
form.setContentsMargins(4, 4, 4, 4)
self.action_accept = QAction(self)
self.action_accept.setShortcut(QApplication.translate("Dialog", "Ctrl+Return", None, -1))
self.action_accept.triggered.connect(self.accept)
self.action_accept.setEnabled(False)
self.commit_msg_edit = QPlainTextEdit(self)
self.commit_msg_edit.setPlaceholderText('Commit message \t(press Ctrl+Enter to commit)')
self.commit_msg_edit.addAction(self.action_accept)
button_box = QDialogButtonBox()
button_box.addButton(QDialogButtonBox.Cancel)
self.commit_button = button_box.addButton('Commit', QDialogButtonBox.AcceptRole)
button_box.accepted.connect(self.accept)
button_box.rejected.connect(self.reject)
form.addWidget(self.commit_msg_edit)
form.addWidget(button_box)
self.setAttribute(Qt.WA_DeleteOnClose)
self.commit_msg_edit.textChanged.connect(self.receive_text_changed)
self.receive_text_changed()
@Slot()
[docs] def receive_text_changed(self):
"""Called when text changes in the commit msg text edit.
Enable/disable commit button accordingly."""
self.commit_msg = self.commit_msg_edit.toPlainText()
cond = self.commit_msg.strip() != ""
self.commit_button.setEnabled(cond)
self.action_accept.setEnabled(cond)