Santiago Payà Miralta avatar Santiago Payà Miralta committed 2672f0a

Connect nodes allowed.

Comments (0)

Files changed (1)

view/genet_window.py

 Has one tab for every work:
 
 * Admin tab: create levels and types.
-* Create tab: create nodes into the network. Must declare type of node and 
+* Create tab: create nodes into the network. Must declare type of node and
 parent in which the node is embebed.
 * Connect tab: connects nodes.
 * Browse tab: shows network graphs (uses networkx, graphviz, ...).
 import pygtk
 
 from control import genet_browser
-from control import genet_creator 
+from control import genet_creator
 from control import genet_global
 
-#from model import class_edge 
+#from model import class_edge
 #from model import class_node
 #from model.db_connection import db
 
 from view import genet_treemodels
-        
+
 class GenetWindow(gtk.Window):
     def __init__(self):
         """
         The window.
-        
+
         """
-        gladefile = "genet.glade"
+        gladefile = "/home/santiago/workspace/genet/view/genet.glade"
         windowname = "genet"
-        self.wTree = gtk.glade.XML (gladefile, windowname)
-        
+        self.wTree = gtk.glade.XML(gladefile, windowname)
+
         # Fill tree views.
         ##
         # Browse tree
         tree = self.wTree.get_widget("treeview_browser")
         model = genet_treemodels.BrowseNodesTreeModel()
         tree.set_model(model)
-    
+
         cell = gtk.CellRendererText()
 
         # Ids column should disapear in production version
         tree = self.wTree.get_widget("treeview_conn_nodes_A")
         model = genet_treemodels.ConnectNodesTreeModel()
         tree.set_model(model)
-    
+
         cell = gtk.CellRendererText()
 
         # Ids column should disapear in production version
         tree = self.wTree.get_widget("treeview_conn_nodes_B")
         model = genet_treemodels.ConnectNodesTreeModel()
         tree.set_model(model)
-    
+
         cell = gtk.CellRendererText()
 
         # Ids column should disapear in production version
         tree = self.wTree.get_widget("treeview_conn_nodes_edge_types")
         model = genet_treemodels.ConnectNodesEdgeTypesTreeModel()
         tree.set_model(model)
-    
+
         cell = gtk.CellRendererText()
 
         # Ids column should disapear in production version
         tree = self.wTree.get_widget("treeview_create_node_types")
         model = genet_treemodels.CreateNodeTypesTreeModel()
         tree.set_model(model)
-    
+
         cell = gtk.CellRendererText()
 
         # Ids column should disapear in production version
         tree = self.wTree.get_widget("treeview_create_node_parents")
         model = genet_treemodels.CreateNodeParentsTreeModel()
         tree.set_model(model)
-    
+
         cell = gtk.CellRendererText()
 
         # Ids column should disapear in production version
         tree = self.wTree.get_widget("treeview_admin_levels")
         model = genet_treemodels.AdminTreeModel()
         tree.set_model(model)
-    
+
         cell = gtk.CellRendererText()
 
         # Ids column should disapear in production version
         # Declare actions dictionary.
         dic = {
             # Browse tab.
-            "on_button_browser_draw_level_clicked" : 
+            "on_button_browser_draw_level_clicked" :
             self.button_browser_draw_level_clicked,
-            "on_button_browser_draw_tree_clicked" : 
+            "on_button_browser_draw_tree_clicked" :
             self.button_browser_draw_tree_clicked,
 
             # Connect nodes tab.
                 self.button_conn_nodes_clicked,
             "on_button_conn_nodes_refresh_clicked" :
                 self.button_conn_nodes_refresh_clicked,
-            
+
             # Create tab.
             "on_button_create_node_clicked" :
                 self.button_create_node_clicked,
-            
+
             # Admin tab.
-            "on_button_create_level_clicked" : 
+            "on_button_create_level_clicked" :
             self.button_create_level_clicked,
-            "on_button_drop_item_clicked" : 
+            "on_button_drop_item_clicked" :
             self.button_drop_item_clicked,
             "on_button_create_node_type_clicked" :
                 self.button_create_node_type_clicked,
 
     def button_browser_draw_tree_clicked(self, widget):
         print 'Tree Clicked!'
-        
+
     ############################################################################
     # Connect nodes tab.
     #
     def button_conn_nodes_clicked(self, widget):
         """Connects nodes selected left and right with an edge type.
-        
+
         The edge type is taken from the edge types tree.
         """
         # TODO all interface flow must be loaded by steps, selecting node A,
         # then edge type and then node B.
+        
         # Get node A level
         root_values = self.get_tree_selected_root_values("treeview_conn_nodes_A")
         level_id = root_values[0]
 
         # Load edge types in this level
-        tree = self.wTree.get_widget("treeview_conn_nodes_edge_types")
-        tree.get_model().reload(int(level_id))
-        tree.expand_all()
-        
+#        tree = self.wTree.get_widget("treeview_conn_nodes_edge_types")
+#        tree.get_model().reload(int(level_id))
+#        tree.expand_all()
+
         # Get type
-#        type_values = self.get_tree_selected_values("treeview_conn_nodes_edge_types")
-#        type_id = type_values[0]
+        type_values = self.get_tree_selected_values("treeview_conn_nodes_edge_types")
+        type_id = type_values[0]
+
+        # Get parent id
+        parent_id = 1
+
+        # Get parent level
+        parentlevel_id = 1
+
+        # Get node A id
+        nA_values = self.get_tree_selected_values("treeview_conn_nodes_A")
+        nA_id = nA_values[0]
+
+        # Get node B id
+        nB_values = self.get_tree_selected_values("treeview_conn_nodes_B")
+        nB_id = nB_values[0]
+
+        genet_creator.connectNodes(level_id, nA_id, nB_id, parent_id, parentlevel_id, type_id, ('Created from code',))
 
     def button_conn_nodes_refresh_clicked(self, widget):
         """ Refresh trees from data model.
         # Create node
         # TODO When there is no parent, parentlevel should be its own level
         # and parent id should be 0.
-        genet_creator.createNode(level_id, parent_id, 
+        genet_creator.createNode(level_id, parent_id,
                                  parentlevel_id, type_id, attributes)
 
         # Refresh tree
         description = self.wTree.get_widget("entry_admin_type").get_text()
 
         # Create type
-        genet_creator.createEdgeType(level, description)
+        genet_creator.createEdgeType(level_id, description)
 
         # Refresh tree
         self.tree_refresh("treeview_admin_levels")
 
     def button_admin_reset_clicked(self, widget):
         genet_global.restartDatabase()
-        
+
         # Refresh tree
         self.tree_refresh("treeview_admin_levels")
 
         tree_selection_model = tree_selection.get_selected()[0]
         tree_selection_iter = tree_selection.get_selected()[1]
         tree_n_columns = tree_selection_model.get_n_columns()
-        
+
         # Get the root from selection. Could be in root now, so root iter is
         # the actually selected iter.
         root_iter = tree_selection_iter
         tree_sel = tree.get_selection()
         tree_sel_model, tree_sel_iter = tree_sel.get_selected()
         tree_n_columns = tree_sel_model.get_n_columns()
-        
+
         values = ()
         for c in range(tree_n_columns):
             values += tree_sel_model.get(tree_sel_iter, c)
         tree = self.wTree.get_widget(tree_widget)
         tree_sel = tree.get_selection()
         tree_sel_model, tree_sel_iter = tree_sel.get_selected()
-        
+
         # Save selected item or path
         tree_sel_path = (0,)
         if tree_sel_iter is not None:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.