本文整理汇总了Python中qutebrowser.keyinput.modeman.enter函数的典型用法代码示例。如果您正苦于以下问题:Python enter函数的具体用法?Python enter怎么用?Python enter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了enter函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _start_cb
def _start_cb(self, elems):
"""Initialize the elements and labels based on the context set."""
if self._context is None:
log.hints.debug("In _start_cb without context!")
return
if elems is None:
message.error("There was an error while getting hint elements")
return
if not elems:
message.error("No elements found.")
return
strings = self._hint_strings(elems)
log.hints.debug("hints: {}".format(', '.join(strings)))
for elem, string in zip(elems, strings):
label = HintLabel(elem, self._context)
label.update_text('', string)
self._context.all_labels.append(label)
self._context.labels[string] = label
keyparsers = objreg.get('keyparsers', scope='window',
window=self._win_id)
keyparser = keyparsers[usertypes.KeyMode.hint]
keyparser.update_bindings(strings)
message_bridge = objreg.get('message-bridge', scope='window',
window=self._win_id)
message_bridge.set_text(self._get_text())
modeman.enter(self._win_id, usertypes.KeyMode.hint,
'HintManager.start')
# to make auto_follow == 'always' work
self._handle_auto_follow()
示例2: _handle_auto_insert_mode
def _handle_auto_insert_mode(self, ok):
"""Handle auto-insert-mode after loading finished."""
ai = False
for mode in (usertypes.KeyMode.hint, usertypes.KeyMode.insert,
usertypes.KeyMode.caret, usertypes.KeyMode.passthrough):
modeman.maybe_leave(self.win_id, mode, 'load finished')
for r in pt_masks:
if re.match(r, self.cur_url.host()) is not None:
print(re.match(r, self.cur_url.host()), re.match(r, self.cur_url.host()).groups())
ai = True
break
if ai:
modeman.enter(self.win_id, usertypes.KeyMode.passthrough,
'load finished', only_if_normal=True)
return
if not config.get('input', 'auto-insert-mode'):
return
mode_manager = objreg.get('mode-manager', scope='window',
window=self.win_id)
cur_mode = mode_manager.mode
if cur_mode == usertypes.KeyMode.insert or not ok:
return
frame = self.page().currentFrame()
try:
elem = webelem.WebElementWrapper(frame.findFirstElement(':focus'))
except webelem.IsNullError:
log.webview.debug("Focused element is null!")
log.modes.debug("focus element: {}".format(repr(elem)))
print("bazqux" in self.cur_url.host(), self.cur_url.host())
if elem.is_editable() or rss:
modeman.enter(self.win_id, usertypes.KeyMode.insert,
'load finished', only_if_normal=True)
示例3: on_current_changed
def on_current_changed(self, idx):
"""Set last-focused-tab and leave hinting mode when focus changed."""
if idx == -1 or self._shutting_down:
# closing the last tab (before quitting) or shutting down
return
tab = self.widget(idx)
log.modes.debug("Current tab changed, focusing {!r}".format(tab))
tab.setFocus()
for mode in (usertypes.KeyMode.hint, usertypes.KeyMode.insert,
usertypes.KeyMode.caret, usertypes.KeyMode.passthrough):
modeman.maybe_leave(self._win_id, mode, 'tab changed')
if self._now_focused is not None:
objreg.register('last-focused-tab', self._now_focused, update=True,
scope='window', window=self._win_id)
ai = False
for r in pt_masks:
if re.match(r, tab.url().host()) is not None:
ai = True
break
if ai:
modeman.enter(self._win_id, usertypes.KeyMode.passthrough,
'load finished', only_if_normal=True)
self._now_focused = tab
self.current_tab_changed.emit(tab)
QTimer.singleShot(0, self.update_window_title)
self._tab_insert_idx_left = self.currentIndex()
self._tab_insert_idx_right = self.currentIndex() + 1
示例4: _start_cb
def _start_cb(self, elems):
"""Initialize the elements and labels based on the context set."""
filterfunc = webelem.FILTERS.get(self._context.group, lambda e: True)
elems = [e for e in elems if filterfunc(e)]
if not elems:
raise cmdexc.CommandError("No elements found.")
strings = self._hint_strings(elems)
log.hints.debug("hints: {}".format(', '.join(strings)))
for e, string in zip(elems, strings):
label = self._draw_label(e, string)
elem = ElemTuple(e, label)
self._context.all_elems.append(elem)
self._context.elems[string] = elem
keyparsers = objreg.get('keyparsers', scope='window',
window=self._win_id)
keyparser = keyparsers[usertypes.KeyMode.hint]
keyparser.update_bindings(strings)
self._context.tab.contents_size_changed.connect(
self.on_contents_size_changed)
message_bridge = objreg.get('message-bridge', scope='window',
window=self._win_id)
message_bridge.set_text(self._get_text())
modeman.enter(self._win_id, usertypes.KeyMode.hint,
'HintManager.start')
示例5: click
def click(self, click_target, *, force_event=False):
"""Simulate a click on the element.
Args:
click_target: A usertypes.ClickTarget member, what kind of click
to simulate.
force_event: Force generating a fake mouse event.
"""
log.webelem.debug("Clicking {!r} with click_target {}, force_event {}"
.format(self, click_target, force_event))
if force_event:
self._click_fake_event(click_target)
return
if click_target == usertypes.ClickTarget.normal:
if self.is_link():
log.webelem.debug("Clicking via JS click()")
self._click_js(click_target)
elif self.is_editable(strict=True):
log.webelem.debug("Clicking via JS focus()")
self._click_editable(click_target)
modeman.enter(self._tab.win_id, usertypes.KeyMode.insert,
'clicking input')
else:
self._click_fake_event(click_target)
elif click_target in [usertypes.ClickTarget.tab,
usertypes.ClickTarget.tab_bg,
usertypes.ClickTarget.window]:
if self.is_link():
self._click_href(click_target)
else:
self._click_fake_event(click_target)
else:
raise ValueError("Unknown ClickTarget {}".format(click_target))
示例6: _start_cb
def _start_cb(self, elems):
"""Initialize the elements and labels based on the context set."""
filterfunc = webelem.FILTERS.get(self._context.group, lambda e: True)
elems = [e for e in elems if filterfunc(e)]
if not elems:
message.error(self._win_id, "No elements found.", immediately=True)
return
strings = self._hint_strings(elems)
log.hints.debug("hints: {}".format(', '.join(strings)))
for elem, string in zip(elems, strings):
label = HintLabel(elem, self._context)
label.update_text('', string)
self._context.all_labels.append(label)
self._context.labels[string] = label
keyparsers = objreg.get('keyparsers', scope='window',
window=self._win_id)
keyparser = keyparsers[usertypes.KeyMode.hint]
keyparser.update_bindings(strings)
message_bridge = objreg.get('message-bridge', scope='window',
window=self._win_id)
message_bridge.set_text(self._get_text())
modeman.enter(self._win_id, usertypes.KeyMode.hint,
'HintManager.start')
# to make auto-follow == 'always' work
self._handle_auto_follow()
示例7: _restore_ctx
def _restore_ctx(self, ctx):
"""Restore state from a PromptContext.
Args:
ctx: A PromptContext previously saved by _get_ctx, or None.
Return: True if a context was restored, False otherwise.
"""
log.statusbar.debug("Restoring context {}".format(ctx))
if ctx is None:
self.hide_prompt.emit()
self._busy = False
return False
self._question = ctx.question
prompt = objreg.get('prompt', scope='window', window=self._win_id)
prompt.txt.setText(ctx.text)
prompt.lineedit.setText(ctx.input_text)
prompt.lineedit.setEchoMode(ctx.echo_mode)
prompt.lineedit.setVisible(ctx.input_visible)
self.show_prompt.emit()
mode = self.KEY_MODES[ctx.question.mode]
ctx.question.aborted.connect(
lambda: modeman.maybe_leave(self._win_id, mode, 'aborted'))
modeman.enter(self._win_id, mode, 'question asked')
return True
示例8: _auto_insert_mode_cb
def _auto_insert_mode_cb(elem):
"""Called from JS after finding the focused element."""
if elem is None:
log.webview.debug("No focused element!")
return
if elem.is_editable():
modeman.enter(self.win_id, usertypes.KeyMode.insert, "load finished", only_if_normal=True)
示例9: on_load_finished
def on_load_finished(self):
"""Handle auto-insert-mode after loading finished.
We don't take loadFinished's ok argument here as it always seems to be
true when the QWebPage has an ErrorPageExtension implemented.
See https://github.com/The-Compiler/qutebrowser/issues/84
"""
ok = not self.page().error_occured
if ok and not self._has_ssl_errors:
self._set_load_status(LoadStatus.success)
elif ok:
self._set_load_status(LoadStatus.warn)
else:
self._set_load_status(LoadStatus.error)
if not config.get('input', 'auto-insert-mode'):
return
mode_manager = objreg.get('mode-manager', scope='window',
window=self._win_id)
cur_mode = mode_manager.mode
if cur_mode == usertypes.KeyMode.insert or not ok:
return
frame = self.page().currentFrame()
try:
elem = webelem.WebElementWrapper(frame.findFirstElement(':focus'))
except webelem.IsNullError:
log.webview.debug("Focused element is null!")
return
log.modes.debug("focus element: {}".format(repr(elem)))
if elem.is_editable():
modeman.enter(self._win_id, usertypes.KeyMode.insert,
'load finished', only_if_normal=True)
示例10: ask_question
def ask_question(self, question, blocking):
"""Display a question in the statusbar.
Args:
question: The Question object to ask.
blocking: If True, this function blocks and returns the result.
Return:
The answer of the user when blocking=True.
None if blocking=False.
"""
log.statusbar.debug("Asking question {}, blocking {}, loops {}, queue "
"{}".format(question, blocking, self._loops,
self._queue))
if self._shutting_down:
# If we're currently shutting down we have to ignore this question
# to avoid segfaults - see
# https://github.com/The-Compiler/qutebrowser/issues/95
log.statusbar.debug("Ignoring question because we're shutting "
"down.")
question.abort()
return None
if self._busy and not blocking:
# We got an async question, but we're already busy with one, so we
# just queue it up for later.
log.statusbar.debug("Adding {} to queue.".format(question))
self._queue.append(question)
return
if blocking:
# If we're blocking we save the old state on the stack, so we can
# restore it after exec, if exec gets called multiple times.
context = self._get_ctx()
self._question = question
self._display_question()
mode = self.KEY_MODES[self._question.mode]
question.aborted.connect(
lambda: modeman.maybe_leave(self._win_id, mode, 'aborted'))
modeman.enter(self._win_id, mode, 'question asked')
if blocking:
loop = qtutils.EventLoop()
self._loops.append(loop)
loop.destroyed.connect(lambda: self._loops.remove(loop))
question.completed.connect(loop.quit)
question.completed.connect(loop.deleteLater)
loop.exec_()
if not self._restore_ctx(context):
# Nothing left to restore, so we can go back to popping async
# questions.
if self._queue:
self._pop_later()
return self._question.answer
else:
question.completed.connect(self._pop_later)
示例11: start
def start(self, group=webelem.Group.all, target=Target.normal,
*args: {'nargs': '*'}):
"""Start hinting.
Args:
group: The hinting mode to use.
- `all`: All clickable elements.
- `links`: Only links.
- `images`: Only images.
target: What to do with the selected element.
- `normal`: Open the link in the current tab.
- `tab`: Open the link in a new tab.
- `tab-bg`: Open the link in a new background tab.
- `yank`: Yank the link to the clipboard.
- `yank-primary`: Yank the link to the primary selection.
- `fill`: Fill the commandline with the command given as
argument.
- `rapid`: Open the link in a new tab and stay in hinting mode.
- `download`: Download the link.
- `userscript`: Call an userscript with `$QUTE_URL` set to the
link.
- `spawn`: Spawn a command.
*args: Arguments for spawn/userscript/fill.
- With `spawn`: The executable and arguments to spawn.
`{hint-url}` will get replaced by the selected
URL.
- With `userscript`: The userscript to execute.
- With `fill`: The command to fill the statusbar with.
`{hint-url}` will get replaced by the selected
URL.
"""
tabbed_browser = objreg.get('tabbed-browser')
widget = tabbed_browser.currentWidget()
if widget is None:
raise cmdexc.CommandError("No WebView available yet!")
mainframe = widget.page().mainFrame()
if mainframe is None:
raise cmdexc.CommandError("No frame focused!")
self._check_args(target, *args)
self._context = HintContext()
self._context.target = target
self._context.baseurl = tabbed_browser.current_url()
self._context.frames = webelem.get_child_frames(mainframe)
self._context.args = args
self._init_elements(mainframe, group)
objreg.get('message-bridge').set_text(self.HINT_TEXTS[target])
self._connect_frame_signals()
try:
modeman.enter(usertypes.KeyMode.hint, 'HintManager.start')
except modeman.ModeLockedError:
self._cleanup()
示例12: set_cmd_text
def set_cmd_text(self, text):
"""Preset the statusbar to some text.
Args:
text: The text to set as string.
"""
self.setText(text)
log.modes.debug("Setting command text, focusing {!r}".format(self))
modeman.enter(self._win_id, usertypes.KeyMode.command, 'cmd focus')
self.setFocus()
self.show_cmd.emit()
示例13: ask_question
def ask_question(self, question, blocking):
"""Dispkay a question in the statusbar.
Args:
question: The Question object to ask.
blocking: If True, this function blocks and returns the result.
Return:
The answer of the user when blocking=True.
None if blocking=False.
"""
log.statusbar.debug("Asking question {}, blocking {}, loops {}, queue "
"{}".format(question, blocking, self._loops,
self._queue))
if self._busy and not blocking:
# We got an async question, but we're already busy with one, so we
# just queue it up for later.
log.statusbar.debug("Adding {} to queue.".format(question))
self._queue.append(question)
return
if blocking:
# If we're blocking we save the old state on the stack, so we can
# restore it after exec, if exec gets called multiple times.
context = self._get_ctx()
self._question = question
mode = self._display_question()
question.aborted.connect(lambda: modeman.maybe_leave(mode, 'aborted'))
mode_manager = objreg.get('mode-manager')
try:
modeman.enter(mode, 'question asked', override=True)
except modeman.ModeLockedError:
if mode_manager.mode() != usertypes.KeyMode.prompt:
question.abort()
return None
mode_manager.locked = True
if blocking:
loop = qtutils.EventLoop()
self._loops.append(loop)
loop.destroyed.connect(lambda: self._loops.remove(loop))
question.completed.connect(loop.quit)
question.completed.connect(loop.deleteLater)
loop.exec_()
if not self._restore_ctx(context):
# Nothing left to restore, so we can go back to popping async
# questions.
if self._queue:
self._pop_later()
return self._question.answer
else:
question.completed.connect(self._pop_later)
示例14: mouserelease_insertmode_cb
def mouserelease_insertmode_cb(elem):
"""Callback which gets called from JS."""
if elem is None:
log.mouse.debug("Element vanished!")
return
if elem.is_editable():
log.mouse.debug("Clicked editable element (delayed)!")
modeman.enter(self._tab.win_id, usertypes.KeyMode.insert,
'click-delayed', only_if_normal=True)
else:
log.mouse.debug("Clicked non-editable element (delayed)!")
if config.get('input', 'auto-leave-insert-mode'):
modeman.leave(self._tab.win_id, usertypes.KeyMode.insert,
'click-delayed', maybe=True)
示例15: _start_cb
def _start_cb(self, elems):
"""Initialize the elements and labels based on the context set."""
if self._context is None:
log.hints.debug("In _start_cb without context!")
return
if not elems:
message.error("No elements found.")
return
# Because _start_cb is called asynchronously, it's possible that the
# user switched to another tab or closed the tab/window. In that case
# we should not start hinting.
tabbed_browser = objreg.get('tabbed-browser', default=None,
scope='window', window=self._win_id)
tab = tabbed_browser.widget.currentWidget()
if tab.tab_id != self._tab_id:
log.hints.debug(
"Current tab changed ({} -> {}) before _start_cb is run."
.format(self._tab_id, tab.tab_id))
return
strings = self._hint_strings(elems)
log.hints.debug("hints: {}".format(', '.join(strings)))
for elem, string in zip(elems, strings):
label = HintLabel(elem, self._context)
label.update_text('', string)
self._context.all_labels.append(label)
self._context.labels[string] = label
keyparsers = objreg.get('keyparsers', scope='window',
window=self._win_id)
keyparser = keyparsers[usertypes.KeyMode.hint]
keyparser.update_bindings(strings)
message_bridge = objreg.get('message-bridge', scope='window',
window=self._win_id)
message_bridge.set_text(self._get_text())
modeman.enter(self._win_id, usertypes.KeyMode.hint,
'HintManager.start')
if self._context.first:
self._fire(strings[0])
return
# to make auto_follow == 'always' work
self._handle_auto_follow()