Skip to content

Instantly share code, notes, and snippets.

@maatthc
Created January 11, 2018 03:38
Show Gist options
  • Save maatthc/561525b67effef42753afcca6dd4d7d3 to your computer and use it in GitHub Desktop.
Save maatthc/561525b67effef42753afcca6dd4d7d3 to your computer and use it in GitHub Desktop.
import serial
import kivy
from kivy.app import App
from kivy.clock import Clock
from kivy.core.window import Window
from kivy.uix.scrollview import ScrollView
from kivy.uix.gridlayout import GridLayout
from kivy.properties import ObjectProperty, StringProperty
from kivy.uix.button import Button
class ProductList(GridLayout):
pass
class ButtonListItem(Button):
wid = StringProperty('')
image = StringProperty('')
title = StringProperty('')
label = StringProperty('')
pass
class KmartSco(App):
def build(self):
#Window.fullscreen = True
self.arduino = serial.Serial('COM5', 115200)
self.event = Clock.schedule_interval(self.readArduino, 1 / 30.)
# Window.size = 400, (4 * 90)
self.layout = ProductList(cols=1)
self.layout.size = Window.size
self.root = ScrollView(
# size_hint=(None, None),
# size=Window.size,
scroll_type=['bars', 'content']
)
self.root.add_widget(self.layout)
print "Finished building.."
def readArduino(self,lixo):
if (self.arduino.inWaiting()>0):
myData = self.arduino.readline()
print myData
if myData.starts with('EPC'):
ib = ButtonListItem(
wid="0",
image="apple.jpg",
title=myData,
label=myData
)
self.layout.add_widget(ib)
if __name__ == '__main__':
KmartSco().run()
#:kivy 1.8.0
<ButtonListItem@Button>:
wid: self.wid
image: self.image
title: self.title
label: self.label
on_press: self.click()
BoxLayout:
orientation: "horizontal"
size: self.parent.size # match the button's size
pos: self.parent.pos # match the button's position
padding: 5
spacing: 10
Image:
size_hint: None, 1
source: root.image
size: 64, 64
valign: "middle"
Label:
size_hint: None, 1
text: root.label
valign: "middle"
size: 400, 64
text_size: self.size
<ProductList@GridLayout>
id: output
cols: 1
size_hint_y: None
height: self.minimum_height
Button:
id: label1
text: 'Welcome to Kmart!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment