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:
parent
5d490a4e22
commit
4652843b38
@ -737,7 +737,11 @@ class CommandDispatcher:
|
|||||||
count: How many steps to zoom in.
|
count: How many steps to zoom in.
|
||||||
"""
|
"""
|
||||||
tab = self._current_widget()
|
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',
|
@cmdutils.register(instance='command-dispatcher', scope='window',
|
||||||
count='count')
|
count='count')
|
||||||
@ -748,7 +752,11 @@ class CommandDispatcher:
|
|||||||
count: How many steps to zoom out.
|
count: How many steps to zoom out.
|
||||||
"""
|
"""
|
||||||
tab = self._current_widget()
|
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',
|
@cmdutils.register(instance='command-dispatcher', scope='window',
|
||||||
count='count')
|
count='count')
|
||||||
@ -768,7 +776,12 @@ class CommandDispatcher:
|
|||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise cmdexc.CommandError(e)
|
raise cmdexc.CommandError(e)
|
||||||
tab = self._current_widget()
|
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')
|
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||||
def tab_only(self, left=False, right=False):
|
def tab_only(self, left=False, right=False):
|
||||||
|
@ -33,7 +33,6 @@ from qutebrowser.config import config
|
|||||||
from qutebrowser.keyinput import modeman
|
from qutebrowser.keyinput import modeman
|
||||||
from qutebrowser.utils import message, log, usertypes, utils, qtutils, objreg
|
from qutebrowser.utils import message, log, usertypes, utils, qtutils, objreg
|
||||||
from qutebrowser.browser import webpage, hints, webelem
|
from qutebrowser.browser import webpage, hints, webelem
|
||||||
from qutebrowser.commands import cmdexc
|
|
||||||
|
|
||||||
|
|
||||||
LoadStatus = usertypes.enum('LoadStatus', ['none', 'success', 'error', 'warn',
|
LoadStatus = usertypes.enum('LoadStatus', ['none', 'success', 'error', 'warn',
|
||||||
@ -369,9 +368,8 @@ class WebView(QWebView):
|
|||||||
if fuzzyval:
|
if fuzzyval:
|
||||||
self._zoom.fuzzyval = int(perc)
|
self._zoom.fuzzyval = int(perc)
|
||||||
if perc < 0:
|
if perc < 0:
|
||||||
raise cmdexc.CommandError("Can't zoom {}%!".format(perc))
|
raise ValueError("Can't zoom {}%!".format(perc))
|
||||||
self.setZoomFactor(float(perc) / 100)
|
self.setZoomFactor(float(perc) / 100)
|
||||||
message.info(self.win_id, "Zoom level: {}%".format(perc))
|
|
||||||
self._default_zoom_changed = True
|
self._default_zoom_changed = True
|
||||||
|
|
||||||
def zoom(self, offset):
|
def zoom(self, offset):
|
||||||
@ -379,9 +377,13 @@ class WebView(QWebView):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
offset: The offset in the zoom level list.
|
offset: The offset in the zoom level list.
|
||||||
|
|
||||||
|
Return:
|
||||||
|
The new zoom percentage.
|
||||||
"""
|
"""
|
||||||
level = self._zoom.getitem(offset)
|
level = self._zoom.getitem(offset)
|
||||||
self.zoom_perc(level, fuzzyval=False)
|
self.zoom_perc(level, fuzzyval=False)
|
||||||
|
return level
|
||||||
|
|
||||||
@pyqtSlot('QUrl')
|
@pyqtSlot('QUrl')
|
||||||
def on_url_changed(self, url):
|
def on_url_changed(self, url):
|
||||||
|
Loading…
Reference in New Issue
Block a user