You need to sign in or sign up before continuing.
window.py 2.49 KB
Newer Older
1
from .utils import write_config, configure_cr_widgets
2
from .utils import make_gtk3_themes_list, make_kv_themes_list, separate_themes
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

from gi.repository import Adw
from gi.repository import Gtk, Gio

@Gtk.Template(resource_path='/ru/ximperlinux/UnifiedThemeSwitcher/window.ui')
class XimperUnifiedThemeSwitcherGuiGtk4Window(Adw.ApplicationWindow):
    __gtype_name__ = 'XimperUnifiedThemeSwitcherGuiGtk4Window'
    
    kv_light_cr = Gtk.Template.Child()
    kv_dark_cr = Gtk.Template.Child()
    
    gtk3_light_cr = Gtk.Template.Child()
    gtk3_dark_cr = Gtk.Template.Child()
    
    change_style_btn = Gtk.Template.Child()
    
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        kv_themes_list = make_kv_themes_list()
        gtk3_themes_list = make_gtk3_themes_list()
23 24
        
        kv_light_themes_list, kv_dark_themes_list, gtk3_light_themes_list, gtk3_dark_themes_list = separate_themes(kv_themes_list, gtk3_themes_list)
25 26

        crs_configurations = [
27 28 29 30
            (self.kv_light_cr, kv_light_themes_list, "KV_LIGHT_THEME"),
            (self.kv_dark_cr, kv_dark_themes_list, "KV_DARK_THEME"),
            (self.gtk3_light_cr, gtk3_light_themes_list, "GTK3_LIGHT_THEME"),
            (self.gtk3_dark_cr, gtk3_dark_themes_list, "GTK3_DARK_THEME")
31 32 33
        ]
        configure_cr_widgets(crs_configurations, self.cr_theme_selected)
 
Roman Alifanov's avatar
Roman Alifanov committed
34 35 36 37 38
        if Gio.Settings.new('org.gnome.desktop.interface').get_string('color-scheme') == 'prefer-dark':
            self.change_style_btn.set_active(True)
        else:
            self.change_style_btn.set_active(False)
            
39
        self.change_style_btn.connect('clicked', self.change_style, "1")
Roman Alifanov's avatar
Roman Alifanov committed
40
        
41 42 43 44 45 46 47
    def cr_theme_selected(self, cr, _pspec, cfg_key):
        cfg_new_value = cr.props.selected_item.props.string
        
        if cfg_new_value is not None and cfg_key is not None:
            print(f"For {cfg_key} selected {cfg_new_value}")
            write_config(cfg_key, cfg_new_value)
    
Roman Alifanov's avatar
Roman Alifanov committed
48
    def change_style(self, _button, name):
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
        schema = 'org.gnome.desktop.interface'
        key = 'color-scheme'

        # Получить текущее значение color-scheme
        settings = Gio.Settings.new(schema)
        current_theme = settings.get_string(key)

        # Установить новое значение color-scheme
        if current_theme == 'default':
            style = 'prefer-dark'
        else:
            style = 'default'

        settings.set_string(key, style)
        print(f"Color scheme changed to: {style}")