# Copyright (C) 2012 Agustin Zubiaga # Copyright (C) 2012 Gonzalo Odiard # 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()