Now About Social Code
aboutsummaryrefslogtreecommitdiff
path: root/src/message.py
blob: 241ceab9803eb0887d117f7f077e0ef5b418dade (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
# 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/gtk/message.ui')
class WeegtkMessage(Gtk.Box):
    __gtype_name__ = 'WeegtkMessage'

    username = Gtk.Template.Child()
    avatar = Gtk.Template.Child()
    message_list = Gtk.Template.Child()

    def __init__(self, username="username", messages=[], **kwargs):
        super().__init__(**kwargs)

        data = {
            "type": "empty"
        }
        self.set_contents(data)

    def set_contents(self, data):
        if data["type"] == "empty":
            self.set_visible(False)
        else:
            self.set_visible(True)
            self.username.set_label(data["username"])
            self.avatar.set_text(data["username"])

            first = True
            for message in data["text"]:
                margin = 5 if not first else 0
                first = False
                msg = Gtk.Label(label=message, selectable=True,
                                wrap=True, halign=0, hexpand=True, hexpand_set=True,
                                xalign=0, margin_top=margin)
                self.message_list.append(msg)