mirror of https://github.com/kivy/kivy.git
showcase: update showcase to use treeview (much better!)
This commit is contained in:
parent
d242354824
commit
da9c4fdb98
|
@ -1,6 +1,7 @@
|
|||
import sys
|
||||
from kivy.app import App
|
||||
from kivy.uix.boxlayout import BoxLayout
|
||||
from kivy.uix.floatlayout import FloatLayout
|
||||
from kivy.uix.anchorlayout import AnchorLayout
|
||||
from kivy.uix.button import Button
|
||||
from kivy.uix.togglebutton import ToggleButton
|
||||
from kivy.uix.slider import Slider
|
||||
|
@ -12,51 +13,96 @@ class ShowcaseApp(App):
|
|||
|
||||
def on_select_node(self, instance, value):
|
||||
self.content.clear_widgets()
|
||||
value = value['widget'].text
|
||||
w = getattr(self, 'show_%s' % value.lower().replace(' ', '_'))()
|
||||
self.content.add_widget(w)
|
||||
try:
|
||||
w = getattr(self, 'show_%s' %
|
||||
value.text.lower().replace(' ', '_'))()
|
||||
self.content.add_widget(w)
|
||||
except Exception, e:
|
||||
print e
|
||||
|
||||
def build(self):
|
||||
root = BoxLayout(orientation='horizontal', padding=20, spacing=20)
|
||||
tree = TreeView(size_hint=(None, 1), width=200)
|
||||
tree.root['widget'].text = 'Widget list'
|
||||
tree = TreeView(size_hint=(None, 1), width=200, hide_root=True,
|
||||
indent_level=0)
|
||||
|
||||
def create_tree(text):
|
||||
return tree.add_node(TreeViewLabel(
|
||||
text=text, is_open=True, no_selection=True))
|
||||
|
||||
def attach_node(text, n):
|
||||
tree.add_node(TreeViewLabel(text=text), n)
|
||||
|
||||
tree.bind(selected_node=self.on_select_node)
|
||||
tree.add_node(TreeViewLabel(text='Buttons'))
|
||||
tree.add_node(TreeViewLabel(text='Toggle Buttons'))
|
||||
tree.add_node(TreeViewLabel(text='Sliders'))
|
||||
tree.add_node(TreeViewLabel(text='Textinput'))
|
||||
n = create_tree('Buttons')
|
||||
attach_node('Options buttons', n)
|
||||
attach_node('Options buttons', n)
|
||||
n = create_tree('Sliders')
|
||||
attach_node('Horizontal sliders', n)
|
||||
attach_node('Vertical sliders', n)
|
||||
n = create_tree('Textinput')
|
||||
attach_node('Monoline textinput', n)
|
||||
attach_node('Multiline textinput', n)
|
||||
n = create_tree('TreeView')
|
||||
attach_node('Standard treeview', n)
|
||||
attach_node('Treeview without root', n)
|
||||
root.add_widget(tree)
|
||||
self.content = content = BoxLayout()
|
||||
root.add_widget(content)
|
||||
return root
|
||||
|
||||
def show_buttons(self):
|
||||
def show_standard_buttons(self):
|
||||
col = BoxLayout(spacing=10)
|
||||
col.add_widget(Button(text='Hello world'))
|
||||
col.add_widget(Button(text='Hello world', state='down'))
|
||||
return col
|
||||
|
||||
def show_toggle_buttons(self):
|
||||
def show_options_buttons(self):
|
||||
col = BoxLayout(spacing=10)
|
||||
col.add_widget(ToggleButton(text='Option 1', group='t1'))
|
||||
col.add_widget(ToggleButton(text='Option 2', group='t1'))
|
||||
col.add_widget(ToggleButton(text='Option 3', group='t1'))
|
||||
return col
|
||||
|
||||
def show_sliders(self):
|
||||
col = BoxLayout(spacing=10)
|
||||
vbox = BoxLayout(orientation='vertical', spacing=10)
|
||||
col.add_widget(vbox)
|
||||
vbox.add_widget(Slider())
|
||||
vbox.add_widget(Slider(value=50))
|
||||
hbox = BoxLayout(spacing=10)
|
||||
col.add_widget(hbox)
|
||||
hbox.add_widget(Slider(orientation='vertical'))
|
||||
hbox.add_widget(Slider(orientation='vertical', value=50))
|
||||
def show_horizontal_sliders(self):
|
||||
col = BoxLayout(orientation='vertical', spacing=10)
|
||||
col.add_widget(Slider())
|
||||
col.add_widget(Slider(value=50))
|
||||
return col
|
||||
|
||||
def show_textinput(self):
|
||||
return TextInput()
|
||||
def show_vertical_sliders(self):
|
||||
col = BoxLayout(spacing=10)
|
||||
col.add_widget(Slider(orientation='vertical'))
|
||||
col.add_widget(Slider(orientation='vertical', value=50))
|
||||
return col
|
||||
|
||||
def show_multiline_textinput(self):
|
||||
col = AnchorLayout()
|
||||
col.add_widget(TextInput(size_hint=(None, None), size=(200, 100)))
|
||||
return col
|
||||
|
||||
def show_monoline_textinput(self):
|
||||
col = AnchorLayout()
|
||||
col.add_widget(TextInput(size_hint=(None, None), size=(200, 32),
|
||||
multiline=False))
|
||||
return col
|
||||
|
||||
def show_standard_treeview(self):
|
||||
return self.populate_treeview(TreeView())
|
||||
|
||||
def show_treeview_without_root(self):
|
||||
return self.populate_treeview(TreeView(hide_root=True))
|
||||
|
||||
def populate_treeview(self, tv):
|
||||
n = tv.add_node(TreeViewLabel(text='Item 1'))
|
||||
for x in xrange(3):
|
||||
tv.add_node(TreeViewLabel(text='Subitem %d' % x), n)
|
||||
n = tv.add_node(TreeViewLabel(text='Item 2', is_open=True))
|
||||
for x in xrange(3):
|
||||
tv.add_node(TreeViewLabel(text='Subitem %d' % x), n)
|
||||
n = tv.add_node(TreeViewLabel(text='Item 3'))
|
||||
for x in xrange(3):
|
||||
tv.add_node(TreeViewLabel(text='Subitem %d' % x), n)
|
||||
return tv
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue