Rename variables for consistency with other code and docstrings
As described in [1], the naming of some variables has become inconsistent with the original code and even docstrings. This commit corrects some of these problems, with the following terminology: - hint text: informative message (see HINT_TEXTS) - hint string: the text displayed on the hint (as instance of str) - hint label: the element representing the hint, added to the DOM - hint: too abstract, sensibly used only in docstrings to refer to the "visual result" This commit amendsb89e0f8803
and8873aba09f
. [1] https://github.com/The-Compiler/qutebrowser/pull/1178#issuecomment-178795190
This commit is contained in:
parent
ca88b7a1cf
commit
1b32444256
@ -23,7 +23,7 @@ import collections
|
|||||||
import functools
|
import functools
|
||||||
import math
|
import math
|
||||||
import re
|
import re
|
||||||
import string
|
from string import ascii_lowercase
|
||||||
|
|
||||||
from PyQt5.QtCore import (pyqtSignal, pyqtSlot, QObject, QEvent, Qt, QUrl,
|
from PyQt5.QtCore import (pyqtSignal, pyqtSlot, QObject, QEvent, Qt, QUrl,
|
||||||
QTimer)
|
QTimer)
|
||||||
@ -389,7 +389,7 @@ class HintManager(QObject):
|
|||||||
label.setStyleProperty('left', '{}px !important'.format(left))
|
label.setStyleProperty('left', '{}px !important'.format(left))
|
||||||
label.setStyleProperty('top', '{}px !important'.format(top))
|
label.setStyleProperty('top', '{}px !important'.format(top))
|
||||||
|
|
||||||
def _draw_label(self, elem, text):
|
def _draw_label(self, elem, string):
|
||||||
"""Draw a hint label over an element.
|
"""Draw a hint label over an element.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -414,7 +414,7 @@ class HintManager(QObject):
|
|||||||
label = webelem.WebElementWrapper(parent.lastChild())
|
label = webelem.WebElementWrapper(parent.lastChild())
|
||||||
label['class'] = 'qutehint'
|
label['class'] = 'qutehint'
|
||||||
self._set_style_properties(elem, label)
|
self._set_style_properties(elem, label)
|
||||||
label.setPlainText(text)
|
label.setPlainText(string)
|
||||||
return label
|
return label
|
||||||
|
|
||||||
def _show_url_error(self):
|
def _show_url_error(self):
|
||||||
@ -877,21 +877,21 @@ class HintManager(QObject):
|
|||||||
def handle_partial_key(self, keystr):
|
def handle_partial_key(self, keystr):
|
||||||
"""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 (text, elems) in self._context.elems.items():
|
for string, elem in self._context.elems.items():
|
||||||
try:
|
try:
|
||||||
if text.startswith(keystr):
|
if string.startswith(keystr):
|
||||||
matched = text[:len(keystr)]
|
matched = string[:len(keystr)]
|
||||||
rest = text[len(keystr):]
|
rest = string[len(keystr):]
|
||||||
match_color = config.get('colors', 'hints.fg.match')
|
match_color = config.get('colors', 'hints.fg.match')
|
||||||
elems.label.setInnerXml(
|
elem.label.setInnerXml(
|
||||||
'<font color="{}">{}</font>{}'.format(
|
'<font color="{}">{}</font>{}'.format(
|
||||||
match_color, matched, rest))
|
match_color, matched, rest))
|
||||||
if self._is_hidden(elems.label):
|
if self._is_hidden(elem.label):
|
||||||
# hidden element which matches again -> show it
|
# hidden element which matches again -> show it
|
||||||
self._show_elem(elems.label)
|
self._show_elem(elem.label)
|
||||||
else:
|
else:
|
||||||
# element doesn't match anymore -> hide it
|
# element doesn't match anymore -> hide it
|
||||||
self._hide_elem(elems.label)
|
self._hide_elem(elem.label)
|
||||||
except webelem.IsNullError:
|
except webelem.IsNullError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -909,15 +909,15 @@ class HintManager(QObject):
|
|||||||
else:
|
else:
|
||||||
self._filterstr = filterstr
|
self._filterstr = filterstr
|
||||||
|
|
||||||
for elems in self._context.all_elems:
|
for elem in self._context.all_elems:
|
||||||
try:
|
try:
|
||||||
if self._filter_matches(filterstr, str(elems.elem)):
|
if self._filter_matches(filterstr, str(elem.elem)):
|
||||||
if self._is_hidden(elems.label):
|
if self._is_hidden(elem.label):
|
||||||
# hidden element which matches again -> show it
|
# hidden element which matches again -> show it
|
||||||
self._show_elem(elems.label)
|
self._show_elem(elem.label)
|
||||||
else:
|
else:
|
||||||
# element doesn't match anymore -> hide it
|
# element doesn't match anymore -> hide it
|
||||||
self._hide_elem(elems.label)
|
self._hide_elem(elem.label)
|
||||||
except webelem.IsNullError:
|
except webelem.IsNullError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -938,10 +938,10 @@ class HintManager(QObject):
|
|||||||
visible = self._context.elems
|
visible = self._context.elems
|
||||||
else:
|
else:
|
||||||
visible = {}
|
visible = {}
|
||||||
for k, e in self._context.elems.items():
|
for string, elem in self._context.elems.items():
|
||||||
try:
|
try:
|
||||||
if not self._is_hidden(e.label):
|
if not self._is_hidden(elem.label):
|
||||||
visible[k] = e
|
visible[string] = elem
|
||||||
except webelem.IsNullError:
|
except webelem.IsNullError:
|
||||||
pass
|
pass
|
||||||
if not visible:
|
if not visible:
|
||||||
@ -1017,8 +1017,8 @@ class HintManager(QObject):
|
|||||||
# Reset filtering
|
# Reset filtering
|
||||||
self.filter_hints(None)
|
self.filter_hints(None)
|
||||||
# Undo keystring highlighting
|
# Undo keystring highlighting
|
||||||
for (text, elems) in self._context.elems.items():
|
for string, elem in self._context.elems.items():
|
||||||
elems.label.setInnerXml(text)
|
elem.label.setInnerXml(string)
|
||||||
handler()
|
handler()
|
||||||
|
|
||||||
@cmdutils.register(instance='hintmanager', scope='tab', hide=True,
|
@cmdutils.register(instance='hintmanager', scope='tab', hide=True,
|
||||||
@ -1042,13 +1042,13 @@ class HintManager(QObject):
|
|||||||
def on_contents_size_changed(self, _size):
|
def on_contents_size_changed(self, _size):
|
||||||
"""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.all_elems:
|
for e in self._context.all_elems:
|
||||||
try:
|
try:
|
||||||
if elems.elem.webFrame() is None:
|
if e.elem.webFrame() is None:
|
||||||
# This sometimes happens for some reason...
|
# This sometimes happens for some reason...
|
||||||
elems.label.removeFromDocument()
|
e.label.removeFromDocument()
|
||||||
continue
|
continue
|
||||||
self._set_style_position(elems.elem, elems.label)
|
self._set_style_position(e.elem, e.label)
|
||||||
except webelem.IsNullError:
|
except webelem.IsNullError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -1085,7 +1085,7 @@ class WordHinter:
|
|||||||
self.dictionary = dictionary
|
self.dictionary = dictionary
|
||||||
try:
|
try:
|
||||||
with open(dictionary, encoding="UTF-8") as wordfile:
|
with open(dictionary, encoding="UTF-8") as wordfile:
|
||||||
alphabet = set(string.ascii_lowercase)
|
alphabet = set(ascii_lowercase)
|
||||||
hints = set()
|
hints = set()
|
||||||
lines = (line.rstrip().lower() for line in wordfile)
|
lines = (line.rstrip().lower() for line in wordfile)
|
||||||
for word in lines:
|
for word in lines:
|
||||||
|
Loading…
Reference in New Issue
Block a user