Advertisement
RoseStorm

kivytut.py

Jul 12th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import kivy
  3. kivy.require("1.9.0")
  4.  
  5. from kivy.app import App
  6. from kivy.uix.gridlayout import GridLayout
  7. from kivy.core.window import Window
  8. from kivy.uix.image import Image
  9. from kivy.uix.popup import Popup
  10. from kivy.uix.listview import ListItemButton
  11. from kivy.properties import ObjectProperty
  12. from kivy.adapters.listadapter import ListAdapter
  13. from bluetooth_search import *
  14. from kivy.uix.button import Button
  15.  
  16.  
  17. class BlueApp(ListItemButton):
  18. # Classe que torna a ListView selecionavel
  19. bluelist = ObjectProperty()
  20.  
  21. def lista(self):
  22. print "LISTA"
  23. #Procura dispositivos bluetooth disponiveis
  24. dev = looking_for()
  25. self.device_id = {}
  26. for addr, name in dev:
  27. self.device_id[name] = addr
  28.  
  29. return self.device_id.keys()
  30.  
  31. def select(self):
  32. print "select"
  33.  
  34. # Se conecta ao dispositivo bluetooth selecionado
  35. if self.bluelist.adapter.selection:
  36. # Pega o texto do item selecionado
  37. selection = self.bluelist.adapter.selection[0].text
  38.  
  39. CustomPopup.fecha()
  40. # Se conecta ao id do dispositivo de acordo com o nome
  41. return connect( (self.device_id[selection], 3))
  42.  
  43.  
  44.  
  45. class CustomPopup(Popup):
  46. # Gerencia os eventos da Popup
  47. def fecha(self):
  48. popup.dismiss()
  49.  
  50. def search(self):
  51. print "Em search"
  52. blue = BlueApp()
  53. blue.lista()
  54. return blue.select()
  55.  
  56. class SampBoxLayout(GridLayout):
  57. #bluelist = ObjectProperty(CustomPopup())
  58.  
  59. def open_popup(self):
  60. the_popup = CustomPopup()
  61. the_popup.open()
  62.  
  63.  
  64. def fecha(self):
  65. the_popup.dismiss()
  66.  
  67.  
  68. # Retorna as strings que controlam o carrinho
  69. # # sao os com botoes implementados
  70. def Forward(self): print"F" #
  71. def Back(self): print"B" #
  72. def Left(self): print"L" #
  73. def Right(self): print"R" #
  74. def Forward_Left(self): print"G"
  75. def Forward_Right(self): print"I"
  76. def Back_Left(self): print"H"
  77. def Back_Right(self): print"J"
  78. def Stop(self): print"S"
  79. def Stop_All (self): print"D"
  80.  
  81.  
  82. def Front_Lights_on(self): print"U"
  83.  
  84. def Front_Lights_off(self): print"u"
  85.  
  86. def Back_Lights_on(self): print"X"
  87. def Back_Lights_off(self): print"x"
  88.  
  89. def Horn_On(self): print"W"
  90. def Horn_Off(self): print"w"
  91.  
  92. def Buzzer(self): print"V" #
  93. def No_Buzzer(self): print"v" #
  94.  
  95. def Speed(self, value): #
  96. if value <= 90:
  97. print str(int(value / 10))
  98. else: print "q"
  99.  
  100.  
  101. class SampleApp(App):
  102. def build(self):
  103. Window.clearcolor=(.9, .9, .9, 1)
  104.  
  105. return SampBoxLayout()
  106.  
  107. def on_pause(self):
  108. # Pausa o app no caso de o usuario alternar para outro app
  109. return True
  110.  
  111. def on_resume(self):
  112. pass
  113.  
  114. sample_app=SampleApp()
  115. sample_app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement