def write_tabbed_file(self, name, type): """ Write a tabbed file to the specified name. The output file type is determined by the type variable. """ from gramps.gen.utils.docgen import CSVTab, ODSTab ofile = None data_cols = [pair[1] for pair in self.column_order() if pair[0]] column_names = [self.COLUMNS[i][0] for i in data_cols] if type == 0: ofile = CSVTab(len(column_names)) else: ofile = ODSTab(len(column_names)) ofile.open(name) ofile.start_page() ofile.start_row() # Headings if self.model.get_flags() & Gtk.TreeModelFlags.LIST_ONLY: headings = column_names else: levels = self.model.get_tree_levels() headings = levels + column_names[1:] data_cols = data_cols[1:] list(map(ofile.write_cell, headings)) ofile.end_row() if self.model.get_flags() & Gtk.TreeModelFlags.LIST_ONLY: # Flat model for row in self.model: ofile.start_row() for index in data_cols: ofile.write_cell(row[index]) ofile.end_row() else: # Tree model iter_ = self.model.get_iter((0, )) if iter_: self.write_node(iter_, len(levels), [], ofile, data_cols) ofile.end_page() ofile.close()
def write_tabbed_file(self, name, type): """ Write a tabbed file to the specified name. The output file type is determined by the type variable. """ from gramps.gen.utils.docgen import CSVTab, ODSTab ofile = None data_cols = [pair[1] for pair in self.column_order() if pair[0]] column_names = [self.COLUMNS[i][0] for i in data_cols] if type == 0: ofile = CSVTab(len(column_names)) else: ofile = ODSTab(len(column_names)) ofile.open(name) ofile.start_page() ofile.start_row() # Headings if self.model.get_flags() & Gtk.TreeModelFlags.LIST_ONLY: headings = column_names else: levels = self.model.get_tree_levels() headings = levels + column_names[1:] data_cols = data_cols[1:] list(map(ofile.write_cell, headings)) ofile.end_row() if self.model.get_flags() & Gtk.TreeModelFlags.LIST_ONLY: # Flat model for row in self.model: ofile.start_row() for index in data_cols: ofile.write_cell(row[index]) ofile.end_row() else: # Tree model iter_ = self.model.get_iter((0,)) if iter_: self.write_node(iter_, len(levels), [], ofile, data_cols) ofile.end_page() ofile.close()