mirror of https://gitlab.com/bashrc2/epicyon
Set dyslexic font during theme change
parent
c18056becc
commit
0c4b8e11c2
33
daemon.py
33
daemon.py
|
@ -2152,7 +2152,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
debug: bool, access_keys: {},
|
debug: bool, access_keys: {},
|
||||||
default_timeline: str, theme_name: str,
|
default_timeline: str, theme_name: str,
|
||||||
allow_local_network_access: bool,
|
allow_local_network_access: bool,
|
||||||
system_language: str) -> None:
|
system_language: str,
|
||||||
|
dyslexic_font: bool) -> None:
|
||||||
"""Receive POST from webapp_theme_designer
|
"""Receive POST from webapp_theme_designer
|
||||||
"""
|
"""
|
||||||
users_path = '/users/' + nickname
|
users_path = '/users/' + nickname
|
||||||
|
@ -2191,7 +2192,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
allow_local_network_access,
|
allow_local_network_access,
|
||||||
system_language)
|
system_language)
|
||||||
set_theme(base_dir, theme_name, domain,
|
set_theme(base_dir, theme_name, domain,
|
||||||
allow_local_network_access, system_language)
|
allow_local_network_access, system_language,
|
||||||
|
dyslexic_font)
|
||||||
|
|
||||||
if calling_domain.endswith('.onion') and onion_domain:
|
if calling_domain.endswith('.onion') and onion_domain:
|
||||||
origin_path_str = \
|
origin_path_str = \
|
||||||
|
@ -2240,7 +2242,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
set_theme_from_designer(base_dir, theme_name, domain,
|
set_theme_from_designer(base_dir, theme_name, domain,
|
||||||
theme_designer_params,
|
theme_designer_params,
|
||||||
allow_local_network_access,
|
allow_local_network_access,
|
||||||
system_language)
|
system_language, dyslexic_font)
|
||||||
|
|
||||||
# set boolean values
|
# set boolean values
|
||||||
if 'rss-icon-at-top' in theme_designer_params:
|
if 'rss-icon-at-top' in theme_designer_params:
|
||||||
|
@ -5066,7 +5068,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.theme_name = fields['themeDropdown']
|
self.server.theme_name = fields['themeDropdown']
|
||||||
set_theme(base_dir, self.server.theme_name, domain,
|
set_theme(base_dir, self.server.theme_name, domain,
|
||||||
allow_local_network_access,
|
allow_local_network_access,
|
||||||
system_language)
|
system_language,
|
||||||
|
self.server.dyslexic_font)
|
||||||
self.server.text_mode_banner = \
|
self.server.text_mode_banner = \
|
||||||
get_text_mode_banner(self.server.base_dir)
|
get_text_mode_banner(self.server.base_dir)
|
||||||
self.server.iconsCache = {}
|
self.server.iconsCache = {}
|
||||||
|
@ -6002,7 +6005,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.allow_local_network_access
|
self.server.allow_local_network_access
|
||||||
set_theme(base_dir, curr_theme, domain,
|
set_theme(base_dir, curr_theme, domain,
|
||||||
allow_local_network_access,
|
allow_local_network_access,
|
||||||
system_language)
|
system_language,
|
||||||
|
self.server.dyslexic_font)
|
||||||
self.server.text_mode_banner = \
|
self.server.text_mode_banner = \
|
||||||
get_text_mode_banner(base_dir)
|
get_text_mode_banner(base_dir)
|
||||||
self.server.iconsCache = {}
|
self.server.iconsCache = {}
|
||||||
|
@ -6256,12 +6260,20 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
# dyslexic font
|
# dyslexic font
|
||||||
if path.startswith('/users/' + admin_nickname + '/') or \
|
if path.startswith('/users/' + admin_nickname + '/') or \
|
||||||
is_artist(base_dir, nickname):
|
is_artist(base_dir, nickname):
|
||||||
self.server.dyslexic_font = False
|
dyslexic_font = False
|
||||||
if fields.get('dyslexicFont'):
|
if fields.get('dyslexicFont'):
|
||||||
if fields['dyslexicFont'] == 'on':
|
if fields['dyslexicFont'] == 'on':
|
||||||
self.server.dyslexic_font = True
|
dyslexic_font = True
|
||||||
set_config_param(base_dir, 'dyslexicFont',
|
if dyslexic_font != self.server.dyslexic_font:
|
||||||
self.server.dyslexic_font)
|
self.server.dyslexic_font = dyslexic_font
|
||||||
|
set_config_param(base_dir, 'dyslexicFont',
|
||||||
|
self.server.dyslexic_font)
|
||||||
|
set_theme(base_dir,
|
||||||
|
self.server.theme_name,
|
||||||
|
self.server.domain,
|
||||||
|
self.server.allow_local_network_access,
|
||||||
|
self.server.system_language,
|
||||||
|
self.server.dyslexic_font)
|
||||||
|
|
||||||
# low bandwidth images checkbox
|
# low bandwidth images checkbox
|
||||||
if path.startswith('/users/' + admin_nickname + '/') or \
|
if path.startswith('/users/' + admin_nickname + '/') or \
|
||||||
|
@ -18157,7 +18169,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.default_timeline,
|
self.server.default_timeline,
|
||||||
self.server.theme_name,
|
self.server.theme_name,
|
||||||
allow_local_network_access,
|
allow_local_network_access,
|
||||||
self.server.system_language)
|
self.server.system_language,
|
||||||
|
self.server.dyslexic_font)
|
||||||
self.server.postreq_busy = False
|
self.server.postreq_busy = False
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -3196,7 +3196,8 @@ if twitter_domain:
|
||||||
args.twitter_replacement_domain = twitter_domain
|
args.twitter_replacement_domain = twitter_domain
|
||||||
|
|
||||||
if set_theme(base_dir, theme_name, domain,
|
if set_theme(base_dir, theme_name, domain,
|
||||||
args.allow_local_network_access, args.language):
|
args.allow_local_network_access, args.language,
|
||||||
|
args.dyslexic_font):
|
||||||
print('Theme set to ' + theme_name)
|
print('Theme set to ' + theme_name)
|
||||||
|
|
||||||
# whether new registrations are open or closed
|
# whether new registrations are open or closed
|
||||||
|
|
8
tests.py
8
tests.py
|
@ -145,7 +145,7 @@ from content import replace_content_duplicates
|
||||||
from content import remove_text_formatting
|
from content import remove_text_formatting
|
||||||
from content import remove_html_tag
|
from content import remove_html_tag
|
||||||
from theme import update_default_themes_list
|
from theme import update_default_themes_list
|
||||||
from theme import set_cs_sparam
|
from theme import set_css_param
|
||||||
from theme import scan_themes_for_scripts
|
from theme import scan_themes_for_scripts
|
||||||
from linked_data_sig import generate_json_signature
|
from linked_data_sig import generate_json_signature
|
||||||
from linked_data_sig import verify_json_signature
|
from linked_data_sig import verify_json_signature
|
||||||
|
@ -3584,18 +3584,18 @@ def _test_save_load_json():
|
||||||
def _test_theme():
|
def _test_theme():
|
||||||
print('test_theme')
|
print('test_theme')
|
||||||
css = 'somestring --background-value: 24px; --foreground-value: 24px;'
|
css = 'somestring --background-value: 24px; --foreground-value: 24px;'
|
||||||
result = set_cs_sparam(css, 'background-value', '32px')
|
result = set_css_param(css, 'background-value', '32px')
|
||||||
assert result == \
|
assert result == \
|
||||||
'somestring --background-value: 32px; --foreground-value: 24px;'
|
'somestring --background-value: 32px; --foreground-value: 24px;'
|
||||||
css = \
|
css = \
|
||||||
'somestring --background-value: 24px; --foreground-value: 24px; ' + \
|
'somestring --background-value: 24px; --foreground-value: 24px; ' + \
|
||||||
'--background-value: 24px;'
|
'--background-value: 24px;'
|
||||||
result = set_cs_sparam(css, 'background-value', '32px')
|
result = set_css_param(css, 'background-value', '32px')
|
||||||
assert result == \
|
assert result == \
|
||||||
'somestring --background-value: 32px; --foreground-value: 24px; ' + \
|
'somestring --background-value: 32px; --foreground-value: 24px; ' + \
|
||||||
'--background-value: 32px;'
|
'--background-value: 32px;'
|
||||||
css = '--background-value: 24px; --foreground-value: 24px;'
|
css = '--background-value: 24px; --foreground-value: 24px;'
|
||||||
result = set_cs_sparam(css, 'background-value', '32px')
|
result = set_css_param(css, 'background-value', '32px')
|
||||||
assert result == '--background-value: 32px; --foreground-value: 24px;'
|
assert result == '--background-value: 32px; --foreground-value: 24px;'
|
||||||
|
|
||||||
|
|
||||||
|
|
43
theme.py
43
theme.py
|
@ -269,7 +269,7 @@ def _remove_theme(base_dir: str):
|
||||||
base_dir + '/' + filename)
|
base_dir + '/' + filename)
|
||||||
|
|
||||||
|
|
||||||
def set_cs_sparam(css: str, param: str, value: str) -> str:
|
def set_css_param(css: str, param: str, value: str) -> str:
|
||||||
"""Sets a CSS parameter to a given value
|
"""Sets a CSS parameter to a given value
|
||||||
"""
|
"""
|
||||||
# is this just a simple string replacement?
|
# is this just a simple string replacement?
|
||||||
|
@ -380,7 +380,7 @@ def _set_theme_from_dict(base_dir: str, name: str,
|
||||||
else:
|
else:
|
||||||
_set_publish_button_at_top(base_dir, False)
|
_set_publish_button_at_top(base_dir, False)
|
||||||
continue
|
continue
|
||||||
css = set_cs_sparam(css, param_name, param_value)
|
css = set_css_param(css, param_name, param_value)
|
||||||
filename = base_dir + '/' + filename
|
filename = base_dir + '/' + filename
|
||||||
with open(filename, 'w+') as cssfile:
|
with open(filename, 'w+') as cssfile:
|
||||||
cssfile.write(css)
|
cssfile.write(css)
|
||||||
|
@ -457,6 +457,27 @@ def disable_grayscale(base_dir: str) -> None:
|
||||||
grayscale_filename)
|
grayscale_filename)
|
||||||
|
|
||||||
|
|
||||||
|
def _set_dyslexic_font(base_dir: str) -> bool:
|
||||||
|
"""sets the dyslexic font if needed
|
||||||
|
"""
|
||||||
|
theme_files = _get_theme_files()
|
||||||
|
for filename in theme_files:
|
||||||
|
template_filename = base_dir + '/' + filename
|
||||||
|
if not os.path.isfile(template_filename):
|
||||||
|
continue
|
||||||
|
with open(template_filename, 'r') as cssfile:
|
||||||
|
css = cssfile.read()
|
||||||
|
css = \
|
||||||
|
set_css_param(css, "*src",
|
||||||
|
"url('./fonts/OpenDyslexic-Regular.woff2" +
|
||||||
|
"') format('woff2')")
|
||||||
|
css = set_css_param(css, "*font-family", "'OpenDyslexic'")
|
||||||
|
filename = base_dir + '/' + filename
|
||||||
|
with open(filename, 'w+') as cssfile:
|
||||||
|
cssfile.write(css)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _set_custom_font(base_dir: str):
|
def _set_custom_font(base_dir: str):
|
||||||
"""Uses a dictionary to set a theme
|
"""Uses a dictionary to set a theme
|
||||||
"""
|
"""
|
||||||
|
@ -484,12 +505,12 @@ def _set_custom_font(base_dir: str):
|
||||||
with open(template_filename, 'r') as cssfile:
|
with open(template_filename, 'r') as cssfile:
|
||||||
css = cssfile.read()
|
css = cssfile.read()
|
||||||
css = \
|
css = \
|
||||||
set_cs_sparam(css, "*src",
|
set_css_param(css, "*src",
|
||||||
"url('./fonts/custom." +
|
"url('./fonts/custom." +
|
||||||
custom_font_ext +
|
custom_font_ext +
|
||||||
"') format('" +
|
"') format('" +
|
||||||
custom_font_type + "')")
|
custom_font_type + "')")
|
||||||
css = set_cs_sparam(css, "*font-family", "'CustomFont'")
|
css = set_css_param(css, "*font-family", "'CustomFont'")
|
||||||
filename = base_dir + '/' + filename
|
filename = base_dir + '/' + filename
|
||||||
with open(filename, 'w+') as cssfile:
|
with open(filename, 'w+') as cssfile:
|
||||||
cssfile.write(css)
|
cssfile.write(css)
|
||||||
|
@ -498,11 +519,13 @@ def _set_custom_font(base_dir: str):
|
||||||
def set_theme_from_designer(base_dir: str, theme_name: str, domain: str,
|
def set_theme_from_designer(base_dir: str, theme_name: str, domain: str,
|
||||||
theme_params: {},
|
theme_params: {},
|
||||||
allow_local_network_access: bool,
|
allow_local_network_access: bool,
|
||||||
system_language: str):
|
system_language: str,
|
||||||
|
dyslexic_font: bool):
|
||||||
custom_theme_filename = base_dir + '/accounts/theme.json'
|
custom_theme_filename = base_dir + '/accounts/theme.json'
|
||||||
save_json(theme_params, custom_theme_filename)
|
save_json(theme_params, custom_theme_filename)
|
||||||
set_theme(base_dir, theme_name, domain,
|
set_theme(base_dir, theme_name, domain,
|
||||||
allow_local_network_access, system_language)
|
allow_local_network_access, system_language,
|
||||||
|
dyslexic_font)
|
||||||
|
|
||||||
|
|
||||||
def reset_theme_designer_settings(base_dir: str, theme_name: str, domain: str,
|
def reset_theme_designer_settings(base_dir: str, theme_name: str, domain: str,
|
||||||
|
@ -819,7 +842,8 @@ def _set_clear_cache_flag(base_dir: str) -> None:
|
||||||
|
|
||||||
|
|
||||||
def set_theme(base_dir: str, name: str, domain: str,
|
def set_theme(base_dir: str, name: str, domain: str,
|
||||||
allow_local_network_access: bool, system_language: str) -> bool:
|
allow_local_network_access: bool, system_language: str,
|
||||||
|
dyslexic_font: bool) -> bool:
|
||||||
"""Sets the theme with the given name as the current theme
|
"""Sets the theme with the given name as the current theme
|
||||||
"""
|
"""
|
||||||
result = False
|
result = False
|
||||||
|
@ -862,7 +886,10 @@ def set_theme(base_dir: str, name: str, domain: str,
|
||||||
_read_variables_file(base_dir, name, variables_file,
|
_read_variables_file(base_dir, name, variables_file,
|
||||||
allow_local_network_access)
|
allow_local_network_access)
|
||||||
|
|
||||||
_set_custom_font(base_dir)
|
if dyslexic_font:
|
||||||
|
_set_dyslexic_font(base_dir)
|
||||||
|
else:
|
||||||
|
_set_custom_font(base_dir)
|
||||||
|
|
||||||
# set the news avatar
|
# set the news avatar
|
||||||
news_avatar_theme_filename = \
|
news_avatar_theme_filename = \
|
||||||
|
|
Loading…
Reference in New Issue