Add some logging about keyboard focus.

This should help with debugging #218 if it occurs again.
This commit is contained in:
Florian Bruhin 2014-10-28 07:44:42 +01:00
parent 8d22d558e2
commit eb5527f897
6 changed files with 18 additions and 4 deletions

View File

@ -220,9 +220,11 @@ class ModeManager(QObject):
if curmode != usertypes.KeyMode.insert:
log.modes.debug("handled: {}, forward-unbound-keys: {}, "
"passthrough: {}, is_non_alnum: {} --> filter: "
"{}".format(handled, self._forward_unbound_keys,
curmode in self.passthrough,
is_non_alnum, filter_this))
"{} (focused: {!r})".format(
handled, self._forward_unbound_keys,
curmode in self.passthrough,
is_non_alnum, filter_this,
QApplication.instance().focusWidget()))
return filter_this
def _eventFilter_keyrelease(self, event):

View File

@ -215,7 +215,7 @@ class MainWindow(QWidget):
cmd.got_cmd.connect(self._commandrunner.run_safely)
cmd.got_search.connect(search_runner.search)
cmd.got_search_rev.connect(search_runner.search_rev)
cmd.returnPressed.connect(tabs.setFocus)
cmd.returnPressed.connect(tabs.on_cmd_return_pressed)
search_runner.do_search.connect(tabs.search)
tabs.got_cmd.connect(self._commandrunner.run_safely)

View File

@ -153,6 +153,7 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
# won't change, so we make sure we emit update_completion.
self.update_completion.emit(self.prefix(), self.split(),
self._cursor_part)
log.modes.debug("Setting command text, focusing {!r}".format(self))
self.setFocus()
self.show_cmd.emit()
@ -212,6 +213,7 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
text += ' '
self.setText(text)
log.completion.debug("Placing cursor after '{}'".format(cursor_str))
log.modes.debug("Completion triggered, focusing {!r}".format(self))
self.setCursorPosition(len(cursor_str))
self.setFocus()
self.show_cmd.emit()

View File

@ -162,6 +162,8 @@ class Prompter(QObject):
mode = usertypes.KeyMode.prompt
else:
raise ValueError("Invalid prompt mode!")
log.modes.debug("Question asked, focusing {!r}".format(
prompt.lineedit))
prompt.lineedit.setFocus()
self.show_prompt.emit()
self._busy = True

View File

@ -497,6 +497,7 @@ class TabbedBrowser(tabwidget.TabWidget):
"""Give focus to current tab if command mode was left."""
if mode == usertypes.KeyMode.command:
widget = self.currentWidget()
log.modes.debug("Left command mode, focusing {!r}".format(widget))
if widget is None:
return
widget.setFocus()
@ -508,6 +509,7 @@ class TabbedBrowser(tabwidget.TabWidget):
# closing the last tab (before quitting)
return
tab = self.widget(idx)
log.modes.debug("Current tab changed, focusing {!r}".format(tab))
tab.setFocus()
modeman.maybe_leave(self._win_id, usertypes.KeyMode.hint,
'tab changed')
@ -520,6 +522,11 @@ class TabbedBrowser(tabwidget.TabWidget):
self._tab_insert_idx_left = self.currentIndex()
self._tab_insert_idx_right = self.currentIndex() + 1
@pyqtSlot()
def on_cmd_return_pressed(self):
"""Set focus when the commandline closes."""
log.modes.debug("Commandline closed, focusing {!r}".format(self))
def on_load_progress(self, tab, perc):
"""Adjust tab indicator on load progress."""
try:

View File

@ -328,6 +328,7 @@ class WebView(QWebView):
@pyqtSlot('QMouseEvent')
def on_mouse_event(self, evt):
"""Post a new mouseevent from a hintmanager."""
log.modes.debug("Hint triggered, focusing {!r}".format(self))
self.setFocus()
QApplication.postEvent(self, evt)