Ignore isNullError while handling label elements.

Fixes #295 (hopefully for real this time!)
This commit is contained in:
Florian Bruhin 2014-12-02 21:16:45 +01:00
parent 99fb516aa3
commit d94f848c82

View File

@ -672,17 +672,22 @@ class HintManager(QObject):
"""Handle a new partial keypress.""" """Handle a new partial keypress."""
log.hints.debug("Handling new keystring: '{}'".format(keystr)) log.hints.debug("Handling new keystring: '{}'".format(keystr))
for (string, elems) in self._context.elems.items(): for (string, elems) in self._context.elems.items():
if string.startswith(keystr): try:
matched = string[:len(keystr)] if string.startswith(keystr):
rest = string[len(keystr):] matched = string[:len(keystr)]
elems.label.setInnerXml('<font color="{}">{}</font>{}'.format( rest = string[len(keystr):]
config.get('colors', 'hints.fg.match'), matched, rest)) match_color = config.get('colors', 'hints.fg.match')
if self._is_hidden(elems.label): elems.label.setInnerXml(
# hidden element which matches again -> unhide it '<font color="{}">{}</font>{}'.format(
elems.label.setStyleProperty('display', 'inline') match_color, matched, rest))
else: if self._is_hidden(elems.label):
# element doesn't match anymore -> hide it # hidden element which matches again -> unhide it
elems.label.setStyleProperty('display', 'none') elems.label.setStyleProperty('display', 'inline')
else:
# element doesn't match anymore -> hide it
elems.label.setStyleProperty('display', 'none')
except webelem.IsNullError:
pass
def filter_hints(self, filterstr): def filter_hints(self, filterstr):
"""Filter displayed hints according to a text. """Filter displayed hints according to a text.
@ -691,14 +696,17 @@ class HintManager(QObject):
filterstr: The string to filer with, or None to show all. filterstr: The string to filer with, or None to show all.
""" """
for elems in self._context.elems.values(): for elems in self._context.elems.values():
if (filterstr is None or try:
str(elems.elem).lower().startswith(filterstr)): if (filterstr is None or
if self._is_hidden(elems.label): str(elems.elem).lower().startswith(filterstr)):
# hidden element which matches again -> unhide it if self._is_hidden(elems.label):
# hidden element which matches again -> unhide it
elems.label.setStyleProperty('display', 'none')
else:
# element doesn't match anymore -> hide it
elems.label.setStyleProperty('display', 'none') elems.label.setStyleProperty('display', 'none')
else: except webelem.IsNullError:
# element doesn't match anymore -> hide it pass
elems.label.setStyleProperty('display', 'none')
visible = {} visible = {}
for k, e in self._context.elems.items(): for k, e in self._context.elems.items():
if not self._is_hidden(e.label): if not self._is_hidden(e.label):
@ -779,11 +787,14 @@ class HintManager(QObject):
"""Reposition hints if contents size changed.""" """Reposition hints if contents size changed."""
log.hints.debug("Contents size changed...!") log.hints.debug("Contents size changed...!")
for elems in self._context.elems.values(): for elems in self._context.elems.values():
if elems.elem.webFrame() is None: try:
# This sometimes happens for some reason... if elems.elem.webFrame() is None:
elems.label.removeFromDocument() # This sometimes happens for some reason...
continue elems.label.removeFromDocument()
self._set_style_position(elems.elem, elems.label) continue
self._set_style_position(elems.elem, elems.label)
except webelem.IsNullError:
pass
@pyqtSlot(usertypes.KeyMode) @pyqtSlot(usertypes.KeyMode)
def on_mode_left(self, mode): def on_mode_left(self, mode):