|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2014 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter the data of a remote repository. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import pyqtSlot, QUrl |
|
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
|
14 |
|
15 from .Ui_GitAddRemoteDialog import Ui_GitAddRemoteDialog |
|
16 |
|
17 |
|
18 class GitAddRemoteDialog(QDialog, Ui_GitAddRemoteDialog): |
|
19 """ |
|
20 Class implementing a dialog to enter the data of a remote repository. |
|
21 """ |
|
22 def __init__(self, parent=None): |
|
23 """ |
|
24 Constructor |
|
25 |
|
26 @param parent reference to the parent widget |
|
27 @type QWidget |
|
28 """ |
|
29 super(GitAddRemoteDialog, self).__init__(parent) |
|
30 self.setupUi(self) |
|
31 |
|
32 self.__updateOK() |
|
33 |
|
34 msh = self.minimumSizeHint() |
|
35 self.resize(max(self.width(), msh.width()), msh.height()) |
|
36 |
|
37 def __updateOK(self): |
|
38 """ |
|
39 Private method to update the status of the OK button. |
|
40 """ |
|
41 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
|
42 self.nameEdit.text() != "" and |
|
43 self.urlEdit.text() != "") |
|
44 |
|
45 @pyqtSlot(str) |
|
46 def on_nameEdit_textChanged(self, txt): |
|
47 """ |
|
48 Private slot handling changes of the entered name. |
|
49 |
|
50 @param txt current text |
|
51 @type str |
|
52 """ |
|
53 self.__updateOK() |
|
54 |
|
55 @pyqtSlot(str) |
|
56 def on_urlEdit_textChanged(self, txt): |
|
57 """ |
|
58 Private slot handling changes of the entered URL. |
|
59 |
|
60 @param txt current text |
|
61 @type str |
|
62 """ |
|
63 self.__updateOK() |
|
64 |
|
65 @pyqtSlot(str) |
|
66 def on_userEdit_textChanged(self, txt): |
|
67 """ |
|
68 Private slot handling changes of the entered user name. |
|
69 |
|
70 @param txt current text |
|
71 @type str |
|
72 """ |
|
73 self.passwordEdit.setEnabled(bool(txt)) |
|
74 |
|
75 def getData(self): |
|
76 """ |
|
77 Public method to get the entered data. |
|
78 |
|
79 @return tuple with name and URL of the remote repository |
|
80 @rtype tuple of (str, str) |
|
81 """ |
|
82 url = QUrl.fromUserInput(self.urlEdit.text()) |
|
83 userName = self.userEdit.text() |
|
84 if userName: |
|
85 url.setUserName(userName) |
|
86 password = self.passwordEdit.text() |
|
87 if password: |
|
88 url.setPassword(password) |
|
89 |
|
90 return self.nameEdit.text(), url.toString() |