1# -*- coding: utf-8 -*- 2 3# Copyright (c) 2018 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> 4# 5 6""" 7Module implementing a dialog to change the URL of a remote git repository. 8""" 9 10from PyQt5.QtCore import pyqtSlot, Qt, QUrl 11from PyQt5.QtWidgets import QDialog, QDialogButtonBox 12 13from .Ui_GitChangeRemoteUrlDialog import Ui_GitChangeRemoteUrlDialog 14 15 16class GitChangeRemoteUrlDialog(QDialog, Ui_GitChangeRemoteUrlDialog): 17 """ 18 Class implementing a dialog to change the URL of a remote git repository. 19 """ 20 def __init__(self, remoteName, remoteUrl, parent=None): 21 """ 22 Constructor 23 24 @param remoteName name of the remote repository 25 @type str 26 @param remoteUrl URL of the remote repository 27 @type str 28 @param parent reference to the parent widget 29 @type QWidget 30 """ 31 super().__init__(parent) 32 self.setupUi(self) 33 34 url = QUrl(remoteUrl) 35 self.__userInfo = url.userInfo() 36 37 self.nameEdit.setText(remoteName) 38 self.urlEdit.setText( 39 url.toString(QUrl.UrlFormattingOption.RemoveUserInfo)) 40 41 self.__updateOK() 42 43 self.newUrlEdit.setFocus(Qt.FocusReason.OtherFocusReason) 44 45 msh = self.minimumSizeHint() 46 self.resize(max(self.width(), msh.width()), msh.height()) 47 48 def __updateOK(self): 49 """ 50 Private method to update the status of the OK button. 51 """ 52 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( 53 bool(self.newUrlEdit.text()) 54 ) 55 56 @pyqtSlot(str) 57 def on_newUrlEdit_textChanged(self, txt): 58 """ 59 Private slot handling changes of the entered URL. 60 61 @param txt current text 62 @type str 63 """ 64 self.__updateOK() 65 66 def getData(self): 67 """ 68 Public method to get the entered data. 69 70 @return tuple with name and new URL of the remote repository 71 @rtype tuple of (str, str) 72 """ 73 url = QUrl.fromUserInput(self.newUrlEdit.text()) 74 if self.__userInfo: 75 url.setUserInfo(self.__userInfo) 76 77 return self.nameEdit.text(), url.toString() 78