FreeCAD
72 строки · 3.4 Кб
1# SPDX-License-Identifier: LGPL-2.1-or-later
2# ***************************************************************************
3# * *
4# * Copyright (c) 2022 FreeCAD Project Association *
5# * *
6# * This file is part of FreeCAD. *
7# * *
8# * FreeCAD is free software: you can redistribute it and/or modify it *
9# * under the terms of the GNU Lesser General Public License as *
10# * published by the Free Software Foundation, either version 2.1 of the *
11# * License, or (at your option) any later version. *
12# * *
13# * FreeCAD is distributed in the hope that it will be useful, but *
14# * WITHOUT ANY WARRANTY; without even the implied warranty of *
15# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16# * Lesser General Public License for more details. *
17# * *
18# * You should have received a copy of the GNU Lesser General Public *
19# * License along with FreeCAD. If not, see *
20# * <https://www.gnu.org/licenses/>. *
21# * *
22# ***************************************************************************
23
24""" Contains a class to handle editing a person (from a Metadata standpoint). """
25
26import os
27from typing import Tuple # Needed until Py 3.9, when tuple supports this directly
28
29from PySide.QtWidgets import QDialog
30
31import FreeCAD
32import FreeCADGui
33
34translate = FreeCAD.Qt.translate
35
36
37class PersonEditor:
38"""Create or edit a maintainer or author record."""
39
40def __init__(self):
41
42self.dialog = FreeCADGui.PySideUic.loadUi(
43os.path.join(os.path.dirname(__file__), "developer_mode_people.ui")
44)
45self.dialog.comboBox.clear()
46self.dialog.comboBox.addItem(
47translate("AddonsInstaller", "Maintainer"), userData="maintainer"
48)
49self.dialog.comboBox.addItem(translate("AddonsInstaller", "Author"), userData="author")
50
51def exec(self) -> Tuple[str, str, str]:
52"""Run the dialog, and return a tuple of the person's record type, their name, and their
53email address. Email may be None. If the others are None it's because the user cancelled
54the interaction."""
55result = self.dialog.exec()
56if result == QDialog.Accepted:
57return (
58self.dialog.comboBox.currentData(),
59self.dialog.nameLineEdit.text(),
60self.dialog.emailLineEdit.text(),
61)
62return "", "", ""
63
64def setup(self, person_type: str = "maintainer", name: str = "", email: str = "") -> None:
65"""Configure the dialog"""
66index = self.dialog.comboBox.findData(person_type)
67if index == -1:
68FreeCAD.Console.PrintWarning(f"Internal Error: unrecognized person type {person_type}")
69index = 0
70self.dialog.comboBox.setCurrentIndex(index)
71self.dialog.nameLineEdit.setText(name)
72self.dialog.emailLineEdit.setText(email)
73