Now About Social Code
aboutsummaryrefslogtreecommitdiff
path: root/src/message.py
blob: a6e69a42dd5523bcb11a3000c3d992774fd789f7 (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
# 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)

        self.set_contents(username, messages)

    def set_contents(self, username, messages):
        self.username.set_label(username)
        self.avatar.set_text(username)

        first = True
        for message in messages:
            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)