Move command-related zoom logic out of WebView.

After f8d66f3fe1 loading a session showed the
zoom percentage of all tabs.

This logic doesn't really belong into webview.py anyways, so it gets moved to
browser/commands.py here.
This commit is contained in:
Florian Bruhin 2015-06-24 23:06:55 +02:00
parent 5d490a4e22
commit 4652843b38
2 changed files with 21 additions and 6 deletions

View File

@ -737,7 +737,11 @@ class CommandDispatcher:
count: How many steps to zoom in.
"""
tab = self._current_widget()
tab.zoom(count)
try:
perc = tab.zoom(count)
except ValueError as e:
raise cmdexc.CommandError(e)
message.info(self._win_id, "Zoom level: {}%".format(perc))
@cmdutils.register(instance='command-dispatcher', scope='window',
count='count')
@ -748,7 +752,11 @@ class CommandDispatcher:
count: How many steps to zoom out.
"""
tab = self._current_widget()
tab.zoom(-count)
try:
perc = tab.zoom(-count)
except ValueError as e:
raise cmdexc.CommandError(e)
message.info(self._win_id, "Zoom level: {}%".format(perc))
@cmdutils.register(instance='command-dispatcher', scope='window',
count='count')
@ -768,7 +776,12 @@ class CommandDispatcher:
except ValueError as e:
raise cmdexc.CommandError(e)
tab = self._current_widget()
tab.zoom_perc(level)
try:
tab.zoom_perc(level)
except ValueError as e:
raise cmdexc.CommandError(e)
message.info(self._win_id, "Zoom level: {}%".format(level))
@cmdutils.register(instance='command-dispatcher', scope='window')
def tab_only(self, left=False, right=False):

View File

@ -33,7 +33,6 @@ from qutebrowser.config import config
from qutebrowser.keyinput import modeman
from qutebrowser.utils import message, log, usertypes, utils, qtutils, objreg
from qutebrowser.browser import webpage, hints, webelem
from qutebrowser.commands import cmdexc
LoadStatus = usertypes.enum('LoadStatus', ['none', 'success', 'error', 'warn',
@ -369,9 +368,8 @@ class WebView(QWebView):
if fuzzyval:
self._zoom.fuzzyval = int(perc)
if perc < 0:
raise cmdexc.CommandError("Can't zoom {}%!".format(perc))
raise ValueError("Can't zoom {}%!".format(perc))
self.setZoomFactor(float(perc) / 100)
message.info(self.win_id, "Zoom level: {}%".format(perc))
self._default_zoom_changed = True
def zoom(self, offset):
@ -379,9 +377,13 @@ class WebView(QWebView):
Args:
offset: The offset in the zoom level list.
Return:
The new zoom percentage.
"""
level = self._zoom.getitem(offset)
self.zoom_perc(level, fuzzyval=False)
return level
@pyqtSlot('QUrl')
def on_url_changed(self, url):