Now About Social Code
aboutsummaryrefslogtreecommitdiff
path: root/src/window.py
blob: 8a4eab74655020f3aae19ced7ab3796d08383fa5 (plain)
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
# window.py
#
# Copyright 2024 Lucas Fryzek
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later

from gi.repository import Adw
from gi.repository import Gtk

@Gtk.Template(resource_path='/com/fryzekconcepts/weegtk/window.ui')
class WeegtkWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'WeegtkWindow'

    stack = Gtk.Template.Child()
    content_page = Gtk.Template.Child()
    color_scheme_button = Gtk.Template.Child()
    split_view = Gtk.Template.Child()
    primary_menu = Gtk.Template.Child()

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        manager = Adw.StyleManager.get_default()

        manager.connect("notify::system-supports-color-schemes",
                        self.notify_system_supports_color_schemes_cb,
                        self,
                        False)

        self.notify_system_supports_color_schemes_cb()
        self.notify_visible_child_cb()

    def set_connect_label(self):
        pass

    def notify_system_supports_color_schemes_cb(self):
        manager = Adw.StyleManager.get_default()
        supports = manager.get_system_supports_color_schemes()

        self.color_scheme_button.set_visible(not supports)

        if supports:
            manager.set_color_scheme(Adw.ColorScheme.DEFAULT)

    @Gtk.Template.Callback()
    def notify_visible_child_cb(self, *args):
        child = self.stack.get_visible_child()
        # When application starts up there are no buffers
        if child is None:
            return
        page = self.stack.get_page(child)
        page_title = "Weegtk" if page.get_title() is None else page.get_title()
        self.content_page.set_title(page_title)
        self.split_view.set_show_content(True)

    def set_page(self, page):
        page_name = page.get_name()
        self.stack.set_visible_child_name(page_name)

    @Gtk.Template.Callback()
    def get_color_scheme_icon_name(self, user_data, dark):
        return "light-mode-symbolic" if dark else "dark-mode-symbolic"

    @Gtk.Template.Callback()
    def color_scheme_button_clicked_cb(self, *args):
        raise NotImplementedError