Coverage for qutebrowser/completion/completionwidget.py : 86%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2014-2018 Florian Bruhin (The Compiler) <mail@qutebrowser.org> # # This file is part of qutebrowser. # # qutebrowser is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # qutebrowser is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
Defines a CompletionView which uses CompletionFiterModel and CompletionModel subclasses to provide completions. """
"""The view showing available completions.
Based on QTreeView but heavily customized so root elements show as category headers, and children show as flat list.
Attributes: pattern: Current filter pattern, used for highlighting. _win_id: The ID of the window this CompletionView is associated with. _height: The height to use for the CompletionView. _height_perc: Either None or a percentage if height should be relative. _delegate: The item delegate used. _column_widths: A list of column widths, in percent. _active: Whether a selection is active.
Signals: update_geometry: Emitted when the completion should be resized. selection_changed: Emitted when the completion item selection changes. """
# Drawing the item foreground will be done by CompletionItemDelegate, so we # don't define that in this stylesheet. QTreeView { font: {{ conf.fonts.completion.entry }}; background-color: {{ conf.colors.completion.even.bg }}; alternate-background-color: {{ conf.colors.completion.odd.bg }}; outline: 0; border: 0px; }
QTreeView::item:disabled { background-color: {{ conf.colors.completion.category.bg }}; border-top: 1px solid {{ conf.colors.completion.category.border.top }}; border-bottom: 1px solid {{ conf.colors.completion.category.border.bottom }}; }
QTreeView::item:selected, QTreeView::item:selected:hover { border-top: 1px solid {{ conf.colors.completion.item.selected.border.top }}; border-bottom: 1px solid {{ conf.colors.completion.item.selected.border.bottom }}; background-color: {{ conf.colors.completion.item.selected.bg }}; }
QTreeView:item::hover { border: 0px; }
QTreeView QScrollBar { width: {{ conf.completion.scrollbar.width }}px; background: {{ conf.colors.completion.scrollbar.bg }}; }
QTreeView QScrollBar::handle { background: {{ conf.colors.completion.scrollbar.fg }}; border: {{ conf.completion.scrollbar.padding }}px solid {{ conf.colors.completion.scrollbar.bg }}; min-height: 10px; }
QTreeView QScrollBar::sub-line, QScrollBar::add-line { border: none; background: none; } """
# WORKAROUND # This is a workaround for weird race conditions with invalid # item indexes leading to segfaults in Qt. # # Some background: http://bugs.quassel-irc.org/issues/663 # The proposed fix there was later reverted because it didn't help. # FIXME set elidemode # https://github.com/qutebrowser/qutebrowser/issues/118
def __repr__(self): return utils.get_repr(self)
def _on_config_changed(self, option):
"""Resize the completion columns based on column_widths."""
pixel_widths[-1] -= delta else:
"""Get the previous/next QModelIndex displayed in the view.
Used by tab_handler.
Args: upwards: Get previous item, not next.
Return: A QModelIndex. """ # No item selected yet else:
# wrap around if we arrived at beginning/end # Item is a real item, not a category header -> success
raise utils.Unreachable
"""Get the index of the previous/next category.
Args: upwards: Get previous item, not next.
Return: A QModelIndex. """ # wrap around to the first item of the last category # wrap around to the first item of the first category # scroll to ensure the category is visible
raise utils.Unreachable
modes=[usertypes.KeyMode.command], scope='window') 'prev-category']) """Shift the focus of the completion menu to another item.
Args: which: 'next', 'prev', 'next-category', or 'prev-category'. history: Navigate through command history if no text was typed. """ status = objreg.get('status-command', scope='window', window=self._win_id) if (status.text() == ':' or status.history.is_browsing() or not self._active): if which == 'next': status.command_history_next() return elif which == 'prev': status.command_history_prev() return else: raise cmdexc.CommandError("Can't combine --history with " "{}!".format(which))
'next': self._next_idx(upwards=False), 'prev': self._next_idx(upwards=True), 'next-category': self._next_category_idx(upwards=False), 'prev-category': self._next_category_idx(upwards=True), }
idx, QItemSelectionModel.ClearAndSelect | QItemSelectionModel.Rows)
# if the last item is focused, try to fetch more
self.hide()
"""Switch completion to a new model.
Called from on_update_completion().
Args: model: The model to use. """
"""Set the pattern on the underlying model."""
self.model().count() > 0): else:
"""Emit the update_geometry signal if the config says so."""
def on_clear_completion_selection(self): """Clear the selection model when an item is activated.""" self.hide() selmod = self.selectionModel() if selmod is not None: selmod.clearSelection() selmod.clearCurrentIndex()
"""Get the completion size according to the config.""" # Get the configured height/percentage. else: height = int(confheight) # Shrink to content size if needed and shrinking is enabled contents_height = ( self.viewportSizeHint().height() + self.horizontalScrollBar().sizeHint().height()) if contents_height <= height: height = contents_height else: # The width isn't really relevant as we're expanding anyways.
"""Extend selectionChanged to call completers selection_changed."""
"""Extend resizeEvent to adjust column size."""
"""Adjust the completion size and scroll when it's freshly shown."""
modes=[usertypes.KeyMode.command], scope='window') def completion_item_del(self): """Delete the current completion item."""
modes=[usertypes.KeyMode.command], scope='window') """Yank the current completion item into the clipboard.
Args: sel: Use the primary selection instead of the clipboard. """ window=self._win_id) raise cmdexc.CommandError("No item selected!") |