Beispiel #1
0
    def populate_bluetooth_panel(self):
        """
                Populates the bluetooth panel
        """
        # clear discovered and paired lists
        self.BTD.reset()
        self.BTP.reset()

        # enable all controls
        self.toggle_controls(True, BLUETOOTH_CONTROLS)
        # disable all if bluetooth is not detected
        if not osmc_bluetooth.is_bluetooth_available():
            self.toggle_controls(False, BLUETOOTH_CONTROLS)
            return
        else:
            if not osmc_bluetooth.is_bluetooth_enabled():
                controls_to_disable = list(BLUETOOTH_CONTROLS)
                controls_to_disable.remove(BLUETOOTH_ENABLE_TOGGLE)
                self.toggle_controls(False, controls_to_disable)
                return

        bluetoothRadioButton = self.getControl(10301)
        bluetoothRadioButton.setSelected(osmc_bluetooth.is_bluetooth_enabled())
        discoveryRadioButton = self.getControl(10303)
        discoveryRadioButton.setSelected(osmc_bluetooth.is_discovering())

        bluetooth_paired_dict = self.populate_bluetooth_dict(True)
        bluetooth_discovered_dict = self.populate_bluetooth_dict(False)

        # add paired devices to the list
        self.paired_bluetooths = list(
            self.create_bluetooth_items(bluetooth_paired_dict))
        # sort the list of paired based on alias
        self.paired_bluetooths.sort(key=self.sort_alias)
        # remove everything from the existing panel
        self.BTP.reset()
        # add the paired devices
        self.BTP.addItems(self.paired_bluetooths)

        # add discovered devices to the list
        self.discovered_bluetooths = list(
            self.create_bluetooth_items(bluetooth_discovered_dict))
        # sort the list of discovered based on alias
        self.discovered_bluetooths.sort(key=self.sort_alias)
        # remove everything from the existing panel
        self.BTD.reset()
        # add the paired devices
        self.BTD.addItems(self.discovered_bluetooths)
Beispiel #2
0
    def populate_bluetooth_panel(self):
        bluetoothRadioButton = self.getControl(BLUETOOTH_ENABLE_TOGGLE)
        bluetoothRadioButton.setSelected(osmc_bluetooth.is_bluetooth_enabled())

        # disable all if bluetooth is not enabled
        if not osmc_bluetooth.is_bluetooth_enabled():
            # disable all controls
            self.toggle_controls(False, BLUETOOTH_CONTROLS)
            return

        self.toggle_controls(True, BLUETOOTH_CONTROLS)
        discoveryRadioButton = self.getControl(BLUETOOTH_DISCOVERY)
        discoveryRadioButton.setSelected(osmc_bluetooth.is_discovering())

        self.bluetooth_population_thread = bluetooth_population_thread(self.BTD, self.BTP)
        self.bluetooth_population_thread.setDaemon(True)
        self.bluetooth_population_thread.start()
Beispiel #3
0
    def populate_bluetooth_panel(self):
        bluetoothRadioButton = self.getControl(BLUETOOTH_ENABLE_TOGGLE)
        bluetoothRadioButton.setSelected(osmc_bluetooth.is_bluetooth_enabled())

        # disable all if bluetooth is not enabled
        if not osmc_bluetooth.is_bluetooth_enabled():
            # disable all controls
            self.toggle_controls(False, BLUETOOTH_CONTROLS)
            return

        self.toggle_controls(True, BLUETOOTH_CONTROLS)
        discoveryRadioButton = self.getControl(BLUETOOTH_DISCOVERY)
        discoveryRadioButton.setSelected(osmc_bluetooth.is_discovering())

        self.bluetooth_population_thread = bluetooth_population_thread(
            self.BTD, self.BTP)
        self.bluetooth_population_thread.setDaemon(True)
        self.bluetooth_population_thread.start()
Beispiel #4
0
    def populate_bluetooth_panel(self):
        """
                Populates the bluetooth panel
        """
        # clear discovered and paired lists
        self.BTD.reset()
        self.BTP.reset()

        bluetoothRadioButton = self.getControl(10301)
        bluetoothRadioButton.setSelected(osmc_bluetooth.is_bluetooth_enabled())

        # disable all if bluetooth is not enabled
        if not osmc_bluetooth.is_bluetooth_enabled():
            # disable all controls
            self.toggle_controls(False, BLUETOOTH_CONTROLS)
            return

        self.toggle_controls(True, BLUETOOTH_CONTROLS)
        discoveryRadioButton = self.getControl(BLUETOOTH_DISCOVERY)

        discoveryRadioButton.setSelected(osmc_bluetooth.is_discovering())

        bluetooth_paired_dict = self.populate_bluetooth_dict(True)
        bluetooth_discovered_dict = self.populate_bluetooth_dict(False)

        # add paired devices to the list
        self.paired_bluetooths = list(self.create_bluetooth_items(bluetooth_paired_dict))
        # sort the list of paired based on alias
        self.paired_bluetooths.sort(key=self.sort_alias)
        # remove everything from the existing panel
        self.BTP.reset()
        # add the paired devices
        self.BTP.addItems(self.paired_bluetooths)

        # add discovered devices to the list
        self.discovered_bluetooths = list(self.create_bluetooth_items(bluetooth_discovered_dict))
        # sort the list of discovered based on alias
        self.discovered_bluetooths.sort(key=self.sort_alias)
        # remove everything from the existing panel
        self.BTD.reset()
        # add the paired devices
        self.BTD.addItems(self.discovered_bluetooths)
