Fix lint, add documentation
This commit is contained in:
parent
98ed6c9812
commit
5a3966ca82
@ -173,7 +173,7 @@ class CurCommandDispatcher(QObject):
|
||||
Args:
|
||||
mode: The hinting mode to use.
|
||||
"""
|
||||
self._tabs.currentWidget()._hintmanager.start(mode)
|
||||
self._tabs.currentWidget().hintmanager.start(mode)
|
||||
|
||||
@pyqtSlot(str, int)
|
||||
def search(self, text, flags):
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
"""A HintManager to draw hints over links."""
|
||||
|
||||
import logging
|
||||
import math
|
||||
|
||||
import qutebrowser.config.config as config
|
||||
@ -75,6 +74,12 @@ class HintManager:
|
||||
"""Calculate the hint strings for elems.
|
||||
|
||||
Inspirated by Vimium.
|
||||
|
||||
Args:
|
||||
elems: The elements to get hint strings for.
|
||||
|
||||
Return:
|
||||
A list of hint strings, in the same order as the elements.
|
||||
"""
|
||||
chars = config.get("hints", "chars")
|
||||
# Determine how many digits the link hints will require in the worst
|
||||
@ -106,6 +111,13 @@ class HintManager:
|
||||
the array.
|
||||
|
||||
Inspired by Vimium.
|
||||
|
||||
Args:
|
||||
hints: A list of hint strings.
|
||||
length: Length of the available charset.
|
||||
|
||||
Return:
|
||||
A list of shuffled hint strings.
|
||||
"""
|
||||
buckets = [[] for i in range(length)]
|
||||
for i, hint in enumerate(hints):
|
||||
@ -123,6 +135,14 @@ class HintManager:
|
||||
digits.
|
||||
|
||||
Inspired by Vimium.
|
||||
|
||||
Args:
|
||||
number: The hint number.
|
||||
chars: The charset to use.
|
||||
digits: The minimum output length.
|
||||
|
||||
Return:
|
||||
A hint string.
|
||||
"""
|
||||
base = len(chars)
|
||||
hintstr = []
|
||||
@ -135,12 +155,17 @@ class HintManager:
|
||||
if number <= 0:
|
||||
break
|
||||
# Pad the hint string we're returning so that it matches digits.
|
||||
for i in range(0, digits - len(hintstr)):
|
||||
for _ in range(0, digits - len(hintstr)):
|
||||
hintstr.insert(0, chars[0])
|
||||
return ''.join(hintstr)
|
||||
|
||||
def _draw_label(self, elem, string):
|
||||
"""Draw a hint label over an element."""
|
||||
"""Draw a hint label over an element.
|
||||
|
||||
Args:
|
||||
elem: The QWebElement to use.
|
||||
string: The hint string to print.
|
||||
"""
|
||||
rect = elem.geometry()
|
||||
css = HintManager.HINT_CSS.format(left=rect.x(), top=rect.y(),
|
||||
config=config.instance)
|
||||
|
@ -42,7 +42,7 @@ class BrowserTab(QWebView):
|
||||
Attributes:
|
||||
page_: The QWebPage behind the view
|
||||
signal_cache: The signal cache associated with the view.
|
||||
_hintmanager: The HintManager instance for this view.
|
||||
hintmanager: The HintManager instance for this view.
|
||||
_zoom: A NeighborList with the zoom levels.
|
||||
_scroll_pos: The old scroll position.
|
||||
_shutdown_callback: Callback to be called after shutdown.
|
||||
@ -76,7 +76,7 @@ class BrowserTab(QWebView):
|
||||
self._init_neighborlist()
|
||||
self.page_ = BrowserPage(self)
|
||||
self.setPage(self.page_)
|
||||
self._hintmanager = HintManager(self.page_.mainFrame())
|
||||
self.hintmanager = HintManager(self.page_.mainFrame())
|
||||
self.signal_cache = SignalCache(uncached=['linkHovered'])
|
||||
self.page_.setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
|
||||
self.page_.linkHovered.connect(self.linkHovered)
|
||||
|
Loading…
Reference in New Issue
Block a user