I am using the Kivy library with python to develop an app.
In the app I have two screens which are almost identical: they both contain lists and they have roughly the same layout (row of buttons above, then list, then row of buttons below).
The biggest difference is the number of buttons on each screen: Screen 1 is 4 buttons across, and screen 2 is 3 buttons across. The buttons will have different behaviors and text depending on the screen.
Is there a way to use the same Kivy definition (sample from screen 1 shown below) but dynamically change what buttons are added when I declare the screens?
EDIT: Added sample code from my python file as well, see below the Kivy sample.
#:kivy 1.8.0
#: import ListAdapter kivy.adapters.listadapter.ListAdapter
#: import ListItemButton kivy.uix.listview.ListItemButton
<ListScreen>:
BoxLayout:
orientation: 'vertical'
BoxLayout:
size_hint_y: .1
Button:
text: 'Save'
Button:
text: 'Load'
Button:
text: 'New'
Button:
text: 'New Search'
ListView:
size_hint_y: .8
adapter:
ListAdapter(data=root.itemList,
selection_mode='single',
allow_empty_selection=False,
cls=ListItemButton)
canvas.before:
Color:
rgb: 1,1,1
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
size_hint_y: .1
Button:
text: 'Add'
Button:
text: 'Remove'
Button:
text: 'View'
Button:
text: 'View Search'
on_press:
root.manager.transition.direction = 'left'
root.manager.current = 'results'
class ListScreen(Screen):
itemList = ListProperty([])
selected_value = StringProperty()
def change(self,change):
self.selected_value = 'Selected: {}'.format(change.text)
sm = ScreenManager()
sm.add_widget(ListScreen(name='list'))
sm.add_widget(ListScreen(name='results'))