Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import kivy
- kivy.require("1.9.0")
- from kivy.app import App
- from kivy.uix.gridlayout import GridLayout
- from kivy.core.window import Window
- from kivy.uix.image import Image
- from kivy.uix.popup import Popup
- from kivy.uix.listview import ListItemButton
- from kivy.properties import ObjectProperty
- from kivy.adapters.listadapter import ListAdapter
- from bluetooth_search import *
- from kivy.uix.button import Button
- class BlueApp(ListItemButton):
- # Classe que torna a ListView selecionavel
- bluelist = ObjectProperty()
- def lista(self):
- print "LISTA"
- #Procura dispositivos bluetooth disponiveis
- dev = looking_for()
- self.device_id = {}
- for addr, name in dev:
- self.device_id[name] = addr
- return self.device_id.keys()
- def select(self):
- print "select"
- # Se conecta ao dispositivo bluetooth selecionado
- if self.bluelist.adapter.selection:
- # Pega o texto do item selecionado
- selection = self.bluelist.adapter.selection[0].text
- CustomPopup.fecha()
- # Se conecta ao id do dispositivo de acordo com o nome
- return connect( (self.device_id[selection], 3))
- class CustomPopup(Popup):
- # Gerencia os eventos da Popup
- def fecha(self):
- popup.dismiss()
- def search(self):
- print "Em search"
- blue = BlueApp()
- blue.lista()
- return blue.select()
- class SampBoxLayout(GridLayout):
- #bluelist = ObjectProperty(CustomPopup())
- def open_popup(self):
- the_popup = CustomPopup()
- the_popup.open()
- def fecha(self):
- the_popup.dismiss()
- # Retorna as strings que controlam o carrinho
- # # sao os com botoes implementados
- def Forward(self): print"F" #
- def Back(self): print"B" #
- def Left(self): print"L" #
- def Right(self): print"R" #
- def Forward_Left(self): print"G"
- def Forward_Right(self): print"I"
- def Back_Left(self): print"H"
- def Back_Right(self): print"J"
- def Stop(self): print"S"
- def Stop_All (self): print"D"
- def Front_Lights_on(self): print"U"
- def Front_Lights_off(self): print"u"
- def Back_Lights_on(self): print"X"
- def Back_Lights_off(self): print"x"
- def Horn_On(self): print"W"
- def Horn_Off(self): print"w"
- def Buzzer(self): print"V" #
- def No_Buzzer(self): print"v" #
- def Speed(self, value): #
- if value <= 90:
- print str(int(value / 10))
- else: print "q"
- class SampleApp(App):
- def build(self):
- Window.clearcolor=(.9, .9, .9, 1)
- return SampBoxLayout()
- def on_pause(self):
- # Pausa o app no caso de o usuario alternar para outro app
- return True
- def on_resume(self):
- pass
- sample_app=SampleApp()
- sample_app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement