def hidratateObject(self, row):
     aux = Contacto()
     aux.id = row["id"]
     aux.name = row["name"]
     aux.last_name = row["last_name"]
     aux.email = row["email"]
     aux.mobile = str(row["mobile"])
     aux.telephone = str(row["telephone"])
     return aux
 def create_contact(self):
     print "========== Create a new contact ================"
     aux = Contacto()
     name = raw_input("[Name] > ")
     aux.set_name(name)
     last_name = raw_input("[Last Name] > ")
     aux.set_last_name(last_name)
     has_errors = True
     while has_errors:
         try:
             email = raw_input("[Email] > ")
             aux.set_email(email)
             has_errors = False
         except EmailValidatorException:
             print "Invalid email"
     
     mobile = raw_input("[Mobile] > ")
     aux.set_mobile(mobile)
     telephone = raw_input("[Telephone] > ")
     aux.set_telephone(telephone)
     aux.id = len(self.contactos) + 1
     self.contactos.append(aux)
    def init_agenda(self):
        #contactos = []
        pepe = Contacto()
        pepe.set_name('pepe')
        pepe.set_last_name('perez')
        pepe.set_email('*****@*****.**')
        pepe.set_mobile('312312')
        pepe.set_telephone('132312312')
        pepe.id = len(self.contactos) + 1
        self.contactos.append(pepe)

        main_menu_text = {1 : 'Create new', 2: 'List', 3 : 'Exit'}
        main_menu_options = {1 : self.create_contact, 2: self.list_contacts, 3 : self.close_program}

        options = { 'main' : { 'text' : main_menu_text, 'options' : main_menu_options}}
        start_point = 'main'

        selected = start_point
        print "========== Welcome to contact 1.0.0 ================"

        while True:
            print "========== Main menu ================"
            displayed = options[selected]['text']
            sel_options = options[selected]['options']
        
            for k, v in displayed.iteritems():
                print " {0} - {1}".format(k, v)
            
            selection = raw_input("[Selection] >") 
            selection_int = 0
            try:
                #print selection
                selection_int = int(selection)
                function = sel_options[selection_int] 
                function()
            except ValueError:
                print "It has to be a number"
 def __init__(self, identifier = 0):
     super(ContactWindow, self).__init__()
     
     self.aux_contact = None
     
     #Database parameter
     self.db = BasicDb()
     
     is_new = True
     if identifier == 0:
         self.set_title("Add Contact")
         self.aux_contact = Contacto()
     else:
         self.set_title("Edit Contact")
         self.aux_contact = self.db.retrieveDb().findOne(identifier)
         is_new = False
         
     self.set_size_request(400, 400)
     
     self.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
     
     self.connect("destroy", self.close_window)
     
     table = gtk.Table(6, 2, True)
     
     self.name_entry = gtk.Entry()
     self.last_name_entry = gtk.Entry()
     self.email_entry = gtk.Entry()
     self.mobile_entry = gtk.Entry()
     self.telephone_entry = gtk.Entry()
     
     if not is_new:
         self.name_entry.set_text(self.aux_contact.name)
         self.last_name_entry.set_text(self.aux_contact.last_name)
         self.email_entry.set_text(self.aux_contact.email)
         self.mobile_entry.set_text(self.aux_contact.mobile)
         self.telephone_entry.set_text(self.aux_contact.telephone)
     
     table.attach(gtk.Label("Name"), 0, 1, 0 ,1 )
     table.attach(self.name_entry, 1, 2, 0 ,1 )
     table.attach(gtk.Label("Last Name"), 0, 1, 1 , 2)
     table.attach(self.last_name_entry, 1, 2, 1 ,2 )
     
     table.attach(gtk.Label("Email"), 0, 1, 2 ,3 )
     table.attach(self.email_entry, 1, 2, 2 ,3 )
     table.attach(gtk.Label("Mobile"), 0, 1, 3 ,4 )
     table.attach(self.mobile_entry, 1, 2, 3 ,4 )
     
     table.attach(gtk.Label("Telephone"), 0, 1, 4 ,5 )
     table.attach(self.telephone_entry, 1, 2, 4 ,5 )
     
     button_save = gtk.Button("Save")
     button_cancel = gtk.Button("Cancel")
     
     button_save.set_size_request(60, 60)
     button_cancel.set_size_request(60, 60)
     
     button_save.connect("clicked", self.save_contacto)
     button_cancel.connect("clicked", self.close_window)
     
     table.attach(button_save, 0, 1, 5 ,6 )
     table.attach(button_cancel, 1, 2, 5 ,6 )
     
     
     self.add(table)
     
     
     self.show_all()
