本文整理汇总了Python中qutebrowser.config.config.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: show_help
def show_help(self, topic=None):
r"""Show help about a command or setting.
Args:
topic: The topic to show help for.
- :__command__ for commands.
- __section__\->__option__ for settings.
"""
if topic is None:
path = 'index.html'
elif topic.startswith(':'):
command = topic[1:]
if command not in cmdutils.cmd_dict:
raise cmdexc.CommandError("Invalid command {}!".format(
command))
path = 'commands.html#{}'.format(command)
elif '->' in topic:
parts = topic.split('->')
if len(parts) != 2:
raise cmdexc.CommandError("Invalid help topic {}!".format(
topic))
try:
config.get(*parts)
except config.NoSectionError:
raise cmdexc.CommandError("Invalid section {}!".format(
parts[0]))
except config.NoOptionError:
raise cmdexc.CommandError("Invalid option {}!".format(
parts[1]))
path = 'settings.html#{}'.format(topic.replace('->', '-'))
else:
raise cmdexc.CommandError("Invalid help topic {}!".format(topic))
self.openurl('qute://help/{}'.format(path))
开发者ID:har5ha,项目名称:qutebrowser,代码行数:34,代码来源:commands.py
示例2: _get_new_tab_idx
def _get_new_tab_idx(self, explicit):
"""Get the index of a tab to insert.
Args:
explicit: Whether the tab was opened explicitely.
Return:
The index of the new tab.
"""
if explicit:
pos = config.get('tabs', 'new-tab-position-explicit')
else:
pos = config.get('tabs', 'new-tab-position')
if pos == 'left':
idx = self._tab_insert_idx_left
# On first sight, we'd think we have to decrement
# self._tab_insert_idx_left here, as we want the next tab to be
# *before* the one we just opened. However, since we opened a tab
# *to the left* of the currently focused tab, indices will shift by
# 1 automatically.
elif pos == 'right':
idx = self._tab_insert_idx_right
self._tab_insert_idx_right += 1
elif pos == 'first':
idx = 0
elif pos == 'last':
idx = -1
else:
raise ValueError("Invalid new-tab-position '{}'.".format(pos))
log.webview.debug("new-tab-position {} -> opening new tab at {}, "
"next left: {} / right: {}".format(
pos, idx, self._tab_insert_idx_left,
self._tab_insert_idx_right))
return idx
开发者ID:HalosGhost,项目名称:qutebrowser,代码行数:34,代码来源:tabbedbrowser.py
示例3: edit
def edit(self, text):
"""Edit a given text.
Args:
text: The initial text to edit.
"""
if self._text is not None:
raise ValueError("Already editing a file!")
self._text = text
try:
self._oshandle, self._filename = tempfile.mkstemp(
text=True, prefix='qutebrowser-editor-')
if text:
encoding = config.get('general', 'editor-encoding')
with open(self._filename, 'w', encoding=encoding) as f:
f.write(text) # pragma: no branch
except OSError as e:
message.error(self._win_id, "Failed to create initial file: "
"{}".format(e))
return
self._proc = guiprocess.GUIProcess(self._win_id, what='editor',
parent=self)
self._proc.finished.connect(self.on_proc_closed)
self._proc.error.connect(self.on_proc_error)
editor = config.get('general', 'editor')
executable = editor[0]
args = [self._filename if arg == '{}' else arg for arg in editor[1:]]
log.procs.debug("Calling \"{}\" with args {}".format(executable, args))
self._proc.start(executable, args)
开发者ID:shawa,项目名称:qutebrowser,代码行数:29,代码来源:editor.py
示例4: undo
def undo(self):
"""Undo removing of a tab."""
# Remove unused tab which may be created after the last tab is closed
last_close = config.get('tabs', 'last-close')
use_current_tab = False
if last_close in ['blank', 'startpage', 'default-page']:
only_one_tab_open = self.count() == 1
no_history = len(self.widget(0).history) == 1
urls = {
'blank': QUrl('about:blank'),
'startpage': QUrl(config.get('general', 'startpage')[0]),
'default-page': config.get('general', 'default-page'),
}
first_tab_url = self.widget(0).url()
last_close_urlstr = urls[last_close].toString().rstrip('/')
first_tab_urlstr = first_tab_url.toString().rstrip('/')
last_close_url_used = first_tab_urlstr == last_close_urlstr
use_current_tab = (only_one_tab_open and no_history and
last_close_url_used)
url, history_data, idx = self._undo_stack.pop()
if use_current_tab:
self.openurl(url, newtab=False)
newtab = self.widget(0)
else:
newtab = self.tabopen(url, background=False, idx=idx)
newtab.history.deserialize(history_data)
开发者ID:nicoddemus,项目名称:qutebrowser,代码行数:29,代码来源:tabbedbrowser.py
示例5: _hint_strings
def _hint_strings(self, elems):
"""Calculate the hint strings for elems.
Inspired by Vimium.
Args:
elems: The elements to get hint strings for.
Return:
A list of hint strings, in the same order as the elements.
"""
hint_mode = config.get('hints', 'mode')
if hint_mode == 'word':
try:
return self._word_hinter.hint(elems)
except WordHintingError as e:
message.error(self._win_id, str(e), immediately=True)
# falls back on letter hints
if hint_mode == 'number':
chars = '0123456789'
else:
chars = config.get('hints', 'chars')
min_chars = config.get('hints', 'min-chars')
if config.get('hints', 'scatter') and hint_mode != 'number':
return self._hint_scattered(min_chars, chars, elems)
else:
return self._hint_linear(min_chars, chars, elems)
开发者ID:djfinlay,项目名称:qutebrowser,代码行数:27,代码来源:hints.py
示例6: _handle_auto_follow
def _handle_auto_follow(self, keystr="", filterstr="", visible=None):
"""Handle the auto-follow option."""
if visible is None:
visible = {string: label
for string, label in self._context.labels.items()
if label.isVisible()}
if len(visible) != 1:
return
auto_follow = config.get('hints', 'auto-follow')
if auto_follow == "always":
follow = True
elif auto_follow == "unique-match":
follow = keystr or filterstr
elif auto_follow == "full-match":
elemstr = str(list(visible.values())[0].elem)
filter_match = self._filter_matches_exactly(filterstr, elemstr)
follow = (keystr in visible) or filter_match
else:
follow = False
# save the keystr of the only one visible hint to be picked up
# later by self.follow_hint
self._context.to_follow = list(visible.keys())[0]
if follow:
# apply auto-follow-timeout
timeout = config.get('hints', 'auto-follow-timeout')
keyparsers = objreg.get('keyparsers', scope='window',
window=self._win_id)
normal_parser = keyparsers[usertypes.KeyMode.normal]
normal_parser.set_inhibited_timeout(timeout)
# unpacking gets us the first (and only) key in the dict.
self._fire(*visible)
开发者ID:julianuu,项目名称:qutebrowser,代码行数:35,代码来源:hints.py
示例7: _draw_textdoc
def _draw_textdoc(self, rect):
"""Draw the QTextDocument of an item.
Args:
rect: The QRect to clip the drawing to.
"""
# We can't use drawContents because then the color would be ignored.
# See: https://qt-project.org/forums/viewthread/21492
clip = QRectF(0, 0, rect.width(), rect.height())
self._painter.save()
if self._opt.state & QStyle.State_Selected:
option = 'completion.item.selected.fg'
elif not self._opt.state & QStyle.State_Enabled:
option = 'completion.category.fg'
else:
option = 'completion.fg'
try:
self._painter.setPen(config.get('colors', option))
except configexc.NoOptionError:
self._painter.setPen(config.get('colors', 'completion.fg'))
ctx = QAbstractTextDocumentLayout.PaintContext()
ctx.palette.setColor(QPalette.Text, self._painter.pen().color())
if clip.isValid():
self._painter.setClipRect(clip)
ctx.clip = clip
self._doc.documentLayout().draw(self._painter, ctx)
self._painter.restore()
开发者ID:JIVS,项目名称:qutebrowser,代码行数:27,代码来源:completiondelegate.py
示例8: search
def search(self, text, reverse=False):
"""Search for a text on the current page.
Args:
text: The text to search for.
reverse: Reverse search direction.
"""
if self._text is not None and self._text != text:
# We first clear the marked text, then the highlights
self.do_search.emit('', 0)
self.do_search.emit('', QWebPage.HighlightAllOccurrences)
self._text = text
self._flags = 0
ignore_case = config.get('general', 'ignore-case')
if ignore_case == 'smart':
if not text.islower():
self._flags |= QWebPage.FindCaseSensitively
elif not ignore_case:
self._flags |= QWebPage.FindCaseSensitively
if config.get('general', 'wrap-search'):
self._flags |= QWebPage.FindWrapsAroundDocument
if reverse:
self._flags |= QWebPage.FindBackward
# We actually search *twice* - once to highlight everything, then again
# to get a mark so we can navigate.
self.do_search.emit(self._text, self._flags)
self.do_search.emit(self._text, self._flags |
QWebPage.HighlightAllOccurrences)
开发者ID:larryhynes,项目名称:qutebrowser,代码行数:28,代码来源:runners.py
示例9: resize_completion
def resize_completion(self):
"""Adjust completion according to config."""
if not self._completion.isVisible():
# It doesn't make sense to resize the completion as long as it's
# not shown anyways.
return
# Get the configured height/percentage.
confheight = str(config.get("completion", "height"))
if confheight.endswith("%"):
perc = int(confheight.rstrip("%"))
height = self.height() * perc / 100
else:
height = int(confheight)
# Shrink to content size if needed and shrinking is enabled
if config.get("completion", "shrink"):
contents_height = (
self._completion.viewportSizeHint().height()
+ self._completion.horizontalScrollBar().sizeHint().height()
)
if contents_height <= height:
height = contents_height
else:
contents_height = -1
# hpoint now would be the bottom-left edge of the widget if it was on
# the top of the main window.
topleft_y = self.height() - self.status.height() - height
topleft_y = qtutils.check_overflow(topleft_y, "int", fatal=False)
topleft = QPoint(0, topleft_y)
bottomright = self.status.geometry().topRight()
rect = QRect(topleft, bottomright)
log.misc.debug("completion rect: {}".format(rect))
if rect.isValid():
self._completion.setGeometry(rect)
开发者ID:forkbong,项目名称:qutebrowser,代码行数:33,代码来源:mainwindow.py
示例10: undo
def undo(self):
"""Undo removing of a tab."""
# Remove unused tab which may be created after the last tab is closed
last_close = config.get("tabs", "last-close")
use_current_tab = False
if last_close in ["blank", "startpage", "default-page"]:
only_one_tab_open = self.count() == 1
no_history = self.widget(0).history().count() == 1
urls = {
"blank": QUrl("about:blank"),
"startpage": QUrl(config.get("general", "startpage")[0]),
"default-page": config.get("general", "default-page"),
}
first_tab_url = self.widget(0).page().mainFrame().requestedUrl()
last_close_urlstr = urls[last_close].toString().rstrip("/")
first_tab_urlstr = first_tab_url.toString().rstrip("/")
last_close_url_used = first_tab_urlstr == last_close_urlstr
use_current_tab = only_one_tab_open and no_history and last_close_url_used
url, history_data = self._undo_stack.pop()
if use_current_tab:
self.openurl(url, newtab=False)
newtab = self.widget(0)
else:
newtab = self.tabopen(url, background=False)
qtutils.deserialize(history_data, newtab.history())
开发者ID:rumpelsepp,项目名称:qutebrowser,代码行数:28,代码来源:tabbedbrowser.py
示例11: close_tab
def close_tab(self, tab, *, add_undo=True):
"""Close a tab.
Args:
tab: The QWebView to be closed.
add_undo: Whether the tab close can be undone.
"""
last_close = config.get('tabs', 'last-close')
count = self.count()
if last_close == 'ignore' and count == 1:
return
# If we are removing a pinned tab, decrease count
if tab.data.pinned:
self.tabBar().pinned_count -= 1
self._remove_tab(tab, add_undo=add_undo)
if count == 1: # We just closed the last tab above.
if last_close == 'close':
self.close_window.emit()
elif last_close == 'blank':
self.openurl(QUrl('about:blank'), newtab=True)
elif last_close == 'startpage':
url = QUrl(config.get('general', 'startpage')[0])
self.openurl(url, newtab=True)
elif last_close == 'default-page':
url = config.get('general', 'default-page')
self.openurl(url, newtab=True)
开发者ID:michaelbeaumont,项目名称:qutebrowser,代码行数:30,代码来源:tabbedbrowser.py
示例12: close_tab
def close_tab(self, tab):
"""Close a tab.
Args:
tab: The QWebView to be closed.
"""
last_close = config.get("tabs", "last-close")
count = self.count()
if last_close == "ignore" and count == 1:
return
self._remove_tab(tab)
if count == 1: # We just closed the last tab above.
if last_close == "close":
self.close_window.emit()
elif last_close == "blank":
self.openurl(QUrl("about:blank"), newtab=True)
elif last_close == "startpage":
url = QUrl(config.get("general", "startpage")[0])
self.openurl(url, newtab=True)
elif last_close == "default-page":
url = config.get("general", "default-page")
self.openurl(url, newtab=True)
开发者ID:rumpelsepp,项目名称:qutebrowser,代码行数:25,代码来源:tabbedbrowser.py
示例13: search
def search(self, text="", reverse=False):
"""Search for a text on the current page. With no text, clear results.
Args:
text: The text to search for.
reverse: Reverse search direction.
"""
view = self._current_widget()
if view.search_text is not None and view.search_text != text:
# We first clear the marked text, then the highlights
view.search('', 0)
view.search('', QWebPage.HighlightAllOccurrences)
flags = 0
ignore_case = config.get('general', 'ignore-case')
if ignore_case == 'smart':
if not text.islower():
flags |= QWebPage.FindCaseSensitively
elif not ignore_case:
flags |= QWebPage.FindCaseSensitively
if config.get('general', 'wrap-search'):
flags |= QWebPage.FindWrapsAroundDocument
if reverse:
flags |= QWebPage.FindBackward
# We actually search *twice* - once to highlight everything, then again
# to get a mark so we can navigate.
view.search(text, flags)
view.search(text, flags | QWebPage.HighlightAllOccurrences)
view.search_text = text
view.search_flags = flags
开发者ID:andor44,项目名称:qutebrowser,代码行数:30,代码来源:commands.py
示例14: _hint_strings
def _hint_strings(self, elems):
"""Calculate the hint strings for elems.
Inspired by Vimium.
Args:
elems: The elements to get hint strings for.
Return:
A list of hint strings, in the same order as the elements.
"""
if not elems:
return []
hint_mode = self._context.hint_mode
if hint_mode == "word":
try:
return self._word_hinter.hint(elems)
except HintingError as e:
message.error(str(e))
# falls back on letter hints
if hint_mode == "number":
chars = "0123456789"
else:
chars = config.get("hints", "chars")
min_chars = config.get("hints", "min-chars")
if config.get("hints", "scatter") and hint_mode != "number":
return self._hint_scattered(min_chars, chars, elems)
else:
return self._hint_linear(min_chars, chars, elems)
开发者ID:shaggytwodope,项目名称:qutebrowser,代码行数:29,代码来源:hints.py
示例15: _get_search_url
def _get_search_url(txt):
"""Get a search engine URL for a text.
Args:
txt: Text to search for.
Return:
The search URL as a QUrl.
"""
log.url.debug("Finding search engine for '{}'".format(txt))
r = re.compile(r'(^\w+)\s+(.+)($|\s+)')
m = r.search(txt)
if m:
engine = m.group(1)
try:
template = config.get('searchengines', engine)
except configexc.NoOptionError:
template = config.get('searchengines', 'DEFAULT')
term = txt
else:
term = m.group(2).rstrip()
log.url.debug("engine {}, term '{}'".format(engine, term))
else:
template = config.get('searchengines', 'DEFAULT')
term = txt
log.url.debug("engine: default, term '{}'".format(txt))
if not term:
raise FuzzyUrlError("No search term given")
url = qurl_from_user_input(template.format(urllib.parse.quote(term)))
qtutils.ensure_valid(url)
return url
开发者ID:helenst,项目名称:qutebrowser,代码行数:31,代码来源:urlutils.py
示例16: paintEvent
def paintEvent(self, _e):
"""Override paintEvent to draw the tabs like we want to."""
p = QStylePainter(self)
tab = QStyleOptionTab()
selected = self.currentIndex()
for idx in range(self.count()):
self.initStyleOption(tab, idx)
if idx == selected:
color = config.get('colors', 'tab.bg.selected')
elif idx % 2:
color = config.get('colors', 'tab.bg.odd')
else:
color = config.get('colors', 'tab.bg.even')
tab.palette.setColor(QPalette.Window, color)
tab.palette.setColor(QPalette.WindowText,
config.get('colors', 'tab.fg'))
indicator_color = self.tabData(idx)
if indicator_color is None:
indicator_color = QColor()
tab.palette.setColor(QPalette.Base, indicator_color)
if tab.rect.right() < 0 or tab.rect.left() > self.width():
# Don't bother drawing a tab if the entire tab is outside of
# the visible tab bar.
continue
p.drawControl(QStyle.CE_TabBarTab, tab)
开发者ID:har5ha,项目名称:qutebrowser,代码行数:25,代码来源:tabwidget.py
示例17: minimumTabSizeHint
def minimumTabSizeHint(self, index):
"""Set the minimum tab size to indicator/icon/... text.
Args:
index: The index of the tab to get a size hint for.
Return:
A QSize.
"""
icon = self.tabIcon(index)
padding_count = 2
if icon.isNull():
icon_size = QSize(0, 0)
else:
extent = self.style().pixelMetric(QStyle.PM_TabBarIconSize, None,
self)
icon_size = icon.actualSize(QSize(extent, extent))
padding_count += 1
indicator_width = config.get('tabs', 'indicator-width')
if indicator_width != 0:
indicator_width += config.get('tabs', 'indicator-space')
padding_width = self.style().pixelMetric(PM_TabBarPadding, None, self)
height = self.fontMetrics().height()
width = (self.fontMetrics().width('\u2026') +
icon_size.width() + padding_count * padding_width +
indicator_width)
return QSize(width, height)
开发者ID:JIVS,项目名称:qutebrowser,代码行数:27,代码来源:tabwidget.py
示例18: paintEvent
def paintEvent(self, _e):
"""Override paintEvent to draw the tabs like we want to."""
# pylint: disable=bad-config-call
# WORKAROUND for https://bitbucket.org/logilab/astroid/issue/104
p = QStylePainter(self)
selected = self.currentIndex()
for idx in range(self.count()):
tab = QStyleOptionTab()
self.initStyleOption(tab, idx)
bg_parts = ['tabs', 'bg']
fg_parts = ['tabs', 'fg']
if idx == selected:
bg_parts.append('selected')
fg_parts.append('selected')
if idx % 2:
bg_parts.append('odd')
fg_parts.append('odd')
else:
bg_parts.append('even')
fg_parts.append('even')
bg_color = config.get('colors', '.'.join(bg_parts))
fg_color = config.get('colors', '.'.join(fg_parts))
tab.palette.setColor(QPalette.Window, bg_color)
tab.palette.setColor(QPalette.WindowText, fg_color)
indicator_color = self.tab_indicator_color(idx)
tab.palette.setColor(QPalette.Base, indicator_color)
if tab.rect.right() < 0 or tab.rect.left() > self.width():
# Don't bother drawing a tab if the entire tab is outside of
# the visible tab bar.
continue
p.drawControl(QStyle.CE_TabBarTab, tab)
开发者ID:NoctuaNivalis,项目名称:qutebrowser,代码行数:35,代码来源:tabwidget.py
示例19: minimumTabSizeHint
def minimumTabSizeHint(self, index):
"""Set the minimum tab size to indicator/icon/... text.
Args:
index: The index of the tab to get a size hint for.
Return:
A QSize.
"""
icon = self.tabIcon(index)
padding = config.get('tabs', 'padding')
padding_h = padding.left + padding.right
padding_v = padding.top + padding.bottom
if icon.isNull():
icon_size = QSize(0, 0)
else:
extent = self.style().pixelMetric(QStyle.PM_TabBarIconSize, None,
self)
icon_size = icon.actualSize(QSize(extent, extent))
padding_h += self.style().pixelMetric(
PixelMetrics.icon_padding, None, self)
indicator_width = config.get('tabs', 'indicator-width')
height = self.fontMetrics().height() + padding_v
width = (self.fontMetrics().width('\u2026') + icon_size.width() +
padding_h + indicator_width)
return QSize(width, height)
开发者ID:ProtractorNinja,项目名称:qutebrowser,代码行数:26,代码来源:tabwidget.py
示例20: _get_icon_rect
def _get_icon_rect(self, opt, text_rect):
"""Get a QRect for the icon to draw.
Args:
opt: QStyleOptionTab
text_rect: The QRect for the text.
Return:
A QRect.
"""
icon_size = opt.iconSize
if not icon_size.isValid():
icon_extent = self.pixelMetric(QStyle.PM_SmallIconSize)
icon_size = QSize(icon_extent, icon_extent)
icon_mode = (QIcon.Normal if opt.state & QStyle.State_Enabled
else QIcon.Disabled)
icon_state = (QIcon.On if opt.state & QStyle.State_Selected
else QIcon.Off)
# reserve space for favicon when tab bar is vertical (issue #1968)
position = config.get('tabs', 'position')
if (opt.icon.isNull() and
position in [QTabWidget.East, QTabWidget.West] and
config.get('tabs', 'show-favicons')):
tab_icon_size = icon_size
else:
actual_size = opt.icon.actualSize(icon_size, icon_mode, icon_state)
tab_icon_size = QSize(
min(actual_size.width(), icon_size.width()),
min(actual_size.height(), icon_size.height()))
icon_rect = QRect(text_rect.left(), text_rect.top() + 1,
tab_icon_size.width(), tab_icon_size.height())
icon_rect = self._style.visualRect(opt.direction, opt.rect, icon_rect)
return icon_rect
开发者ID:NoctuaNivalis,项目名称:qutebrowser,代码行数:33,代码来源:tabwidget.py
注:本文中的qutebrowser.config.config.get函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论