|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a prompt dialog for the Mercurial command server. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import pyqtSlot, Qt |
|
13 from PyQt5.QtGui import QTextCursor |
|
14 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QLineEdit |
|
15 |
|
16 from .Ui_HgClientPromptDialog import Ui_HgClientPromptDialog |
|
17 |
|
18 |
|
19 class HgClientPromptDialog(QDialog, Ui_HgClientPromptDialog): |
|
20 """ |
|
21 Class implementing a prompt dialog for the Mercurial command server. |
|
22 """ |
|
23 def __init__(self, size, message, parent=None): |
|
24 """ |
|
25 Constructor |
|
26 |
|
27 @param size maximum length of the requested input (integer) |
|
28 @param message message sent by the server (string) |
|
29 @param parent reference to the parent widget (QWidget) |
|
30 """ |
|
31 super(HgClientPromptDialog, self).__init__(parent) |
|
32 self.setupUi(self) |
|
33 |
|
34 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
|
35 |
|
36 self.inputEdit.setMaxLength(size) |
|
37 self.messageEdit.setPlainText(message) |
|
38 |
|
39 tc = self.messageEdit.textCursor() |
|
40 tc.movePosition(QTextCursor.End) |
|
41 self.messageEdit.setTextCursor(tc) |
|
42 self.messageEdit.ensureCursorVisible() |
|
43 |
|
44 self.inputEdit.setFocus(Qt.OtherFocusReason) |
|
45 |
|
46 @pyqtSlot(str) |
|
47 def on_inputEdit_textChanged(self, txt): |
|
48 """ |
|
49 Private slot to handle changes of the user input. |
|
50 |
|
51 @param txt text entered by the user (string) |
|
52 """ |
|
53 self.buttonBox.button(QDialogButtonBox.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.Password) |
|
64 else: |
|
65 self.inputEdit.setEchoMode(QLineEdit.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() |