本文整理汇总了Python中kivy.adapters.listadapter.ListAdapter.get_view方法的典型用法代码示例。如果您正苦于以下问题:Python ListAdapter.get_view方法的具体用法?Python ListAdapter.get_view怎么用?Python ListAdapter.get_view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.adapters.listadapter.ListAdapter
的用法示例。
在下文中一共展示了ListAdapter.get_view方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TreeView
# 需要导入模块: from kivy.adapters.listadapter import ListAdapter [as 别名]
# 或者: from kivy.adapters.listadapter.ListAdapter import get_view [as 别名]
class TreeView(BoxLayout):
""" Main middle col, parent selected n uncles left, child nodes on right """
def __init__(self, **kwargs):
super(TreeView, self).__init__(**kwargs)
self.parent_and_uncles_list_adapter = ListAdapter(
data=[El.get("TEXT") for El in parentMap[selectedParent]],
selection_mode='single',
allow_empty_selection=False,
cls=ListItemButton)
self.add_widget(ListView(adapter=self.parent_and_uncles_list_adapter))
self.parent_and_uncles_list_adapter.get_view(selectedIndexList[-2]).trigger_action(duration=0)
self.main_list_adapter = ListAdapter(
data=[El.get("TEXT") for El in selectedParent],
selection_mode='single',
allow_empty_selection=False,
cls=ListItemButton)
self.add_widget(ListView(adapter=self.main_list_adapter))
self.main_list_adapter.get_view(selectedIndexList[-1]).trigger_action(duration=0)
child_list_adapter = ListAdapter(
data=[El.get("TEXT") for El in selectedParent[selectedIndexList[-1]]],
selection_mode='single',
allow_empty_selection=True,
cls=ListItemButton)
self.add_widget(ListView(adapter=child_list_adapter))
示例2: __init__
# 需要导入模块: from kivy.adapters.listadapter import ListAdapter [as 别名]
# 或者: from kivy.adapters.listadapter.ListAdapter import get_view [as 别名]
def __init__(self, settings, channel, **kwargs):
super(ChannelSelectView, self).__init__(**kwargs)
self.register_event_type('on_channel_selected')
self.register_event_type('on_channel_cancel')
data = []
channel_list = self.ids.channelList
available_channels = list(settings.runtimeChannels.get_active_channels().iterkeys())
available_channels.sort()
try:
for available_channel in available_channels:
data.append({'text': available_channel, 'is_selected': False})
args_converter = lambda row_index, rec: {'text': rec['text'], 'size_hint_y': None, 'height': dp(50)}
list_adapter = ListAdapter(data=data,
args_converter=args_converter,
cls=ChannelItemButton,
selection_mode='single',
allow_empty_selection=True)
channel_list.adapter = list_adapter
#select the current channel
index = 0
for item in list_adapter.data:
if item['text'] == channel:
view = list_adapter.get_view(index)
view.trigger_action(duration=0) #duration=0 means make it an instant selection
index += 1
list_adapter.bind(on_selection_change=self.on_select)
self.channel = channel
except Exception as e:
Logger.error("ChannelSelectView: Error initializing: " + str(e))
示例3: NewProjectDialog
# 需要导入模块: from kivy.adapters.listadapter import ListAdapter [as 别名]
# 或者: from kivy.adapters.listadapter.ListAdapter import get_view [as 别名]
class NewProjectDialog(BoxLayout):
listview = ObjectProperty(None)
''':class:`~kivy.uix.listview.ListView` used for showing file paths.
:data:`listview` is a :class:`~kivy.properties.ObjectProperty`
'''
select_button = ObjectProperty(None)
''':class:`~kivy.uix.button.Button` used to select the list item.
:data:`select_button` is a :class:`~kivy.properties.ObjectProperty`
'''
cancel_button = ObjectProperty(None)
''':class:`~kivy.uix.button.Button` to cancel the dialog.
:data:`cancel_button` is a :class:`~kivy.properties.ObjectProperty`
'''
adapter = ObjectProperty(None)
''':class:`~kivy.uix.listview.ListAdapter` used for selecting files.
:data:`adapter` is a :class:`~kivy.properties.ObjectProperty`
'''
image = ObjectProperty(None)
'''Type of :class:`~kivy.uix.image.Image` to display image of selected
new template.
:data:`image` is a :class:`~kivy.properties.ObjectProperty`
'''
list_parent = ObjectProperty(None)
'''Parent of listview.
:data:`list_parent` is a :class:`~kivy.properties.ObjectProperty`
'''
prev_selection = NumericProperty(0)
'''to memorize the previous selection.
:attr:`prev_selection` is a :class:
`~kivy.properties.NumericProperty`, defaults to (0).
'''
__events__ = ('on_select', 'on_cancel')
def __init__(self, **kwargs):
super(NewProjectDialog, self).__init__(**kwargs)
item_strings = list(NEW_PROJECTS.keys())
item_strings.sort()
self.adapter = ListAdapter(cls=Factory.DesignerListItemButton,
data=item_strings,
selection_mode='single',
allow_empty_selection=False)
self.adapter.check_for_empty_selection = self.check_for_empty_selection
self.adapter.bind(on_selection_change=self.on_adapter_selection_change)
self.listview = ListView(adapter=self.adapter)
self.listview.size_hint = (0.5, 1)
self.listview.pos_hint = {'top': 1}
self.list_parent.add_widget(self.listview, 1)
self.on_adapter_selection_change(self.adapter)
def on_parent(self, *args):
if self.parent:
Window.bind(on_key_down=self._on_keyboard_down)
else:
Window.unbind(on_key_down=self._on_keyboard_down)
def _on_keyboard_down(self, keyboard, key, codepoint,
text, modifier, *args):
'''To detect which key is pressed
'''
if modifier:
return False
key_str = Keyboard.keycode_to_string(Window._system_keyboard, key)
if key_str == 'up':
v = self.adapter.get_view(self.prev_selection - 1)
if v is not None:
self.adapter.handle_selection(v)
return True
if key_str == 'down':
v = self.adapter.get_view(self.prev_selection + 1)
if v is not None:
self.adapter.handle_selection(v)
return True
if key_str == 'enter':
self.dispatch('on_select')
return True
def check_for_empty_selection(self, *args):
if not self.adapter.allow_empty_selection:
if len(self.adapter.selection) == 0:
# Select the first item if we have it.
v = self.adapter.get_view(self.prev_selection)
if v is not None:
self.adapter.handle_selection(v)
def on_adapter_selection_change(self, adapter):
'''Event handler for 'on_selection_change' event of adapter.
'''
name = adapter.selection[0].text.lower() + '.png'
name = name.replace(' and ', '_')
image_source = join(NEW_TEMPLATE_IMAGE_PATH, name)
_dir = get_kd_dir()
image_source = join(_dir, image_source)
#.........这里部分代码省略.........
示例4: InputScreen
# 需要导入模块: from kivy.adapters.listadapter import ListAdapter [as 别名]
# 或者: from kivy.adapters.listadapter.ListAdapter import get_view [as 别名]
class InputScreen(GridLayout):
# Create interface
def __init__(self, **kwargs):
self.controller = kwargs.pop('controller', None)
super(InputScreen, self).__init__(**kwargs)
self.cols = 2
# Text input
self.text = ShortcutTextInput(multiline=True, focus=True, keyboard_handler=self._on_keyboard_down)
self.add_widget(self.text)
self.text.bind(text=self._on_text)
self.text.hint_text="Begin typing to test text prediction."
# predictions
obj_printer = lambda obj: "{} - {}".format(str(obj), self.current_prediction.get(obj, 0))
args_converter = lambda row_index, obj: {'text': obj_printer(obj),
'size_hint_y': None,
'height': 25}
self.prediction_adapter = ListAdapter(data=[],
args_converter=args_converter,
selection_mode='single',
allow_empty_selection=False,
cls=ListItemLabel)
self.prediction_list = ListView(adapter=self.prediction_adapter)
self.add_widget(self.prediction_list)
self.current_prediction = FreqDist()
# Record history
self.previous_record = None
self.in_word = False
# Handle non-standard shortcuts
# Mainly prediction selection and confirmation
def _on_keyboard_down(self, keyboard, keycode, text, modifiers):
# print keycode
if keycode[1] == 'tab':
# Change selected prediction
self.change_selection('shift' in modifiers)
return True
elif keycode[1] == 'up':
self.change_selection(True)
return True
elif keycode[1] == 'down':
self.change_selection(False)
return True
elif keycode[1] == 'enter':
# Use the current prediction
self._accept_prediction()
return True
elif keycode[1] == 'spacebar':
# Record word
self._accept_word(self._current_word())
return False
elif keycode[1] == 'backspace':
# Remove previous word from record
self.undo_word()
return False
else:
# Default behaviour
return False
# Select a different prediction to use
def change_selection(self, direction):
# Get current index
selection = self.prediction_adapter.selection[0]
index = self._selection_index(selection)
# Deselect the current selection
self._deselect_current()
# whether to move back or forward
if direction:
index -= 1
else:
index += 1
index = index % len(self.prediction_adapter.cached_views)
# Select next
self._select_at_index(index)
# Get the index of the currently selected prediction
def _selection_index(self, selection):
for i, view in self.prediction_adapter.cached_views.iteritems():
if view == selection:
return i
# Deselect the currently selected prediction
def _deselect_current(self):
selection = self.prediction_adapter.selection[0]
index = self._selection_index(selection)
self.prediction_adapter.get_view(index).deselect()
# Select the prediction with the given index
def _select_at_index(self, index):
#.........这里部分代码省略.........
示例5: CompletionBubble
# 需要导入模块: from kivy.adapters.listadapter import ListAdapter [as 别名]
# 或者: from kivy.adapters.listadapter.ListAdapter import get_view [as 别名]
class CompletionBubble(Bubble):
list_view = ObjectProperty(None, allownone=True)
'''(internal) Reference a ListView with a list of SuggestionItems
:data:`list_view` is a :class:`~kivy.properties.ObjectProperty`
'''
adapter = ObjectProperty(None)
'''(internal) Reference a ListView adapter
:data:`adapter` is a :class:`~kivy.properties.ObjectProperty`
'''
__events__ = ('on_complete', 'on_cancel', )
def __init__(self, **kwargs):
super(CompletionBubble, self).__init__(**kwargs)
Window.bind(on_touch_down=self.on_window_touch_down)
def on_window_touch_down(self, win, touch):
'''Disable the completion if the user clicks anywhere
'''
if not self.collide_point(*touch.pos):
self.dispatch('on_cancel')
def _create_list_view(self, data):
'''Create the ListAdapter
'''
self.adapter = ListAdapter(
data=data,
args_converter=self._args_converter,
cls=SuggestionItem,
selection_mode='single',
allow_empty_selection=False
)
self.adapter.bind(on_selection_change=self.on_selection_change)
self.list_view = CompletionListView(adapter=self.adapter)
self.add_widget(self.list_view)
def _args_converter(self, index, completion):
return {'text': completion.name,
'is_selected': False,
'complete': completion.complete,
'selected_by_touch': self.selected_by_touch}
def selected_by_touch(self, item):
self.dispatch('on_complete', item.complete)
def show_completions(self, completions, force_scroll=False):
'''Update the Completion ListView with completions
'''
if completions == []:
fake_completion = type('obj', (object,),
{'name': 'No suggestions', 'complete': ''})
completions.append(fake_completion)
Window.bind(on_key_down=self.on_key_down)
if not self.list_view:
self._create_list_view(completions)
else:
self.adapter.data = completions
if force_scroll:
self.list_view.scroll_to(0)
def on_selection_change(self, *args):
pass
def _scroll_item(self, new_index):
'''Update the scroll view position to display the new_index item
'''
item = self.adapter.get_view(new_index)
if item:
item.trigger_action(0)
if new_index > 2 and new_index < len(self.adapter.data) - 1:
self.list_view.scroll_to(new_index - 3)
def on_key_down(self, instance, key, *args):
'''Keyboard listener to grab key codes and interact with the
Completion box
'''
selected_item = self.adapter.selection[0]
selected_index = selected_item.index
if self.list_view.scrolled:
# recreate list view after mouse scroll due to the bug kivy/#3418
self.remove_widget(self.list_view)
self.list_view = None
self.show_completions(self.adapter.data)
return self.on_key_down(instance, key, args)
if key == 273:
# up
if selected_index > 0:
self._scroll_item(selected_index - 1)
return True
elif key == 274:
# down
if selected_index < len(self.adapter.data) - 1:
self._scroll_item(selected_index + 1)
return True
elif key in [9, 13, 32]:
#.........这里部分代码省略.........