def __init__(self, padre): self.padre = padre arch = leerglade.leer('nav_timbrados.glade') self.nav = arch.get_object self.nav('window1').set_title('Registro de Timbrados') 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 = Timbrados() self.tipo_comprobantes = TipoComprobantes() 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()
class RegTimbrados: def __init__(self, padre): self.padre = padre arch = leerglade.leer('nav_timbrados.glade') self.nav = arch.get_object self.nav('window1').set_title('Registro de Timbrados') 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 = Timbrados() self.tipo_comprobantes = TipoComprobantes() 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.tim_all(): 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], str(row[3]), str(row[4]), row[5], 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').grab_focus() 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(nro_timbrado=pk) self.formulario() self.frm('entry1').set_text(str(self.entity.nro_timbrado)) self.frm('entry2').set_text(self.entity.fecha_vigencia.strftime('%d/%m/%Y')) self.frm('entry3').set_text(self.entity.fecha_vencimiento.strftime('%d/%m/%Y')) self.frm('entry4').set_text(str(self.entity.numero_inicial)) self.frm('entry5').set_text(str(self.entity.numero_final)) self.set_active_combo(str(self.entity.idtipo_comprobante)) 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_timbrados.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('Formulario de Timbrados') self.frm('window1').show_all() arch.connect_signals(self) self.validar_entrys(None) self.cargar_combos() 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): it = self.frm('combobox1').get_active() self.entity.nro_timbrado = self.frm('entry1').get_text() self.entity.fecha_vigencia = self.frm('entry2').get_text() self.entity.fecha_vencimiento = self.frm('entry3').get_text() self.entity.numero_inicial = self.frm('entry4').get_text() self.entity.numero_final = self.frm('entry5').get_text() self.entity.idtipo_comprobante = self.frm('liststore1')[it][0].split('-')[0] if self.entity.save(): self.frm('window1').destroy() self.consultar() def cancelar_cb(self, widget): self.frm('window1').destroy() def cargar_combos(self): for row in self.tipo_comprobantes.all(order_by=1, descripcion__ilike="%%"): self.frm('liststore1').append([str(row[0])+'-'+row[1]]) self.frm('combobox1').set_active(0) def set_active_combo(self, pk): it = 0 for row in self.frm('liststore1'): if row[0].split('-')[0] == str(pk): self.frm('combobox1').set_active(it) break it += 1 def buscar_fechas(self, widget, icon_pos, event): Calendar.Pegar(self.frm('window1'), widget) def set_focus(self, widget): if widget in (self.frm('entry2'), self.frm('entry3')): widget.set_text(Format.fecha(widget.get_text())) widget.get_toplevel().child_focus(Gtk.DirectionType.TAB_FORWARD)