user-stylesheet can be read from relative paths
This ist just a first draft to approach issue622 (https://github.com/The-Compiler/qutebrowser/issues/622) and my very first babysteps with python. With this change it is possible to set a user-stylesheet with a relative path, eg.: :set ui user-stylesheet mystyle.css where mystyle.css is in the ~/.config/qutebrowser/.
This commit is contained in:
parent
ee0eabc202
commit
58f031630c
2
.gitignore
vendored
2
.gitignore
vendored
@ -22,3 +22,5 @@ __pycache__
|
||||
/htmlcov
|
||||
/.tox
|
||||
/testresults.html
|
||||
tags
|
||||
*.swp
|
||||
|
@ -34,6 +34,7 @@ from PyQt5.QtWidgets import QTabWidget, QTabBar
|
||||
|
||||
from qutebrowser.commands import cmdutils
|
||||
from qutebrowser.config import configexc
|
||||
from qutebrowser.utils import standarddir
|
||||
|
||||
|
||||
SYSTEM_PROXY = object() # Return value for Proxy type
|
||||
@ -792,6 +793,9 @@ class RegexList(List):
|
||||
raise configexc.ValidationError(value, "items may not be empty!")
|
||||
|
||||
|
||||
# TODO(lamar) Issue622, relative paths for some config files and directories
|
||||
# should be implemented here in the base class for files and below in the base
|
||||
# class for directories.
|
||||
class File(BaseType):
|
||||
|
||||
"""A file on the local filesystem."""
|
||||
@ -806,6 +810,10 @@ class File(BaseType):
|
||||
raise configexc.ValidationError(value, "may not be empty!")
|
||||
value = os.path.expanduser(value)
|
||||
try:
|
||||
if not os.path.isabs(value):
|
||||
relpath = os.path.join(standarddir.config(), value)
|
||||
if os.path.isfile(relpath):
|
||||
value = relpath
|
||||
if not os.path.isfile(value):
|
||||
raise configexc.ValidationError(value, "must be a valid file!")
|
||||
if not os.path.isabs(value):
|
||||
@ -1160,6 +1168,10 @@ class UserStyleSheet(File):
|
||||
value = os.path.expandvars(value)
|
||||
value = os.path.expanduser(value)
|
||||
try:
|
||||
if not os.path.isabs(value):
|
||||
relpath = os.path.join(standarddir.config(), value)
|
||||
if os.path.isfile(relpath):
|
||||
value = relpath
|
||||
if not os.path.isabs(value):
|
||||
# probably a CSS, so we don't handle it as filename.
|
||||
# FIXME We just try if it is encodable, maybe we should
|
||||
|
Loading…
Reference in New Issue
Block a user