-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaddonmanager_devmode_person_editor.py
71 lines (60 loc) · 3.42 KB
/
addonmanager_devmode_person_editor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# SPDX-License-Identifier: LGPL-2.1-or-later
# ***************************************************************************
# * *
# * Copyright (c) 2022 FreeCAD Project Association *
# * *
# * This file is part of FreeCAD. *
# * *
# * FreeCAD 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 2.1 of the *
# * License, or (at your option) any later version. *
# * *
# * FreeCAD 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 FreeCAD. If not, see *
# * <https://www.gnu.org/licenses/>. *
# * *
# ***************************************************************************
"""Contains a class to handle editing a person (from a Metadata standpoint)."""
import os
from typing import Tuple # Needed until Py 3.9, when tuple supports this directly
from PySideWrapper import QtWidgets
import addonmanager_freecad_interface as fci
translate = fci.translate
class PersonEditor:
"""Create or edit a maintainer or author record."""
def __init__(self):
self.dialog = fci.loadUi(
os.path.join(os.path.dirname(__file__), "developer_mode_people.ui")
)
self.dialog.comboBox.clear()
self.dialog.comboBox.addItem(
translate("AddonsInstaller", "Maintainer"), userData="maintainer"
)
self.dialog.comboBox.addItem(translate("AddonsInstaller", "Author"), userData="author")
def exec(self) -> Tuple[str, str, str]:
"""Run the dialog, and return a tuple of the person's record type, their name, and their
email address. Email may be None. If the others are None it's because the user cancelled
the interaction."""
result = self.dialog.exec()
if result == QtWidgets.QDialog.Accepted:
return (
self.dialog.comboBox.currentData(),
self.dialog.nameLineEdit.text(),
self.dialog.emailLineEdit.text(),
)
return "", "", ""
def setup(self, person_type: str = "maintainer", name: str = "", email: str = "") -> None:
"""Configure the dialog"""
index = self.dialog.comboBox.findData(person_type)
if index == -1:
fci.Console.PrintWarning(f"Internal Error: unrecognized person type {person_type}")
index = 0
self.dialog.comboBox.setCurrentIndex(index)
self.dialog.nameLineEdit.setText(name)
self.dialog.emailLineEdit.setText(email)