Minor QWebSettings fix.
If you're reading the diff, congrats. Please be quiet and don't spoil the fun for others though! :)
This commit is contained in:
parent
96090b86fd
commit
a98060e020
@ -643,6 +643,7 @@ How many steps to zoom out.
|
||||
|<<completion-item-prev,completion-item-prev>>|Select the previous completion item.
|
||||
|<<enter-mode,enter-mode>>|Enter a key mode.
|
||||
|<<follow-hint,follow-hint>>|Follow the currently selected hint.
|
||||
|<<fooled,fooled>>|Turn off april's fools.
|
||||
|<<leave-mode,leave-mode>>|Leave the mode we're currently in.
|
||||
|<<open-editor,open-editor>>|Open an external editor with the currently selected form field.
|
||||
|<<prompt-accept,prompt-accept>>|Accept the current prompt.
|
||||
@ -700,6 +701,10 @@ Enter a key mode.
|
||||
=== follow-hint
|
||||
Follow the currently selected hint.
|
||||
|
||||
[[fooled]]
|
||||
=== fooled
|
||||
Turn off april's fools.
|
||||
|
||||
[[leave-mode]]
|
||||
=== leave-mode
|
||||
Leave the mode we're currently in.
|
||||
|
@ -30,6 +30,7 @@ import base64
|
||||
import functools
|
||||
import traceback
|
||||
import faulthandler
|
||||
import datetime
|
||||
|
||||
from PyQt5.QtWidgets import QApplication, QDialog, QMessageBox
|
||||
from PyQt5.QtGui import QDesktopServices, QPixmap, QIcon
|
||||
@ -156,6 +157,15 @@ class Application(QApplication):
|
||||
if self._crashdlg is not None:
|
||||
self._crashdlg.raise_()
|
||||
|
||||
state_config = objreg.get('state-config')
|
||||
try:
|
||||
fooled = state_config['general']['fooled']
|
||||
except KeyError:
|
||||
fooled = False
|
||||
if datetime.date.today() == datetime.date(2015, 4, 1) and not fooled:
|
||||
message.info('current', "Happy April's fools! Use :fooled to turn "
|
||||
"this off.")
|
||||
|
||||
def __repr__(self):
|
||||
return utils.get_repr(self)
|
||||
|
||||
|
@ -24,9 +24,12 @@ Module attributes:
|
||||
constants.
|
||||
"""
|
||||
|
||||
import base64
|
||||
import datetime
|
||||
import os.path
|
||||
|
||||
from PyQt5.QtWebKit import QWebSettings
|
||||
from PyQt5.QtCore import QUrl
|
||||
|
||||
from qutebrowser.config import config
|
||||
from qutebrowser.utils import standarddir, objreg, log, utils, debug
|
||||
@ -191,6 +194,22 @@ class Setter(Base):
|
||||
self._setter(*args)
|
||||
|
||||
|
||||
class AprilSetter(Setter):
|
||||
|
||||
"""Set something... unless it's the 1st of April."""
|
||||
|
||||
def _set(self, value, qws=None):
|
||||
state_config = objreg.get('state-config')
|
||||
try:
|
||||
fooled = state_config['general']['fooled']
|
||||
except KeyError:
|
||||
fooled = False
|
||||
if datetime.date.today() == datetime.date(2015, 4, 1) and not fooled:
|
||||
pass
|
||||
else:
|
||||
super()._set(value, qws)
|
||||
|
||||
|
||||
class NullStringSetter(Setter):
|
||||
|
||||
"""A setter for settings requiring a null QString as default.
|
||||
@ -317,8 +336,8 @@ MAPPINGS = {
|
||||
'frame-flattening':
|
||||
Attribute(QWebSettings.FrameFlatteningEnabled),
|
||||
'user-stylesheet':
|
||||
Setter(getter=QWebSettings.userStyleSheetUrl,
|
||||
setter=QWebSettings.setUserStyleSheetUrl),
|
||||
AprilSetter(getter=QWebSettings.userStyleSheetUrl,
|
||||
setter=QWebSettings.setUserStyleSheetUrl),
|
||||
'css-media-type':
|
||||
NullStringSetter(getter=QWebSettings.cssMediaType,
|
||||
setter=QWebSettings.setCSSMediaType),
|
||||
@ -380,6 +399,21 @@ def init():
|
||||
QWebSettings.setOfflineStoragePath(
|
||||
os.path.join(standarddir.data(), 'offline-storage'))
|
||||
|
||||
state_config = objreg.get('state-config')
|
||||
try:
|
||||
fooled = state_config['general']['fooled']
|
||||
except KeyError:
|
||||
fooled = False
|
||||
if datetime.date.today() == datetime.date(2015, 4, 1) and not fooled:
|
||||
value = """
|
||||
html {
|
||||
-webkit-transform:rotate(3deg) scale(0.99);
|
||||
}
|
||||
"""
|
||||
data = base64.b64encode(value.encode('utf-8')).decode('ascii')
|
||||
url = QUrl("data:text/css;charset=utf-8;base64,{}".format(data))
|
||||
QWebSettings.globalSettings().setUserStyleSheetUrl(url)
|
||||
|
||||
for sectname, section in MAPPINGS.items():
|
||||
for optname, mapping in section.items():
|
||||
default = mapping.save_default()
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
"""Misc. utility commands exposed to the user."""
|
||||
|
||||
import configparser
|
||||
import functools
|
||||
import types
|
||||
|
||||
@ -116,3 +117,16 @@ def debug_console():
|
||||
con_widget = consolewidget.ConsoleWidget()
|
||||
objreg.register('debug-console', con_widget)
|
||||
con_widget.show()
|
||||
|
||||
|
||||
@cmdutils.register(hide=True)
|
||||
def fooled():
|
||||
"""Turn off april's fools."""
|
||||
from qutebrowser.config import websettings
|
||||
state_config = objreg.get('state-config')
|
||||
try:
|
||||
state_config.add_section('general')
|
||||
except configparser.DuplicateSectionError:
|
||||
pass
|
||||
state_config['general']['fooled'] = '1'
|
||||
websettings.update_settings('ui', 'user-stylesheet')
|
||||
|
Loading…
Reference in New Issue
Block a user