Example #1
0
 def cbRefreshStatus(self):
     self.refreshStatusTimer.stop()
     mac_address = self.cb_mac_address
     name = self.cb_name
     try:
         ret = iBluetoothctl.connect(mac_address)
         if ret is False:
             msg = _("Can't not pair with selected device!")
             self["ConnStatus"].setText(msg)
         else:
             iBluetoothctl.trust(mac_address)
             msg = _("Connection with:\n") + name + " (" + mac_address + ")"
             self["ConnStatus"].setText(msg)
             self["key_yellow"].setText(_("Disconnect"))
     except:
         msg = _("Can't not pair with selected device!")
         self["ConnStatus"].setText(msg)
	def cbRefreshStatus(self):
		self.refreshStatusTimer.stop()
		mac_address = self.cb_mac_address
		name = self.cb_name
		try:
			ret = iBluetoothctl.connect(mac_address)
			if ret is False:
				msg = _("Can't not pair with selected device!")
				self["ConnStatus"].setText(msg)
			else:
				iBluetoothctl.trust(mac_address)
				msg = _("Connection with:\n") + name + " (" + mac_address + ")"
				self["ConnStatus"].setText(msg)
				self["key_yellow"].setText(_("Disconnect"))
		except:
			msg = _("Can't not pair with selected device!")
			self["ConnStatus"].setText(msg)