class ContactWindow(gtk.Window):
    
    def __init__(self, identifier = 0):
        super(ContactWindow, self).__init__()
        
        self.aux_contact = None
        
        #Database parameter
        self.db = BasicDb()
        
        is_new = True
        if identifier == 0:
            self.set_title("Add Contact")
            self.aux_contact = Contacto()
        else:
            self.set_title("Edit Contact")
            self.aux_contact = self.db.retrieveDb().findOne(identifier)
            is_new = False
            
        self.set_size_request(400, 400)
        
        self.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
        
        self.connect("destroy", self.close_window)
        
        table = gtk.Table(6, 2, True)
        
        self.name_entry = gtk.Entry()
        self.last_name_entry = gtk.Entry()
        self.email_entry = gtk.Entry()
        self.mobile_entry = gtk.Entry()
        self.telephone_entry = gtk.Entry()
        
        if not is_new:
            self.name_entry.set_text(self.aux_contact.name)
            self.last_name_entry.set_text(self.aux_contact.last_name)
            self.email_entry.set_text(self.aux_contact.email)
            self.mobile_entry.set_text(self.aux_contact.mobile)
            self.telephone_entry.set_text(self.aux_contact.telephone)
        
        table.attach(gtk.Label("Name"), 0, 1, 0 ,1 )
        table.attach(self.name_entry, 1, 2, 0 ,1 )
        table.attach(gtk.Label("Last Name"), 0, 1, 1 , 2)
        table.attach(self.last_name_entry, 1, 2, 1 ,2 )
        
        table.attach(gtk.Label("Email"), 0, 1, 2 ,3 )
        table.attach(self.email_entry, 1, 2, 2 ,3 )
        table.attach(gtk.Label("Mobile"), 0, 1, 3 ,4 )
        table.attach(self.mobile_entry, 1, 2, 3 ,4 )
        
        table.attach(gtk.Label("Telephone"), 0, 1, 4 ,5 )
        table.attach(self.telephone_entry, 1, 2, 4 ,5 )
        
        button_save = gtk.Button("Save")
        button_cancel = gtk.Button("Cancel")
        
        button_save.set_size_request(60, 60)
        button_cancel.set_size_request(60, 60)
        
        button_save.connect("clicked", self.save_contacto)
        button_cancel.connect("clicked", self.close_window)
        
        table.attach(button_save, 0, 1, 5 ,6 )
        table.attach(button_cancel, 1, 2, 5 ,6 )
        
        
        self.add(table)
        
        
        self.show_all()
        
    def save_contacto(self, widget):
        try:
            self.aux_contact.set_name(self.name_entry.get_text())
            self.aux_contact.set_last_name(self.last_name_entry.get_text())
            self.aux_contact.set_email(self.email_entry.get_text())
            self.aux_contact.set_mobile(self.mobile_entry.get_text())
            self.aux_contact.set_telephone(self.telephone_entry.get_text())
            if self.aux_contact.id > 0:
                self.db.retrieveDb().update(self.aux_contact)
            else:
                self.db.retrieveDb().insert(self.aux_contact)
            self.destroy()   
        except EmailValidatorException, e:
            md = gtk.MessageDialog(self, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, e.args[0])
            md.run()
            md.destroy()
