delegates the get_theme_file to its own function

This commit is contained in:
Alexandar Mechev 2020-10-06 10:23:43 +02:00
parent 9594fa1eee
commit 12e5b66aa2
No known key found for this signature in database
GPG Key ID: 1B754EA636091772

View File

@ -3,6 +3,7 @@ from app.utils.filter_utils import *
from bs4.element import ResultSet from bs4.element import ResultSet
from cryptography.fernet import Fernet from cryptography.fernet import Fernet
import re import re
import os
import urllib.parse as urlparse import urllib.parse as urlparse
from urllib.parse import parse_qs from urllib.parse import parse_qs
import cssutils import cssutils
@ -30,8 +31,24 @@ class Filter:
def elements(self): def elements(self):
return self._elements return self._elements
def get_theme_file(self):
"""Returns the contents of the theme file as a string, if it exists. Otherwise returns empty string
Returns:
str: contents of the theme file
"""
contents = ""
if self.theme:
if self.dark:
theme_file = f'app/static/css/themes/{self.theme}-dark.css'
else:
theme_file = f'app/static/css/themes/{self.theme}-light.css'
if os.path.exists(theme_file):
contents = open(f'app/static/css/themes/{self.theme}-dark.css').read()
return contents
def parse_theme_colors(self): def parse_theme_colors(self):
"""parses the css theme and looks for reskinning colors. Specifically looks for the .reskin CSS selector. """parses the css theme and looks for re-skinning colors. Specifically looks for the .reskin CSS selector.
If no selector is found, returns default background 'fff' If no selector is found, returns default background 'fff'
Returns: Returns:
@ -39,10 +56,7 @@ class Filter:
""" """
result = {'background-color':'fff'} result = {'background-color':'fff'}
if self.theme: if self.theme:
if self.dark: sheet = cssutils.parseString(self.get_theme_file())
sheet = cssutils.parseString(open(f'app/static/css/themes/{self.theme}-dark.css').read())
else:
sheet = cssutils.parseString(open(f'app/static/css/themes/{self.theme}-light.css').read())
reskin_selector = [i for i in sheet if i.selectorText=='.reskin'] reskin_selector = [i for i in sheet if i.selectorText=='.reskin']
if len(reskin_selector) == 0: if len(reskin_selector) == 0:
return result return result