2019-03-26 14:18:19 +00:00
|
|
|
from gi.repository import Gtk
|
|
|
|
|
2019-04-01 20:40:59 +00:00
|
|
|
from uberwriter.settings import Settings
|
2019-04-01 16:00:17 +00:00
|
|
|
from uberwriter.helpers import get_css_path
|
2019-03-26 14:18:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Theme:
|
|
|
|
"""
|
|
|
|
The Theme enum lists all supported themes using their "gtk-theme-name" value.
|
|
|
|
|
|
|
|
The light variant is listed first, followed by the dark variant, if any.
|
|
|
|
"""
|
|
|
|
|
2019-03-29 01:30:43 +00:00
|
|
|
previous = None
|
2019-03-26 14:18:19 +00:00
|
|
|
settings = Settings.new()
|
|
|
|
|
2019-04-19 11:01:43 +00:00
|
|
|
def __init__(self, name, web_css_path, is_dark, inverse_name):
|
2019-03-26 14:18:19 +00:00
|
|
|
self.name = name
|
|
|
|
self.web_css_path = web_css_path
|
|
|
|
self.is_dark = is_dark
|
|
|
|
self.inverse_name = inverse_name
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_for_name(cls, name, default=None):
|
|
|
|
current_theme = default or defaultThemes[0]
|
|
|
|
for theme in defaultThemes:
|
|
|
|
if name == theme.name:
|
|
|
|
current_theme = theme
|
|
|
|
return current_theme
|
|
|
|
|
|
|
|
@classmethod
|
2019-04-14 00:58:45 +00:00
|
|
|
def get_current_changed(cls):
|
2019-03-26 14:18:19 +00:00
|
|
|
theme_name = Gtk.Settings.get_default().get_property('gtk-theme-name')
|
2019-04-27 03:13:48 +00:00
|
|
|
dark_mode_auto = cls.settings.get_boolean('dark-mode-auto')
|
|
|
|
dark_mode = cls.settings.get_boolean('dark-mode')
|
2019-03-26 14:18:19 +00:00
|
|
|
current_theme = cls.get_for_name(theme_name)
|
2019-03-29 00:46:53 +00:00
|
|
|
if not dark_mode_auto and dark_mode != current_theme.is_dark and current_theme.inverse_name:
|
2019-03-26 14:18:19 +00:00
|
|
|
current_theme = cls.get_for_name(current_theme.inverse_name, current_theme.name)
|
2019-03-29 01:30:43 +00:00
|
|
|
changed = current_theme != cls.previous
|
|
|
|
cls.previous = current_theme
|
|
|
|
return current_theme, changed
|
|
|
|
|
2019-04-14 00:58:45 +00:00
|
|
|
@classmethod
|
|
|
|
def get_current(cls):
|
|
|
|
current_theme, _ = cls.get_current_changed()
|
|
|
|
return current_theme
|
|
|
|
|
2019-03-29 01:30:43 +00:00
|
|
|
def __eq__(self, other):
|
|
|
|
return isinstance(other, self.__class__) and \
|
|
|
|
self.name == other.name and \
|
|
|
|
self.web_css_path == other.web_css_path and \
|
|
|
|
self.is_dark == other.is_dark and \
|
|
|
|
self.inverse_name == other.inverse_name
|
2019-03-26 14:18:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
defaultThemes = [
|
|
|
|
# https://gitlab.gnome.org/GNOME/gtk/tree/master/gtk/theme/Adwaita
|
2019-04-19 11:08:11 +00:00
|
|
|
Theme('Adwaita', get_css_path('web/adwaita.css'), False, 'Adwaita-dark'),
|
|
|
|
Theme('Adwaita-dark', get_css_path('web/adwaita_dark.css'), True, 'Adwaita'),
|
2019-03-26 14:20:43 +00:00
|
|
|
# https://github.com/NicoHood/arc-theme/tree/master/common/gtk-3.0/3.20/sass
|
2019-04-19 11:08:11 +00:00
|
|
|
Theme('Arc', get_css_path('web/arc.css'), False, 'Arc-Dark'),
|
|
|
|
Theme('Arc-Darker', get_css_path('web/arc_darker.css'), False, 'Arc-Dark'),
|
|
|
|
Theme('Arc-Dark', get_css_path('web/arc_dark.css'), True, 'Arc'),
|
2019-03-26 14:21:12 +00:00
|
|
|
# https://gitlab.gnome.org/GNOME/gtk/tree/master/gtk/theme/HighContrast
|
2019-04-19 11:08:11 +00:00
|
|
|
Theme('HighContrast', get_css_path('web/highcontrast.css'), False, 'HighContrastInverse'),
|
|
|
|
Theme('HighContrastInverse', get_css_path('web/highcontrast_inverse.css'), True, 'HighContrast')
|
2019-03-26 14:18:19 +00:00
|
|
|
]
|