本文整理汇总了Python中kivy.uix.stacklayout.StackLayout.clear_widgets方法的典型用法代码示例。如果您正苦于以下问题:Python StackLayout.clear_widgets方法的具体用法?Python StackLayout.clear_widgets怎么用?Python StackLayout.clear_widgets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.uix.stacklayout.StackLayout
的用法示例。
在下文中一共展示了StackLayout.clear_widgets方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Catalog
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import clear_widgets [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)
示例2: EventListbox
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import clear_widgets [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]
示例3: Catalog
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import clear_widgets [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)
示例4: Peta
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import clear_widgets [as 别名]
#.........这里部分代码省略.........
)
self.bLayout.add_widget(self.jaringanJalanButton)
self.bLayout.add_widget(self.jaringanAirBersihButton)
self.bLayout.add_widget(self.jaringanGegorongButton)
self.bLayout.add_widget(self.saranaPublik)
self.bLayout.add_widget(self.zoomInButton)
self.bLayout.add_widget(self.zoomOutButton)
## LEGEND CONTAINER ##
self.legendContainer = StackLayout(
orientation="lr-tb",
size_hint=(None, None),
minimum_width=366,
minimum_height=672,
width=366,
height=105,
pos_hint={"x": 0.75, "y": 0.70},
)
self.legendContainer.add_widget(self.legendBatasWil)
self.mapScreen = MapLayout()
# self.add_widget(self.mapScreen)
self.add_widget(self.mapScreen.mapBound)
self.add_widget(self.bLayout)
self.add_widget(self.Navigation)
self.add_widget(self.legendContainer)
self.zoomIdx = 0
## Filter Button function method ##
def jalan(self, b, **kwargs):
if b.state == "down":
self.mapScreen.addJalan()
self.legendContainer.add_widget(self.legendJalan)
# log
gv.logger.log_button("view :" + "jalan")
elif b.state == "normal":
self.mapScreen.removeJalan()
self.legendContainer.remove_widget(self.legendJalan)
# log
gv.logger.log_button("close :" + "jalan")
def air(self, b, **kwargs):
if b.state == "down":
self.mapScreen.addAir()
self.legendContainer.add_widget(self.legendAir)
# log
gv.logger.log_button("view :" + "air bersih")
elif b.state == "normal":
self.mapScreen.removeAir()
self.legendContainer.remove_widget(self.legendAir)
# log
gv.logger.log_button("close :" + "air bersih")
def gorong(self, b, **kwargs):
if b.state == "down":
self.mapScreen.addGorong()
self.legendContainer.add_widget(self.legendGorong)
# log
gv.logger.log_button("view :" + "gorong-gorong")
elif b.state == "normal":
self.mapScreen.removeGorong()
self.legendContainer.remove_widget(self.legendGorong)
# log
gv.logger.log_button("close :" + "gorong-gorong")
def sarana(self, b, **kwargs):
if b.state == "down":
self.mapScreen.addSarana()
self.legendContainer.add_widget(self.legendSarana)
# log
gv.logger.log_button("view :" + "sarana")
elif b.state == "normal":
self.mapScreen.removeSarana()
self.legendContainer.remove_widget(self.legendSarana)
# log
gv.logger.log_button("close :" + "sarana")
def reset(self):
self.mapScreen.resetMap()
self.legendContainer.clear_widgets()
self.legendContainer.add_widget(self.legendBatasWil)
self.jaringanJalanButton.state = "normal"
self.jaringanAirBersihButton.state = "normal"
self.jaringanGegorongButton.state = "normal"
self.saranaPublik.state = "normal"
def zoomIn(self, button=None, **args):
self.mapScreen.zoomingIn()
def zoomOut(self, button=None, **args):
self.mapScreen.zoomingOut()
示例5: MainController
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import clear_widgets [as 别名]
#.........这里部分代码省略.........
self.button_up.bind(on_press=self.go_up)
self.button_down.bind(on_press=self.go_down)
self.button_report.bind(on_press=self.run_report)
return self
def load_previous_day(self, button):
self.db = self.get_db_file(self.previous_day(self.current_day))
self.clear_stack_src().build_stack_src(self.db).update_stack_view(len(self.stack_src))
def load_next_day(self, button):
if not self.current_day == date.today():
self.db = self.get_db_file(self.next_day(self.current_day))
self.clear_stack_src().build_stack_src(self.db).update_stack_view(len(self.stack_src))
@staticmethod
def previous_day(current_day=date.today()):
return current_day - timedelta(days=1)
@staticmethod
def next_day(current_day=date.today()):
return current_day + timedelta(days=1)
def go_up(self, button):
limit = self.stack_current_limit - 1 if self.stack_current_limit > ROWS_IN_STACK else self.stack_current_limit
self.update_stack_view(limit)
def go_down(self, button):
limit = min(self.stack_current_limit + 1, len(self.stack_src))
self.update_stack_view(limit)
def run_report(self, button):
TimeParser(self.db).parse_rows()
def update_stack_src(self, project_title, project_description):
row = self.build_row_dict(self.timer_label.time_label.text, self.timer_label.time_label.time, project_title,
project_description)
self.stack_src.append(row)
return self
def clear_stack_src(self):
self.stack_src = []
return self
def insert_row(self, row):
self.db.set(str(datetime.now()), row)
self.db.dump()
return self
@staticmethod
def build_row_dict(time_text, time, project_title, project_description):
return {
'time_text': time_text,
'time': time,
'project_title': project_title,
'project_description': project_description
}
def add_new_row(self, button):
project_title = self.row_form.text_project.text
project_description = self.row_form.text_description.text
self.insert_row(self.build_row_dict(self.timer_label.time_label.text, self.timer_label.time_label.time,
project_title, project_description))
self.update_stack_src(project_title, project_description)
self.update_stack_view(len(self.stack_src))
self.row_form.text_description.text = ''
def get_style_stack_row(self, row):
stack_row = self.display_row_label(self.stack_src[row])
stack_row.size = 300, 30
stack_row.pos_hint = {'right': 1, 'center_y': 0.5}
return stack_row
def update_stack_view(self, limit):
self.stack_current_limit = limit
stack_range = self.get_stack_range(limit)
self.stack_layout.clear_widgets()
for row in range(stack_range['start'], stack_range['limit']):
stack_row = self.get_style_stack_row(row)
self.stack_layout.add_widget(stack_row)
return self
@staticmethod
def get_stack_range(limit):
start = 0 if limit - ROWS_IN_STACK <= 0 else limit - ROWS_IN_STACK
return {'start': start, 'limit': limit}
@staticmethod
def display_row_label(row_dict):
return Label(text=row_dict['time_text'] + " - \n" + row_dict['project_title'] + " "
+ row_dict['project_description'], size_hint=(1., .1), pos=(0, 0), markup=True)
# return StackRowLabel(row_dict['time_text'], row_dict['project_title'] + row_dict['project_description'])
@staticmethod
def rgba2float(r, g, b, a=1.0):
return float("{0:.2f}".format(r/256.0)), float("{0:.2f}".format(g/256.0)), float("{0:.2f}".format(b/256.0)), a
@staticmethod
def log_str(value):
Logger.info(str(value))