|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter the data for a project URL. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtCore import pyqtSlot |
|
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox |
|
12 |
|
13 from .Ui_AddProjectUrlDialog import Ui_AddProjectUrlDialog |
|
14 |
|
15 |
|
16 class AddProjectUrlDialog(QDialog, Ui_AddProjectUrlDialog): |
|
17 """ |
|
18 Class implementing a dialog to enter the data for a project URL. |
|
19 """ |
|
20 def __init__(self, name="", url="", parent=None): |
|
21 """ |
|
22 Constructor |
|
23 |
|
24 @param name name of the project URL (defaults to "") |
|
25 @type str (optional) |
|
26 @param url address of the project URL (defaults to "") |
|
27 @type str (optional) |
|
28 @param parent reference to the parent widget (defaults to None) |
|
29 @type QWidget (optional) |
|
30 """ |
|
31 super().__init__(parent) |
|
32 self.setupUi(self) |
|
33 |
|
34 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
|
35 |
|
36 self.nameComboBox.lineEdit().setClearButtonEnabled(True) |
|
37 self.nameComboBox.addItems([ |
|
38 "", |
|
39 "Bug Tracker", |
|
40 "Change Log", |
|
41 "Documentation", |
|
42 "Donation", |
|
43 "Download", |
|
44 "Funding", |
|
45 "Homepage", |
|
46 "Issues Tracker", |
|
47 "News", |
|
48 "Release Notes", |
|
49 ]) |
|
50 |
|
51 self.nameComboBox.editTextChanged.connect(self.__updateOK) |
|
52 self.urlEdit.textChanged.connect(self.__updateOK) |
|
53 |
|
54 self.nameComboBox.setEditText(name) |
|
55 self.urlEdit.setText(url) |
|
56 |
|
57 msh = self.minimumSizeHint() |
|
58 self.resize(max(self.width(), msh.width()), msh.height()) |
|
59 |
|
60 @pyqtSlot() |
|
61 def __updateOK(self): |
|
62 """ |
|
63 Private slot to update the enabled state of the OK button. |
|
64 """ |
|
65 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( |
|
66 bool(self.nameComboBox.currentText()) and |
|
67 bool(self.urlEdit.text()) and |
|
68 self.urlEdit.text().startswith(("http://", "https://")) |
|
69 ) |
|
70 |
|
71 def getUrl(self): |
|
72 """ |
|
73 Public method to get the data for the project URL. |
|
74 |
|
75 @return tuple containing the name and address of the project URL |
|
76 @rtype tuple of (str, str) |
|
77 """ |
|
78 return ( |
|
79 self.nameComboBox.currentText(), |
|
80 self.urlEdit.text(), |
|
81 ) |