Fix lint, add documentation

This commit is contained in:
Florian Bruhin 2014-04-21 00:24:08 +02:00
parent 98ed6c9812
commit 5a3966ca82
3 changed files with 31 additions and 6 deletions

View File

@ -173,7 +173,7 @@ class CurCommandDispatcher(QObject):
Args: Args:
mode: The hinting mode to use. mode: The hinting mode to use.
""" """
self._tabs.currentWidget()._hintmanager.start(mode) self._tabs.currentWidget().hintmanager.start(mode)
@pyqtSlot(str, int) @pyqtSlot(str, int)
def search(self, text, flags): def search(self, text, flags):

View File

@ -17,7 +17,6 @@
"""A HintManager to draw hints over links.""" """A HintManager to draw hints over links."""
import logging
import math import math
import qutebrowser.config.config as config import qutebrowser.config.config as config
@ -75,6 +74,12 @@ class HintManager:
"""Calculate the hint strings for elems. """Calculate the hint strings for elems.
Inspirated by Vimium. 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") chars = config.get("hints", "chars")
# Determine how many digits the link hints will require in the worst # Determine how many digits the link hints will require in the worst
@ -106,6 +111,13 @@ class HintManager:
the array. the array.
Inspired by Vimium. 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)] buckets = [[] for i in range(length)]
for i, hint in enumerate(hints): for i, hint in enumerate(hints):
@ -123,6 +135,14 @@ class HintManager:
digits. digits.
Inspired by Vimium. 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) base = len(chars)
hintstr = [] hintstr = []
@ -135,12 +155,17 @@ class HintManager:
if number <= 0: if number <= 0:
break break
# Pad the hint string we're returning so that it matches digits. # 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]) hintstr.insert(0, chars[0])
return ''.join(hintstr) return ''.join(hintstr)
def _draw_label(self, elem, string): 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() rect = elem.geometry()
css = HintManager.HINT_CSS.format(left=rect.x(), top=rect.y(), css = HintManager.HINT_CSS.format(left=rect.x(), top=rect.y(),
config=config.instance) config=config.instance)

View File

@ -42,7 +42,7 @@ class BrowserTab(QWebView):
Attributes: Attributes:
page_: The QWebPage behind the view page_: The QWebPage behind the view
signal_cache: The signal cache associated with 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. _zoom: A NeighborList with the zoom levels.
_scroll_pos: The old scroll position. _scroll_pos: The old scroll position.
_shutdown_callback: Callback to be called after shutdown. _shutdown_callback: Callback to be called after shutdown.
@ -76,7 +76,7 @@ class BrowserTab(QWebView):
self._init_neighborlist() self._init_neighborlist()
self.page_ = BrowserPage(self) self.page_ = BrowserPage(self)
self.setPage(self.page_) self.setPage(self.page_)
self._hintmanager = HintManager(self.page_.mainFrame()) self.hintmanager = HintManager(self.page_.mainFrame())
self.signal_cache = SignalCache(uncached=['linkHovered']) self.signal_cache = SignalCache(uncached=['linkHovered'])
self.page_.setLinkDelegationPolicy(QWebPage.DelegateAllLinks) self.page_.setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
self.page_.linkHovered.connect(self.linkHovered) self.page_.linkHovered.connect(self.linkHovered)