Skip to content

Instantly share code, notes, and snippets.

@tshirtman
Created July 15, 2012 17:52
Show Gist options
  • Select an option

  • Save tshirtman/3117901 to your computer and use it in GitHub Desktop.

Select an option

Save tshirtman/3117901 to your computer and use it in GitHub Desktop.
<YourWidget>:
canvas.before:
Color:
rgb: self.variable_color
Rectangle:
pos: self.pos
size: self.size
<MyScrollView>:
canvas:
Color:
rgb: 1, 1, 1
Rectangle:
pos: self.pos
size: self.size
<MyGridLayout>:
canvas:
Color:
rgb: 1, 1, 1
Rectangle:
pos: self.pos
size: self.size
from kivy.uix.widget import Widget
from kivy.uix.gridlayout import GridLayout
from kivy.uix.scrollview import ScrollView
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.tabbedpanel import TabbedPanel, TabbedPanelHeader
from kivy.core.window import Window
from kivy.properties import ListProperty
from kivy.app import App
class YourWidget(Label):
variable_color = ListProperty((1, 1, 1))
def __init__(self, **kwargs):
super(YourWidget, self).__init__(**kwargs)
#Label.halign="left"
def on_touch_down(self, touch):
if touch.y > self.y and touch.y < self.y + self.height:
if self.variable_color == [1, 1, 1]:
self.variable_color = (0, 0, 1)
else:
self.variable_color = (1, 1, 1)
class MyScrollView(ScrollView):
pass
class MyGridLayout(GridLayout):
pass
class pathways(Widget):
def __init__(self, **kwargs):
super(pathways, self).__init__(**kwargs)
self.layoutMain = MyGridLayout(cols=1, spacing=1, size_hint=(None, None), width=400)
self.layoutMain.bind(minimum_height=self.layoutMain.setter('height'))
self.layoutChose = MyGridLayout(cols=1, spacing=1, size_hint=(None, None), width=400)
self.layoutChose.bind(minimum_height=self.layoutChose.setter('height'))
for i in range(30):
btn = YourWidget(text='[color=000000]' + str(i) + 'Hello World[/color]', markup=True, size=(400, 20), size_hint=(None, None))
# the next line fix the alignement
btn.bind(texture_size=btn.setter('size'))
self.layoutMain.add_widget(btn)
self.troot = MyScrollView(size_hint=(None, None))
self.troot.size = (400, 320)
self.troot.center = 300, Window.height - 300
self.troot.add_widget(self.layoutMain)
self.troot2 = MyScrollView(size_hint=(None, None))
self.troot2.size = (400, 320)
self.troot2.center = 750, Window.height - 300
self.troot2.add_widget(self.layoutChose)
self.add_widget(self.troot2)
self.add_widget(self.troot)
self.layoutMain.bind(on_touch_up=self.moveChild)
self.layoutChose.bind(on_touch_up=self.moveChild)
def moveChild(self, touch, *l):
T = []
for childF in self.layoutChose.children[:]:
if childF.variable_color == [0, 0, 1]:
T.append(childF.text)
self.layoutChose.remove_widget(childF)
for childT in self.layoutMain.children[:]:
if childT.text in T:
childT.variable_color = [1, 1, 1]
if childT.variable_color == [0, 0, 1]:
btn = YourWidget(text=childT.text, markup=True, size=(400, 20), size_hint=(None, None))
self.layoutChose.add_widget(btn)
class Editor(App):
def build(self):
tp = TabbedPanel()
tp.default_tab_text = 'Files Setup'
tp.default_tab.content = Button(text="Just a button")
th1 = TabbedPanelHeader(text='Organisms')
tp.add_widget(th1)
pathways()
#Listtt2 = pathways()
th1.content = pathways()
return tp
if __name__ == '__main__':
Editor().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment