1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# MIT License
#
# Copyright (c) 2024 Unknown
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# SPDX-License-Identifier: MIT
from .utils import write_config, configure_cr_widgets
from .utils import make_gtk3_themes_list, make_kv_themes_list, separate_themes
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)
self.change_style_btn.connect('clicked', self.change_style)
kv_themes_list = make_kv_themes_list()
gtk3_themes_list = make_gtk3_themes_list()
kv_light_themes_list, kv_dark_themes_list, gtk3_light_themes_list, gtk3_dark_themes_list = separate_themes(kv_themes_list, gtk3_themes_list)
crs_configurations = [
(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")
]
configure_cr_widgets(crs_configurations, self.cr_theme_selected)
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)
def change_style(self, _button):
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}")