本文整理汇总了Python中kivy.uix.treeview.TreeView.bind方法的典型用法代码示例。如果您正苦于以下问题:Python TreeView.bind方法的具体用法?Python TreeView.bind怎么用?Python TreeView.bind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.uix.treeview.TreeView
的用法示例。
在下文中一共展示了TreeView.bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_content
# 需要导入模块: from kivy.uix.treeview import TreeView [as 别名]
# 或者: from kivy.uix.treeview.TreeView import bind [as 别名]
def update_content(self, *args):
widget = self.console.widget
if not widget:
return
from kivy.uix.scrollview import ScrollView
self.root = root = BoxLayout()
self.sv = sv = ScrollView(scroll_type=["bars", "content"])
treeview = TreeView(hide_root=True, size_hint_y=None)
treeview.bind(minimum_height=treeview.setter("height"))
keys = list(widget.properties().keys())
keys.sort()
node = None
wk_widget = weakref.ref(widget)
for key in keys:
text = '%s' % key
node = TreeViewProperty(text=text, key=key, widget_ref=wk_widget)
node.bind(is_selected=self.show_property)
try:
widget.bind(**{
key: partial(self.update_node_content, weakref.ref(node))
})
except:
pass
treeview.add_node(node)
root.add_widget(sv)
sv.add_widget(treeview)
self.console.set_content(root)
示例2: build
# 需要导入模块: from kivy.uix.treeview import TreeView [as 别名]
# 或者: from kivy.uix.treeview.TreeView import bind [as 别名]
def build(self):
root = BoxLayout(orientation='horizontal', padding=20, spacing=20)
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)
n = create_tree('Widgets')
attach_node('Standard widgets', n)
attach_node('Complex widgets', n)
attach_node('Scatters', n)
attach_node('Treeviews', n)
attach_node('Popup', n)
n = create_tree('Layouts')
attach_node('Anchor Layout', n)
attach_node('Box Layout', n)
attach_node('Float Layout', n)
attach_node('Grid Layout', n)
attach_node('Stack Layout', n)
root.add_widget(tree)
self.content = content = BoxLayout()
root.add_widget(content)
sc = Showcase()
sc.content.add_widget(root)
self.content.add_widget(StandardWidgets())
return sc
示例3: create_scrollable_treeview
# 需要导入模块: from kivy.uix.treeview import TreeView [as 别名]
# 或者: from kivy.uix.treeview.TreeView import bind [as 别名]
def create_scrollable_treeview(nested_dicts, onclick, root_label):
tv = TreeView(root_options={'text': root_label})
def populate_tree(parent, level, index, path):
obj = level if index is None else level[index]
if hasattr(obj, 'name'):
label = TreeViewLabel(text=obj.name,
onclick=onclick)
label.path = copy(path)
tv.add_node(label, parent)
else:
try:
indices = obj.iterkeys()
except AttributeError:
indices = xrange(len(obj))
# This `if` is a hack to deal with the root of the given tree
if index is None:
group_node = None
else:
group_node = TreeViewLabel(text=index)
tv.add_node(group_node, parent)
for index in indices:
populate_tree(group_node, obj, index, path + [index])
populate_tree(None, nested_dicts, None, [])
# Make the tree scrollable inside the ScrollView
tv.size_hint_y = None
tv.bind(minimum_height=tv.setter('height'))
scrollable = ScrollView()
scrollable.add_widget(tv)
return scrollable
示例4: getTreeViewAsFiles
# 需要导入模块: from kivy.uix.treeview import TreeView [as 别名]
# 或者: from kivy.uix.treeview.TreeView import bind [as 别名]
def getTreeViewAsFiles(self):
try:
tv = TreeView(hide_root=True)
tv.size_hint = 1, None
tv.bind(minimum_height = tv.setter('height'))
for key in self.config_files:
newnode = tv.add_node(TreeViewLabel(text=self.config_files[key].filename, font_size=self.label_font_size, color=self.filename_label_color))
for child_filename in self.config_files[key].child_files:
self._addFileNodeToFileTreeView(tv, newnode, self.config_files[key].child_files[child_filename])
for configkey in self.config_files[key].config:
if isinstance(self.config_files[key].config[configkey], dict):
self._addDictNodeToFileTreeView(tv, newnode, configkey, self.config_files[key].config[configkey])
else:
tv.add_node(TreeViewLabel(text=str(configkey) + ':' + str(self.config_files[key].config[configkey]), font_size=self.label_font_size, color=self.key_label_color), newnode)
scv = ScrollView(pos = (0, 0), bar_width = 10)
scv.add_widget(tv)
return scv
except:
e = sys.exc_info()[0]
self.log.exception("Error: %s" % e )
raise
示例5: build
# 需要导入模块: from kivy.uix.treeview import TreeView [as 别名]
# 或者: from kivy.uix.treeview.TreeView import bind [as 别名]
def build(self):
root = BoxLayout(orientation='horizontal', padding=20, spacing=20)
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)
n = create_tree('Buttons')
attach_node('Standard buttons', n)
attach_node('Options buttons', n)
n = create_tree('Sliders')
attach_node('Horizontal sliders', n)
attach_node('Vertical sliders', n)
n = create_tree('Scatter')
attach_node('Scatter with image', n)
attach_node('Scatter with buttons', 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)
sc = Showcase()
sc.content.add_widget(root)
return sc
示例6: build
# 需要导入模块: from kivy.uix.treeview import TreeView [as 别名]
# 或者: from kivy.uix.treeview.TreeView import bind [as 别名]
def build(self):
root = BoxLayout(orientation="horizontal", padding=20, spacing=20)
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)
n = create_tree("Buttons")
attach_node("Standard buttons", n)
attach_node("Options buttons", n)
attach_node("Horizontal sliders", n)
attach_node("Vertical sliders", n)
attach_node("Scatter with image", n)
attach_node("Scatter with buttons", n)
attach_node("Monoline textinput", n)
attach_node("Multiline textinput", n)
attach_node("Standard treeview", n)
attach_node("Treeview without root", n)
attach_node("Accordion", n)
attach_node("Popup", n)
attach_node("Switch", n)
n = create_tree("Experimentals")
attach_node("Filechooser icon", n)
attach_node("Filechooser list", n)
root.add_widget(tree)
self.content = content = BoxLayout()
root.add_widget(content)
sc = Showcase()
sc.content.add_widget(root)
return sc
示例7: build
# 需要导入模块: from kivy.uix.treeview import TreeView [as 别名]
# 或者: from kivy.uix.treeview.TreeView import bind [as 别名]
def build(self):
#for i in range(30):
# btn = Button(text=str(i), size=(480, 40),
# size_hint=(None, None))
# layout.add_widget(btn)
tv = TreeView(root_options=dict(text='Tree One'), hide_root=True, indent_level=4)
tv.size_hint = 1, None
tv.bind(minimum_height = tv.setter('height'))
populate_tree_view(tv)
root = ScrollView(pos = (0, 0))
root.add_widget(tv)
return root
示例8: AddAsset
# 需要导入模块: from kivy.uix.treeview import TreeView [as 别名]
# 或者: from kivy.uix.treeview.TreeView import bind [as 别名]
def AddAsset(self):
"""show the add asset dialog"""
try:
popup = Popup(title="select asset")
popup.size_hint = (0.8,0.8)
tv = TreeView(root_options=dict(text='Tree One'), hide_root=True, indent_level=4)
tv.size_hint = 1, None
tv.bind(minimum_height = tv.setter('height'))
tv.load_func = self.populateTreeNode
tv.bind(selected_node=self.on_assetSelected)
root = ScrollView(pos = (0, 0))
root.add_widget(tv)
popup.add_widget(root)
popup.open()
except Exception as e:
showError(e)
示例9: fill_tree
# 需要导入模块: from kivy.uix.treeview import TreeView [as 别名]
# 或者: from kivy.uix.treeview.TreeView import bind [as 别名]
def fill_tree(self, filtre):
self.scroll.clear_widgets()
tree = TreeView(hide_root=True, size_hint_y=None, size_hint_x = 0.6)
tree.bind(minimum_height=tree.setter('height'),
selected_node=self.show_details)
self.scroll.add_widget(tree)
for uv in self.uvs:
if uv[0].startswith(filtre.upper()) and uv[1] != 0:
node = TreeViewLabel(text=u"%s (%s €)" % (uv[0],
uv[1]*0.06),
font_size=30, size_hint_y=None,
padding=(20,20))
tree.add_node(node)
self.tree = tree
示例10: FileCheckUi
# 需要导入模块: from kivy.uix.treeview import TreeView [as 别名]
# 或者: from kivy.uix.treeview.TreeView import bind [as 别名]
class FileCheckUi(App):
tv = None
def build(self):
l = BoxLayout(orientation='vertical')
b = Button(text='Run')
b.bind(on_press=self.btn_run)
b.size_hint = 1, 1
sv = ScrollView()
sv.size_hint = 1, 10
self.tv = TreeView(root_options=dict(text='Results'))
self.tv.size_hint = 1, None
self.tv.bind(minimum_height = self.tv.setter('height'))
sv.add_widget(self.tv)
l.add_widget(b)
l.add_widget(sv)
return l
def list2tree(self, lbl, lst):
tvn = self.tv.add_node(TreeViewLabel(text=lbl))
for t in lst:
self.tv.add_node(TreeViewLabel(text=t), tvn)
def report(self, added, error, missing):
self.report_clear ()
self.list2tree ('Added', added)
self.list2tree('Error', error)
self.list2tree('Missing', missing)
def report_clear(self):
while len (self.tv.root.nodes) > 0:
self.tv.remove_node (self.tv.root.nodes[0])
def btn_run(self, value):
fdb = '/sdcard/Download/filedb.csv'
self.dw = None
self.dw = CsvTest.DirWalker ()
self.dw.filedb.load( fdb)
self.dw.walk ( '/sdcard/Download')
self.dw.filedb.save (fdb)
self.report( self.dw.filedb.added,
self.dw.filedb.errors,
self.dw.filedb.not_visited())
示例11: POSFMApp
# 需要导入模块: from kivy.uix.treeview import TreeView [as 别名]
# 或者: from kivy.uix.treeview.TreeView import bind [as 别名]
class POSFMApp(App):
def build(self):
layout = FloatLayout()
self.tv = TreeView(root_options=dict(text='Tree One'), hide_root=True, indent_level=0, indent_start=0)
self.tv.size_hint = 1, None
self.tv.bind(minimum_height = self.tv.setter('height'))
self.populate_tree_view(self.tv)
self.camera = Button(text = 'Camera', size_hint =(1/3.,.23),
background_color=[1,0,0,.6], pos_hint={'x':0,'y':0})
self.add = Button(text = 'Add', size_hint =(1/3.,.23),
background_color=[1,0,0,.6], pos_hint={'x':1/3.,'y':0})
self.sort = Button(text = 'Sort', size_hint =(1/3.,.23),
background_color=[1,0,0,.6], pos_hint={'x':2/3.,'y':0})
root = ScrollView(pos = (0, 0))
root.add_widget(self.tv)
layout.add_widget(root)
layout.add_widget(self.camera)
layout.add_widget(self.add)
layout.add_widget(self.sort)
return layout
def populate_tree_view(self, tv):
for i, item in enumerate(foodlist):
if item.categ not in usedcat.keys():
catbutton = TreeViewButton(text='%s' % item.categ, font_size = '50sp',
size = (100, 450), background_color=[1,1,0,1])
catbutton.bind(on_press=self.cat_clicked)
g = self.tv.add_node(catbutton)
usedcat[item.categ] = g
else:
g = usedcat[item.categ]
itembutton = TreeViewButton(text='%s' % item.name, font_size = '30sp',
size = (100,150), background_color=[0,1,1,1])
itembutton.outline_height = 10
self.tv.add_node(itembutton, g)
def cat_clicked(self, button):
self.tv.toggle_node(button)
示例12: build
# 需要导入模块: from kivy.uix.treeview import TreeView [as 别名]
# 或者: from kivy.uix.treeview.TreeView import bind [as 别名]
def build(self):
root = BoxLayout(orientation='horizontal', padding=20, spacing=20)
tree = TreeView(size_hint=(None, 1), width=200, hide_root=True, indent_level=0)
tree.bind(selected_node=self.on_select_node)
n = tree.add_node(TreeViewLabel(text=u'Меню', is_open=True, no_selection=True))
n = tree.add_node(TreeViewLabel(text=u'Управление', is_open=True, no_selection=True))
tree.add_node(TreeViewLabel(text=u'Открыть'), n, )
tree.add_node(TreeViewLabel(text=u'Закрыть'), n)
n = tree.add_node(TreeViewLabel(text=u'Настройки', is_open=True, no_selection=True))
#tree.add_node(TreeViewLabel(text='Что то еще'), n)
root.add_widget(tree)
self.content = content = BoxLayout()
root.add_widget(content)
sc = Showcase()
sc.content.add_widget(root)
return sc
示例13: show_key
# 需要导入模块: from kivy.uix.treeview import TreeView [as 别名]
# 或者: from kivy.uix.treeview.TreeView import bind [as 别名]
def show_key(self, gloup):
tree = TreeView(size_hint=(1, 1), hide_root=True,
indent_level=20)
def getReadableSize(size):
units = ['o', 'Ko', 'Mo', 'Go']
unit = 0
while size > 1024 and unit < 3:
size = size / 1024.0
unit = unit + 1
return "%.2f %s" % (size, units[unit])
tree.bind(selected_node=self.show_file)
self.content.clear_widgets()
self.content.add_widget(tree)
dirNodes = dict()
# la racine
dirNodes[path_to_watch] = tree.add_node(TreeViewLabel(
text="Ordinateur", is_open=True, no_selection=True))
for root, dirs, files in os.walk(path_to_watch):
for diritem in dirs:
fulldiritem = os.path.join(root, diritem)
dirNodes[fulldiritem] = tree.add_node(TreeViewLabel(
text=diritem, is_open=False, no_selection=True), dirNodes[root])
for fileitem in files:
(a, ext) = os.path.splitext(fileitem)
if fileitem[0] !='.':
label = "%s (%s)" % (fileitem, getReadableSize(os.path.getsize(os.path.join(root, fileitem)))) #FIXME Aligner à droite
if ext == '.pdf':
tree.add_node(TreeViewLabelPath(os.path.join(root, fileitem), text=label), dirNodes[root])
else:
tree.add_node(TreeViewLabel(text=label, no_selection=True), dirNodes[root]) # FIXME Faire du gris
示例14: getMergedTreeView
# 需要导入模块: from kivy.uix.treeview import TreeView [as 别名]
# 或者: from kivy.uix.treeview.TreeView import bind [as 别名]
def getMergedTreeView(self):
try:
tv = TreeView(hide_root=True)
tv.size_hint = 1, None
tv.bind(minimum_height = tv.setter('height'))
for key in self.config_files:
merged_dict = self.config_files[key].get_merged_config()
for key in merged_dict:
if isinstance(merged_dict[key], dict):
newnode = tv.add_node(TreeViewLabel(text=str(key), font_size=self.label_font_size, color=self.key_label_color))
self._addNodeToMergedTreeView(tv, newnode, merged_dict[key])
else:
newnode = tv.add_node(TreeViewLabel(text=str(key) + ':' + str(merged_dict[key]), font_size=self.label_font_size, color=self.key_label_color))
scv = ScrollView(pos = (0, 0), bar_width = 10)
scv.add_widget(tv)
return scv
except:
e = sys.exc_info()[0]
self.log.exception("Error: %s" % e )
raise
示例15: MainScreen
# 需要导入模块: from kivy.uix.treeview import TreeView [as 别名]
# 或者: from kivy.uix.treeview.TreeView import bind [as 别名]
class MainScreen(Screen):
file_view = ObjectProperty(None)
Builder.load_file('gui/mainscreen.kv')
stop = threading.Event()
def setup_cloud_task(self):
try:
controller.setup_cloud(AES_CRYPTO)
except CloudTokenError as err:
open_popup_error('Cloud Token', err)
self.stop.set()
def on_pre_enter(self, *args):
controller.setup_stash()
# use thread for background task, use clock in a background task to access the ui
threading.Thread(target=self.setup_cloud_task).start()
file_names = controller.get_uploaded_file_names()
self.file_view = TreeView(hide_root=True, indent_level=4)
self.file_view.size_hint = 1, None
self.file_view.bind(minimum_height=self.file_view.setter('height'))
self.scroll_view.add_widget(self.file_view)
for file_name in file_names:
self.file_view.add_node(TreeViewLabel(text=file_name))
self.max_storage_size = controller.get_max_storage_size()
self.usage_bar.max = self.max_storage_size
self.update_storage_view()
def dismiss_popup(self):
self._popup.dismiss()
def select_file(self):
content = LoadDialog(load=self.upload_file, cancel=self.dismiss_popup)
self._popup = Popup(title="Upload file", content=content, size_hint=(0.9, 0.9))
self._popup.open()
def update_storage_view(self):
self.used_storage_size = controller.get_used_storage_size()
self.usage_label.text = controller.get_data_type_format(self.used_storage_size, self.max_storage_size)
self.usage_bar.value = self.used_storage_size
def get_free_storage_size(self):
return self.max_storage_size - self.used_storage_size
def split_input_file_task(self):
controller.save_file_input(self.filename, self.file_input, AES_CRYPTO)
self.file_view.add_node(TreeViewLabel(text=self.filename))
self.update_storage_view()
try:
controller.update_data(self.filename, AES_CRYPTO)
except CloudTokenError as err:
open_popup_error('Cloud Token', err)
self.stop.set()
def upload_file_task(self):
with open(os.path.join(self.path, self.filename[0]), utils.READ_BINARY_MODE) as file:
self.file_input = file.read()
if controller.is_storage_available(len(self.file_input), self.get_free_storage_size()):
self.filename = os.path.basename(self.filename[0])
self.split_input_file_task()
else:
open_popup('Upload Error', 'Not enough storage available.')
self.stop.set()
def upload_file(self, path, filename):
self.path = path
self.filename = filename
threading.Thread(target=self.upload_file_task).start()
self.dismiss_popup()
def get_selected_node(self):
selected_node = self.file_view.selected_node
if selected_node is None:
raise NoSelectedNode('No file has been selected.')
return selected_node
def select_location(self):
try:
self.selected_node_text = self.get_selected_node().text
except NoSelectedNode as err:
open_popup_error('Download error', err)
return
content = SaveDialog(save=self.save, cancel=self.dismiss_popup)
content.file_name_label.text = self.selected_node_text
self._popup = Popup(title="Download file", content=content,
size_hint=(0.9, 0.9))
self._popup.open()
def download_file_task(self):
try:
controller.download_selected_file(self.selected_node_text, self.path, self.filename, AES_CRYPTO)
open_popup('Download file', 'Download was successful')
except (DownloadFileError, FileSizeError, CloudTokenError) as err:
open_popup_error('Download error', err)
return
self.stop.set()
def save(self, path, filename):
#.........这里部分代码省略.........