Commits

Santiago Payà Miralta committed 4283aff

Schema interface finished. Start creatting graph.

  • Participants
  • Parent commits 73aaa5f

Comments (0)

Files changed (9)

File control/genet_browser.py

 Related to paths and interlevel chains.
 
 """
-
+from control import genet_global 
 from model.db_connection import db
 
 def listLevels():
     """
     st = "SELECT description, id FROM gn____edge_types;"
     return db.query(st).getresult()
+
+def listNodes(level):
+    """
+    List nodes from db.
+
+    @returns list the nodes
+    """
+    tag_level = genet_global.tagName(level)
+
+    st = "SELECT id, id FROM gn_" + tag_level + "_nodes;"
+    return db.query(st).getresult()
+

File control/genet_creator.py

         "WHERE level = " + level + ";"
     ids = db.query(st).getresult()
     if len(ids):
-        for i in ids[0]:
-            dropEdgeType(i)        
+        for i in ids:
+            dropEdgeType(i[0])        
 
     # Nodes.
     st = "SELECT id " \
         "WHERE level = " + level + ";"
     ids = db.query(st).getresult()
     if len(ids):
-        for i in ids[0]:
-            dropNodeType(i)        
+        for i in ids:
+            dropNodeType(i[0])        
 
     # Delete entry into the levels table.
     st = "DELETE FROM gn____levels " \

File control/test_data.py

 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ################################################################################
 
-from model.class_edge import edge
-from model.class_node import node
+from model import class_edge 
+from model import class_node
 from model.db_connection import db
-from model.db_schema import *
 
-################################################################################
-# Insert tables.
-# 
-print insertNodeType('01', 'vaults', 'Vaults and manholes.')
-print insertNodeType('01', 'poles', 'Poles and towers.')
-print insertNodeType('02', 'closures', 'Splicing boxes.')
-print insertNodeType('03', 'splices', 'Splices.')
-
-print insertEdgeType('01', 'trails', 'Trenchs.')
-print insertEdgeType('02', 'cables', 'Cables.')
-print insertEdgeType('03', 'fibers', 'Fibers.')
-
-print dropLevelTables('00')
-print createLevelTables('00')
-
-print dropLevelTables('01')
-print createLevelTables('01')
-
-print dropLevelTables('02')
-print createLevelTables('02')
-
-print dropLevelTables('LL')
-print createLevelTables('LL')
-
-################################################################################
+##
 # Insert data.
 #
-N001 = node('01', 0, 2323, 2)
+N001 = class_node.node(1, 0, 0, 2)
 print N001.store(db)
 
-N002 = node('01', 0, 0, 1)
+N002 = class_node.node(1, 0, 0, 2)
 print N002.store(db)
 
-N003 = node('01', 0, 0, 2)
+N003 = class_node.node(1, 0, 0, 2)
 print N003.store(db)
-N003.idtype = 1
+N003.idtype = 4
 print N003.store(db)
 
-E001 = edge('01', N001.id, N002.id, 0, 0, 2)
+E001 = class_edge.edge(1, N001.id, N002.id, 0, 0, 3)
 print E001.store(db)
 
+E002 = class_edge.edge(1, N002.id, N003.id, 0, 0, 3)
+print E002.store(db)
+
+E003 = class_edge.edge(1, N003.id, N001.id, 0, 0, 3)
+print E003.store(db)
+
+E004 = class_edge.edge(1, N001.id, N002.id, 0, 0, 3)
+print E004.store(db)
+
 for r in db.query("SELECT * FROM gn_01_nodes").dictresult():
-    print 'id: %(id)s - iddown: %(iddown)s - idtype: %(idtype)s' % r
+    print 'id %(id)s, idtype %(idtype)s' % r
 
 for r in db.query("SELECT * FROM gn_01_edges").dictresult():
-    print 'id: %(id)s - idnA: %(idna)s - idnB: %(idnb)s - iddown: %(iddown)s - idtype: %(idtype)s' % r
+    print 'id %(id)s, idnA %(idna)s, idnB %(idnb)s, idtype %(idtype)s' % r

File control/test_networkx.py

 
 import pylab as P
 import networkx as NX
-from test_data import *
+from control import test_data
 
 ################################################################################
-# Level 00
+# Level 01
 #
-G00 = NX.XGraph(name='Level 00', multiedges=True, selfloops=True)
+G01 = NX.XGraph(name='Level 01', multiedges=True, selfloops=True)
 
-for r in db.query("SELECT * FROM gn_00_edges").dictresult():
-    G00.add_edges_from([(r['idna'], r['idnb'], r['id'])])
+for r in db.query("SELECT * FROM gn_01_edges").dictresult():
+    G01.add_edges_from([(r['idna'], r['idnb'], r['id'])])
     
 # May be there are isolated nodes.
