Пример #1
0
 def __init__(self, padre):
     self.padre = padre
     arch = leerglade.leer('nav_contactos.glade')
     self.nav = arch.get_object
     self.nav('window1').set_title('Registro de Contactos')
     self.nav('window1').set_default_size(800, 600)
     self.nav('window1').set_position(1)
     self.nav('bt_nuevo').set_label('Nuevo')
     self.nav('bt_editar').set_label('Editar')
     self.nav('bt_eliminar').set_label('Eliminar')
     self.nav('bt_cerrar').set_label('Cerrar')
     self.entity = Contactos()
     self.entity_1 = ContactosTipos()
     self.tipocontactos = TipoContactos()
     self.nav('window1').set_transient_for(self.padre.main('window1'))
     self.nav('window1').set_modal(True)
     self.nav('window1').set_border_width(5)
     self.nav('window1').show_all()
     arch.connect_signals(self)
     self.consultar()
Пример #2
0
class RegContactos:
    def __init__(self, padre):
        self.padre = padre
        arch = leerglade.leer('nav_contactos.glade')
        self.nav = arch.get_object
        self.nav('window1').set_title('Registro de Contactos')
        self.nav('window1').set_default_size(800, 600)
        self.nav('window1').set_position(1)
        self.nav('bt_nuevo').set_label('Nuevo')
        self.nav('bt_editar').set_label('Editar')
        self.nav('bt_eliminar').set_label('Eliminar')
        self.nav('bt_cerrar').set_label('Cerrar')
        self.entity = Contactos()
        self.entity_1 = ContactosTipos()
        self.tipocontactos = TipoContactos()
        self.nav('window1').set_transient_for(self.padre.main('window1'))
        self.nav('window1').set_modal(True)
        self.nav('window1').set_border_width(5)
        self.nav('window1').show_all()
        arch.connect_signals(self)
        self.consultar()

    def consultar(self, widget=None):
        self.nav('liststore1').clear()
        color = False
        for row in self.entity.all(order_by=1, razon_social__ilike='%' + self.nav('entry1').get_text() + '%'):
            if not color:
                t_color = "#FFFFDA"
                color = True
            else:
                t_color = "#A9FFA9"
                color = False
            self.nav('liststore1').append([str(row[0]), row[1], row[2], row[3], row[4], t_color])

        if len(self.nav('liststore1')) == 0:
            self.nav('bt_editar').set_sensitive(False)
            self.nav('bt_eliminar').set_sensitive(False)
            self.nav('label1').set_text(' 0 Registros Encontrados')
        else:
            self.nav('bt_editar').set_sensitive(True)
            self.nav('bt_eliminar').set_sensitive(True)
            self.nav('label1').set_text(' %s Registros Encontrados' % len(self.nav('liststore1')))

        self.nav('entry1').set_text(self.nav('entry1').get_text().upper())

    def bt_nuevo_cb(self, widget):
        self.formulario()
        self.frm('entry1').set_text(str(self.entity.get_max()))
        self.frm('entry1').grab_focus()
        self.consultar_tipos()

    def bt_editar_cb(self, widget):
        sl, it = self.nav('treeview1').get_selection().get_selected()
        try:
            pk = sl.get_value(it, 0)
        except:
            msg.errorMsgBox(self.nav('window1'), "Sin selección", "Es necesario seleccionar un registo para la edición")
            return

        datos = self.entity.find(idcontacto=pk)
        self.formulario()
        self.frm('entry1').set_text(str(self.entity.idcontacto))
        self.frm('entry2').set_text(self.entity.razon_social)
        self.frm('entry3').set_text(self.entity.ruc_ci)
        self.frm('entry4').set_text(self.entity.direccion)
        self.frm('entry5').set_text(self.entity.telefono)
        self.consultar_tipos()

    def bt_eliminar_cb(self, widget):
        sl, it = self.nav('treeview1').get_selection().get_selected()
        try:
            pk = sl.get_value(it, 0)
        except:
            msg.errorMsgBox(self.nav('window1'), "Sin selección", "Es necesario seleccionar un registo")
            return
        res = msg.preguntaMsgBox(self.nav('window1'), "Eliminar Registro", "Estas Seguro?")

        if res == -8:
            kwargs = {
                self.entity.__pks__[0]: pk
            }
            datos = self.entity.find(**kwargs)
            if self.entity.delete():
                self.consultar()

    def bt_cerrar_cb(self, widget):
        self.nav('window1').destroy()

    def formulario(self):
        arch = leerglade.leer('frm_contactos.glade')
        self.frm = arch.get_object
        self.frm('window1').set_default_size(500, -1)
        self.frm('window1').set_transient_for(self.nav('window1'))
        self.frm('window1').set_position(1)
        self.frm('window1').set_modal(True)
        self.frm('window1').set_border_width(5)
        self.frm('window1').set_title('Registro de Contactos')
        self.frm('window1').show_all()
        arch.connect_signals(self)
        self.validar_entrys(None)
        self.cargar_combo_tipos()


    def validar_entrys(self, widget=None):
        if len(self.frm('entry1').get_text()) == 0 \
            or len(self.frm('entry2').get_text()) == 0\
            or len(self.frm('entry3').get_text()) == 0\
            or len(self.frm('entry4').get_text()) == 0\
            or len(self.frm('entry5').get_text()) == 0:
            self.frm('button2').set_sensitive(False)
        else:
            self.frm('button2').set_sensitive(True)

        if widget is not None:
            #convierte todos los valores de los campos en mayusculas
            widget.set_text(widget.get_text().upper())

    def guardar_cb(self, widget):
        self.entity.idcontacto = self.frm('entry1').get_text()
        self.entity.razon_social = self.frm('entry2').get_text()
        self.entity.ruc_ci = self.frm('entry3').get_text()
        self.entity.direccion = self.frm('entry4').get_text()
        self.entity.telefono = self.frm('entry5').get_text()
        if self.entity.save():
            self.frm('notebook1').set_current_page(1)
            self.consultar()
            self.frm('button2').set_sensitive(False)

    def cancelar_cb(self, widget):
        self.frm('window1').destroy()

    # Codigo relacionado con la pestanha de tipos

    def bt_mas_cb(self, widget):
        #idtipo = self.frm('combobox1').get_active_text().split('-')[0]
        it = self.frm('combobox1').get_active()
        idtipo = self.frm('liststore1')[it][0].split('-')[0]

        self.entity_1.idcontacto = self.frm('entry1').get_text()
        self.entity_1.idtipo_contacto = idtipo
        if self.entity_1.save():
            self.consultar_tipos()

    def bt_menos_cb(self, widget):
        sl, it = self.frm('treeview1').get_selection().get_selected()
        try:
            idtipo = sl.get_value(it, 0)
        except:
            msg.errorMsgBox(self.nav('window1'), "Sin selección", "Es necesario seleccionar un registo")
            return
        res = msg.preguntaMsgBox(self.nav('window1'), "Eliminar Registro", "Estas Seguro?")
        if res == -8:
            kwargs = {
                'idtipo_contacto': idtipo,
                'idcontacto': self.frm('entry1').get_text()
            }
            datos = self.entity_1.find(**kwargs)
            if self.entity_1.delete():
                self.consultar_tipos()

    def cargar_combo_tipos(self):
        for row in self.tipocontactos.all_combo():
            self.frm('liststore1').append([str(row[0])])
        self.frm('combobox1').set_active(0)

    def consultar_tipos(self):
        color = False
        if len(self.frm('entry1').get_text()) == 0:
            idcontacto = 0
        else:
            idcontacto = self.frm('entry1').get_text()
        self.frm('liststore2').clear()
        for row in self.entity_1.all(idcontacto=idcontacto):
            if not color:
                t_color = "#FFFFDA"
                color = True
            else:
                t_color = "#A9FFA9"
                color = False
            self.frm('liststore2').append([str(row[0]), row[1], t_color])

    def set_focus(self, widget):
        widget.get_toplevel().child_focus(Gtk.DirectionType.TAB_FORWARD)