Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/fontslist.py
blob: 85115013e4d9044353a14d59b0ea35ea183d690e (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
81
82
83
84
85
86
87
# Copyright (C) 2012 Agustin Zubiaga <aguz@sugarlabs.org>
# Copyright (C) 2012 Gonzalo Odiard <godiard@sugarlabs.org>

# 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, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

from gi.repository import Gtk
from sugar3.graphics import style


class FontsList(Gtk.EventBox):

    def __init__(self):
        super(FontsList, self).__init__()

        self.modify_bg(Gtk.StateType.NORMAL,
                       style.COLOR_WHITE.get_gdk_color())

        self.vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.vbox.set_spacing(6)
        self.add(self.vbox)

        self.load_fonts()

        self.show()

    def load_fonts(self):
        for i in range(7):
            item = FontItem('Font Preview')
            self.vbox.pack_start(item, False, False, 0)
            item.queue_draw()


class FontItem(Gtk.EventBox):

    def __init__(self, fontname):
        super(FontItem, self).__init__()

        hbox = Gtk.Box()
        checkbutton = Gtk.CheckButton()
        #checkbutton.connect()
        fontpreview = Gtk.Label(fontname)
        hbox.pack_start(checkbutton, False, False, 10)
        hbox.pack_start(fontpreview, False, True, 5)

        height = style.GRID_CELL_SIZE
        self.set_size_request(-1, height)

        self.connect('draw', self._on_draw)

        self.add(hbox)
        self.show_all()

    def _on_draw(self, widget, context):
        alloc = widget.get_allocation()

        x = float(style.DEFAULT_PADDING)
        y = 0
        w = float(alloc.width - (style.DEFAULT_PADDING * 2))
        h = style.GRID_CELL_SIZE
        r = style.zoom(10)

        context.move_to(x + r, y)
        context.line_to(x + w - r, y)
        context.curve_to(x + w, y, x + w, y, x + w, y + r)
        context.line_to(x + w, y + h - r)
        context.curve_to(x + w, y + h, x + w, y + h, x + w - r, y + h)
        context.line_to(x + r, y + h)
        context.curve_to(x, y + h, x, y + h, x, y + h - r)
        context.line_to(x, y + r)
        context.curve_to(x, y, x, y, x + r, y)
        context.close_path()

        panel_grey = style.COLOR_PANEL_GREY.get_rgba()
        context.set_source_rgba(*panel_grey)
        context.fill_preserve()