Add title/text to questions
This commit is contained in:
parent
e3581a50ca
commit
523369882a
@ -207,10 +207,11 @@ class NetworkManager(QNetworkAccessManager):
|
|||||||
self.setCache(cache)
|
self.setCache(cache)
|
||||||
cache.setParent(app)
|
cache.setParent(app)
|
||||||
|
|
||||||
def _ask(self, text, mode, owner=None):
|
def _ask(self, title, text, mode, owner=None):
|
||||||
"""Ask a blocking question in the statusbar.
|
"""Ask a blocking question in the statusbar.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
title: The title to display to the user.
|
||||||
text: The text to display to the user.
|
text: The text to display to the user.
|
||||||
mode: A PromptMode.
|
mode: A PromptMode.
|
||||||
owner: An object which will abort the question if destroyed, or
|
owner: An object which will abort the question if destroyed, or
|
||||||
@ -220,6 +221,7 @@ class NetworkManager(QNetworkAccessManager):
|
|||||||
The answer the user gave or None if the prompt was cancelled.
|
The answer the user gave or None if the prompt was cancelled.
|
||||||
"""
|
"""
|
||||||
q = usertypes.Question()
|
q = usertypes.Question()
|
||||||
|
q.title = title
|
||||||
q.text = text
|
q.text = text
|
||||||
q.mode = mode
|
q.mode = mode
|
||||||
self.shutting_down.connect(q.abort)
|
self.shutting_down.connect(q.abort)
|
||||||
@ -284,7 +286,7 @@ class NetworkManager(QNetworkAccessManager):
|
|||||||
|
|
||||||
if ssl_strict == 'ask':
|
if ssl_strict == 'ask':
|
||||||
err_string = '\n'.join('- ' + err.errorString() for err in errors)
|
err_string = '\n'.join('- ' + err.errorString() for err in errors)
|
||||||
answer = self._ask('SSL errors - continue?\n{}'.format(err_string),
|
answer = self._ask('SSL errors - continue?', err_string,
|
||||||
mode=usertypes.PromptMode.yesno, owner=reply)
|
mode=usertypes.PromptMode.yesno, owner=reply)
|
||||||
log.webview.debug("Asked for SSL errors, answer {}".format(answer))
|
log.webview.debug("Asked for SSL errors, answer {}".format(answer))
|
||||||
if answer:
|
if answer:
|
||||||
@ -343,7 +345,8 @@ class NetworkManager(QNetworkAccessManager):
|
|||||||
|
|
||||||
if user is None:
|
if user is None:
|
||||||
# netrc check failed
|
# netrc check failed
|
||||||
answer = self._ask("Username ({}):".format(authenticator.realm()),
|
answer = self._ask("Authentication required",
|
||||||
|
authenticator.realm(),
|
||||||
mode=usertypes.PromptMode.user_pwd,
|
mode=usertypes.PromptMode.user_pwd,
|
||||||
owner=reply)
|
owner=reply)
|
||||||
if answer is not None:
|
if answer is not None:
|
||||||
@ -362,7 +365,7 @@ class NetworkManager(QNetworkAccessManager):
|
|||||||
authenticator.setPassword(password)
|
authenticator.setPassword(password)
|
||||||
else:
|
else:
|
||||||
answer = self._ask(
|
answer = self._ask(
|
||||||
"Proxy username ({}):".format(authenticator.realm()),
|
"Proxy authentication required", authenticator.realm(),
|
||||||
mode=usertypes.PromptMode.user_pwd)
|
mode=usertypes.PromptMode.user_pwd)
|
||||||
if answer is not None:
|
if answer is not None:
|
||||||
authenticator.setUser(answer.user)
|
authenticator.setUser(answer.user)
|
||||||
|
@ -98,8 +98,8 @@ class BrowserPage(QWebPage):
|
|||||||
if (self._is_shutting_down or
|
if (self._is_shutting_down or
|
||||||
config.get('content', 'ignore-javascript-prompt')):
|
config.get('content', 'ignore-javascript-prompt')):
|
||||||
return (False, "")
|
return (False, "")
|
||||||
answer = self._ask("js: {}".format(msg), usertypes.PromptMode.text,
|
answer = self._ask('Javascript prompt', msg,
|
||||||
default)
|
usertypes.PromptMode.text, default)
|
||||||
if answer is None:
|
if answer is None:
|
||||||
return (False, "")
|
return (False, "")
|
||||||
else:
|
else:
|
||||||
@ -196,10 +196,11 @@ class BrowserPage(QWebPage):
|
|||||||
suggested_file)
|
suggested_file)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _ask(self, text, mode, default=None):
|
def _ask(self, title, text, mode, default=None):
|
||||||
"""Ask a blocking question in the statusbar.
|
"""Ask a blocking question in the statusbar.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
title: The title to display.
|
||||||
text: The text to display to the user.
|
text: The text to display to the user.
|
||||||
mode: A PromptMode.
|
mode: A PromptMode.
|
||||||
default: The default value to display.
|
default: The default value to display.
|
||||||
@ -208,6 +209,7 @@ class BrowserPage(QWebPage):
|
|||||||
The answer the user gave or None if the prompt was cancelled.
|
The answer the user gave or None if the prompt was cancelled.
|
||||||
"""
|
"""
|
||||||
q = usertypes.Question()
|
q = usertypes.Question()
|
||||||
|
q.title = title
|
||||||
q.text = text
|
q.text = text
|
||||||
q.mode = mode
|
q.mode = mode
|
||||||
q.default = default
|
q.default = default
|
||||||
@ -478,7 +480,7 @@ class BrowserPage(QWebPage):
|
|||||||
if (self._is_shutting_down or
|
if (self._is_shutting_down or
|
||||||
config.get('content', 'ignore-javascript-alert')):
|
config.get('content', 'ignore-javascript-alert')):
|
||||||
return
|
return
|
||||||
self._ask("[js alert] {}".format(msg), usertypes.PromptMode.alert)
|
self._ask('Javascript alert', msg, usertypes.PromptMode.alert)
|
||||||
|
|
||||||
def javaScriptConfirm(self, frame, msg):
|
def javaScriptConfirm(self, frame, msg):
|
||||||
"""Override javaScriptConfirm to use the statusbar."""
|
"""Override javaScriptConfirm to use the statusbar."""
|
||||||
@ -488,8 +490,7 @@ class BrowserPage(QWebPage):
|
|||||||
|
|
||||||
if self._is_shutting_down:
|
if self._is_shutting_down:
|
||||||
return False
|
return False
|
||||||
ans = self._ask("[js confirm] {}".format(msg),
|
ans = self._ask('Javascript confirm', msg, usertypes.PromptMode.yesno)
|
||||||
usertypes.PromptMode.yesno)
|
|
||||||
return bool(ans)
|
return bool(ans)
|
||||||
|
|
||||||
def javaScriptConsoleMessage(self, msg, line, source):
|
def javaScriptConsoleMessage(self, msg, line, source):
|
||||||
|
@ -105,19 +105,18 @@ class PromptContainer(QWidget):
|
|||||||
|
|
||||||
def __init__(self, win_id, parent=None):
|
def __init__(self, win_id, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.setObjectName('Prompt')
|
|
||||||
self.setAttribute(Qt.WA_StyledBackground, True)
|
|
||||||
self._layout = QVBoxLayout(self)
|
self._layout = QVBoxLayout(self)
|
||||||
self._layout.setContentsMargins(10, 10, 10, 10)
|
self._layout.setContentsMargins(10, 10, 10, 10)
|
||||||
self._prompt = None
|
self._prompt = None
|
||||||
style.set_register_stylesheet(self)
|
|
||||||
|
|
||||||
# FIXME review this
|
|
||||||
self._shutting_down = False
|
self._shutting_down = False
|
||||||
self._loops = []
|
self._loops = []
|
||||||
self._queue = collections.deque()
|
self._queue = collections.deque()
|
||||||
self._win_id = win_id
|
self._win_id = win_id
|
||||||
|
|
||||||
|
self.setObjectName('Prompt')
|
||||||
|
self.setAttribute(Qt.WA_StyledBackground, True)
|
||||||
|
style.set_register_stylesheet(self)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return utils.get_repr(self, loops=len(self._loops),
|
return utils.get_repr(self, loops=len(self._loops),
|
||||||
queue=len(self._queue), prompt=self._prompt)
|
queue=len(self._queue), prompt=self._prompt)
|
||||||
@ -337,15 +336,25 @@ class _BasePrompt(QWidget):
|
|||||||
def __init__(self, question, parent=None):
|
def __init__(self, question, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.question = question
|
self.question = question
|
||||||
self._layout = QGridLayout(self)
|
self._vbox = QVBoxLayout(self)
|
||||||
self._layout.setVerticalSpacing(15)
|
self._vbox.setSpacing(15)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return utils.get_repr(self, question=self.question, constructor=True)
|
return utils.get_repr(self, question=self.question, constructor=True)
|
||||||
|
|
||||||
def _init_title(self, title, *, span=1):
|
def _init_title(self, question):
|
||||||
label = QLabel('<b>{}</b>'.format(title), self)
|
if question.title is None:
|
||||||
self._layout.addWidget(label, 0, 0, 1, span)
|
title = question.text
|
||||||
|
text = None
|
||||||
|
else:
|
||||||
|
title = question.title
|
||||||
|
text = question.text
|
||||||
|
|
||||||
|
title_label = QLabel('<b>{}</b>'.format(title), self)
|
||||||
|
self._vbox.addWidget(title_label)
|
||||||
|
if text is not None:
|
||||||
|
text_label = QLabel(text)
|
||||||
|
self._vbox.addWidget(text_label)
|
||||||
|
|
||||||
def accept(self, value=None):
|
def accept(self, value=None):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
@ -357,10 +366,10 @@ class _BasePrompt(QWidget):
|
|||||||
class LineEditPrompt(_BasePrompt):
|
class LineEditPrompt(_BasePrompt):
|
||||||
|
|
||||||
def __init__(self, question, parent=None):
|
def __init__(self, question, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(question, parent)
|
||||||
self._lineedit = QLineEdit(self)
|
self._lineedit = QLineEdit(self)
|
||||||
self._layout.addWidget(self._lineedit, 1, 0)
|
self._init_title(question)
|
||||||
self._init_title(question.text)
|
self._vbox.addWidget(self._lineedit)
|
||||||
if question.default:
|
if question.default:
|
||||||
self._lineedit.setText(question.default)
|
self._lineedit.setText(question.default)
|
||||||
self.setFocusProxy(self._lineedit)
|
self.setFocusProxy(self._lineedit)
|
||||||
@ -402,25 +411,23 @@ class AuthenticationPrompt(_BasePrompt):
|
|||||||
|
|
||||||
def __init__(self, question, parent=None):
|
def __init__(self, question, parent=None):
|
||||||
super().__init__(question, parent)
|
super().__init__(question, parent)
|
||||||
self._init_title(question.text, span=2)
|
self._init_title(question)
|
||||||
|
|
||||||
user_label = QLabel("Username:", self)
|
user_label = QLabel("Username:", self)
|
||||||
self._user_lineedit = QLineEdit(self)
|
self._user_lineedit = QLineEdit(self)
|
||||||
|
|
||||||
password_label = QLabel("Password:", self)
|
password_label = QLabel("Password:", self)
|
||||||
self._password_lineedit = QLineEdit(self)
|
self._password_lineedit = QLineEdit(self)
|
||||||
self._password_lineedit.setEchoMode(QLineEdit.Password)
|
self._password_lineedit.setEchoMode(QLineEdit.Password)
|
||||||
self._layout.addWidget(user_label, 1, 0)
|
|
||||||
self._layout.addWidget(self._user_lineedit, 1, 1)
|
grid = QGridLayout()
|
||||||
self._layout.addWidget(password_label, 2, 0)
|
grid.addWidget(user_label, 1, 0)
|
||||||
self._layout.addWidget(self._password_lineedit, 2, 1)
|
grid.addWidget(self._user_lineedit, 1, 1)
|
||||||
|
grid.addWidget(password_label, 2, 0)
|
||||||
|
grid.addWidget(self._password_lineedit, 2, 1)
|
||||||
|
self._vbox.addLayout(grid)
|
||||||
|
|
||||||
assert not question.default, question.default
|
assert not question.default, question.default
|
||||||
|
|
||||||
spacer = QSpacerItem(0, 10)
|
|
||||||
self._layout.addItem(spacer, 3, 0)
|
|
||||||
|
|
||||||
help_1 = QLabel("<b>Accept:</b> Enter")
|
|
||||||
help_2 = QLabel("<b>Abort:</b> Escape")
|
|
||||||
self._layout.addWidget(help_1, 4, 0)
|
|
||||||
self._layout.addWidget(help_2, 5, 0)
|
|
||||||
self.setFocusProxy(self._user_lineedit)
|
self.setFocusProxy(self._user_lineedit)
|
||||||
|
|
||||||
def accept(self, value=None):
|
def accept(self, value=None):
|
||||||
@ -449,7 +456,7 @@ class YesNoPrompt(_BasePrompt):
|
|||||||
|
|
||||||
def __init__(self, question, parent=None):
|
def __init__(self, question, parent=None):
|
||||||
super().__init__(question, parent)
|
super().__init__(question, parent)
|
||||||
self._init_title(question.text)
|
self._init_title(question)
|
||||||
# FIXME
|
# FIXME
|
||||||
# "Enter/y: yes"
|
# "Enter/y: yes"
|
||||||
# "n: no"
|
# "n: no"
|
||||||
@ -471,7 +478,7 @@ class AlertPrompt(_BasePrompt):
|
|||||||
|
|
||||||
def __init__(self, question, parent=None):
|
def __init__(self, question, parent=None):
|
||||||
super().__init__(question, parent)
|
super().__init__(question, parent)
|
||||||
self._init_title(question.text)
|
self._init_title(question)
|
||||||
# FIXME
|
# FIXME
|
||||||
# Enter: acknowledge
|
# Enter: acknowledge
|
||||||
|
|
||||||
|
@ -335,6 +335,7 @@ class Question(QObject):
|
|||||||
For yesno, None (no default), True or False.
|
For yesno, None (no default), True or False.
|
||||||
For text, a default text as string.
|
For text, a default text as string.
|
||||||
For user_pwd, a default username as string.
|
For user_pwd, a default username as string.
|
||||||
|
title: The question title to show.
|
||||||
text: The prompt text to display to the user.
|
text: The prompt text to display to the user.
|
||||||
answer: The value the user entered (as password for user_pwd).
|
answer: The value the user entered (as password for user_pwd).
|
||||||
is_aborted: Whether the question was aborted.
|
is_aborted: Whether the question was aborted.
|
||||||
@ -363,13 +364,14 @@ class Question(QObject):
|
|||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._mode = None
|
self._mode = None
|
||||||
self.default = None
|
self.default = None
|
||||||
|
self.title = None
|
||||||
self.text = None
|
self.text = None
|
||||||
self.answer = None
|
self.answer = None
|
||||||
self.is_aborted = False
|
self.is_aborted = False
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return utils.get_repr(self, text=self.text, mode=self._mode,
|
return utils.get_repr(self, title=self.title, text=self.text,
|
||||||
default=self.default)
|
mode=self._mode, default=self.default)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def mode(self):
|
def mode(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user