-for r in db.query("SELECT * FROM gn_00_nodes").dictresult():
-    G00.add_node(r['id'])
+for r in db.query("SELECT * FROM gn_01_nodes").dictresult():
+    G01.add_node(r['id'])
 
-print 'G00 nodes:', G00.nodes()
-print 'G00 edges:', G00.edges()
+print 'G01 nodes:', G01.nodes()
+print 'G01 edges:', G01.edges()
 
-pos = NX.spring_layout(G00)
-NX.draw_networkx(G00, pos)
+pos = NX.spring_layout(G01)
+NX.draw_networkx(G01, pos)
 P.show()
 
-P.savefig("genet_L0.png")
-print "Wrote genet_L0.png"
+P.savefig("genet_L1.png")
+print "Wrote genet_L1.png"
 
 ################################################################################
 # Level 1

File model/class_edge.py

 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ################################################################################
+
+from control import genet_global
+
 """
 Define base class `edge' with the minimal attributes as abstract 
 attributes.
 * idnB: other side id.
 
 """
-
 class edge:
     """
     Simple class with basic attributes.
     
     The the edge itself, 'idnA' and 'idnB' should be from the same level, 
-    this is resolved at execution time from an intelligent interface.
+    this is resolved at execution time from an intelligent interface, but
+    the schema does not restricts.
 
     """
     def __init__(self, level, idnA, idnB, idparent, parentlevel, idtype):
         @param db is the database object.
         @eturns the SQL statement and node id.
         """
+        # Uniformly define the tablename level.
+        tag_level = genet_global.tagName(self.level)
+
+        # If the edge already exists.
         if self.id:
-            st = "UPDATE gn_" + str(self.level) + "_edges SET " \
+
+            # Update the edges table.
+            st1 = "UPDATE gn_" + tag_level + "_edges SET " \
                 "idnA = " + str(self.idnA) + ", " \
                 "idnB" + str(self.idnB) + ", " \
                 "idtype = " + str(self.idtype) + " " \
                 "WHERE id = " + str(self.id) + ";"
-            db.query(st)
-            return st, self.id
-        # TODO UPDATE tree
+            db.query(st1)
 
+            # Update the tree table.
+            st2 = "UPDATE gn____tree SET " \
+                "idparent = " + str(self.idparent) + ", " \
+                "parentlevel = " + str(self.parentlevel) + ", " \
+                "childlevel = " + str(self.level) + " " \
+                "WHERE idchild = " + str(self.id) + ";"
+            db.query(st2)
+
+            return st1, st2, self.id
+
+        # If the edge does not exist.
         else:
-            st1 = "INSERT INTO gn_" + str(self.level) + "_edges(idna, idnb, iddown, downlevel, idtype) " \
+
+            # Insert the edge into the table.
+            st1 = "INSERT INTO gn_" + tag_level + "_edges(idna, idnb, idtype) " \
                 "VALUES(" \
                 + str(self.idnA) + ", " \
                 + str(self.idnB) + ", " \
                 + str(self.idtype) + ") " \
                 "RETURNING id;"
             self.id = db.query(st1).getresult()[0][0]
+
+            # Insert the node into the tree.
             st2 = "INSERT INTO gn____tree(idparent, idchild, parentlevel, childlevel) " \
                 "VALUES(" \
                 + str(self.idparent) + ", " \
                 + str(self.parentlevel) + ", " \
                 + str(self.level) + ");" 
             db.query(st2)
+
             return st1, st2, self.id
         

File model/class_node.py

 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ################################################################################
+
+from control import genet_global
+
 """
 Define base class `node' with the minimal attributes as abstract 
 attributes.
 * level: topological level, ISO level, layer, ...
 * id: its own identifier.
 * idtype: what kind of element is.
+* idparent: from which element is a child.
+* parentlevel: the level from where the parent is.
 
 """
-
 class node:
     """
     Simple class with basic attributes.
 
+    @param level id
+    @param idparent id
+    @param parentlevel id
+    @param idtype id
     """
-    def __init__(self, level, iddown, downlevel, idtype):
+    def __init__(self, level, idparent, parentlevel, idtype):
         self.id = None
         self.level = level
-        self.iddown = iddown
-        self.downlevel = downlevel
+        self.idparent = idparent
+        self.parentlevel = parentlevel
         self.idtype = idtype
     
     def store(self, db):
         @param db is the database object.
         @returns the SQL statement and node id.
         """
+        # Uniformly define the tablename level.
+        tag_level = genet_global.tagName(self.level)
+
+        # If the node already exists.
         if self.id:
-            st = "UPDATE gn_" + str(self.level) + "_nodes SET " \
+
+            # Update the nodes table.            
+            st1 = "UPDATE gn_" + tag_level + "_nodes SET " \
                 "idtype = " + str(self.idtype) + " " \
                 "WHERE id = " + str(self.id) + ";"
-            db.query(st)
+            db.query(st1)
+
+            # Update the tree table.
+            st2 = "UPDATE gn____tree SET " \
+                "idparent = " + str(self.idparent) + ", " \
+                "parentlevel = " + str(self.parentlevel) + ", " \
+                "childlevel = " + str(self.level) + " " \
+                "WHERE idchild = " + str(self.id) + ";"
+            db.query(st2)
+
+            return st1, st2, self.id
+
+        # If the node does not exist.
         else:
-            st = "INSERT INTO gn_" + str(self.level) + "_nodes(iddown, downlevel, idtype) " \
+            
+            # Insert the node into the table.
+            st1 = "INSERT INTO gn_" + tag_level + "_nodes(idtype) " \
                 "VALUES(" \
                 + str(self.idtype) + ") " \
                 "RETURNING id;"
-            self.id = db.query(st).getresult()[0][0]
-        return st, self.id
+            self.id = db.query(st1).getresult()[0][0]
+
+            # Insert the node into the tree.
+            st2 = "INSERT INTO gn____tree(idparent, idchild, parentlevel, childlevel) " \
+                "VALUES (" \
+                + str(self.idparent) + ", " \
+                + str(self.id) + ", " \
+                + str(self.parentlevel) + ", " \
+                + str(self.level) + ");" 
+            db.query(st2)
+
+            return st1, st2, self.id
+

File model/db_schema.py

     CREATE TABLE "gn____tree" (
         "idparent" integer,
         "idchild" integer,
-        "parentlevel" varchar(32),
-        "childlevel" varchar(32)
+        "parentlevel" integer,
+        "childlevel" integer
     ) WITH (OIDS = FALSE);
     -- Child has only one parent.
     ALTER TABLE "gn____tree" 

File view/genet.glade

                   <placeholder/>
                 </child>
                 <child>
-                  <widget class="GtkButton" id="button_connect_nodes">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="receives_default">True</property>
-                    <property name="label" translatable="yes">Connect</property>
-                    <property name="response_id">0</property>
-                    <signal name="clicked" handler="on_button_connect_nodes_clicked"/>
-                  </widget>
-                  <packing>
-                    <property name="left_attach">1</property>
-                    <property name="right_attach">2</property>
-                    <property name="top_attach">1</property>
-                    <property name="bottom_attach">2</property>
-                  </packing>
-                </child>
-                <child>
-                  <widget class="GtkLabel" id="label_browser_level">
-                    <property name="visible">True</property>
-                    <property name="label" translatable="yes">Level</property>
-                  </widget>
-                </child>
-                <child>
-                  <widget class="GtkComboBoxEntry" id="comboboxentry_browser_level">
+                  <widget class="GtkComboBoxEntry" id="comboboxentry_browser_nB">
                     <property name="visible">True</property>
                     <child internal-child="entry">
-                      <widget class="GtkEntry" id="comboboxentry-entry6">
+                      <widget class="GtkEntry" id="comboboxentry-entry4">
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                       </widget>
                     </child>
                   </widget>
                   <packing>
-                    <property name="left_attach">1</property>
-                    <property name="right_attach">2</property>
+                    <property name="left_attach">2</property>
+                    <property name="right_attach">3</property>
+                    <property name="top_attach">1</property>
+                    <property name="bottom_attach">2</property>
                   </packing>
                 </child>
                 <child>
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkComboBoxEntry" id="comboboxentry_browser_nB">
+                  <widget class="GtkComboBoxEntry" id="comboboxentry_browser_level">
                     <property name="visible">True</property>
                     <child internal-child="entry">
-                      <widget class="GtkEntry" id="comboboxentry-entry4">
+                      <widget class="GtkEntry" id="comboboxentry-entry6">
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                       </widget>
                     </child>
                   </widget>
                   <packing>
-                    <property name="left_attach">2</property>
-                    <property name="right_attach">3</property>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="label_browser_level">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Level</property>
+                  </widget>
+                </child>
+                <child>
+                  <widget class="GtkButton" id="button_connect_nodes">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="label" translatable="yes">Connect</property>
+                    <property name="response_id">0</property>
+                    <signal name="clicked" handler="on_button_connect_nodes_clicked"/>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
                     <property name="top_attach">1</property>
                     <property name="bottom_attach">2</property>
                   </packing>
               </packing>
             </child>
             <child>
-              <widget class="GtkTable" id="table1">
+              <widget class="GtkTable" id="table_creator">
                 <property name="visible">True</property>
                 <property name="n_rows">5</property>
                 <property name="n_columns">5</property>
                 <child>
-                  <placeholder/>
+                  <widget class="GtkComboBox" id="combobox_creator_edge_types">
+                    <property name="visible">True</property>
+                    <property name="items" translatable="yes"></property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">3</property>
+                    <property name="right_attach">4</property>
+                    <property name="top_attach">2</property>
+                    <property name="bottom_attach">3</property>
+                    <property name="x_options">GTK_FILL</property>
+                  </packing>
                 </child>
                 <child>
                   <placeholder/>
                   <placeholder/>
                 </child>
                 <child>
-                  <placeholder/>
+                  <widget class="GtkComboBox" id="combobox_creator_edge_nodeB">
+                    <property name="visible">True</property>
+                    <property name="items" translatable="yes"></property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">2</property>
+                    <property name="right_attach">3</property>
+                    <property name="top_attach">2</property>
+                    <property name="bottom_attach">3</property>
+                    <property name="x_options">GTK_FILL</property>
+                  </packing>
                 </child>
                 <child>
-                  <placeholder/>
+                  <widget class="GtkComboBox" id="combobox_creator_edge_nodeA">
+                    <property name="visible">True</property>
+                    <property name="items" translatable="yes"></property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">2</property>
+                    <property name="bottom_attach">3</property>
+                    <property name="x_options">GTK_FILL</property>
+                  </packing>
                 </child>
                 <child>
-                  <placeholder/>
+                  <widget class="GtkComboBox" id="combobox_creator_node_types">
+                    <property name="visible">True</property>
+                    <property name="items" translatable="yes"></property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">1</property>
+                    <property name="bottom_attach">2</property>
+                    <property name="x_options">GTK_FILL</property>
+                  </packing>
                 </child>
                 <child>
-                  <placeholder/>
+                  <widget class="GtkComboBox" id="combobox_creator_levels">
+                    <property name="visible">True</property>
+                    <property name="items" translatable="yes"></property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="x_options">GTK_FILL</property>
+                  </packing>
                 </child>
                 <child>
-                  <placeholder/>
+                  <widget class="GtkButton" id="button_create_edge">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="label" translatable="yes">Create</property>
+                    <property name="response_id">0</property>
+                    <signal name="clicked" handler="on_button_create_edge_clicked"/>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">4</property>
+                    <property name="right_attach">5</property>
+                    <property name="top_attach">2</property>
+                    <property name="bottom_attach">3</property>
+                  </packing>
                 </child>
                 <child>
-                  <placeholder/>
+                  <widget class="GtkLabel" id="label_create_edge">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Edge</property>
+                  </widget>
+                  <packing>
+                    <property name="top_attach">2</property>
+                    <property name="bottom_attach">3</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="label_create_modify_level">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">In this level</property>
+                  </widget>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="label_create_node">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Node</property>
+                  </widget>
+                  <packing>
+                    <property name="top_attach">1</property>
+                    <property name="bottom_attach">2</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkButton" id="button_create_refresh">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="label" translatable="yes">Refresh</property>
+                    <property name="response_id">0</property>
+                    <signal name="clicked" handler="on_button_create_refresh_clicked"/>
+                  </widget>
+                  <packing>
+                    <property name="top_attach">4</property>
+                    <property name="bottom_attach">5</property>
+                  </packing>
                 </child>
                 <child>
                   <widget class="GtkButton" id="button_create_node">
                     <property name="receives_default">True</property>
                     <property name="label" translatable="yes">Create</property>
                     <property name="response_id">0</property>
+                    <signal name="clicked" handler="on_button_create_node_clicked"/>
                   </widget>
                   <packing>
-                    <property name="left_attach">3</property>
-                    <property name="right_attach">4</property>
+                    <property name="left_attach">4</property>
+                    <property name="right_attach">5</property>
+                    <property name="top_attach">1</property>
+                    <property name="bottom_attach">2</property>
                   </packing>
                 </child>
-                <child>
-                  <widget class="GtkComboBox" id="combobox_creator_node_type">
-                    <property name="visible">True</property>
-                  </widget>
-                  <packing>
-                    <property name="left_attach">2</property>
-                    <property name="right_attach">3</property>
-                  </packing>
-                </child>
-                <child>
-                  <widget class="GtkComboBox" id="combobox_creator_node_level">
-                    <property name="visible">True</property>
-                  </widget>
-                  <packing>
-                    <property name="left_attach">1</property>
-                    <property name="right_attach">2</property>
-                  </packing>
-                </child>
-                <child>
-                  <widget class="GtkLabel" id="label_creator_node">
-                    <property name="visible">True</property>
-                    <property name="label" translatable="yes">Node</property>
-                  </widget>
-                </child>
               </widget>
               <packing>
                 <property name="position">1</property>
               </packing>
             </child>
             <child>
-              <widget class="GtkLabel" id="label_creator">
+              <widget class="GtkLabel" id="label_create">
                 <property name="visible">True</property>
                 <property name="label" translatable="yes">Create</property>
               </widget>
               </packing>
             </child>
             <child>
-              <widget class="GtkTable" id="table_creator">
+              <widget class="GtkTable" id="table_admin">
                 <property name="visible">True</property>
                 <property name="n_rows">6</property>
                 <property name="n_columns">5</property>
                 <child>
-                  <widget class="GtkLabel" id="label_admin_modify_level">
-                    <property name="visible">True</property>
-                    <property name="label" translatable="yes">In this level</property>
-                  </widget>
-                  <packing>
-                    <property name="top_attach">2</property>
-                    <property name="bottom_attach">3</property>
-                  </packing>
-                </child>
-                <child>
-                  <widget class="GtkComboBox" id="combobox_creator_levels">
-                    <property name="visible">True</property>
-                    <property name="items" translatable="yes"></property>
-                  </widget>
-                  <packing>
-                    <property name="left_attach">1</property>
-                    <property name="right_attach">2</property>
-                    <property name="top_attach">2</property>
-                    <property name="bottom_attach">3</property>
-                  </packing>
-                </child>
-                <child>
                   <placeholder/>
                 </child>
                 <child>
                   <placeholder/>
                 </child>
                 <child>
-                  <widget class="GtkLabel" id="label_creator_node_type">
-                    <property name="visible">True</property>
-                    <property name="label" translatable="yes">Node type</property>
-                  </widget>
-                  <packing>
-                    <property name="top_attach">3</property>
-                    <property name="bottom_attach">4</property>
-                  </packing>
-                </child>
-                <child>
-                  <widget class="GtkHSeparator" id="hseparator1">
-                    <property name="visible">True</property>
-                  </widget>
-                  <packing>
-                    <property name="right_attach">5</property>
-                    <property name="top_attach">1</property>
-                    <property name="bottom_attach">2</property>
-                    <property name="y_padding">5</property>
-                  </packing>
-                </child>
-                <child>
-                  <widget class="GtkButton" id="button_drop_edge_type">
+                  <widget class="GtkButton" id="button_drop_level">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">True</property>
                     <property name="label" translatable="yes">Delete</property>
                     <property name="response_id">0</property>
-                    <signal name="clicked" handler="on_button_drop_edge_type_clicked"/>
+                    <signal name="clicked" handler="on_button_drop_level_clicked"/>
                   </widget>
                   <packing>
                     <property name="left_attach">4</property>
                     <property name="right_attach">5</property>
-                    <property name="top_attach">4</property>
-                    <property name="bottom_attach">5</property>
+                    <property name="top_attach">2</property>
+                    <property name="bottom_attach">3</property>
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkButton" id="button_drop_node_type">
+                  <widget class="GtkLabel" id="label_creator_level">
                     <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="receives_default">True</property>
-                    <property name="label" translatable="yes">Delete</property>
-                    <property name="response_id">0</property>
-                    <signal name="clicked" handler="on_button_drop_node_type_clicked"/>
+                    <property name="label" translatable="yes">Level</property>
                   </widget>
-                  <packing>
-                    <property name="left_attach">4</property>
-                    <property name="right_attach">5</property>
-                    <property name="top_attach">3</property>
-                    <property name="bottom_attach">4</property>
-                  </packing>
                 </child>
                 <child>
-                  <widget class="GtkButton" id="button_create_node_type">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="receives_default">True</property>
-                    <property name="label" translatable="yes">Create</property>
-                    <property name="response_id">0</property>
-                    <signal name="clicked" handler="on_button_create_node_type_clicked"/>
-                  </widget>
-                  <packing>
-                    <property name="left_attach">2</property>
-                    <property name="right_attach">3</property>
-                    <property name="top_attach">3</property>
-                    <property name="bottom_attach">4</property>
-                  </packing>
-                </child>
-                <child>
-                  <widget class="GtkEntry" id="entry_creator_edge_type">
+                  <widget class="GtkEntry" id="entry_admin_level">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                   </widget>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="right_attach">2</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkButton" id="button_create_level">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="label" translatable="yes">Create</property>
+                    <property name="response_id">0</property>
+                    <signal name="clicked" handler="on_button_create_level_clicked"/>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">2</property>
+                    <property name="right_attach">3</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkComboBox" id="combobox_admin_edge_types">
+                    <property name="visible">True</property>
+                    <property name="items" translatable="yes"></property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">3</property>
+                    <property name="right_attach">4</property>
+                    <property name="top_attach">4</property>
+                    <property name="bottom_attach">5</property>
+                    <property name="x_options">GTK_FILL</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkComboBox" id="combobox_admin_node_types">
+                    <property name="visible">True</property>
+                    <property name="items" translatable="yes"></property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">3</property>
+                    <property name="right_attach">4</property>
+                    <property name="top_attach">3</property>
+                    <property name="bottom_attach">4</property>
+                    <property name="x_options">GTK_FILL</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkButton" id="button_admin_refresh">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="label" translatable="yes">Refresh</property>
+                    <property name="response_id">0</property>
+                    <signal name="clicked" handler="on_button_admin_refresh_clicked"/>
+                  </widget>
+                  <packing>
+                    <property name="top_attach">5</property>
+                    <property name="bottom_attach">6</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkEntry" id="entry_admin_node_type">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">3</property>
+                    <property name="bottom_attach">4</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkButton" id="button_admin_reset">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="label" translatable="yes">Reset</property>
+                    <property name="response_id">0</property>
+                    <signal name="clicked" handler="on_button_admin_reset_clicked"/>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">4</property>
+                    <property name="right_attach">5</property>
+                    <property name="top_attach">5</property>
+                    <property name="bottom_attach">6</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkLabel" id="label_creator_edge_type">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Edge type</property>
+                  </widget>
+                  <packing>
                     <property name="top_attach">4</property>
                     <property name="bottom_attach">5</property>
                   </packing>
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkLabel" id="label_creator_edge_type">
-                    <property name="visible">True</property>
-                    <property name="label" translatable="yes">Edge type</property>
-                  </widget>
-                  <packing>
-                    <property name="top_attach">4</property>
-                    <property name="bottom_attach">5</property>
-                  </packing>
-                </child>
-                <child>
-                  <widget class="GtkButton" id="button_admin_reset">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="receives_default">True</property>
-                    <property name="label" translatable="yes">Reset</property>
-                    <property name="response_id">0</property>
-                    <signal name="clicked" handler="on_button_admin_reset_clicked"/>
-                  </widget>
-                  <packing>
-                    <property name="left_attach">4</property>
-                    <property name="right_attach">5</property>
-                    <property name="top_attach">5</property>
-                    <property name="bottom_attach">6</property>
-                  </packing>
-                </child>
-                <child>
-                  <widget class="GtkEntry" id="entry_creator_node_type">
+                  <widget class="GtkEntry" id="entry_admin_edge_type">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                   </widget>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="right_attach">2</property>
+                    <property name="top_attach">4</property>
+                    <property name="bottom_attach">5</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkButton" id="button_create_node_type">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="label" translatable="yes">Create</property>
+                    <property name="response_id">0</property>
+                    <signal name="clicked" handler="on_button_create_node_type_clicked"/>
+                  </widget>
+                  <packing>
+                    <property name="left_attach">2</property>
+                    <property name="right_attach">3</property>
                     <property name="top_attach">3</property>
                     <property name="bottom_attach">4</property>
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkButton" id="button_admin_refresh">
+                  <widget class="GtkButton" id="button_drop_node_type">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">True</property>
-                    <property name="label" translatable="yes">Refresh</property>
+                    <property name="label" translatable="yes">Delete</property>
                     <property name="response_id">0</property>
-                    <signal name="clicked" handler="on_button_admin_refresh_clicked"/>
+                    <signal name="clicked" handler="on_button_drop_node_type_clicked"/>
                   </widget>
                   <packing>
-                    <property name="top_attach">5</property>
-                    <property name="bottom_attach">6</property>
-                  </packing>
-                </child>
-                <child>
-                  <widget class="GtkComboBox" id="combobox_creator_node_types">
-                    <property name="visible">True</property>
-                    <property name="items" translatable="yes"></property>
-                  </widget>
-                  <packing>
-                    <property name="left_attach">3</property>
-                    <property name="right_attach">4</property>
+                    <property name="left_attach">4</property>
+                    <property name="right_attach">5</property>
                     <property name="top_attach">3</property>
                     <property name="bottom_attach">4</property>
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkComboBox" id="combobox_creator_edge_types">
+                  <widget class="GtkButton" id="button_drop_edge_type">
                     <property name="visible">True</property>
-                    <property name="items" translatable="yes"></property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="label" translatable="yes">Delete</property>
+                    <property name="response_id">0</property>
+                    <signal name="clicked" handler="on_button_drop_edge_type_clicked"/>
                   </widget>
                   <packing>
-                    <property name="left_attach">3</property>
-                    <property name="right_attach">4</property>
+                    <property name="left_attach">4</property>
+                    <property name="right_attach">5</property>
                     <property name="top_attach">4</property>
                     <property name="bottom_attach">5</property>
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkButton" id="button_create_level">
+                  <widget class="GtkHSeparator" id="hseparator1">
                     <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="receives_default">True</property>
-                    <property name="label" translatable="yes">Create</property>
-                    <property name="response_id">0</property>
-                    <signal name="clicked" handler="on_button_create_level_clicked"/>
                   </widget>
                   <packing>
-                    <property name="left_attach">2</property>
-                    <property name="right_attach">3</property>
+                    <property name="right_attach">5</property>
+                    <property name="top_attach">1</property>
+                    <property name="bottom_attach">2</property>
+                    <property name="y_padding">5</property>
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkEntry" id="entry_creator_level">
+                  <widget class="GtkLabel" id="label_creator_node_type">
                     <property name="visible">True</property>
-                    <property name="can_focus">True</property>
+                    <property name="label" translatable="yes">Node type</property>
+                  </widget>
+                  <packing>
+                    <property name="top_attach">3</property>
+                    <property name="bottom_attach">4</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkComboBox" id="combobox_admin_levels">
+                    <property name="visible">True</property>
+                    <property name="items" translatable="yes"></property>
                   </widget>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="right_attach">2</property>
+                    <property name="top_attach">2</property>
+                    <property name="bottom_attach">3</property>
+                    <property name="x_options">GTK_FILL</property>
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkLabel" id="label_creator_level">
+                  <widget class="GtkLabel" id="label_admin_modify_level">
                     <property name="visible">True</property>
-                    <property name="label" translatable="yes">Level</property>
-                  </widget>
-                </child>
-                <child>
-                  <widget class="GtkButton" id="button_drop_level">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="receives_default">True</property>
-                    <property name="label" translatable="yes">Delete</property>
-                    <property name="response_id">0</property>
-                    <signal name="clicked" handler="on_button_drop_level_clicked"/>
+                    <property name="label" translatable="yes">In this level</property>
                   </widget>
                   <packing>
-                    <property name="left_attach">4</property>
-                    <property name="right_attach">5</property>
                     <property name="top_attach">2</property>
                     <property name="bottom_attach">3</property>
                   </packing>

File view/genet_window.py

 from control import genet_creator 
 from control import genet_global
 
+from model import class_edge 
+from model import class_node
+from model.db_connection import db
+
 class window:
     def __init__(self):
         """
         
         # Declare dictionary.
         dic = {
+            # Browse tab.
             "on_button_connect_nodes_clicked" : 
             self.button_connect_nodes_clicked,
+
+            # Create tab.
+            "on_button_create_node_clicked" :
+            self.button_create_node_clicked,
+            "on_button_create_edge_clicked" :
+            self.button_create_edge_clicked,
+            "on_button_create_refresh_clicked" :
+            self.button_create_refresh_clicked,
+
+            # Admin tab.
             "on_button_create_level_clicked" : 
             self.button_create_level_clicked,
             "on_button_drop_level_clicked" : 
         return
 
     ############################################################################
-    # Browser tab.
+    # Browse tab.
     #
     def button_connect_nodes_clicked(self,widget):
         print 'Clicked!'
         
     ############################################################################
-    # Creator tab.
+    # Create tab.
     #
+    def button_create_node_clicked(self, widget):
+        # Get level
+        combo = self.wTree.get_widget("combobox_creator_levels")
+        combo_model = combo.get_model()
+        combo_index = combo.get_active()
+        level = combo_model[combo_index][1]
+
+        # Get type
+        combo = self.wTree.get_widget("combobox_creator_node_types")
+        combo_model = combo.get_model()
+        combo_index = combo.get_active()
+        type = combo_model[combo_index][1]
+
+        # Create node
+        N = class_node.node(level, 0, 0, type)
+        N.store(db)
+
+        # TODO Refresh the combo when touched.    
+        self.button_create_refresh_clicked(None)
+
+    def button_create_edge_clicked(self, widget):
+        # Get level
+        combo = self.wTree.get_widget("combobox_creator_levels")
+        combo_model = combo.get_model()
+        combo_index = combo.get_active()
+        level = combo_model[combo_index][1]
+
+        # Get nodeA and nodeB
+        combo = self.wTree.get_widget("combobox_creator_edge_nodeA")
+        combo_model = combo.get_model()
+        combo_index = combo.get_active()
+        nA = combo_model[combo_index][1]
+
+        combo = self.wTree.get_widget("combobox_creator_edge_nodeB")
+        combo_model = combo.get_model()
+        combo_index = combo.get_active()
+        nB = combo_model[combo_index][1]
+
+        # Get type
+        combo = self.wTree.get_widget("combobox_creator_edge_types")
+        combo_model = combo.get_model()
+        combo_index = combo.get_active()
+        type = combo_model[combo_index][1]
+
+        # Create edge
+        E = class_edge.edge(level, nA, nB, 0, 0, type)
+        E.store(db)
+
+        # TODO Refresh the combo when touched.    
+        self.button_create_refresh_clicked(None)
+
+    def button_create_refresh_clicked(self, widget):
+        # TODO Refresh the combo when touched.    
+        self.refreshCombo("combobox_creator_levels", 'levels')
+        self.refreshCombo("combobox_creator_node_types", 'node_types')
+        self.refreshCombo("combobox_creator_edge_types", 'edge_types')
+
+        # Get level
+        combo = self.wTree.get_widget("combobox_creator_levels")
+        combo_model = combo.get_model()
+        combo_index = combo.get_active()
+        level = combo_model[combo_index][1]
+
+        self.refreshCombo("combobox_creator_edge_nodeA", 'nodes', level)
+        self.refreshCombo("combobox_creator_edge_nodeB", 'nodes', level)
 
     ############################################################################
     # Admin tab.
     #
     def button_create_level_clicked(self,widget):
         # Get description
-        description = self.wTree.get_widget("entry_creator_level").get_text()
+        description = self.wTree.get_widget("entry_admin_level").get_text()
 
         # Create level
         genet_creator.createLevel(description)
 
     def button_drop_level_clicked(self,widget):
         # Get level
-        combo = self.wTree.get_widget("combobox_creator_levels")
+        combo = self.wTree.get_widget("combobox_admin_levels")
         combo_model = combo.get_model()
         combo_index = combo.get_active()
         level = combo_model[combo_index][1]
 
     def button_create_node_type_clicked(self, widget):
         # Get level
-        combo = self.wTree.get_widget("combobox_creator_levels")
+        combo = self.wTree.get_widget("combobox_admin_levels")
         combo_model = combo.get_model()
         combo_index = combo.get_active()
         level = combo_model[combo_index][1]
 
         # Get description
-        description = self.wTree.get_widget("entry_creator_node_type").get_text()
+        description = self.wTree.get_widget("entry_admin_node_type").get_text()
 
         # Create type
         genet_creator.createNodeType(level, description)
 
     def button_drop_node_type_clicked(self, widget):
         # Get type
-        combo = self.wTree.get_widget("combobox_creator_node_types")
+        combo = self.wTree.get_widget("combobox_admin_node_types")
         combo_model = combo.get_model()
         combo_index = combo.get_active()
         type = combo_model[combo_index][1]
        
     def button_create_edge_type_clicked(self, widget):
         # Get level
-        combo = self.wTree.get_widget("combobox_creator_levels")
+        combo = self.wTree.get_widget("combobox_admin_levels")
         combo_model = combo.get_model()
         combo_index = combo.get_active()
         level = combo_model[combo_index][1]
 
         # Get description
-        description = self.wTree.get_widget("entry_creator_edge_type").get_text()
+        description = self.wTree.get_widget("entry_admin_edge_type").get_text()
 
         # Create type
         genet_creator.createEdgeType(level, description)
 
     def button_drop_edge_type_clicked(self, widget):
         # Get type
-        combo = self.wTree.get_widget("combobox_creator_edge_types")
+        combo = self.wTree.get_widget("combobox_admin_edge_types")
         combo_model = combo.get_model()
         combo_index = combo.get_active()
         type = combo_model[combo_index][1]
 
     def button_admin_refresh_clicked(self, widget):
         # TODO Refresh the combo when touched.    
-        self.refreshCombo("combobox_creator_levels", 'levels')
-        self.refreshCombo("combobox_creator_node_types", 'node_types')
-        self.refreshCombo("combobox_creator_edge_types", 'edge_types')
+        self.refreshCombo("combobox_admin_levels", 'levels')
+        self.refreshCombo("combobox_admin_node_types", 'node_types')
+        self.refreshCombo("combobox_admin_edge_types", 'edge_types')
 
     def button_admin_reset_clicked(self, widget):
         genet_global.restartDatabase()
     def main(self):
         gtk.main()
 
-    def refreshCombo(self, name, function):
+    def refreshCombo(self, name, function, level = None):
         combo = self.wTree.get_widget(name)
 
         if function == 'levels':
             list = genet_browser.listNodeTypes()
         elif function == 'edge_types':
             list = genet_browser.listEdgeTypes()
+        elif function == 'nodes':
+            list = genet_browser.listNodes(level)
 
         model = gtk.ListStore(str, str)
         for i in list: