#!python
import kivy
kivy.require('1.5.1')
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.stacklayout import StackLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.scrollview import ScrollView
from kivy.uix.slider import Slider
from functools import partial
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
kation = None
def getkation():
return kation.ids.i.source
Builder.load_string("""
<ButtonsApp>:
orientation: "vertical"
Button:
border: (0,0,0,0)
id: b
on_press: root.select()
Image:
id: i
source:
size: 750, 750
allow_stretch: True
center_x: self.parent.center_x
center_y: self.parent.center_y
""")
class ButtonsApp(App, BoxLayout):
def build(self):
return self
def select(self):
global kation
if kation == None:
kation = self
else:
kation.ids.b.background_color = (1,1,1,1)
kation = self
self.ids.b.background_color = (0,1,0,1)
print(kation.ids.i.source)
class kationApp(App):
def build(self):
return self.layout
def make(self):
#this layout is the child widget for the main popup
layout1 = StackLayout(orientation='lr-bt')
#this button is a child of layout1
#closebutton = Button(text='close', size_hint=(0.9,0.05))
#closebutton.bind(on_press=popup.dismiss)
#another child of layout1 and this is the scrollview which will have a custom draggable scrollbar
scrlv = ScrollView(size_hint=(0.9,0.95))
#the last child of layout1 and this will act as the draggable scrollbar
s = Slider(min=0, max=1, value=25, orientation='vertical', step=0.01, size_hint=(0.1, 0.95))
scrlv.bind(scroll_y=partial(self.slider_change, s))
#what this does is, whenever the slider is dragged, it scrolls the previously added scrollview by the same amount the slider is dragged
s.bind(value=partial(self.scroll_change, scrlv))
layout2 = GridLayout(cols=1, size_hint_y=None)
layout2.bind(minimum_height=layout2.setter('height'))
#find anions
f = open('klst', mode = 'r')
f = f.read().strip().split()
for i in f:
btn = ButtonsApp(size_hint_y=None, height=200, valign='middle', halign='middle')
btn.ids.i.source = './kpng/{}'.format(i)
layout2.add_widget(btn)
scrlv.add_widget(layout2)
#layout1.add_widget(closebutton)
layout1.add_widget(scrlv)
layout1.add_widget(s)
'''title = Button(text = '[b][i]Choose a Kation:[/b][/i]',
font_size = 15,
markup = True)
print(title.text)
layout1.add_widget(title)'''
#bl = BoxLayout( )
#bl.add_widget(layout1)
self.layout = layout1
def scroll_change(self, scrlv, instance, value):
scrlv.scroll_y = value
def slider_change(self, s, instance, value):
if value >= 0:
#this to avoid 'maximum recursion depth exceeded' error
s.value=value
if __name__ == '__main__':
a = kationApp()
a.make()
a.run()