# Path: kano_settings/common.py
# IMAGES_DIR = os.path.join(media, "Graphics")
# 
# Path: kano_settings/templates.py
# class Template(Gtk.Box):
# 
#     def __init__(
#         self,
#         title,
#         description,
#         button_text,
#         is_plug=False,
#         back_btn=False
#     ):
# 
#         Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
# 
#         self.title = Heading(title, description, is_plug, back_btn)
#         self.title.container.set_margin_bottom(0)
#         self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
#         self.align = Gtk.Alignment(xscale=0, yscale=0, xalign=0.5, yalign=0.3)
#         self.align.add(self.box)
#         self.kano_button = KanoButton(button_text)
#         self.kano_button.pack_and_align()
#         self.kano_button.align.set_padding(0, 30, 0, 0)
# 
#         self.pack_start(self.title.container, False, False, 0)
#         self.pack_start(self.align, True, True, 0)
#         self.pack_end(self.kano_button.align, False, False, 0)
# 
#     def set_prev_callback(self, cb):
#         self.title.set_prev_callback(cb)
# 
# Path: kano_settings/system/bt/interface.py
# def is_bluetooth_available():
#     try:
#         dbus_obj_paths = get_dbus_object_paths()
# 
#         return BASE_DEVICE_OBJ_PATH in dbus_obj_paths
#     except Exception as e:
#         logger.error("Couldn't connect to DBus to see if bluetooth is " \
#                      "available, asuming not",
#                      exception=e)
#         return False
# 
# def device_scan(callback, clear=True, timeout=10, *cb_args, **cb_kwargs):
#     if not is_bluetooth_available():
#         logger.warn("No bluetooth available")
#         return
# 
#     if clear:
#         clear_all_devices()
# 
#     def parse_results(callback):
#         stop_discovering_devices()
#         devices = get_available_devices()
#         callback(devices, *cb_args, **cb_kwargs)
# 
#     scan_thr = threading.Timer(
#         timeout, parse_results, kwargs={'callback': callback}
#     )
# 
#     discover_devices()
#     scan_thr.start()


import os
import threading
from gi import require_version
from gi.repository import Gtk, GObject
from kano.gtk3.scrolled_window import ScrolledWindow
from kano.gtk3.buttons import KanoButton
from kano.gtk3.kano_dialog import KanoDialog
from kano.gtk3.blur_overlay import BlurOverlay
from kano.logging import logger
from kano.decorators import queue_cb
from kano_settings.common import IMAGES_DIR
from kano_settings.templates import Template
from kano_settings.system.bt.interface import is_bluetooth_available, \
    device_scan
        def _end_populate():
            self.unset_loading()

        @queue_cb(callback=_end_populate, gtk=True)
        def _do_populate(devices):
            if not devices:
                logger.info("No devices")
                GObject.idle_add(self.set_no_devices_nearby)

            for idx, device in enumerate(devices):
                logger.info("Adding device {}".format(device))
                GObject.idle_add(self.add_device, device, idx)

        if not is_bluetooth_available():
            logger.info("No adapter")
            self.set_no_adapter_available()
            return

        self.set_loading()
        device_scan(_do_populate)


    def refresh(self, *dummy_args, **dummy_kwargs):
        self.empty()
        self.populate()


class BluetoothConfig(Template):

    def __init__(self, win):

# Path: kano_settings/common.py
# IMAGES_DIR = os.path.join(media, "Graphics")
# 
# Path: kano_settings/templates.py
# class Template(Gtk.Box):
# 
#     def __init__(
#         self,
#         title,
#         description,
#         button_text,
#         is_plug=False,
#         back_btn=False
#     ):
# 
#         Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
# 
#         self.title = Heading(title, description, is_plug, back_btn)
#         self.title.container.set_margin_bottom(0)
#         self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
#         self.align = Gtk.Alignment(xscale=0, yscale=0, xalign=0.5, yalign=0.3)
#         self.align.add(self.box)
#         self.kano_button = KanoButton(button_text)
#         self.kano_button.pack_and_align()
#         self.kano_button.align.set_padding(0, 30, 0, 0)
# 
#         self.pack_start(self.title.container, False, False, 0)
#         self.pack_start(self.align, True, True, 0)
#         self.pack_end(self.kano_button.align, False, False, 0)
# 
#     def set_prev_callback(self, cb):
#         self.title.set_prev_callback(cb)
# 
# Path: kano_settings/system/bt/interface.py
# def is_bluetooth_available():
#     try:
#         dbus_obj_paths = get_dbus_object_paths()
# 
#         return BASE_DEVICE_OBJ_PATH in dbus_obj_paths
#     except Exception as e:
#         logger.error("Couldn't connect to DBus to see if bluetooth is " \
#                      "available, asuming not",
#                      exception=e)
#         return False
# 
# def device_scan(callback, clear=True, timeout=10, *cb_args, **cb_kwargs):
#     if not is_bluetooth_available():
#         logger.warn("No bluetooth available")
#         return
# 
#     if clear:
#         clear_all_devices()
# 
#     def parse_results(callback):
#         stop_discovering_devices()
#         devices = get_available_devices()
#         callback(devices, *cb_args, **cb_kwargs)
# 
#     scan_thr = threading.Timer(
#         timeout, parse_results, kwargs={'callback': callback}
#     )
# 
#     discover_devices()
#     scan_thr.start()


# Path: kano_settings/bluetooth_config.py
import os
import threading
from gi import require_version
from gi.repository import Gtk, GObject
from kano.gtk3.scrolled_window import ScrolledWindow
from kano.gtk3.buttons import KanoButton
from kano.gtk3.kano_dialog import KanoDialog
from kano.gtk3.blur_overlay import BlurOverlay
from kano.logging import logger
from kano.decorators import queue_cb
from kano_settings.common import IMAGES_DIR
from kano_settings.templates import Template
from kano_settings.system.bt.interface import is_bluetooth_available, \
    device_scan

        def _end_populate():
            self.unset_loading()

        @queue_cb(callback=_end_populate, gtk=True)
        def _do_populate(devices):
            if not devices:
                logger.info("No devices")
                GObject.idle_add(self.set_no_devices_nearby)

            for idx, device in enumerate(devices):
                logger.info("Adding device {}".format(device))
                GObject.idle_add(self.add_device, device, idx)

        if not is_bluetooth_available():
            logger.info("No adapter")
            self.set_no_adapter_available()
            return

        self.set_loading()
        device_scan(_do_populate)


    def refresh(self, *dummy_args, **dummy_kwargs):
        self.empty()
        self.populate()


class BluetoothConfig(Template):

    def __init__(self, win):

        Template.__init__(