def saveNodeFile(self):
        """ save the nodes file with the value store in the nodes list """

        # open file 'nodes.txt'
        try:
            f = file(self.nodesFile, 'w')
        except:
            displayError(self, 'Cannot open the file %s' %self.nodesFile)
            return 0

        # write node infos in the nodes file
        for node in self.nodeList:
            pseudo = node['pseudo']
            host = node['host']
            port = str(node['port'])
            posX = str(node['posX'])
            posY = str(node['posY'])
            isDistant = str(node['isDistant'])
            isConnected = str(node['isConnected'])
            line = pseudo + ';' + host + ';'+ port + ';' + posX + ';' + posY + ';' + isDistant + ';' + isConnected + '\n'
            f.write(line)

        f.close()

        return 1
    def OnNewLocalNodeButton(self, event):
        """ create a new local node in the list """

        dlg = newLocalNodeDialog(self)
        if dlg.ShowModal() == wxID_OK:
            pseudo = dlg.pseudoTextCtrl.GetValue()
            if pseudo == "":
                displayError(self, "Can't create the node : your node pseudo is empty !")
            else:
                #self.controller.createNode()
                self.controller.log('new local node ')
                filename = str(pseudo) + ".host"
                while filename not in os.listdir("."):
                    time.sleep(0.1)

                f = file(filename, 'r')
                host = f.readlines()[0]
                f.close()
                
                list={'pseudo':pseudo, 'host':host, 'port':port, 'posX':'', 'posY':'', 'isDistant':0, 'isConnected':0}

                # store the new node in the lists
                self.nodeList.append(list)
                self.pseudoList.append(pseudo)
                self.nodesListBox.Append(pseudo)

                # save the new node in the nodes file
                self.saveNodeFile()

        dlg.Destroy()
    def OnNewLocalNodeButton(self, event):
        """ create a new local node in the list """

        dlg = newLocalNodeDialog(self)
        if dlg.ShowModal() == wx.ID_OK:
            pseudo = dlg.pseudoTextCtrl.GetValue()
            if pseudo == "":
                displayError(self, "Can't create the node : your node pseudo is empty !")
            else:
                self.controller.createNode(pseudo)                
    def OnNewDistantNodeButton(self, event):
        """ create a new distant node in the list """

        dlg = newDistantNodeDialog(self)
        if dlg.ShowModal() == wxID_OK:
            host = dlg.hostTextCtrl.GetValue()
            port = dlg.portTextCtrl.GetValue()
            if host == "":
                displayError(self, "Can't create the node : your node host is empty !")
            elif port == "":
                displayError(self, "Can't create the node : your node port is empty !")
            else:
                pseudo = host + ":" + port
                list={'pseudo':pseudo, 'host':host, 'port':port, 'posX':'', 'posY':'', 'isDistant':1, 'isConnected':0}

                # store the new node in the lists
                self.nodeList.append(list)
                self.pseudoList.append(pseudo)
                self.nodesListBox.Append(pseudo)

                # save the new node in the nodes file
                self.saveNodeFile()
        dlg.Destroy()
 def OnNodeCreationFailure(self, reason):
     """ The node wasn't created"""
     displayError(self, 'Error, node not created: ' + reason)