示例#1
0
文件: treeview.py 项目: gmork2/kvnm
def populate_tree_view(tree_view: TreeView,
                       parent: Union[TreeView, TreeViewLabel, None],
                       node: Tree) -> None:
    """
    Populates a TreeView recursively from node data.

    :param tree_view:
    :param parent:
    :param node:
    :return:
    """
    if parent is None:
        tree_node = tree_view.add_node(
            TreeViewLabel(
                text=node['node_id'],
                is_open=True
            ))
    else:
        tree_node = tree_view.add_node(
            TreeViewLabel(
                text=node['node_id'],
                is_open=False
            ),
            parent
        )

    for child_node in node['children']:
        populate_tree_view(
            tree_view, tree_node, child_node
        )
示例#2
0
文件: main2.py 项目: stdgn/kivy-tr
class agacGorunumu(App):

    def build(self):
        duzen=BoxLayout(orientation='vertical')
        
        self.agac_koku = TreeView(hide_root=True, size_hint_y=0.8)
        
        kuruyemisler=[('Sert Kabuklular',('Ceviz', 'Fındık', 'Badem')), 
                      ('Meyve Kuruları',('Dut', 'Vişne', 'Kayısı', 'İncir'))]
        
        for ky in kuruyemisler:
            eb=self.agac_koku.add_node(TreeViewLabel(text=ky[0]))
            for k in ky[1]:
                self.agac_koku.add_node(TreeViewLabel(text=k),eb)

        duzen.add_widget(self.agac_koku)
        dgm=Button(text='Elemanları Yaz', size_hint_y=0.2)
        dgm.bind(on_press=self.elemanlari_yaz)
        duzen.add_widget(dgm)
        
        return duzen
        
        
    def elemanlari_yaz(self, *args):
        for eb in self.agac_koku.iterate_all_nodes():
            print eb.level, eb.text
            
        if self.agac_koku.selected_node:
            print "Seçili Eleman", self.agac_koku.selected_node.text
            
         
        print self.agac_koku.get_node_at_pos((1,1))
 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
示例#4
0
    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
示例#5
0
    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"],
                                  bar_width='10dp')
        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:
            node = TreeViewProperty(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)
示例#6
0
    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)
示例#7
0
    def build(cls):

        #if exists(cls.pickle_fn()):
        #   result = pickle.load(open(cls.pickle_fn(), "rb" ) )

        tv = TreeView(hide_root=True)
        tv.size_hint = 1, None
        tv.bind(minimum_height=tv.setter('height'))

        data = Data()
        groups = data.get_groups()
        ingredients = data.get_ingredients()

        def already_created(node, text):
            if hasattr(node, 'text'):
                return node.text == text
            else:
                return False

        for group in groups:
            if len(
                    list(
                        filter(
                            lambda seq: already_created(seq, group['group']),
                            tv.iterate_all_nodes()))) == 0:
                node_group = tv.add_node(TreeViewLabel(text=group['group']))

            node_group = list(
                filter(lambda seq: already_created(seq, group['group']),
                       tv.iterate_all_nodes()))
            if len(node_group) > 0:
                if len(
                        list(
                            filter(
                                lambda seq: already_created(
                                    seq, group['subgroup']),
                                tv.iterate_all_nodes()))) == 0:
                    node_subgroup = tv.add_node(
                        TreeViewLabel(text=group['subgroup']), node_group[0])

        for ingredient in ingredients:
            node_subgroup = list(
                filter(
                    lambda seq: already_created(seq, ingredient['food_subgroup'
                                                                ]),
                    tv.iterate_all_nodes()))
            if len(node_subgroup) > 0:
                tv.add_node(
                    IngredientListPopupItem(
                        prop_id=ingredient['id'],
                        name=ingredient['name'],
                        name_scientific=ingredient['name_scientific'],
                        description=ingredient['description']),
                    node_subgroup[0])
            else:
                print('error adding {0}', ingredient['name'])

        cls.tv = tv
示例#8
0
 def build(self):
     boxLayout = BoxLayout()
     tv = TreeView()
     for i in range(5):
         node = TreeViewButton()
         for i2 in range(5):
             node.add_widget(Label())
         tv.add_node(node)
     # tv.root_options.set
     #tv.add_node(TreeViewLabel(text='My first item'))
     #tv.add_node(TreeViewLabel(text='My second item'))
     boxLayout.add_widget(tv)
     return boxLayout
示例#9
0
    def __init__(self, **kwargs):
        super(GroupScreen, self).__init__(**kwargs)

        clients = self.consultasector()

        bridge_view = TreeView()
        for s in clients:
            x = str(s[0]) + " - " + str(s[1])
            bridge_view.add_node(
                TreeViewLabel(text=str(x).capitalize(),
                              even_color=[0.5, 0.1, 0.1, 1],
                              odd_color=[0.1, 0.1, 0.5, 1]))

        self.add_widget(bridge_view)
示例#10
0
文件: main.py 项目: mbaser/kivy-tr
    def build(self):
        agac_koku = TreeView()
        ebeveyn1=agac_koku.add_node(TreeViewLabel(text='Ebeveyn 1'))
        
        cocuk11=agac_koku.add_node(TreeViewLabel(text='Çocuk 1 1'), ebeveyn1)
        cocuk12=agac_koku.add_node(TreeViewLabel(text='Çocuk 1 2'), ebeveyn1)
        
        cocuk121=agac_koku.add_node(TreeViewLabel(text='Çocuk 1 2 1'), cocuk12)
        cocuk122=agac_koku.add_node(TreeViewLabel(text='Çocuk 1 2 2'), cocuk12)
        
        ebeveyn2=agac_koku.add_node(TreeViewLabel(text='Ebeveyn 2'))
        cocuk21=agac_koku.add_node(TreeViewLabel(text='Çocuk 2 1'), ebeveyn2)
        cocuk22=agac_koku.add_node(TreeViewLabel(text='Çocuk 2 2'), ebeveyn2)

        
        return agac_koku
示例#11
0
    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
示例#12
0
文件: main.py 项目: mbaser/kivy-tr
class agacGorunumu(App):

    def build(self):
        duzen=BoxLayout(orientation='vertical')
        
        self.agac_koku = TreeView(hide_root=True)
        
        kuruyemisler=[('Sert Kabuklular',('Ceviz', 'Fındık', 'Badem')), 
                      ('Meyve Kuruları',('Dut', 'Vişne', 'Kayısı', 'İncir'))]
        
        for ky in kuruyemisler:
            eb=self.agac_koku.add_node(TreeViewLabel(text=ky[0]))
            for k in ky[1]:
                self.agac_koku.add_node(TreeViewLabel(text=k),eb)
        
        duzen.add_widget(self.agac_koku)
        
        return duzen
示例#13
0
class agacGorunumu(App):
    def build(self):
        duzen = BoxLayout(orientation='vertical')

        self.agac_koku = TreeView(hide_root=True)

        kuruyemisler = [('Sert Kabuklular', ('Ceviz', 'Fındık', 'Badem')),
                        ('Meyve Kuruları', ('Dut', 'Vişne', 'Kayısı', 'İncir'))
                        ]

        for ky in kuruyemisler:
            eb = self.agac_koku.add_node(TreeViewLabel(text=ky[0]))
            for k in ky[1]:
                self.agac_koku.add_node(TreeViewLabel(text=k), eb)

        duzen.add_widget(self.agac_koku)

        return duzen
示例#14
0
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())
示例#15
0
 def __init__(self, **kwargs):
     super(AssignmentsList, self).__init__(**kwargs)
     l = Label(text='ASSIGNMENT LIST')
     tv = TreeView(root_options=dict(text='Assignments'), hide_root=True)
     for t in tour:
         for node in t:
             if node in E:
                 itemNameTemp = str(data[node][1]) + ' ' + str(
                     data[node][2])
                 branchNameTemp = tv.add_node(
                     TreeViewLabel(text=itemNameTemp, is_open=True))
         for node in t:
             if node not in E:
                 dropItem = str(data[node][1]) + ' ' + str(data[node][2])
                 tv.add_node(TreeViewLabel(text=dropItem), branchNameTemp)
     # self.add_widget(l)
     self.add_widget(tv)
     tv.bind(on_node_expand=lambda self, evt: ViewMap().nodeExpanded())
     tv.bind(on_node_collapse=lambda self, evt: ViewMap().nodeColapsed())
示例#16
0
 def _populate(self, root_label: str, images: Iterable[ImageDescriptor]):
     tree = TreeView(root_options=dict(text=root_label))
     nodes = {Path('.'): None}
     for img in images:
         for parent in reversed(img.path.parents):
             if parent not in nodes:
                 node = SelectableTreeViewLabel(path=parent,
                                                text=parent.name)
                 node.bind(on_path_changed=self.on_nodes_path_changed)
                 nodes[parent] = tree.add_node(node, nodes[parent.parent])
     self.add_widget(tree)
示例#17
0
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)
示例#18
0
    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
示例#19
0
    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
示例#20
0
    def __init__(self, **kwargs):
        super(Tela, self).__init__(**kwargs)
        tv = TreeView(hide_root=False, indent_level=4)

        n1 = tv.add_node(TreeViewLabel(text='Item 1'))
        tv.add_node(TreeViewLabel(text='SubItem 1'), n1)
        tv.add_node(TreeViewLabel(text='SubItem 2'), n1)

        n2 = tv.add_node(TreeViewLabel(text='Item 2'))
        tv.add_node(TreeViewLabel(text='SubItem 1'), n2)
        tv.add_node(TreeViewLabel(text='SubItem 2'), n2)

        self.add_widget(tv)
示例#21
0
 def build(self):
     box = BoxLayout()
     tree = DroppableTreeView()
     tree.add_node(DraggableNode(text='node1',relation_manager=tree.relation_manager))
     tree.add_node(DraggableNode(text='node2',relation_manager=tree.relation_manager))
     tree.add_node(DraggableNode(text='node3',relation_manager=tree.relation_manager))
     tree.add_node(DraggableNode(text='node4',relation_manager=tree.relation_manager))
     box.add_widget(tree)
     tree2 = TreeView()
     node = TreeViewLabel(text='node1')
     tree2.add_node(node)
     tree2.add_node(TreeViewLabel(text='node2'),node)
     tree2.add_node(TreeViewLabel(text='node3'))
     tree2.add_node(TreeViewLabel(text='node4'))
     box.add_widget(tree2)
     return box
示例#22
0
    def build(self):
        agac_koku = TreeView()
        ebeveyn1 = agac_koku.add_node(TreeViewLabel(text='Ebeveyn 1'))

        cocuk11 = agac_koku.add_node(TreeViewLabel(text='Çocuk 1 1'), ebeveyn1)
        cocuk12 = agac_koku.add_node(TreeViewLabel(text='Çocuk 1 2'), ebeveyn1)

        cocuk121 = agac_koku.add_node(TreeViewLabel(text='Çocuk 1 2 1'),
                                      cocuk12)
        cocuk122 = agac_koku.add_node(TreeViewLabel(text='Çocuk 1 2 2'),
                                      cocuk12)

        ebeveyn2 = agac_koku.add_node(TreeViewLabel(text='Ebeveyn 2'))
        cocuk21 = agac_koku.add_node(TreeViewLabel(text='Çocuk 2 1'), ebeveyn2)
        cocuk22 = agac_koku.add_node(TreeViewLabel(text='Çocuk 2 2'), ebeveyn2)

        return agac_koku
示例#23
0
    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
示例#24
0
文件: kiosk.py 项目: apuyou/selfprint
	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
示例#25
0
class MainWindow(BoxLayout):
    def __init__(self, **kwargs):
        BoxLayout.__init__(self, **kwargs)

        self.nodes = []
        self.tree = TreeView(hide_root=True)

        #   Create UI
        self.add_node()
        self.add_widget(self.tree)

    def add_node(self):
        parent_nodes = []
        remove_list = []
        parent_texts = []
        add_list = []
        add_nodes = []

        # Add root node
        for g in game_data:
            if not g[1]:
                node = self.get_node(g[0])
                node.is_open = True
                self.tree.add_node(node)
                parent_nodes.append(node)
                remove_list.append(g)
                parent_texts.append(g[0])

        # Remove parents level 1
        for rm in remove_list:
            print('remove ', rm[0])
            game_data.remove(rm)
        remove_list = []

        c = 0
        while game_data and c < 5:
            print('data is ', game_data)
            for index, g in enumerate(game_data):
                if g[1] in parent_texts:
                    print(g[0], ' is child of ', parent_texts)
                    add_list.append(g)

            parent_texts = []

            for p in parent_nodes:
                for g in add_list:
                    if g[1] == p.text:
                        node = self.get_node(g[0])
                        self.tree.add_node(node, parent=p)
                        add_nodes.append(node)
                        parent_texts.append(g[0])
                        remove_list.append(g)

            # Clear list
            parent_nodes = add_nodes
            add_nodes = []
            print(parent_nodes)

            # Remove
            for rm in remove_list:
                game_data.remove(rm)
                remove_list = []

            c += 1

    @staticmethod
    def get_node(text):
        img = Image(source='C:\\Users\\PredatorPy\\Pictures\\Wallpaper\\eun-jin-dia.jpg', size_hint_x=0.1)
        node = None
        if text:
            node = MyNode(img, text)
        return node

    def cb(self, e, e2, e3):
        print('cb', e, e2, e3)

    def state(self, e):
        print(e)

    def on_touch_up(self, t):
        pass
class RowSelectorWidget(BoxLayout):
    def __init__(self, **kwargs):
        super(RowSelectorWidget, self).__init__(**kwargs)
        self.tree_view = TreeView(hide_root=True, indent_level=4)
        self.add_widget(self.tree_view)
        self.row_values = {}
        self.callback = self.null_callback

    def null_callback(self):
        pass

    def set_callback(self, callback_func):
        self.callback = callback_func

    def on_touch_down(self, touch):
        super(RowSelectorWidget, self).on_touch_down(touch)
        self.callback()

    def setDemoRows(self, numRows):
        self.clearRows()
        for i in range(numRows):
            self.addRow('Row ' + str(i))

    def addRow(self, row_val):
        node = TreeViewLabel(text=str(row_val))
        self.tree_view.add_node(node)
        self.row_values[node] = row_val

    def clearRows(self):
        self.row_values = {}
        self.remove_widget(self.tree_view)
        self.tree_view = TreeView(hide_root=True, indent_level=4)
        self.add_widget(self.tree_view)

    def setRows(self, row_list):
        self.clearRows()
        for r in row_list:
            self.addRow(r)

    def get_selected_row(self):
        sel_node = self.tree_view.selected_node
        if sel_node and sel_node in self.row_values.keys():
            return self.row_values[sel_node]
        else:
            return None

    def remove_selected_row(self):
        sel_node = self.tree_view.selected_node
        if sel_node is not None:
            self.row_values[sel_node] = None
            del self.row_values[sel_node]
            self.tree_view.remove_node(sel_node)

    def get_height(self, expected_node_height=1.0):
        HEIGHT_FACTOR = 1.1575
        height = 0
        for node in self.tree_view.iterate_all_nodes():
            height += dp(node.height * expected_node_height * HEIGHT_FACTOR)
        return height

    def get_num_Rows(self):
        return len(self.row_values)