Beispiel #5
0
    def handle_bluetooth_selection(self, control_id):
        if control_id == BLUETOOTH_ENABLE_TOGGLE:  # Enable Bluetooth
            if osmc_bluetooth.is_bluetooth_enabled():
                osmc_bluetooth.toggle_bluetooth_state(False)
            else:
                osmc_bluetooth.toggle_bluetooth_state(True)

        if control_id == BLUETOOTH_DISCOVERY:  # Discovery
            if not osmc_bluetooth.is_discovering():
                osmc_bluetooth.start_discovery()
            else:
                osmc_bluetooth.stop_discovery()
            xbmc.sleep(100)

        if control_id == 6000:  # paired devices
            item = self.BTP.getSelectedItem()
            if item:
                address = item.getProperty('address')
                alias = item.getProperty('alias')
                # 'Bluetooth' , 'Remove Device'
                if DIALOG.yesno(lang(32020), lang(32021) + ' ' + alias + '?'):
                    osmc_bluetooth.remove_device(address)
                self.setFocusId(BLUETOOTH_ENABLE_TOGGLE)

        if control_id == 7000:  # Discovered devices
            item = self.BTD.getSelectedItem()
            if item:
                address = item.getProperty('address')
                alias = item.getProperty('alias')
                #              'Connect With Device'            'No'     Pair and Connect'    'pair'
                selection = DIALOG.select(
                    lang(32022) + ' ' + alias + '?',
                    [lang(32055), lang(32056),
                     lang(32057)])
                if selection == 0:
                    return
                if selection == 1:
                    self.show_busy_dialogue()
                    script_base_path = os.path.join(
                        __addon__.getAddonInfo('path'), 'resources',
                        'lib') + '/'
                    result = osmc_bluetooth.pair_device(
                        address, script_base_path)
                    self.setFocusId(BLUETOOTH_DISCOVERY)
                    if not result:
                        #         'Pairing with'                       'failed'
                        message = lang(32024) + ' ' + alias + ' ' + lang(32025)
                        #                                                     'Bluetooth'
                        xbmc.executebuiltin("XBMC.Notification(%s,%s,%s)" %
                                            (lang(32020), message, "2500"))
                        return
                    self.clear_busy_dialogue()
                osmc_bluetooth.connect_device(address)
                osmc_bluetooth.set_device_trusted(address, True)
Beispiel #6
0
    def handle_bluetooth_selection(self, control_id):
        if control_id == BLUETOOTH_ENABLE_TOGGLE:  # Enable Bluetooth
            self.show_busy_dialogue()
            if osmc_bluetooth.is_bluetooth_enabled():
                osmc_bluetooth.toggle_bluetooth_state(False)
            else:
                osmc_bluetooth.toggle_bluetooth_state(True)
            self.clear_busy_dialogue()

        if control_id == BLUETOOTH_DISCOVERY:  # Discovery
            if not osmc_bluetooth.is_discovering():
                osmc_bluetooth.start_discovery()
            else:
                osmc_bluetooth.stop_discovery()
            xbmc.sleep(100)

        if control_id == 6000:  # paired devices
            item = self.BTP.getSelectedItem()
            if item:
                address = item.getProperty('address')
                alias = item.getProperty('alias')
                # 'Bluetooth' , 'Remove Device'
                if DIALOG.yesno(lang(32020), lang(32021) + ' ' + alias + '?'):
                    osmc_bluetooth.remove_device(address)
                    self.setFocusId(BLUETOOTH_ENABLE_TOGGLE)
                    self.bluetooth_population_thread.update_bluetooth_lists()

        if control_id == 7000:  # Discovered devices
            item = self.BTD.getSelectedItem()
            if item:
                address = item.getProperty('address')
                alias = item.getProperty('alias')
                #              'Connect With Device'            'No'     Pair and Connect'    'pair'
                selection = DIALOG.select(lang(32022) + ' ' + alias + '?', [lang(32055),lang(32056), lang(32057)])
                if selection == 0:
                    return
                self.show_busy_dialogue()
                self.setFocusId(BLUETOOTH_DISCOVERY)
                if selection == 1:
                    script_base_path = os.path.join(__addon__.getAddonInfo('path'), 'resources', 'lib') + '/'
                    result = osmc_bluetooth.pair_device(address, script_base_path)

                    if not result:
                        #         'Pairing with'                       'failed'
                        message = lang(32024) + ' ' + alias + ' ' + lang(32025)
                        #                                                     'Bluetooth'
                        xbmc.executebuiltin("XBMC.Notification(%s,%s,%s)" % (lang(32020), message, "2500"))
                        return
                osmc_bluetooth.connect_device(address)
                osmc_bluetooth.set_device_trusted(address, True)
                self.bluetooth_population_thread.update_bluetooth_lists()
                self.clear_busy_dialogue()
