class AnagraficaPrintPreview(GladeWidget): """ Print preview """ # FIXME: a lot of duplicated code from AnagraficaFilter here! def __init__(self, anagrafica, windowTitle, previewTemplate, veter=False): GladeWidget.__init__(self, root='htmlviewer', path="htmlviewer.glade") self.windowTitle = windowTitle self.visualizzatore_html.set_title(windowTitle) self._anagrafica = anagrafica self._veter = veter self.bodyWidget = FilterWidget(owner=self, resultsElement='html') self.bodyWidget.filter_navigation_hbox.destroy() self.bodyWidget.info_label.set_markup("INSERT INFO") self.html_scrolledwindow.add_with_viewport( self.bodyWidget.getTopLevel()) self.print_on_screen_html = self.bodyWidget.resultsElement self._gtkHtmlDocuments = None self._previewTemplate = previewTemplate self.html = createHtmlObj(self) #Prendo tutti i dati dalla finestra di filtraggio, compresi i dati # di ordinamento e di batchSize self._changeOrderBy = self.bodyWidget._changeOrderBy self.orderBy = self.bodyWidget.orderBy self.batchSize = self.bodyWidget.batchSize self.offset = self.bodyWidget.offset self.numRecords = self.bodyWidget.numRecords self._filterClosure = self._anagrafica.filter._filterClosure self._filterCountClosure = self._anagrafica.filter._filterCountClosure self.placeWindow(self.visualizzatore_html) self.bodyWidget.generic_button.set_property('visible', False) def test(): self.html_code = "<html><body></body></html>" #self.html.load_html_string(self.html_code, "file:///"+sys.path[0]+os.sep) #self.html.show() #renderHTML(self.print_on_screen_html, self.html_code) #generaButton = self.bodyWidget.generic_button #generaButton.connect('clicked', self.on_generic_button_clicked ) #generaButton.set_label("Genera Pdf Anteprima Html") #if Environment.pg3: #glib.idle_add(test) #else: #gobject.idle_add(test) if Environment.pg3: glib.idle_add(self.refresh) else: gobject.idle_add(self.refresh) #self.refresh() def on_pdf_button_clicked(self, button): from PrintDialog import PrintDialogHandler from xhtml2pdf import pisa f = self.html_code.replace("€","€") g = file(Environment.tempDir + ".temp.pdf", "wb") pbar(self.pbar, pulse=True, text="GENERAZIONE STAMPA ATTENDERE") pisa.CreatePDF(str(f), g) g .close() pbar(self.pbar, stop=True) anag = PrintDialogHandler(self, self.windowTitle) anagWindow = anag.getTopLevel() returnWindow = self.bodyWidget.getTopLevel().get_toplevel() anagWindow.set_transient_for(returnWindow) anagWindow.show_all() def on_csv_button_clicked(self, button): messageInfo(msg="NON ANCORA IMPLEMENTATO") def on_generic_combobox_changed(self, combobox): if self.codBar_combo.get_active() == 0: from PrintDialog import PrintDialogHandler from xhtml2pdf import pisa f = self.html_code g = file(Environment.tempDir + ".temp.pdf", "wb") pisa.CreatePDF(str(f), g) g .close() anag = PrintDialogHandler(self, self.windowTitle) anagWindow = anag.getTopLevel() returnWindow = self.bodyWidget.getTopLevel().get_toplevel() anagWindow.set_transient_for(returnWindow) anagWindow.show_all() #self.codBar_combo.set_active(0) elif self.codBar_combo.get_active() == 1: print "ANTEPRIMA CSV" else: self.codBar_combo.set_active(-1) def _refreshPageCount(self): """ Aggiorna la paginazione """ self.bodyWidget.numRecords = self.numRecords self.bodyWidget._refreshPageCount() @timeit def refresh(self): """ show the html page in the custom widget""" self.bodyWidget.orderBy = self.orderBy self.bodyWidget.veter = self._veter #self.pbar_dialog.run() #self.pbar_dialog.destroy() daos = self.bodyWidget.runFilter(offset=None, batchSize=None, filterClosure=self._filterClosure, ) #pbar(self.pbar_report,parziale=daos.index(ragsoc), totale=len(nomi), text=ragsoc, noeta=False) #pbar(self.pbar_report,parziale=1, totale=4) if hasattr(self._anagrafica,"funzione_ordinamento") and self._anagrafica.funzione_ordinamento == "cliforn": if self._anagrafica.aa < 0: daos.sort(key=lambda x: x.intestatario.strip().upper()) else: daos.sort(key=lambda x: x.intestatario.strip().upper(),reverse=True) elif hasattr(self._anagrafica,"funzione_ordinamento") and self._anagrafica.funzione_ordinamento == "impo": for t in daos: try: t._totaleImponibileScontato except: t.totali if self._anagrafica.aa < 0: daos.sort(key=lambda x: x._totaleImponibileScontato) else: daos.sort(key=lambda x: x._totaleImponibileScontato,reverse=True) self.numRecords = self.bodyWidget.countFilterResults( self._filterCountClosure, ) # self._refreshPageCount() #pbar(self.pbar_report,parziale=2, totale=4) pageData = {} self.html_code = "<html><body></body></html>" if self._veter: daos = daos[:] da = [] for d in daos: c = [] for a in d.righe: if "TRIPLICE" in a.rig.arti.denominazione_famiglia: c.append(a) if len(c)>0: da.append(d) daos = da #pbar(self.pbar_report,parziale=2.5, totale=4) if daos: pageData = { "file": self._previewTemplate[1], #"dao":daos, "objects": daos } self.html_code = renderTemplate(pageData) #pbar(self.pbar_report,parziale=3.75, totale=4) #pbar(self.pbar_report,stop=True) #self.pbar_dialog.hide() renderHTML(self.print_on_screen_html, self.html_code) def on_print_on_screen_dialog_response(self, dialog, responseId): if responseId == GTK_RESPONSE_CLOSE: self.on_print_on_screen_dialog_delete_event() def on_print_on_screen_dialog_delete_event(self, dialog=None, event=None): self.destroy()
class AnagraficaPrintPreview(GladeWidget): """ Print preview """ # FIXME: a lot of duplicated code from AnagraficaFilter here! def __init__(self, anagrafica, windowTitle, previewTemplate, tipo=None): GladeWidget.__init__(self, root='htmlviewer', path="htmlviewer.glade") self.windowTitle = windowTitle self.visualizzatore_html.set_title(windowTitle) self._anagrafica = anagrafica self._tipo = tipo self.bodyWidget = FilterWidget(owner=self, resultsElement='html') self.bodyWidget.filter_navigation_hbox.destroy() self.bodyWidget.info_label.set_markup("INSERT INFO") self.html_scrolledwindow.add_with_viewport( self.bodyWidget.getTopLevel()) self.print_on_screen_html = self.bodyWidget.resultsElement self._gtkHtmlDocuments = None self._previewTemplate = previewTemplate self.html = createHtmlObj(self) #Prendo tutti i dati dalla finestra di filtraggio, compresi i dati # di ordinamento e di batchSize self._changeOrderBy = self.bodyWidget._changeOrderBy self.orderBy = self.bodyWidget.orderBy self.batchSize = self.bodyWidget.batchSize self.offset = self.bodyWidget.offset self.numRecords = self.bodyWidget.numRecords self._filterClosure = self._anagrafica.filter._filterClosure self._filterCountClosure = self._anagrafica.filter._filterCountClosure self.placeWindow(self.visualizzatore_html) self.bodyWidget.generic_button.set_property('visible', False) def test(): self.html_code = "<html><body></body></html>" glib.idle_add(self.refresh) def on_csv_button_clicked(self, button): messageInfo(msg="NON ANCORA IMPLEMENTATO") def on_generic_combobox_changed(self, combobox): if self.codBar_combo.get_active() == 0: from PrintDialog import PrintDialogHandler from xhtml2pdf import pisa f = self.html_code g = file(Environment.tempDir + ".temp.pdf", "wb") pisa.CreatePDF(str(f), g) g .close() anag = PrintDialogHandler(self, self.windowTitle) anagWindow = anag.getTopLevel() returnWindow = self.bodyWidget.getTopLevel().get_toplevel() anagWindow.set_transient_for(returnWindow) anagWindow.show_all() #self.codBar_combo.set_active(0) elif self.codBar_combo.get_active() == 1: print "ANTEPRIMA CSV" else: self.codBar_combo.set_active(-1) def _refreshPageCount(self): """ Aggiorna la paginazione """ self.bodyWidget.numRecords = self.numRecords self.bodyWidget._refreshPageCount() @timeit def refresh(self): """ show the html page in the custom widget""" self.bodyWidget.orderBy = self.orderBy self.bodyWidget.tipo = self._tipo # self.pbar_dialog.run() # self.pbar_dialog.destroy() daos = self.bodyWidget.runFilter(offset=None, batchSize=None, filterClosure=self._filterClosure, ) azienda = Azienda().getRecord(id=Environment.azienda) # pbar(self.pbar_report,parziale=daos.index(ragsoc), totale=len(nomi), text=ragsoc, noeta=False) #pbar(self.pbar_report,parziale=1, totale=4) if hasattr(self._anagrafica,"funzione_ordinamento") and self._anagrafica.funzione_ordinamento == "cliforn": if self._anagrafica.aa < 0: daos.sort(key=lambda x: x.intestatario.strip().upper()) else: daos.sort(key=lambda x: x.intestatario.strip().upper(),reverse=True) elif hasattr(self._anagrafica,"funzione_ordinamento") and self._anagrafica.funzione_ordinamento == "impo": for t in daos: try: t._totaleImponibileScontato except: t.totali if self._anagrafica.aa < 0: daos.sort(key=lambda x: x._totaleImponibileScontato) else: daos.sort(key=lambda x: x._totaleImponibileScontato,reverse=True) self.numRecords = self.bodyWidget.countFilterResults( self._filterCountClosure, ) # self._refreshPageCount() #pbar(self.pbar_report,parziale=2, totale=4) pageData = {} self.html_code = "<html><body></body></html>" if self._tipo == "veter": daos = daos[:] da = [] for d in daos: c = [] for a in d.righe: if "TRIPLICE" in a.rig.arti.denominazione_famiglia: c.append(a) if len(c)>0: da.append(d) daos = da elif self._tipo == "massa": daos=daos[:] articoli_dict = {} if daos: cliente = daos[0].CLI else: cliente = None for d in daos: for x in d.righe: if x.id_articolo: if x.rig.arti.APADR and (x.rig.arti.APADR.percentuale_carbonio or x.rig.arti.APADR.percentuale_cov or x.rig.arti.APADR.percentuale_secco): a_adr = x.rig.arti # print(a_adr) if a_adr in articoli_dict: articoli_dict[a_adr] += ( x.quantita*x.moltiplicatore ) else: articoli_dict[a_adr] = ( x.quantita * x.moltiplicatore ) print(self._anagrafica.filter) daData = self._anagrafica.filter.daData aData = self._anagrafica.filter.aData pageData = { "file" : "report_massa.html", "rows": articoli_dict, "azienda":azienda, "cliente":cliente, "daData":daData, "aData":aData, "daos":daos, } self.html_code = renderTemplate(pageData) try: renderHTML(self.print_on_screen_html, str(self.html_code)) except: renderHTML(self.print_on_screen_html, self.html_code) return #pbar(self.pbar_report,parziale=2.5, totale=4) if daos: pageData = { "file": self._previewTemplate[1], #"dao":daos, "objects": daos, "azienda" : azienda, } self.html_code = renderTemplate(pageData) #pbar(self.pbar_report,parziale=3.75, totale=4) #pbar(self.pbar_report,stop=True) #self.pbar_dialog.hide() try: renderHTML(self.print_on_screen_html, str(self.html_code)) except: renderHTML(self.print_on_screen_html, self.html_code) def on_print_on_screen_dialog_response(self, dialog, responseId): if responseId == GTK_RESPONSE_CLOSE: self.on_print_on_screen_dialog_delete_event() def on_print_on_screen_dialog_delete_event(self, dialog=None, event=None): self.destroy() def on_pdf_button_clicked(self, button): from PrintDialog import PrintDialogHandler operation = Gtk.PrintOperation() setting = Gtk.PageSetup() ps = Gtk.PaperSize.new_custom("cc", "cc", 210, 297, gtk.Unit.MM) st = Gtk.PrintSettings() s = Gtk.PageSetup() s.set_paper_size(ps) margine_fondo = float(setconf("Stampa", "report_margine_basso") or 4.3) s.set_bottom_margin(margine_fondo, gtk.Unit.MM) margine_sinistro = float( setconf("Stampa", "report_margine_sinistro") or 4.3) s.set_left_margin(margine_sinistro, gtk.Unit.MM) margine_destro = float( setconf("Stampa", "report_margine_destro") or 4.3) s.set_right_margin(margine_destro, gtk.Unit.MM) margine_alto = float(setconf("Stampa", "report_margine_alto") or 4.3) s.set_top_margin(margine_alto, gtk.Unit.MM) orientamento = str(setconf("Stampa", "report_ori")) if not orientamento or orientamento == "orizzontale": s.set_orientation(Gtk.PageOrientation.LANDSCAPE) operation.set_default_page_setup(s) operation.set_export_filename(Environment.tempDir + ".temp.pdf") #import xhtml2pdf.pisa as pisa #import cStringIO #data= self.print_on_screen_html.get_main_frame().get_data_source().get_data().str #g = open(Environment.tempDir + "ciccio.html", "w") # pdf = pisa.CreatePDF( # cStringIO.StringIO(data), # g # ) #g.write(data) #g.close() p = self.print_on_screen_html.get_main_frame().print_full(operation, gtk.PrintOperationAction.EXPORT) pbar(self.pbar, pulse=True, text="GENERAZIONE STAMPA ATTENDERE") pbar(self.pbar, stop=True) anag = PrintDialogHandler(self, self.windowTitle, tipo="report") anagWindow = anag.getTopLevel() returnWindow = self.bodyWidget.getTopLevel().get_toplevel() anagWindow.set_transient_for(returnWindow) anagWindow.show_all()
class Anagrafica(GladeWidget): """ Classe base per le anagrafiche semplici """ def __init__(self, windowTitle, recordMenuLabel, filterElement, detailElement, path=None, url_help="http://www.promogest.me/promoGest/faq"): if not path: path='anagrafica_semplice_window.glade' GladeWidget.__init__(self, root='anagrafica_semplice_window', path=path) Environment.windowGroup.append(self.anagrafica_semplice_window) self.anagrafica_semplice_window.set_title(windowTitle) self.record_menu.set_label(recordMenuLabel) self.bodyWidget = FilterWidget(owner=self, filtersElement=filterElement) #self.anagrafica_scrolledwindow.add(self.bodyWidget.getTopLevel()) self.anagrafica_viewport.add(self.bodyWidget.getTopLevel()) self.bodyWidget.filter_body_label.set_no_show_all(True) self.bodyWidget.filter_body_label.set_property('visible', False) self.bodyWidget.generic_button.set_no_show_all(True) self.bodyWidget.generic_button.set_property('visible', False) self.filter = self.bodyWidget.filtersElement self.url_help = url_help self.filterTopLevel = self.filter.getTopLevel() self.filterTopLevel.set_sensitive(True) self.detail = detailElement self.anagrafica_treeview = self.bodyWidget.resultsElement self._treeViewModel = None self._rowEditingPath = None self._tabPressed = False # mapping fields and methods from bodyWidget to this class self.anagrafica_filter_navigation_hbox = self.bodyWidget.filter_navigation_hbox self.anagrafica_filter_frame = self.bodyWidget.filter_frame self._widgetFirstFocus = self.bodyWidget._firstFocusWidget self._changeOrderBy = self.bodyWidget._changeOrderBy self.orderBy = self.bodyWidget.orderBy = None self.batchSize = self.bodyWidget.batchSize = int(setconf("Numbers", "batch_size")) self.offset = self.bodyWidget.offset = 0 self.numRecords = self.bodyWidget.numRecords = 0 self._filterClosure = None self.placeWindow(self.anagrafica_semplice_window) self.draw() self.setFocus() def draw(self): """ Facoltativo ma suggerito per indicare la lunghezza massima della cella di testo """ self._treeViewModel = self.filter.filter_listore self.refresh() def show_all(self): """ Visualizza/aggiorna tutta la struttura dell'anagrafica """ self.anagrafica_semplice_window.show_all() def on_credits_menu_activate(self, widget): creditsDialog = GladeWidget(root='credits_dialog',path='credits_dialog.glade', callbacks_proxy=self) creditsDialog.getTopLevel().set_transient_for(self.getTopLevel()) creditsDialog.getTopLevel().show_all() response = creditsDialog.credits_dialog.run() if response == GTK_RESPONSE_OK: creditsDialog.credits_dialog.destroy() def on_send_Email_activate(self, widget): sendemail = SendEmail() def on_help_activated(self, widget): webbrowser.open_new_tab(self.url_help) def on_licenza_menu_activate(self, widget): licenzaDialog = GladeWidget(root='licenza_dialog',path="licenza_dialog.glade", callbacks_proxy=self) licenzaDialog.getTopLevel().set_transient_for(self.getTopLevel()) licenseText = '' try: lines = open('./LICENSE').readlines() for l in lines: licenseText += l except: licenseText = 'Lavori in corso ....' print 'License file not found (LICENSE).' textBuffer = licenzaDialog.licenza_textview.get_buffer() textBuffer.set_text(licenseText) licenzaDialog.licenza_textview.set_buffer(textBuffer) licenzaDialog.getTopLevel().show_all() response = licenzaDialog.licenza_dialog.run() if response == GTK_RESPONSE_OK: licenzaDialog.licenza_dialog.destroy() def on_record_new_activate(self, widget,codice=None): """ Nuovo record """ if codice: self.detail.setDao(None, codice=codice) else: self.detail.setDao(None) if self._windowName == 'AnagraficaBanche': from AnagraficaBancheEdit import AnagraficaBancheEdit anag = AnagraficaBancheEdit(self, codice=codice) return self.filterTopLevel.set_sensitive(False) self.anagrafica_filter_navigation_hbox.set_sensitive(False) self.anagrafica_filter_frame.set_sensitive(False) self.anagrafica_treeview_set_edit(True) self.anagrafica_treeview.set_headers_clickable(False) self.anagrafica_treeview.set_enable_search(False) self.record_new_button.set_sensitive(False) self.record_new_menu.set_sensitive(False) self.record_save_button.set_sensitive(True) self.record_save_menu.set_sensitive(True) self.record_cancel_button.set_sensitive(True) self.record_cancel_menu.set_sensitive(True) self.record_undo_button.set_sensitive(False) self.record_undo_menu.set_sensitive(False) self.record_delete_button.set_sensitive(False) self.record_delete_menu.set_sensitive(False) def on_record_delete_activate(self, widget): """ Eliminazione record """ if not YesNoDialog(msg='Confermi l\'eliminazione ?', transient=None): self.anagrafica_treeview.grab_focus() return self.detail.deleteDao() self.refresh() self.filterTopLevel.set_sensitive(True) self.anagrafica_filter_navigation_hbox.set_sensitive(True) self.anagrafica_filter_frame.set_sensitive(True) self.anagrafica_treeview_set_edit(False) self.anagrafica_treeview.set_headers_clickable(True) self.anagrafica_treeview.set_enable_search(True) self.record_new_button.set_sensitive(True) self.record_new_menu.set_sensitive(True) self.record_save_button.set_sensitive(False) self.record_save_menu.set_sensitive(False) self.record_cancel_button.set_sensitive(False) self.record_cancel_menu.set_sensitive(False) self.record_undo_button.set_sensitive(False) self.record_undo_menu.set_sensitive(False) self.record_delete_button.set_sensitive(False) self.record_delete_menu.set_sensitive(False) self.setFocus() def on_record_save_activate(self, widget, path=None, column=None): """ Salvataggio record """ self.anagrafica_treeview.grab_focus() try: self.detail.saveDao() except Exception: self.anagrafica_treeview_set_edit(True) return self.filterTopLevel.set_sensitive(True) self.anagrafica_filter_navigation_hbox.set_sensitive(True) self.anagrafica_filter_frame.set_sensitive(True) self.anagrafica_treeview_set_edit(False) self.anagrafica_treeview.set_headers_clickable(True) self.anagrafica_treeview.set_enable_search(True) self.refresh() self.record_new_button.set_sensitive(True) self.record_new_menu.set_sensitive(True) self.record_save_button.set_sensitive(False) self.record_save_menu.set_sensitive(False) self.record_cancel_button.set_sensitive(False) self.record_cancel_menu.set_sensitive(False) self.record_undo_button.set_sensitive(False) self.record_undo_menu.set_sensitive(False) self.record_delete_button.set_sensitive(False) self.record_delete_menu.set_sensitive(False) self.setFocus() def on_record_cancel_activate(self, widget): """ Annullamento modifiche record """ if self._rowEditingPath is None: return dialog = gtk.MessageDialog(self.getTopLevel(), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_DIALOG_MESSAGE_QUESTION, GTK_BUTTON_YES_NO, 'Abbandonare le modifiche ?') response = dialog.run() dialog.destroy() if response != GTK_RESPONSE_YES: self.anagrafica_treeview.grab_focus() return self.anagrafica_treeview.grab_focus() self.detail.updateDao() self.filterTopLevel.set_sensitive(True) self.anagrafica_filter_navigation_hbox.set_sensitive(True) self.anagrafica_filter_frame.set_sensitive(True) self.anagrafica_treeview_set_edit(False) self.anagrafica_treeview.set_headers_clickable(True) self.anagrafica_treeview.set_enable_search(True) self.refresh() self.record_new_button.set_sensitive(True) self.record_new_menu.set_sensitive(True) self.record_save_button.set_sensitive(False) self.record_save_menu.set_sensitive(False) self.record_cancel_button.set_sensitive(False) self.record_cancel_menu.set_sensitive(False) self.record_undo_button.set_sensitive(False) self.record_undo_menu.set_sensitive(False) self.record_delete_button.set_sensitive(False) self.record_delete_menu.set_sensitive(False) self.setFocus() def on_export_csv_button_clicked(self, button): dao = self.detail.setDao(None) from ExportCsv import ExportCsv anag = ExportCsv(self, dao=dao) dao=None return def on_record_undo_activate(self, widget): """ Rilettura record """ if self._rowEditingPath is None: return dialog = gtk.MessageDialog(self.getTopLevel(), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_DIALOG_MESSAGE_QUESTION, GTK_BUTTON_YES_NO, 'Cancellare le modifiche ?') response = dialog.run() dialog.destroy() if response != GTK_RESPONSE_YES: self.anagrafica_treeview.grab_focus() self.anagrafica_treeview_set_edit(True) return self.anagrafica_treeview.grab_focus() self.detail.updateDao() self.filterTopLevel.set_sensitive(False) self.anagrafica_filter_navigation_hbox.set_sensitive(False) self.anagrafica_filter_frame.set_sensitive(False) self.anagrafica_treeview.set_headers_clickable(False) self.anagrafica_treeview.set_enable_search(False) self.record_new_button.set_sensitive(False) self.record_new_menu.set_sensitive(False) self.record_save_button.set_sensitive(True) self.record_save_menu.set_sensitive(True) self.record_cancel_button.set_sensitive(True) self.record_cancel_menu.set_sensitive(True) self.record_undo_button.set_sensitive(True) self.record_undo_menu.set_sensitive(True) self.record_delete_button.set_sensitive(True) self.record_delete_menu.set_sensitive(True) self.record_edit_button.set_sensitive(False) self.record_edit_menu.set_sensitive(False) def on_record_edit_activate(self, widget): """ Modifica record """ self.detail.updateDao() if self._windowName == 'AnagraficaBanche': from AnagraficaBancheEdit import AnagraficaBancheEdit anag = AnagraficaBancheEdit(self, dao=self.detail.dao) return self.filterTopLevel.set_sensitive(False) self.anagrafica_filter_navigation_hbox.set_sensitive(False) self.anagrafica_filter_frame.set_sensitive(False) self.anagrafica_treeview_set_edit(True) self.anagrafica_treeview.set_headers_clickable(False) self.anagrafica_treeview.set_enable_search(False) self.record_new_button.set_sensitive(False) self.record_new_menu.set_sensitive(False) self.record_save_button.set_sensitive(True) self.record_save_menu.set_sensitive(True) self.record_cancel_button.set_sensitive(True) self.record_cancel_menu.set_sensitive(True) self.record_undo_button.set_sensitive(True) self.record_undo_menu.set_sensitive(True) self.record_delete_button.set_sensitive(True) self.record_delete_menu.set_sensitive(True) self.record_edit_button.set_sensitive(False) self.record_edit_menu.set_sensitive(False) def setFocus(self, widget=None): """ Da il fuoco al widget indicato o al primo widget """ if widget is None: self.filter._widgetFirstFocus.grab_focus() else: widget.grab_focus() def on_filter_treeview_row_activated(self, treeview, path, column): """ Gestisce la conferma della riga """ if self._rowEditingPath is None: self.on_record_edit_activate(self.record_edit_button) def on_filter_treeview_cursor_changed(self, treeview): """ Gestisce lo spostamento tra le righe """ sel = self.anagrafica_treeview.get_selection() if not sel: return (model, iterator) = sel.get_selected() if self._rowEditingPath is not None: if iterator: row = model[iterator] if row.path != self._rowEditingPath: sel.select_path(self._rowEditingPath) return else: if iterator is None: return dao = model.get_value(iterator, 0) self.detail.setDao(dao) self.record_edit_button.set_sensitive(True) self.record_edit_menu.set_sensitive(True) def on_filter_treeview_selection_changed(self, selection): pass def _newRow(self, modelRow): """ Crea una nuova riga """ sel = self.anagrafica_treeview.get_selection() (model, iterator) = sel.get_selected() iterator = model.append(modelRow) sel.select_iter(iterator) def _getRowEditingPath(self, model, iterator): """ Restituisce il path relativo alla riga che e' in modifica """ if iterator is not None: row = model[iterator] self._rowEditingPath = row.path def on_filter_treeview_keypress_event(self, treeview, event): """ Gestisce la pressione del tab su una cella """ if event.keyval == 65289: self._tabPressed = True def on_column_edited(self, cell, path, value, treeview, editNext=True, column=None): """ Gestisce l'immagazzinamento dei valori nelle celle """ model = treeview.get_model() iterator = model.get_iter(path) if column is None: column = cell.column row = model[iterator] if row.path == self._rowEditingPath: if cell.__class__ is gtk.CellRendererText: try: length = cell.get_data('max_length') model.set_value(iterator, column+1, value[:length]) except: model.set_value(iterator, column+1, value) elif cell.__class__ is gtk.CellRendererToggle: model.set_value(iterator, column+1, not cell.get_active()) columns = treeview.get_columns() if column+1 <= columns: if self._tabPressed: self._tabPressed = False gobject.timeout_add(1, treeview.set_cursor, gtk.TreePath(str(path)), treeview.get_column(column+1), editNext) def anagrafica_treeview_set_edit(self, flag): """ Mette la riga corrente della treeview in stato di edit / browse """ sel = self.anagrafica_treeview.get_selection() (model, iterator) = sel.get_selected() columns = self.anagrafica_treeview.get_columns() for c in columns: renderers = c.get_cells() for r in renderers: if r.__class__ is gtk.CellRendererText: r.set_property('editable', flag) elif r.__class__ is gtk.CellRendererToggle: r.set_property('activatable', flag) if flag: self._getRowEditingPath(model, iterator) row = model[iterator] column = self.anagrafica_treeview.get_column(0) self.anagrafica_treeview.grab_focus() self.anagrafica_treeview.set_cursor(row.path, column, True) else: self._rowEditingPath = None def on_anagrafica_window_close(self, widget, event=None): """ Gestisce la richiesta di uscita dall'anagrafica """ if self._rowEditingPath is not None: dialog = gtk.MessageDialog(self.getTopLevel(), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_DIALOG_MESSAGE_QUESTION, GTK_BUTTON_YES_NO, 'Confermi la chiusura ?') response = dialog.run() dialog.destroy() if response != GTK_RESPONSE_YES: return True self.destroy() #def draw(self): #""" #Disegna i contenuti dell'elenco dell' anagrafica. Metodo invocato #una sola volta, dopo la costruzione dell'oggetto #""" #raise NotImplementedError def refresh(self): """ Aggiorna il l'elenco dell'anagrafica in base ai parametri impostati """ raise NotImplementedError def clear(self): """ Annulla i parametri impostati per la ricerca """ self.filter.clear() def runFilter(self, offset='__default__', batchSize='__default__', progressCB=None, progressBatchSize=0): """ Recupera i dati """ self.bodyWidget.orderBy = self.orderBy return self.bodyWidget.runFilter(offset=offset, batchSize=batchSize, progressCB=progressCB, progressBatchSize=progressBatchSize, filterClosure=self._filterClosure) def _refreshPageCount(self): """ Aggiorna la paginazione """ self.bodyWidget.numRecords = self.numRecords self.bodyWidget._refreshPageCount()