示例#27
0
class JournalOverviewScreen(Screen):
    def __init__(self, **kwargs):
        super(JournalOverviewScreen, self).__init__(**kwargs)
        v_layout = BoxLayout(orientation='vertical', spacing=30)
        self.tree_view = TreeView(root_options=dict(text='Tree One'),
                                  hide_root=True,
                                  indent_level=4)
        self.tree_view.size_hint = (1, None)
        self.tree_view.bind(minimum_height=self.tree_view.setter('height'))
        scroll = ScrollView(pos=(0, 0))
        scroll.add_widget(self.tree_view)
        v_layout.add_widget(scroll)
        change_journal_layout = BoxLayout(orientation='horizontal',
                                          spacing=5,
                                          size_hint_y=0.1)
        change_journal_layout.add_widget(Label(text='Journal file:'))
        self.journal_file_input = TextInput(
            text=App.get_running_app().journal_file)
        change_journal_layout.add_widget(self.journal_file_input)
        change_journal_layout.add_widget(
            Button(text='Set another', on_press=self.set_another_journal))
        v_layout.add_widget(change_journal_layout)
        back_to_progress_button = Button(text='Back', size_hint_y=0.2)
        back_to_progress_button.on_press = self.goto_progress
        v_layout.add_widget(back_to_progress_button)
        self.add_widget(v_layout)

    def on_pre_enter(self):
        self.populate_tree_view()

    def on_leave(self):
        for node in self.tree_view.iterate_all_nodes():
            self.tree_view.remove_node(node)

    def populate_tree_view(self):
        journal = App.get_running_app().journal
        journal_node = self.tree_view.add_node(
            TreeViewLabel(text='Journal', is_open=True))
        for training in journal.trainings:
            training_node = self.tree_view.add_node(
                TreeViewLabel(text=training.description['date'] +
                              ': Training'), journal_node)
            label_str = 'Start time: ' + \
                        str( training.description['start_time'] )
            #training.description['start_time'].strftime('%H:%M:%S')
            self.tree_view.add_node(TreeViewLabel(text=label_str),
                                    training_node)
            label_str = 'End time: ' + \
                        str( training.description['end_time'] )
            self.tree_view.add_node(TreeViewLabel(text=label_str),
                                    training_node)
            label_str = 'Duration: ' + \
                        str( training.description['duration'] )
            self.tree_view.add_node(TreeViewLabel(text=label_str),
                                    training_node)
            label_str = 'Training program: ' + \
                        str( training.description['training_program'] )
            self.tree_view.add_node(TreeViewLabel(text=label_str),
                                    training_node)
            label_str = 'Training index in program: ' + \
                        str( training.description['training_index_in_program'] )
            self.tree_view.add_node(TreeViewLabel(text=label_str),
                                    training_node)
            for exercise in training.exercises:
                title_node_text = 'Exercise: ' + exercise.description['name']
                if 'Metric' in exercise.description.get('type'):
                    title_node_text = 'Metric: ' + exercise.description['name']
                exc_node = self.tree_view.add_node(
                    TreeViewLabel(text=title_node_text), training_node)
                for essential_field in exercise.essential_fields:
                    label_str = essential_field + \
                                ': ' + str( exercise.description[essential_field] )
                    self.tree_view.add_node(TreeViewLabel(text=label_str),
                                            exc_node)
                if exercise.description['comment']:
                    label_str = 'Comment: ' + \
                                str( exercise.description['comment'] )
                    self.tree_view.add_node(TreeViewLabel(text=label_str),
                                            exc_node)
            if training.description['comment']:
                label_str = 'Comment: ' + \
                            str( training.description['comment'] )
                self.tree_view.add_node(TreeViewLabel(text=label_str),
                                        training_node)

    def goto_progress(self):
        self.parent.current = 'view_progress'

    def set_another_journal(self, *rest):
        app = App.get_running_app()
        journal_file = self.journal_file_input.text
        filename, file_extension = os.path.splitext(journal_file)
        if file_extension != '.json':
            self.show_not_json_popup()
            return
        if journal_file != app.journal_file:
            app.journal_file = journal_file
            if os.path.isfile(app.journal_file):
                app.journal = Journal.load_journal(app.journal_file)
            else:
                app.journal = Journal()
        app.write_config()
        for node in self.tree_view.iterate_all_nodes():
            self.tree_view.remove_node(node)
        self.populate_tree_view()

    def show_not_json_popup(self):
        popup_content = BoxLayout(orientation='vertical')
        popup_content.add_widget(
            Label(text='The journal file is expected ' +
                  'to have a ".json" extension.\n' + 'Please, specify ' +
                  'another file.',
                  haling='center'))
        close_btn = Button(text='Ok', size_hint_y=0.2)
        popup_content.add_widget(close_btn)
        popup = Popup(title='Error: journal file is not JSON',
                      content=popup_content,
                      size_hint=(None, None),
                      size=(400, 400))
        close_btn.bind(on_press=popup.dismiss)
        popup.open()
示例#28
0
		def _on_view_manager( self ) :
			"""

			:return:
			"""

			if not self._view_manager :
				self._view_manager = screen.ViewManagerScreen()
				self._view_manager.name = 'screen_view_manager'
				self._view_manager.id = 'view_manager_screen'
				tv = TreeView( root_options=dict( text = 'king console' , font_size = 18 ) )
				self._rube_widget = tv

				layout = GridLayout( orientation='horizontal' , size_hint_y = None  , cols=1 , size = (480 , 900 ))
				# action bar
				ab = Builder.load_string( self._retr_resource( 'action_bar_plus' ) )


				layout.add_widget( ab )

				# scroll
				sv = ScrollView()

				# tree view
				n1 = tv.add_node(screen.TreeManagerLabel(text='main context') )
				n2 = tv.add_node(screen.TreeManagerLabel(text='transport'), n1)
				tv.add_node(screen.TreeManagerLabel(text='syn ack'), n2)
				n3 = tv.add_node(screen.TreeManagerLabel(text='mini mport scan'), n2)
				tv.add_node(screen.TreeManagerLabel(text='discovery & port manip'), n3)
				tv.add_node(screen.TreeManagerLabel(text='nmap firewalk'), n3)
				tv.add_node(screen.TreeManagerLabel(text='atomic firewalk'), n3)


				n4 = tv.add_node(screen.TreeManagerLabel(text='network'), n1)
				tv.add_node(screen.TreeManagerLabel(text='ping'), n4)
				n5 = tv.add_node(screen.TreeManagerLabel(text='ping subnet'), n4)
				tv.add_node(screen.TreeManagerLabel(text='beaucoup ping' ) , n5),
				n6 = tv.add_node(screen.TreeManagerLabel(text='application & discovery'), n1)
				n7 = tv.add_node(screen.TreeManagerLabel(text='quick fingerprint'), n6)
				tv.add_node(screen.TreeManagerLabel(text='fat ingerprint'), n6)
				tv.add_node(screen.TreeManagerLabel(text='baby snmp'), n7)
				tv.add_node(screen.TreeManagerLabel(text='upnp'), n7)
				tv.add_node(screen.TreeManagerLabel(text='ip geography'), n7)
				n8 = tv.add_node(screen.TreeManagerLabel(text='datalink'), n1)
				tv.add_node(screen.TreeManagerLabel(text='arp'), n8)
				n9 = tv.add_node(screen.TreeManagerLabel(text='arp scan'), n8)
				tv.add_node(screen.TreeManagerLabel(text='arp monitor'), n9)
				n10 = tv.add_node(screen.TreeManagerLabel(text='streams'), n1)
				tv.add_node(screen.TreeManagerLabel(text='payload policy'), n10)
				tv.add_node(screen.TreeManagerLabel(text='traceroute context' ) )
				tv.add_node(screen.TreeManagerLabel(text='packet stream context' ) )

				layout.add_widget( tv )
				sv.add_widget( layout )


				self._view_manager.add_widget( sv )
				self.root.add_widget( self._view_manager )

			self.root.current = self._view_manager.name
示例#29
0
class MainScreen(GridLayout):
    def __init__(self, **kwargs):
        super(MainScreen, self).__init__(**kwargs)

        self.cols = 2
        self.tfa = TextInput(multiline=False)
        self.tfa.bind(text=self.on_text)
        self.tfa.bind(on_text_validate=self.on_enter)
        self.add_widget(self.tfa)
        button = Button(text='Search', font_size=14)
        button.bind(on_press=self.on_search)
        self.add_widget(button)
        self.values = TreeView(root_options={'text': 'Suggestions'})
        self.add_widget(self.values)
        self.lock = Lock()

        self.suggestions_list = SafeDataModel()
        self.recent_list = list()

    def on_text(self, instance, value):
        if value != "" and not value.isspace() and len(value) > MIN_SEARCH:
            thread = Thread(target=self.get_suggestions_task)
            thread.start()
        else:
            self.refresh_widget_from_list(self.recent_list)

    def refresh_widget_from_model(self, model, force=False):
        if (force and model.get_last_index()
            ) or model.get_last_index() > model.get_displayed():
            last_retrieved, data = model.get_latest()
            self.add_nkeys(self.values, data, AUTO_LIST)
            model.set_displayed(model.get_last_index())
            self.values.canvas.ask_update()

    def refresh_widget_from_list(self, strings):
        self.add_nkeys(self.values, strings, AUTO_LIST)
        self.values.canvas.ask_update()

    def get_suggestions_task(self):
        url = "https://contextualwebsearch-websearch-v1.p.rapidapi.com/api/spelling/AutoComplete"
        params = {'text': self.tfa.text}
        headers = {
            "X-RapidAPI-Key":
            "5b7ec33f4dmsh08ea9efedd164b7p1392d6jsn645e17978f7f"
        }
        response = requests.get(url, params=params, headers=headers)
        if response.status_code == 200:
            data = json.loads(response.text)
            self.suggestions_list.add(data)
            self.refresh_widget_from_model(self.suggestions_list)

    def suggestion_node_clicked(self, instance, value):
        self.tfa.text = instance.text

    def on_enter(self, instance):
        self.search(self.tfa.text)

    def on_search(self, instance):
        self.search(self.tfa.text)

    def search(self, text):
        if text != "" and not text.isspace():
            url = "https://contextualwebsearch.com/search/" + quote(text)
            webbrowser.open(url)
            self.recent_list.append(text)

    def add_nkeys(self, tree, data, n):
        self.lock.acquire()
        self.clear_tree(self.values)

        for key in data:
            node = TreeViewLabel(text=key)
            node.bind(on_touch_down=self.suggestion_node_clicked)
            self.values.add_node(node)
            count = count + 1
        self.lock.release()

    def clear_tree(self, tree):
        #for node in tree.iterate_all_nodes():
        #    tree.remove_node(node)
        for node in tree.root.nodes:
            tree.remove_node(node)
示例#30
0
class KivyPanelABM(GridLayout):
    def __init__(self, lista, nombreABM, **kwargs):
        # make sure we aren't overriding any important functionality
        super(KivyPanelABM, self).__init__(**kwargs)
        self.cols = 2
        self.nombreABM = nombreABM
        self.lista = TreeView(hide_root=True, size_hint_x=0.9)
        self.add_widget(self.lista)
        self.panelbotoneraAcciones = GridLayout(cols=1,
                                                size_hint_x=0.1,
                                                size_hint_y=None,
                                                size=(0, 32))
        # self.panelbotoneraAcciones.padding=[100,10,10,10]
        self.btnAdd = Button(background_normal="Add.png",
                             size_hint=(None, None),
                             size=(32, 32))
        self.btnAdd.bind(on_press=self.btnEventAdd)
        self.btnEdit = Button(background_normal="Edit.png",
                              size_hint=(None, None),
                              size=(32, 32))
        self.btnEdit.bind(on_press=self.btnEventEdit)
        self.btnDel = Button(background_normal="Delete.png",
                             size_hint=(None, None),
                             size=(32, 32))
        self.btnDel.bind(on_press=self.btnEventDel)

        self.panelbotoneraAcciones.add_widget(self.btnAdd)
        self.panelbotoneraAcciones.add_widget(self.btnEdit)
        self.panelbotoneraAcciones.add_widget(self.btnDel)
        self.add_widget(self.panelbotoneraAcciones)

        for elemento in lista:
            self.lista.add_node(TreeViewLabel(text=elemento))

    def getLista(self):
        list = []
        print("arbol: " + str(self.lista))
        for nodo in self.lista.iterate_all_nodes(node=None):
            list.append(nodo.text)
        return list[1:]

    def btnEventAdd(self, value):
        panel = GridLayout(cols=1)
        self.text = TextInput()
        panel.add_widget(self.text)
        # botonGuardar = Button(text="guardar")uardar)
        panel.add_widget(Button(text="guardar", on_press=self.guardar))
        self.popup = Popup(title='Agregar ' + self.nombreABM,
                           content=panel,
                           size_hint=(1, 0.6))
        self.popup.open()

    def guardar(self, value):
        self.lista.add_node(TreeViewLabel(text=self.text.text))
        self.popup.dismiss()

    def __deleteItem__(self):
        if self.lista.selected_node:
            self.lista.remove_node(self.lista.selected_node)

    def btnEventDel(self, value):
        self.__deleteItem__()

    def btnEventEdit(self, value):
        panel = GridLayout(cols=1)
        self.text = TextInput(text=self.lista.get_selected_node().text)
        panel.add_widget(self.text)
        panel.add_widget(Button(text="guardar", on_press=self.modificar))
        self.popup = Popup(title='Editar ' + self.nombreABM,
                           content=panel,
                           size_hint=(1, 0.6))
        self.popup.open()

    def modificar(self, value):
        self.lista.get_selected_node().text = self.text.text
        # self.lista.add_node(TreeViewLabel(text=self.text.text))
        self.popup.dismiss()
示例#31
0
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):
        self.path = path
        self.filename = filename
        threading.Thread(target=self.download_file_task).start()
        self.dismiss_popup()

    def delete_file_task(self):
        controller.delete_selected_node(self.selected_node_text)
        self.update_storage_view()
        self.stop.set()

    def delete_selected_file(self):
        try:
            self.selected_node = self.get_selected_node()
            self.selected_node_text = self.selected_node.text
        except NoSelectedNode as err:
            open_popup_error('Delete error', err)
            return
        self.file_view.remove_node(self.selected_node)
        threading.Thread(target=self.delete_file_task).start()