Beispiel #7
0
    def populate_bluetooth_panel(self):
        bluetoothRadioButton = self.getControl(BLUETOOTH_ENABLE_TOGGLE)
        bluetoothRadioButton.setSelected(osmc_bluetooth.is_bluetooth_enabled())

        # disable all if bluetooth is not enabled
        if not osmc_bluetooth.is_bluetooth_enabled():
            # disable all controls
            self.toggle_controls(False, BLUETOOTH_CONTROLS)
            return

        self.toggle_controls(True, BLUETOOTH_CONTROLS)
        discoveryRadioButton = self.getControl(BLUETOOTH_DISCOVERY)
        discoveryRadioButton.setSelected(osmc_bluetooth.is_discovering())
        # Start Bluetooth Poulation Thread
        threadRunning = False
        for t in threading.enumerate():
            if t.getName() == BLUETOOTH_THREAD_NAME:
                threadRunning = True
        if not threadRunning:
            log('Starting ' + BLUETOOTH_THREAD_NAME)
            self.bluetooth_population_thread = bluetooth_population_thread(self.BTD, self.BTP)
            self.bluetooth_population_thread.setDaemon(True)
            self.bluetooth_population_thread.start()
Beispiel #8
0
    def populate_bluetooth_panel(self):
        bluetoothRadioButton = self.getControl(BLUETOOTH_ENABLE_TOGGLE)
        bluetoothRadioButton.setSelected(osmc_bluetooth.is_bluetooth_enabled())

        # disable all if bluetooth is not enabled
        if not osmc_bluetooth.is_bluetooth_enabled():
            # disable all controls
            self.toggle_controls(False, BLUETOOTH_CONTROLS)
            return

        self.toggle_controls(True, BLUETOOTH_CONTROLS)
        discoveryRadioButton = self.getControl(BLUETOOTH_DISCOVERY)
        discoveryRadioButton.setSelected(osmc_bluetooth.is_discovering())
        # Start Bluetooth Poulation Thread
        threadRunning = False
        for t in threading.enumerate():
            if t.getName() == BLUETOOTH_THREAD_NAME:
                threadRunning = True
        if not threadRunning:
            log('Starting ' + BLUETOOTH_THREAD_NAME)
            self.bluetooth_population_thread = bluetooth_population_thread(
                self.BTD, self.BTP)
            self.bluetooth_population_thread.setDaemon(True)
            self.bluetooth_population_thread.start()
Beispiel #9
0
    def run(self):
        runs = 0
        while not self.exit:
            # ask the thread to exit if bluetooth is no longer enabled
            if not osmc_bluetooth.is_bluetooth_enabled():
                self.stop_thread()
            # update gui every 2 seconds
            if runs % 200 == 0 and not self.exit:
                self.update_bluetooth_lists()
            # every 4 seconds output debug info
            if runs % 400 == 0 and not self.exit:
                log('-- DISCOVERED ---')
                log(self.discovered_dict)
                log('-- TRUSTED --')
                log(self.trusted_dict)

            xbmc.sleep(10)
            runs += 1
        log('Bluetooth thread ended')
