Skip to content

Instantly share code, notes, and snippets.

@KristerV
Created February 28, 2013 21:53
Show Gist options
  • Save KristerV/5060439 to your computer and use it in GitHub Desktop.
Save KristerV/5060439 to your computer and use it in GitHub Desktop.
#:kivy 1.5.1
FloatLayout:
size_hint: (1,1)
bookcover: bookcover
Carousel:
pos_hint: {'center_x': 0.5, 'top': app.booky}
size_hint: (1,1)
id: bookcover
#:kivy 1.5.1
GridLayout:
cols: 3
librarybook: librarybook
id: librarybook
Button
Button
Button:
text: 'Book1'
on_press: app.build_book()
Button
Button
Button
'''
Carousel example with button inside.
This is a tiny test for testing the scroll distance/timeout
And ensure the down/up are dispatched if no gesture is done.
'''
from kivy.uix.carousel import Carousel
from kivy.uix.gridlayout import GridLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.properties import ObjectProperty, StringProperty, NumericProperty, BooleanProperty
from kivy.core.window import Window
class dragB(Button):
def __init__(self, **kwargs):
super(dragB, self).__init__(**kwargs)
self.size_hint= (0.8,0.1)
self.pos_hint= {'center_x': 0.5, 'top': 1}
self.background_color=(1,0,0,1)
def on_touch_move(self, touch):
b = App.get_running_app().booky
newpos = b-(b-touch.y/Window.size[1])/3
if self.state == 'down':
App.get_running_app().booky = newpos
self.pos_hint= {'center_x': 0.5, 'top': newpos}
print App.get_running_app().Book.bookcover
class InsertBookApp(App):
# Define containers
container = ObjectProperty(None)
bookcover = ObjectProperty(None)
librarybook = ObjectProperty(None)
# variables
booky = NumericProperty(1)
def build(self):
# load kv files
self.root = Builder.load_file('root.kv')
self.Book = Builder.load_file('book.kv')
self.Library = Builder.load_file('library.kv')
# connect containers
self.container = self.root.container
self.bookcover = self.Book.bookcover
self.librarybook = self.Library.librarybook
self.root.add_widget(self.Library)
return self.root
def build_book(self):
self.bookcover.add_widget(Button(text='page1', background_color=(0,1,0,1)))
self.bookcover.add_widget(Button(text='page2', background_color=(0,1,0,1)))
self.bookcover.add_widget(Button(text='page3', background_color=(0,1,0,1)))
self.bookcover.add_widget(Button(text='page4', background_color=(0,1,0,1)))
self.root.add_widget(self.Book)
self.root.add_widget(dragB())
print self
def drag_book(self, btn):
print btn
def drag_book_stop(self, btn):
print 'release'
if __name__ == '__main__':
InsertBookApp().run()
#:kivy 1.5.1
FloatLayout:
container: container
id: container
canvas.before:
Color:
rgb: .25,.3,.4,1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment