Commits

Santiago Payà Miralta  committed 0d7196e

Treeview function that returns all columns data for any tree.

  • Participants
  • Parent commits 386a361

Comments (0)

Files changed (1)

File view/genet_window.py

         parentlevel_id = self.get_create_node_parents_tree_level()
 
         # Get parent
-        parent_values = self.get_create_node_parents_tree_selected_values()
+        parent_values = self.get_tree_selected_values("treeview_create_node_parents")
+#        parent_values = self.get_create_node_parents_tree_selected_values()
         parent_id = parent_values[0]
 
         # Get attributes
         tree_model = tree.get_model()
         tree_model.reload()
 
-    def get_create_nodes_tree_level(self):
+    def get_create_node_types_tree_level(self):
+        """Get level from selection.
+        """
         # Get all information from the selected row in the tree
         tree = self.wTree.get_widget("treeview_create_node_types")
         tree_selection = tree.get_selection()
 
     def get_create_node_types_tree_selected_values(self):
         # Get all information from the selected row in the tree
-        tree = self.wTree.get_widget("treeview_create_node_type")
+        tree = self.wTree.get_widget("treeview_create_node_types")
+        tree_selection = tree.get_selection()
+        tree_selection_model = tree_selection.get_selected()[0]
+        tree_selection_iter = tree_selection.get_selected()[1]
+        
+        values = tree_selection_model.get(tree_selection_iter, 0, 1, 2)
+
+        return values
+
+    def get_create_node_parents_tree_level(self):
+        """Get level from selection.
+        
+        TODO May be could get level from DB if get type_id from values selected
+        so could have only one function with the widget's name as parameter and
+        returns the selected values.
+        """
+        # Get all information from the selected row in the tree
+        tree = self.wTree.get_widget("treeview_create_node_parents")
+        tree_selection = tree.get_selection()
+        tree_selection_model = tree_selection.get_selected()[0]
+        tree_selection_iter = tree_selection.get_selected()[1]
+        
+        # Get if selection has a parent or if it is the parent
+        parent_iter = tree_selection_model.iter_parent(tree_selection_iter)
+        if parent_iter is None:
+            values = tree_selection_model.get(tree_selection_iter, 0, 1, 2)
+            level = values[0]
+        else:
+            parent_values = tree_selection_model.get(parent_iter, 0, 1, 2)
+            level = parent_values[0]
+
+        return level        
+
+    def get_create_node_parents_tree_selected_values(self):
+        # Get all information from the selected row in the tree
+        tree = self.wTree.get_widget("treeview_create_node_parents")
         tree_selection = tree.get_selection()
         tree_selection_model = tree_selection.get_selected()[0]
         tree_selection_iter = tree_selection.get_selected()[1]
     def main(self):
         gtk.main()
 
+    def get_tree_selected_values(self, tree_widget):
+        """Get all information from the selected row in the tree.
+        """
+        tree = self.wTree.get_widget(tree_widget)
+        tree_selection = tree.get_selection()
+        tree_selection_model = tree_selection.get_selected()[0]
+        tree_selection_iter = tree_selection.get_selected()[1]
+        tree_columns = tree_selection_model.get_n_columns()
+        
+        values = ()
+        for c in range(tree_columns):
+            values += tree_selection_model.get(tree_selection_iter, c)
+
+        return values
+
 app = window()
 app.main()