本文整理汇总了Python中kivy.uix.stacklayout.StackLayout.bind方法的典型用法代码示例。如果您正苦于以下问题:Python StackLayout.bind方法的具体用法?Python StackLayout.bind怎么用?Python StackLayout.bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.uix.stacklayout.StackLayout
的用法示例。
在下文中一共展示了StackLayout.bind方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LogBox
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import bind [as 别名]
class LogBox(ScrollView):
_current_selection = 0
def __init__(self, root):
super(LogBox, self).__init__()
self.root = root
self.size_hint = (1, None)
self.height = 150
self.stack = StackLayout()
self.stack.orientation = 'lr-tb'
self.stack.size_hint = (1, None)
self.stack.bind(minimum_height=self.stack.setter('height'))
self.add_widget(self.stack)
def add(self, note):
self.stack.add_widget(LogEntry(note))
def get_entry(self, at):
if at == 0:
return None
if at > len(self.stack.children):
return None
return self.stack.children[len(self.stack.children)-at]
def get_current_entry(self):
return self.get_entry(self.current_selection)
@property
def current_selection(self):
return self._current_selection
@current_selection.setter
def current_selection(self, value):
for child in self.stack.children:
child.color = [1,1,1,1]
if value > len(self.stack.children):
self._current_selection = 0
return
self._current_selection = value
self.stack.children[len(self.stack.children)-value].color = [1,0,0,1]
# We send a KEY ON signal for each note
# only if we are on play mode.
# Reset done status for each note.
if self.root.app.playing:
for note in self.get_current_entry().notes:
note['done'] = False
arduino.send(str.format("+{0}", note['note']))
示例2: createStack
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import bind [as 别名]
def createStack(self):
"""Works out how to display the league matches.
Layout depends on the number of matches found.
"""
matches = self.leagueobject.LeagueMatches
x = len(matches)
# Single column, no scrolling
if x <= 10:
self.spacer = True
w = 1
scroll = False
self.h = 42 * x
# Dual columns, no scrolling
elif x <= 20:
self.spacer = False
w = 0.5
scroll = False
self.h = round(x/2.0) * 42
# Dual columns, scrolling
else:
self.spacer = False
w = 0.5
scroll = True
self.h = round(x/2.0) * 42
# Create a stack layout
stack = StackLayout(orientation="tb-lr",
size_hint_y=None,
height=self.h)
stack.bind(minimum_height=stack.setter('height'))
# Add the league matches to it.
for l in matches:
lg = LeagueGame(match=l, size_hint=(w, None))
stack.add_widget(lg)
# Create a scroll view
scroll = ScrollView(size_hint=(1, 1))
scroll.add_widget(stack)
return scroll
示例3: Catalog
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import bind [as 别名]
class Catalog(BoxLayout):
def __init__(self,**kwargs):
super(Catalog, self).__init__(**kwargs)
#self.orientation = 'vertical'
self.search_bar = BoxLayout(size_hint=(1.0,0.05))
self.search_bar.add_widget(Label(text='Search',size_hint=(0.25,1.0)))
self.search_text = (TextInput(multiline=False))
self.search_bar.add_widget(self.search_text)
self.filter_bar = BoxLayout(size_hint=(1.0,0.05))
self.AHSE = ToggleButton(text='AHSE',size_hint=(0.25,1.0))
self.ENGR = ToggleButton(text='ENGR',size_hint=(0.25,1.0))
self.MTH = ToggleButton(text='MTH',size_hint=(0.25,1.0))
self.SCI = ToggleButton(text='SCI',size_hint=(0.25,1.0))
self.filter_bar.add_widget(self.AHSE)
self.filter_bar.add_widget(self.ENGR)
self.filter_bar.add_widget(self.MTH)
self.filter_bar.add_widget(self.SCI)
self.scrollview = ScrollView(size_hint=(1.0,0.9),size=(400,400))
self.courses = StackLayout(spacing=5,size_hint_y=None)
self.courses.bind(minimum_height=self.courses.setter('height'))
for course_object in catalog:
course_item = Course_Item(course=course_object,size_hint=(0.245,None),height=200)
self.courses.add_widget(course_item)
self.scrollview.add_widget(self.courses)
self.add_widget(self.search_bar)
self.add_widget(self.filter_bar)
self.add_widget(self.scrollview)
Clock.schedule_interval(self.update_favorites,0.1)
Clock.schedule_interval(self.search_function,0.1)
def search_function(self,instance):
query = self.search_text.text.lower()
searched_items = []
filtered_items = []
#fills up the temp list the first time it runs
if len(search_temp_list) == 0:
for course_item in self.courses.children:
search_temp_list.append(course_item)
#if the query is not empty, do term search
if query != "":
for course_item in search_temp_list:
if query == course_item.course.name.lower() or query == course_item.course.code or query == course_item.course.prof.lower():
searched_items.append(course_item)
for keyword in course_item.course.keywords:
if query == keyword.lower():
searched_items.append(course_item)
else:
searched_items = search_temp_list
if self.AHSE.state == 'normal' and self.ENGR.state == 'normal' and self.MTH.state == 'normal' and self.SCI.state == 'normal':
filtered_items = searched_items
else:
if self.AHSE.state == 'down':
for course_item in searched_items:
if course_item.course.credits['AHSE'] > 0:
filtered_items.append(course_item)
if self.ENGR.state == 'down':
for course_item in searched_items:
if course_item.course.credits['ENGR'] > 0 and course_item not in filtered_items:
filtered_items.append(course_item)
if self.MTH.state == 'down':
for course_item in searched_items:
if course_item.course.credits['MTH'] > 0 and course_item not in filtered_items:
filtered_items.append(course_item)
if self.SCI.state == 'down':
for course_item in searched_items:
if course_item.course.credits['SCI'] > 0 and course_item not in filtered_items:
filtered_items.append(course_item)
if len(self.courses.children) != len(filtered_items):
self.courses.clear_widgets()
for course_item in filtered_items:
self.courses.add_widget(course_item)
def update_favorites(self,instance):
for course_item in self.courses.children:
if course_item.favorite.state == 'normal' and course_item.course in favorite_courses:
favorite_courses.remove(course_item.course)
if course_item.favorite.state == 'down' and course_item.course not in favorite_courses:
favorite_courses.append(course_item.course)
示例4: EventListbox
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import bind [as 别名]
class EventListbox(StackLayout):
def __init__(self, **kwargs):
super(EventListbox, self).__init__(**kwargs)
self.is_updating = False
self.orientation = 'lr-tb'
self.items = []
self.bind(pos=self.draw, size=self.draw)
self.data_bindings = dict()
self.selected_view = None
self.selected_item = None
# content
self.content = StackLayout(orientation = 'lr-tb')
self.content.size_hint_y = None #for scrollviewer
self.content.bind(minimum_height=self.content.setter('height'))
self.scrollview = ScrollView(size_hint=[1, 1])
self.scrollview.do_scroll_x = False
self.scrollview.add_widget(self.content)
self.add_widget(self.scrollview)
def begin_update(self):
self.is_updating = True
def end_update(self):
self.is_updating = False
self.draw()
def add_item(self, item):
self.items.append(item)
if not self.is_updating:
self.draw()
def clear_items(self):
del self.items[:]
self.clear_selection()
self.draw()
def clear_selection(self):
self.selected_view = None
self.selected_item = None
def draw(self, *args):
self.content.clear_widgets()
self.data_bindings.clear()
n = len(self.items)
i = 0
while i < n:
item_wgt = EventWidget(self.items[i])
item_wgt.height = self.height/4
item_wgt.size_hint = [1, None] #for scrollviewer parent
item_wgt.bind(on_touch_down=self.selection_change)
self.content.add_widget(item_wgt)
self.data_bindings[item_wgt] = self.items[i]
i += 1
# self.draw_background()
def selection_change(self, instance, touch):
for item_wgt in self.content.children:
if item_wgt.collide_point(touch.x, touch.y):
self.selected_view = item_wgt
self.selected_item = self.data_bindings[item_wgt]
示例5: Catalog
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import bind [as 别名]
class Catalog(BoxLayout):
"""Tab that displays available courses and allows user to search for, see details about, and add courses to planner tab"""
def __init__(self,sm,**kwargs):
super(Catalog,self).__init__(**kwargs)
self.orientation = 'vertical'
self.sm = sm
## Search Bar ##
self.search_bar = BoxLayout(size_hint=(1.0,0.05))
self.search_text = TextInput(multiline=False,size_hint =(0.6,1.0))
self.create_course_popup = Build_Course(self.sm)
self.create_course_button = Button(text='Create a Course',size_hint=(0.2,1.0),on_press=self.create_course_popup.open_pop_up)
self.search_bar.add_widget(Label(text='Search',size_hint=(0.2,1.0)))
self.search_bar.add_widget(self.search_text)
self.search_bar.add_widget(self.create_course_button)
## Filter Buttons ##
self.filter_bar = BoxLayout(size_hint=(1.0,0.05))
self.AHSE = ToggleButton(text='AHSE',size_hint=(0.25,1.0))
self.ENGR = ToggleButton(text='ENGR',size_hint=(0.25,1.0))
self.MTH = ToggleButton(text='MTH',size_hint=(0.25,1.0))
self.SCI = ToggleButton(text='SCI',size_hint=(0.25,1.0))
self.filter_bar.add_widget(self.AHSE)
self.filter_bar.add_widget(self.ENGR)
self.filter_bar.add_widget(self.MTH)
self.filter_bar.add_widget(self.SCI)
## Scrollview of Courses ##
self.scrollview = ScrollView(size_hint=(1.0,0.9),size=(400,400),scroll_timeout=5)
self.courses = StackLayout(spacing=5,size_hint_y=None)
self.courses.bind(minimum_height=self.courses.setter('height'))
self.scrollview.add_widget(self.courses)
## Add Widgets to Tab ##
self.add_widget(self.search_bar)
self.add_widget(self.filter_bar)
self.add_widget(self.scrollview)
Clock.schedule_interval(self.search_function,0.1)
def search_function(self,instance):
"""Allows user to search for courses by name, keyword, professor, or course code and filter courses by type"""
query = self.search_text.text.lower()
searched_items = []
filtered_items = []
#fills up the temp list the first time the function is called (copy of list of all courses)
if len(search_temp_list) == 0:
for course_item in self.courses.children:
search_temp_list.append(course_item)
#if the query is not empty, does term search first
if query != "":
for course_item in search_temp_list:
if query == course_item.course.name.lower() or query == course_item.course.code or query == course_item.course.prof.lower():
searched_items.append(course_item)
for keyword in course_item.course.keywords:
if query == keyword.lower():
searched_items.append(course_item)
#if the query is empty, searched courses = all courses
else:
searched_items = search_temp_list
#if none of the buttons are down, keep all searched courses
if self.AHSE.state == 'normal' and self.ENGR.state == 'normal' and self.MTH.state == 'normal' and self.SCI.state == 'normal':
filtered_items = searched_items
#if a button is down, shows only courses in that category (holding multiple buttons shows more courses)
else:
if self.AHSE.state == 'down':
for course_item in searched_items:
if course_item.course.credits['AHSE'] > 0:
filtered_items.append(course_item)
if self.ENGR.state == 'down':
for course_item in searched_items:
if course_item.course.credits['ENGR'] > 0 and course_item not in filtered_items:
filtered_items.append(course_item)
if self.MTH.state == 'down':
for course_item in searched_items:
if course_item.course.credits['MTH'] > 0 and course_item not in filtered_items:
filtered_items.append(course_item)
if self.SCI.state == 'down':
for course_item in searched_items:
if course_item.course.credits['SCI'] > 0 and course_item not in filtered_items:
filtered_items.append(course_item)
if len(self.courses.children) != len(filtered_items):
self.courses.clear_widgets()
for course_item in filtered_items:
self.courses.add_widget(course_item)
示例6: DragTab
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import bind [as 别名]
class DragTab(BoxLayout):
def __init__(self,**kwargs):
super(DragTab,self).__init__(**kwargs)
#Base Layer is a BoxLayout
#right-hand column is StackLayout, lefthand is a vertical box layout
self.scrollview = ScrollView(size=(400,400),size_hint=(0.3,1))
self.courses = StackLayout(spacing=5,size_hint_y=None,orientation='tb-rl')
self.courses.bind(minimum_height=self.courses.setter('height'))
self.scrollview.add_widget(self.courses)
self.lefthand=BoxLayout(orientation='vertical', size_hint=(.7,1))
self.Planner=GridLayout(size_hint=(1,.9),rows=2, cols=4, spacing=3)
self.slot1=Semester(text="Fall "+ str(all_globals.user.grad_year-4))
self.Planner.add_widget(self.slot1)
self.slot2=Semester(text="Fall "+ str(all_globals.user.grad_year-3))
self.Planner.add_widget(self.slot2)
self.slot3=Semester(text="Fall "+ str(all_globals.user.grad_year-2))
self.Planner.add_widget(self.slot3)
self.slot4=Semester(text="Fall "+ str(all_globals.user.grad_year-1))
self.Planner.add_widget(self.slot4)
self.slot5=Semester(text="Spring "+ str(all_globals.user.grad_year-3))
self.Planner.add_widget(self.slot5)
self.slot6=Semester(text="Spring "+ str(all_globals.user.grad_year-2))
self.Planner.add_widget(self.slot6)
self.slot7=Semester(text="Spring "+ str(all_globals.user.grad_year-1))
self.Planner.add_widget(self.slot7)
self.slot8=Semester(text="Spring "+ str(all_globals.user.grad_year))
self.Planner.add_widget(self.slot8)
self.lefthand.add_widget(self.Planner)
self.stats_widget=BoxLayout(size_hint=(1, .1))
self.recycle=Button(size_hint=(.25, 1), text= 'Recycle \n Course')
self.stats=Label(size_hint=(.75,1),color=(1,1,1,.3))
self.stats_widget.add_widget(self.recycle)
self.stats_widget.add_widget(self.stats)
self.lefthand.add_widget(self.stats_widget)
#Now stuff it all in
self.add_widget(self.lefthand)
self.add_widget(self.scrollview)
# if len(self.lefthand.children)>=2:
Clock.schedule_interval(self.update_stats_widget, .1)
def add_Icon(self,course):
Icon=DragableButton(course=course,text=course.keywords[0],height=100,size_hint_y=None,
droppable_zone_objects=[],
bound_zone_objects=[],
kill_zone_objects=[],
drag_opacity=.5,
remove_on_drag=True)
# Icon.text_size=self.size
Icon.bound_zone_objects.append(self.Planner)
Icon.bound_zone_objects.append(self.scrollview)
Icon.bound_zone_objects.append(self.recycle)
Icon.droppable_zone_objects.append(self.slot1.coursehouse)
Icon.droppable_zone_objects.append(self.slot2.coursehouse)
Icon.droppable_zone_objects.append(self.slot3.coursehouse)
Icon.droppable_zone_objects.append(self.slot4.coursehouse)
Icon.droppable_zone_objects.append(self.slot5.coursehouse)
Icon.droppable_zone_objects.append(self.slot6.coursehouse)
Icon.droppable_zone_objects.append(self.slot7.coursehouse)
Icon.droppable_zone_objects.append(self.slot8.coursehouse)
Icon.droppable_zone_objects.append(self.courses)
Icon.kill_zone_objects.append(self.recycle)
self.courses.add_widget(Icon)
print Icon.droppable_zone_objects
def update_stats_widget(self, dt):
##DON'T REWRITE OVER THE USER INFORMATION WITH THE DUMMY DATA!!!!!!
Fixed=False
all_globals.user.credits['AHSE'] = 0#course.course.pre_credits['AHSE']
all_globals.user.credits['ENGR'] = 0#course.course.pre_credits['ENGR']
all_globals.user.credits['MTH'] = 0#course.course.pre_credits['MTH']
all_globals.user.credits['SCI'] = 0#course.course.pre_credits['SCI']
for child in self.lefthand.children[:]:
if child.height> 300:
for semester_block in child.children[:]:
for semester_element in semester_block.children[:]:
if semester_element.height>100:
for course in semester_element.children[:]:
all_globals.user.credits['AHSE'] += course.course.credits['AHSE']
all_globals.user.credits['ENGR'] += course.course.credits['ENGR']
all_globals.user.credits['MTH'] += course.course.credits['MTH']
all_globals.user.credits['SCI'] += course.course.credits['SCI']
for child in self.lefthand.children[:]:
if child.height>300:
Fixed=True
#.........这里部分代码省略.........
示例7: DragTab
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import bind [as 别名]
class DragTab(BoxLayout):
def __init__(self,**kwargs):
super(DragTab,self).__init__(**kwargs)
#Base Layer is a BoxLayout
#right-hand column is StackLayout, lefthand is a vertical box layout
FreshColor=[0.2,0.65,0.8,0.85]
SophColor=[0.2,0.65,0.8,0.75]
JuniColor=[0.2,0.65,0.8,0.6]
SeniColor=[0.2,0.65,0.8,0.45]
self.scrollview = ScrollView(size=(400,400),size_hint=(0.3,1.0),scroll_timeout=10)
self.courses = StackLayout(spacing=5,size_hint_y=None,orientation='rl-tb')
self.courses.bind(minimum_height=self.courses.setter('height'))
self.scrollview.add_widget(self.courses)
self.lefthand=BoxLayout(orientation='vertical', size_hint=(.7,1))
self.Planner=GridLayout(size_hint=(1,.85),rows=2, cols=4, spacing=3)
self.slot1=Semester(text="Fall "+ str(all_globals.user.grad_year-4), color=FreshColor)
self.slot2=Semester(text="Fall "+ str(all_globals.user.grad_year-3), color=SophColor)
self.slot3=Semester(text="Fall "+ str(all_globals.user.grad_year-2), color=JuniColor)
self.slot4=Semester(text="Fall "+ str(all_globals.user.grad_year-1), color=SeniColor)
self.slot5=Semester(text="Spring "+ str(all_globals.user.grad_year-3), color=FreshColor)
self.slot6=Semester(text="Spring "+ str(all_globals.user.grad_year-2), color=SophColor)
self.slot7=Semester(text="Spring "+ str(all_globals.user.grad_year-1), color=JuniColor)
self.slot8=Semester(text="Spring "+ str(all_globals.user.grad_year), color=SeniColor)
self.slots=[self.slot1, self.slot2, self.slot3, self.slot4, self.slot5, self.slot6, self.slot7, self.slot8]
for sem_obj in self.slots:
self.Planner.add_widget(sem_obj)
self.lefthand.add_widget(self.Planner)
self.stats_widget=BoxLayout(size_hint=(1, .15))
self.recycle=Button(size_hint=(.2, 1),background_normal='recycle.png',background_down='recycle.png')#,text= 'Recycle \n Course')
self.stats=Label(size_hint=(1,1),color=(1,1,1,.3))
self.stats_widget.add_widget(self.recycle)
self.stats_widget.add_widget(self.stats)
self.lefthand.add_widget(self.stats_widget)
#Now stuff it all in
self.add_widget(self.lefthand)
self.add_widget(self.scrollview)
Clock.schedule_interval(self.update_stats_widget, .1)
def add_Icon(self,course):
Icon=DragableButton(course=course,text=course.keywords[0],height=100,size_hint_y=None,
droppable_zone_objects=[],
bound_zone_objects=[],
kill_zone_objects=[],
drag_opacity=.5,
remove_on_drag=True)
Icon.bound_zone_objects.append(self.Planner)
Icon.bound_zone_objects.append(self.scrollview)
Icon.bound_zone_objects.append(self.courses)
Icon.bound_zone_objects.append(self.recycle)
for sem in self.slots:
Icon.add_droppable_zone(sem.coursehouse)
Icon.droppable_zone_objects.append(self.scrollview)
Icon.droppable_zone_objects.append(self.courses)
Icon.kill_zone_objects.append(self.recycle)
self.courses.add_widget(Icon)
def update_stats_widget(self, dt):
# When the user gets pre-credits as an attribute, we can stop writing over
# Fixed=False
all_globals.user.credits['AHSE'] = 0#course.course.pre_credits['AHSE']
all_globals.user.credits['ENGR'] = 0#course.course.pre_credits['ENGR']
all_globals.user.credits['MTH'] = 0#course.course.pre_credits['MTH']
all_globals.user.credits['SCI'] = 0#course.course.pre_credits['SCI']
all_globals.user.courses=[]
for semester_obj in self.slots:
for icon in semester_obj.coursehouse.children[:]:
all_globals.user.courses.append(icon.course.code)
all_globals.user.credits['AHSE'] += icon.course.credits['AHSE']
all_globals.user.credits['ENGR'] += icon.course.credits['ENGR']
all_globals.user.credits['MTH'] += icon.course.credits['MTH']
all_globals.user.credits['SCI'] += icon.course.credits['SCI']
self.stats_widget.remove_widget(self.stats)
self.stats=Label(size_hint=(1,1),text='AHSE: '+str(all_globals.user.credits['AHSE'])+' '+'ENGR: '+str(all_globals.user.credits['ENGR'])+' '+'MTH: '+str(all_globals.user.credits['MTH'])+' '+'SCI: '+str(all_globals.user.credits['SCI'])+' ',color=(1,1,1,1))
print all_globals.user.courses
self.stats_widget.add_widget(self.stats)
for sem in self.slots:
sem.Me.clear_widgets()
adjust=4
for sem in self.slots[0:4]:
sem.Me.add_widget(Label(text="Fall "+ str(all_globals.user.grad_year-adjust)))
adjust-=1
#.........这里部分代码省略.........