Example #6
0
 def agregar(self, nombre, telefono):
     self.contacto[nombre] = Contacto(nombre, telefono)
    def __init__(self, identifier=0):
        super(ContactWindow, self).__init__()

        self.aux_contact = None

        #Database parameter
        self.db = BasicDb()

        is_new = True
        if identifier == 0:
            self.set_title("Add Contact")
            self.aux_contact = Contacto()
        else:
            self.set_title("Edit Contact")
            self.aux_contact = self.db.retrieveDb().findOne(identifier)
            is_new = False

        self.set_size_request(400, 400)

        self.set_position(gtk.WIN_POS_CENTER_ON_PARENT)

        self.connect("destroy", self.close_window)

        table = gtk.Table(6, 2, True)

        self.name_entry = gtk.Entry()
        self.last_name_entry = gtk.Entry()
        self.email_entry = gtk.Entry()
        self.mobile_entry = gtk.Entry()
        self.telephone_entry = gtk.Entry()

        if not is_new:
            self.name_entry.set_text(self.aux_contact.name)
            self.last_name_entry.set_text(self.aux_contact.last_name)
            self.email_entry.set_text(self.aux_contact.email)
            self.mobile_entry.set_text(self.aux_contact.mobile)
            self.telephone_entry.set_text(self.aux_contact.telephone)

        table.attach(gtk.Label("Name"), 0, 1, 0, 1)
        table.attach(self.name_entry, 1, 2, 0, 1)
        table.attach(gtk.Label("Last Name"), 0, 1, 1, 2)
        table.attach(self.last_name_entry, 1, 2, 1, 2)

        table.attach(gtk.Label("Email"), 0, 1, 2, 3)
        table.attach(self.email_entry, 1, 2, 2, 3)
        table.attach(gtk.Label("Mobile"), 0, 1, 3, 4)
        table.attach(self.mobile_entry, 1, 2, 3, 4)

        table.attach(gtk.Label("Telephone"), 0, 1, 4, 5)
        table.attach(self.telephone_entry, 1, 2, 4, 5)

        button_save = gtk.Button("Save")
        button_cancel = gtk.Button("Cancel")

        button_save.set_size_request(60, 60)
        button_cancel.set_size_request(60, 60)

        button_save.connect("clicked", self.save_contacto)
        button_cancel.connect("clicked", self.close_window)

        table.attach(button_save, 0, 1, 5, 6)
        table.attach(button_cancel, 1, 2, 5, 6)

        self.add(table)

        self.show_all()
