|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a prompt dialog for the Mercurial command server. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtCore import pyqtSlot, Qt |
|
11 from PyQt6.QtGui import QTextCursor |
|
12 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QLineEdit |
|
13 |
|
14 from .Ui_HgClientPromptDialog import Ui_HgClientPromptDialog |
|
15 |
|
16 |
|
17 class HgClientPromptDialog(QDialog, Ui_HgClientPromptDialog): |
|
18 """ |
|
19 Class implementing a prompt dialog for the Mercurial command server. |
|
20 """ |
|
21 def __init__(self, size, message, parent=None): |
|
22 """ |
|
23 Constructor |
|
24 |
|
25 @param size maximum length of the requested input (integer) |
|
26 @param message message sent by the server (string) |
|
27 @param parent reference to the parent widget (QWidget) |
|
28 """ |
|
29 super().__init__(parent) |
|
30 self.setupUi(self) |
|
31 |
|
32 self.buttonBox.button( |
|
33 QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
|
34 |
|
35 self.inputEdit.setMaxLength(size) |
|
36 self.messageEdit.setPlainText(message) |
|
37 |
|
38 tc = self.messageEdit.textCursor() |
|
39 tc.movePosition(QTextCursor.MoveOperation.End) |
|
40 self.messageEdit.setTextCursor(tc) |
|
41 self.messageEdit.ensureCursorVisible() |
|
42 |
|
43 self.inputEdit.setFocus(Qt.FocusReason.OtherFocusReason) |
|
44 |
|
45 @pyqtSlot(str) |
|
46 def on_inputEdit_textChanged(self, txt): |
|
47 """ |
|
48 Private slot to handle changes of the user input. |
|
49 |
|
50 @param txt text entered by the user (string) |
|
51 """ |
|
52 self.buttonBox.button( |
|
53 QDialogButtonBox.StandardButton.Ok).setEnabled(bool(txt)) |
|
54 |
|
55 @pyqtSlot(bool) |
|
56 def on_passwordCheckBox_toggled(self, isOn): |
|
57 """ |
|
58 Private slot to handle the password checkbox toggled. |
|
59 |
|
60 @param isOn flag indicating the status of the check box (boolean) |
|
61 """ |
|
62 if isOn: |
|
63 self.inputEdit.setEchoMode(QLineEdit.EchoMode.Password) |
|
64 else: |
|
65 self.inputEdit.setEchoMode(QLineEdit.EchoMode.Normal) |
|
66 |
|
67 def getInput(self): |
|
68 """ |
|
69 Public method to get the user input. |
|
70 |
|
71 @return user input (string) |
|
72 """ |
|
73 return self.inputEdit.text() |
|
74 |
|
75 def isPassword(self): |
|
76 """ |
|
77 Public method to check, if the input was a password. |
|
78 |
|
79 @return flag indicating a password |
|
80 @rtype bool |
|
81 """ |
|
82 return self.passwordCheckBox.isChecked() |