#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright (C) 2013 Agustin Zubiaga # 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 gi.repository import Gdk from gi.repository import GdkPixbuf from gi.repository import GObject import os from sugar3.activity import activity from sugar3.graphics import style from sugar3.graphics.icon import Icon from gettext import gettext as _ ICONS_DIR = os.path.join(activity.get_bundle_path(), "icons") def get_icon(icon_id): icon_path = os.path.join(ICONS_DIR, icon_id + ".svg") if not os.path.exists(icon_path): icon_path = os.path.join(ICONS_DIR, "bluetooth.svg") return icon_path class DeviceList(Gtk.TreeView): def __init__(self): super(DeviceList, self).__init__() self.model = Gtk.ListStore(GdkPixbuf.Pixbuf, str, str) self.set_model(self.model) column = Gtk.TreeViewColumn('Devices') cell = Gtk.CellRendererPixbuf() column.pack_start(cell, False) column.add_attribute(cell, "pixbuf", 0) self.append_column(column) column = Gtk.TreeViewColumn() cell = Gtk.CellRendererText() column.pack_start(cell, True) column.add_attribute(cell, "markup", 1) self.append_column(column) column = Gtk.TreeViewColumn() cell = Gtk.CellRendererText() column.pack_start(cell, False) column.add_attribute(cell, "markup", 2) self.append_column(column) #self.modify_base(Gdk.Color(255, 255, 255)) def add_device(self, i): icon = get_icon(i["Icon"]) pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(icon, style.GRID_CELL_SIZE, style.GRID_CELL_SIZE) self.model.append([pixbuf, '%s' % i["Name"], '%s' % i["Address"]]) def set_devices(self, devices): for i in devices: self.add_device(i) class EmptyWidgets(Gtk.EventBox): __gsignals__ = { 'search-again': (GObject.SignalFlags.RUN_FIRST, None, [])} def __init__(self): Gtk.EventBox.__init__(self) self.modify_bg(Gtk.StateType.NORMAL, style.COLOR_WHITE.get_gdk_color()) vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) mvbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) vbox.pack_start(mvbox, True, False, 0) image_icon = Icon(pixel_size=style.LARGE_ICON_SIZE, file='activity/activity-bluetooth.svg', stroke_color=style.COLOR_BUTTON_GREY.get_svg(), fill_color=style.COLOR_TRANSPARENT.get_svg()) mvbox.pack_start(image_icon, False, False, style.DEFAULT_PADDING) label = Gtk.Label('%s' % (style.COLOR_BUTTON_GREY.get_html(), _('No devices found'))) label.set_use_markup(True) mvbox.pack_start(label, False, False, style.DEFAULT_PADDING) hbox = Gtk.Box() search_btn = Gtk.Button() search_btn.connect('clicked', lambda w: self.emit('search-again')) refresh_image = Gtk.Image.new_from_stock(Gtk.STOCK_REFRESH, Gtk.IconSize.BUTTON) buttonbox = Gtk.Box() buttonbox.pack_start(refresh_image, False, True, 0) buttonbox.pack_end(Gtk.Label(_('Search again')), True, True, 5) search_btn.add(buttonbox) hbox.pack_start(search_btn, True, False, 0) mvbox.pack_start(hbox, False, False, style.DEFAULT_PADDING) self.add(vbox) self.show_all()