Example #3
0
    def keyYellow(self):
        if self["key_yellow"].getText() == _('Disconnect'):
            print("[BluetoothManager] Disconnecting")
            if brand not in ("xcore", "edision"):
                cmd = "hidd --killall"
                rc = Console().ePopen(cmd)
                if not rc:
                    self["ConnStatus"].setText(_("No connected to any device"))
                    self["key_yellow"].setText(_("Connect"))
                self.showConnections()
            else:
                paired_devices = iBluetoothctl.get_paired_devices()
                if paired_devices is not None:
                    for d in paired_devices:
                        if d is not None:
                            mac_address = d['mac_address']
                            name = d['name']
                            try:
                                iBluetoothctl.remove(mac_address)
                            except:
                                pass
                            try:
                                iBluetoothctl.disconnect(mac_address)
                            except:
                                pass
                            msg = _("Disconnect with:\n"
                                    ) + name + " (" + mac_address + ")"
                            self["ConnStatus"].setText(msg)
                            self["key_yellow"].setText(_("Connect"))
        else:
            print("[BluetoothManager] Connecting")
            selectedItem = self["devicelist"].getCurrent()
            if selectedItem is None or selectedItem[
                    0] == "Scanning for devices...":  ## If list is empty somehow or somebody pressed button while scanning
                return

            print("[BluetoothManager] trying to pair with: ", selectedItem[1])
            msg = _("Trying to pair with:") + " " + selectedItem[1]
            self["ConnStatus"].setText(msg)

            if brand not in ("xcore", "edision"):
                cmd = "hidd --connect " + selectedItem[1]
                self.taskManager.append(cmd, self.cbPrintAvailConnections,
                                        self.cbRunNextTask)
                cmd = "hidd --show"
                rc = Console().ePopen(cmd)
                if rc:
                    print("[BluetoothManager] can NOT connect with: ",
                          selectedItem[1])
                    msg = _("Can't not pair with selected device!")
                    self["ConnStatus"].setText(msg)
                self.taskManager.append(cmd, self.cbPrintCurrentConnections,
                                        self.cbStopDone)
                self.taskManager.next()
            else:
                mac_address = None
                name = None
                iBluetoothctl.pairable_on()
                iBluetoothctl.start_scan()
                for i in range(0, 20):
                    time.sleep(0.5)
                    available_devices = iBluetoothctl.get_available_devices()
                    if available_devices is not None:
                        for d in available_devices:
                            if selectedItem[1] in str(d):
                                mac_address = d['mac_address']
                                name = d['name']
                    if mac_address is not None:
                        break

                if mac_address is not None:
                    iBluetoothctl.agent_noinputnooutput()
                    iBluetoothctl.default_agent()
                    ret = iBluetoothctl.pair(mac_address)
                    if config.btdevicesmanager.audioaddress.getValue() is "":
                        config.btdevicesmanager.audioaddress.setValue(
                            mac_address)
                    if ret is False:
                        if iBluetoothctl.passkey is not None:
                            self.cb_mac_address = mac_address
                            self.cb_name = name
                            msg = _("Please Enter Passkey: \n"
                                    ) + iBluetoothctl.passkey
                            self["ConnStatus"].setText(msg)
                            self.refreshStatusTimer.start(10000, True)
                    else:
                        iBluetoothctl.trust(mac_address)
                        ret = iBluetoothctl.connect(mac_address)
                        msg = _("Connection with:\n"
                                ) + name + " (" + mac_address + ")"
                        self["ConnStatus"].setText(msg)
                        self["key_yellow"].setText(_("Disconnect"))
                else:
                    print("[BluetoothManager] can NOT connect with: ",
                          selectedItem[1])
                    msg = _("Can't not pair with selected device!")
                    self["ConnStatus"].setText(msg)
	def keyYellow(self):
		if self["key_yellow"].getText() == _('Disconnect'):
			print "[BluetoothManager] Disconnecting"
			if brandoem not in ("xcore","edision"):
				cmd = "hidd --killall"
				rc = os.system(cmd)
				if not rc:
					self["ConnStatus"].setText(_("No connected to any device"))
					self["key_yellow"].setText(_("Connect"))
				self.showConnections()
			else:
				paired_devices = iBluetoothctl.get_paired_devices()
				if paired_devices is not None:
					for d in paired_devices:
						if d is not None:
							mac_address = d['mac_address']
							name = d['name']
							try:
								iBluetoothctl.remove(mac_address)
							except:
								pass
							try:
								iBluetoothctl.disconnect(mac_address)
							except:
								pass
							msg = _("Disconnect with:\n") + name + " (" + mac_address + ")"
							self["ConnStatus"].setText(msg)
							self["key_yellow"].setText(_("Connect"))
		else:
			print "[BluetoothManager] Connecting"
			selectedItem = self["devicelist"].getCurrent()
			if selectedItem is None or selectedItem[0] == "Scanning for devices...": ## If list is empty somehow or somebody pressed button while scanning
				return
			      
			print "[BluetoothManager] trying to pair with: ", selectedItem[1]
			msg = _("Trying to pair with:") + " " + selectedItem[1]
			self["ConnStatus"].setText(msg)
			
			if brandoem not in ("xcore","edision"):
				cmd = "hidd --connect " + selectedItem[1]
				self.taskManager.append(cmd, self.cbPrintAvailConnections, self.cbRunNextTask)
				cmd = "hidd --show"
				rc = os.system(cmd)
				if rc:
					print "[BluetoothManager] can NOT connect with: ", selectedItem[1]
					msg = _("Can't not pair with selected device!")
					self["ConnStatus"].setText(msg)
				self.taskManager.append(cmd, self.cbPrintCurrentConnections, self.cbStopDone)
				self.taskManager.next()
			else:
				mac_address = None
				name = None
				iBluetoothctl.pairable_on()
				iBluetoothctl.start_scan()
				for i in range(0, 20):
					time.sleep(0.5)
					available_devices = iBluetoothctl.get_available_devices()
					if available_devices is not None:
						for d in available_devices:
							if selectedItem[1] in str(d):
								mac_address = d['mac_address']
								name = d['name']
					if mac_address is not None:
						break

				if mac_address is not None:
					iBluetoothctl.agent_noinputnooutput()
					iBluetoothctl.default_agent()
					ret = iBluetoothctl.pair(mac_address)
					if config.btdevicesmanager.audioaddress.getValue() is "":
						config.btdevicesmanager.audioaddress.setValue(mac_address)
					if ret is False:
						if iBluetoothctl.passkey is not None:
							self.cb_mac_address = mac_address
							self.cb_name = name
							msg = _("Please Enter Passkey: \n") + iBluetoothctl.passkey
							self["ConnStatus"].setText(msg)
							self.refreshStatusTimer.start(10000, True)
					else:
						iBluetoothctl.trust(mac_address)
						ret = iBluetoothctl.connect(mac_address)
						msg = _("Connection with:\n") + name + " (" + mac_address + ")"
						self["ConnStatus"].setText(msg)
						self["key_yellow"].setText(_("Disconnect"))
				else:
					print "[BluetoothManager] can NOT connect with: ", selectedItem[1]
					msg = _("Can't not pair with selected device!")
					self["ConnStatus"].setText(msg)