2019-11-11 07:17:43 -06:00
|
|
|
import os
|
|
|
|
import json
|
|
|
|
from pgadmin.utils.preferences import Preferences
|
|
|
|
|
|
|
|
|
|
|
|
def get_all_themes():
|
2019-11-20 03:35:20 -06:00
|
|
|
# Themes file is copied in generated directory
|
2019-11-11 07:17:43 -06:00
|
|
|
theme_file_path = os.path.join(
|
|
|
|
os.path.dirname(os.path.realpath(__file__)),
|
2019-11-20 03:35:20 -06:00
|
|
|
'../../static/js/generated',
|
2019-11-11 07:17:43 -06:00
|
|
|
'pgadmin.themes.json'
|
|
|
|
)
|
|
|
|
|
|
|
|
all_themes = {
|
|
|
|
"standard": {
|
|
|
|
"disp_name": "Standard",
|
|
|
|
"cssfile": "pgadmin",
|
|
|
|
"preview_img": "standard_preview.png"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try:
|
|
|
|
all_themes.update(json.load(open(theme_file_path)))
|
2022-01-12 03:23:19 -06:00
|
|
|
except Exception:
|
2019-11-11 07:17:43 -06:00
|
|
|
pass
|
|
|
|
|
|
|
|
return all_themes
|
|
|
|
|
|
|
|
|
2020-07-06 01:18:23 -05:00
|
|
|
def themes(app):
|
2019-11-11 07:17:43 -06:00
|
|
|
@app.context_processor
|
|
|
|
def inject_theme_func():
|
|
|
|
def get_theme_css():
|
|
|
|
all_themes = get_all_themes()
|
|
|
|
theme_css = all_themes['standard']['cssfile'] + '.css'
|
2021-09-09 03:40:37 -05:00
|
|
|
theme = 'standard'
|
2019-11-11 07:17:43 -06:00
|
|
|
try:
|
|
|
|
misc_preference = Preferences.module('misc')
|
|
|
|
theme = misc_preference.preference('theme').get()
|
2020-06-26 02:48:27 -05:00
|
|
|
if theme in all_themes:
|
2019-11-11 07:17:43 -06:00
|
|
|
theme_css = all_themes[theme]['cssfile'] + '.css'
|
|
|
|
except Exception:
|
|
|
|
# Let the default theme go if exception occurs
|
|
|
|
pass
|
|
|
|
|
2021-06-29 04:03:36 -05:00
|
|
|
return theme_css, theme
|
2019-11-11 07:17:43 -06:00
|
|
|
|
|
|
|
return {
|
|
|
|
'get_theme_css': get_theme_css,
|
|
|
|
}
|