Beispiel #10
0
    def handle_bluetooth_selection(self, control_id):
        # 10300 - No Action Here - Refresh - populate_bluetooth_panel() will be called by calling code
        if control_id == BLUETOOTH_ENABLE_TOGGLE:  # Enable Bluetooth
            if osmc_bluetooth.is_bluetooth_enabled():
                osmc_bluetooth.toggle_bluetooth_state(False)
            else:
                osmc_bluetooth.toggle_bluetooth_state(True)

        if control_id == BLUETOOTH_DISCOVERY:  # Discovery
            if not osmc_bluetooth.is_discovering():
                osmc_bluetooth.start_discovery()
            else:
                osmc_bluetooth.stop_discovery()
            time.sleep(1)

        if control_id == 6000:  # paired devices
            item = self.BTP.getSelectedItem()
            if item:
                address = item.getProperty('address')
                alias = item.getProperty('alias')
                # 'Bluetooth' , 'Remove Device'
                if DIALOG.yesno(lang(32020), lang(32021) + ' ' + alias + '?'):
                    osmc_bluetooth.remove_device(address)
                    self.setFocusId(BLUETOOTH_REFRESH)

        if control_id == 7000:  # Discovered devices
            item = self.BTD.getSelectedItem()
            if item:
                address = item.getProperty('address')
                alias = item.getProperty('alias')
                # 'Bluetooth' ,        'Pair with Device'
                if DIALOG.yesno(lang(32020), lang(32022) + ' ' + alias + '?'):
                    script_base_path = os.path.join(__addon__.getAddonInfo('path'), 'resources', 'lib') + '/'
                    result = osmc_bluetooth.pair_device(address, script_base_path)
                    self.setFocusId(BLUETOOTH_REFRESH)
                    if result:
                        # 'Paired Sucessfully with'
                        message = lang(32023) + ' ' + alias
                    else:
                        # 'Pairing with'                            'failed'
                        message = lang(32024) + ' ' + alias + ' ' + lang(32025)
                    # 'Bluetooth'
                    xbmc.executebuiltin("XBMC.Notification(%s,%s,%s)" % (lang(32020), message, "2500"))
Beispiel #11
0
    def run(self):
        runs = 0
        while not self.exit:
            # ask the thread to exit if bluetooth is no longer enabled
            if not osmc_bluetooth.is_bluetooth_enabled():
                self.stop_thread()
            # update gui every 2 seconds
            if runs % 200 == 0:
                trusted_dict = self.populate_bluetooth_dict(True)
                discovered_dict = self.populate_bluetooth_dict(False)
                 # every 5 seconds output debug info
                log('-- DISCOVERED ---')
                log(discovered_dict)
                log('-- TRUSTED --')
                log(trusted_dict)
                self.update_list_control(discovered_dict, self.discovered_list_control)
                self.update_list_control(trusted_dict, self.trusted_list_control)

            xbmc.sleep(10)
            runs += 1
Beispiel #12
0
    def run(self):
        runs = 0
        while not self.exit:
            # ask the thread to exit if bluetooth is no longer enabled
            if not osmc_bluetooth.is_bluetooth_enabled():
                self.stop_thread()
            # update gui every 2 seconds
            if runs % 200 == 0:
                trusted_dict = self.populate_bluetooth_dict(True)
                discovered_dict = self.populate_bluetooth_dict(False)
                # every 5 seconds output debug info
                log('-- DISCOVERED ---')
                log(discovered_dict)
                log('-- TRUSTED --')
                log(trusted_dict)
                self.update_list_control(discovered_dict,
                                         self.discovered_list_control)
                self.update_list_control(trusted_dict,
                                         self.trusted_list_control)

            xbmc.sleep(10)
            runs += 1
Beispiel #13
0
    def handle_bluetooth_selection(self, control_id):
        # 10300 - No Action Here - Refresh - populate_bluetooth_panel() will be called by calling code
        if control_id == 10301:  # Enable Bluetooth
            osmc_bluetooth.toggle_bluetooth_state(
                not osmc_bluetooth.is_bluetooth_enabled())

        if control_id == 10303:  # Discovery
            if not osmc_bluetooth.is_discovering():
                osmc_bluetooth.start_discovery()
            else:
                osmc_bluetooth.stop_discovery()

        if control_id == 6000:  # paired devices
            item = self.BTP.getSelectedItem()
            address = item.getProperty('address')
            alias = item.getProperty('alias')
            # 'Bluetooth' , 'Remove Device'
            if DIALOG.yesno(lang(32020), lang(32021) + ' ' + alias + '?'):
                osmc_bluetooth.remove_device(address)

        if control_id == 7000:  # Discovered devices
            item = self.BTD.getSelectedItem()
            address = item.getProperty('address')
            alias = item.getProperty('alias')
            # 'Bluetooth' , 'Pair with Device'
            if DIALOG.yesno(lang(32020), lang(32022) + ' ' + alias + '?'):
                script_base_path = os.path.join(__addon__.getAddonInfo('path'),
                                                'resources', 'lib') + '/'
                result = osmc_bluetooth.pair_device(address, script_base_path)
                if result:
                    # 'Paired Sucessfully with'
                    message = lang(32023) + ' ' + alias
                else:
                    # 'Pairing with'         'failed'
                    message = lang(32024) + alias + lang(320025)
                # 'Bluetooth'
                xbmc.executebuiltin("XBMC.Notification(%s,%s,%s)" %
                                    (lang(32020), message, "2500"))