class ContactWindow(gtk.Window):
    def __init__(self, identifier=0):
        super(ContactWindow, self).__init__()

        self.aux_contact = None

        #Database parameter
        self.db = BasicDb()

        is_new = True
        if identifier == 0:
            self.set_title("Add Contact")
            self.aux_contact = Contacto()
        else:
            self.set_title("Edit Contact")
            self.aux_contact = self.db.retrieveDb().findOne(identifier)
            is_new = False

        self.set_size_request(400, 400)

        self.set_position(gtk.WIN_POS_CENTER_ON_PARENT)

        self.connect("destroy", self.close_window)

        table = gtk.Table(6, 2, True)

        self.name_entry = gtk.Entry()
        self.last_name_entry = gtk.Entry()
        self.email_entry = gtk.Entry()
        self.mobile_entry = gtk.Entry()
        self.telephone_entry = gtk.Entry()

        if not is_new:
            self.name_entry.set_text(self.aux_contact.name)
            self.last_name_entry.set_text(self.aux_contact.last_name)
            self.email_entry.set_text(self.aux_contact.email)
            self.mobile_entry.set_text(self.aux_contact.mobile)
            self.telephone_entry.set_text(self.aux_contact.telephone)

        table.attach(gtk.Label("Name"), 0, 1, 0, 1)
        table.attach(self.name_entry, 1, 2, 0, 1)
        table.attach(gtk.Label("Last Name"), 0, 1, 1, 2)
        table.attach(self.last_name_entry, 1, 2, 1, 2)

        table.attach(gtk.Label("Email"), 0, 1, 2, 3)
        table.attach(self.email_entry, 1, 2, 2, 3)
        table.attach(gtk.Label("Mobile"), 0, 1, 3, 4)
        table.attach(self.mobile_entry, 1, 2, 3, 4)

        table.attach(gtk.Label("Telephone"), 0, 1, 4, 5)
        table.attach(self.telephone_entry, 1, 2, 4, 5)

        button_save = gtk.Button("Save")
        button_cancel = gtk.Button("Cancel")

        button_save.set_size_request(60, 60)
        button_cancel.set_size_request(60, 60)

        button_save.connect("clicked", self.save_contacto)
        button_cancel.connect("clicked", self.close_window)

        table.attach(button_save, 0, 1, 5, 6)
        table.attach(button_cancel, 1, 2, 5, 6)

        self.add(table)

        self.show_all()

    def save_contacto(self, widget):
        try:
            self.aux_contact.set_name(self.name_entry.get_text())
            self.aux_contact.set_last_name(self.last_name_entry.get_text())
            self.aux_contact.set_email(self.email_entry.get_text())
            self.aux_contact.set_mobile(self.mobile_entry.get_text())
            self.aux_contact.set_telephone(self.telephone_entry.get_text())
            if self.aux_contact.id > 0:
                self.db.retrieveDb().update(self.aux_contact)
            else:
                self.db.retrieveDb().insert(self.aux_contact)
            self.destroy()
        except EmailValidatorException, e:
            md = gtk.MessageDialog(self, gtk.DIALOG_DESTROY_WITH_PARENT,
                                   gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE,
                                   e.args[0])
            md.run()
            md.destroy()
Example #9
0
    def create_contact(self):
        print "========== Create a new contact ================"
        aux = Contacto()
        name = raw_input("[Name] > ")
        aux.set_name(name)
        last_name = raw_input("[Last Name] > ")
        aux.set_last_name(last_name)
        has_errors = True
        while has_errors:
            try:
                email = raw_input("[Email] > ")
                aux.set_email(email)
                has_errors = False
            except EmailValidatorException:
                print "Invalid email"

        mobile = raw_input("[Mobile] > ")
        aux.set_mobile(mobile)
        telephone = raw_input("[Telephone] > ")
        aux.set_telephone(telephone)
        aux.id = len(self.contactos) + 1
        self.contactos.append(aux)
Example #10
0
    def init_agenda(self):
        #contactos = []
        pepe = Contacto()
        pepe.set_name('pepe')
        pepe.set_last_name('perez')
        pepe.set_email('*****@*****.**')
        pepe.set_mobile('312312')
        pepe.set_telephone('132312312')
        pepe.id = len(self.contactos) + 1
        self.contactos.append(pepe)

        main_menu_text = {1: 'Create new', 2: 'List', 3: 'Exit'}
        main_menu_options = {
            1: self.create_contact,
            2: self.list_contacts,
            3: self.close_program
        }

        options = {
            'main': {
                'text': main_menu_text,
                'options': main_menu_options
            }
        }
        start_point = 'main'

        selected = start_point
        print "========== Welcome to contact 1.0.0 ================"

        while True:
            print "========== Main menu ================"
            displayed = options[selected]['text']
            sel_options = options[selected]['options']

            for k, v in displayed.iteritems():
                print " {0} - {1}".format(k, v)

            selection = raw_input("[Selection] >")
            selection_int = 0
            try:
                #print selection
                selection_int = int(selection)
                function = sel_options[selection_int]
                function()
            except ValueError:
                print "It has to be a number"
Example #11
0
 def obtenerContactos(self):
     lista_contactos = []
     for contacto in self.contactos:
         nuevo_contacto = Contacto(contacto)
         lista_contactos.append(nuevo_contacto)
     return lista_contactos