def on_write_table(self, obj): f = Gtk.FileChooserDialog(_("Select filename"), parent=self.window, action=Gtk.FileChooserAction.SAVE, buttons=(_('_Cancel'), Gtk.ResponseType.CANCEL, _('_Save'), Gtk.ResponseType.OK)) f.set_current_folder(get_curr_dir()) status = f.run() f.hide() if status == Gtk.ResponseType.OK: name = conv_to_unicode(f.get_filename()) doc = ODSTab(len(self.row_data)) doc.creator(self.db.get_researcher().get_name()) spreadsheet = TableReport(name, doc) new_titles = [] skip_columns = [] index = 0 for title in self.table_titles: if title == 'sort': skip_columns.append(index) else: new_titles.append(title) index += 1 spreadsheet.initialize(len(new_titles)) spreadsheet.write_table_head(new_titles) index = 0 for top in self.row_data: spreadsheet.set_row(index%2) index += 1 spreadsheet.write_table_data(top,skip_columns) spreadsheet.finalize() f.destroy()
def on_write_table(self, obj): f = Gtk.FileChooserDialog(_("Select filename"), parent=self.window, action=Gtk.FileChooserAction.SAVE, buttons=(_('_Cancel'), Gtk.ResponseType.CANCEL, _('_Save'), Gtk.ResponseType.OK)) f.set_current_folder(get_curr_dir()) status = f.run() f.hide() if status == Gtk.ResponseType.OK: name = f.get_filename() doc = ODSTab(len(self.row_data)) doc.creator(self.db.get_researcher().get_name()) spreadsheet = TableReport(name, doc) new_titles = [] skip_columns = [] index = 0 for title in self.table_titles: if title == 'sort': skip_columns.append(index) else: new_titles.append(title) index += 1 spreadsheet.initialize(len(new_titles)) spreadsheet.write_table_head(new_titles) index = 0 for top in self.row_data: spreadsheet.set_row(index % 2) index += 1 spreadsheet.write_table_data(top, skip_columns) spreadsheet.finalize() f.destroy()
def save(self): """ save action """ doc = ODSTab(len(self.stats_list)) doc.creator(self.db.get_researcher().get_name()) name = self.dbstate.db.get_default_person().get_handle() + '.ods' if self.path != '.': name = os.path.join(self.path, name) try: import io io.open(name, "w", encoding='utf8') except PermissionError or IsADirectoryError: WarningDialog(_("You do not have write rights on this folder")) return spreadsheet = TableReport(name, doc) new_titles = [] skip_columns = [] index = 0 for title in self.titles: if title == 'sort': skip_columns.append(index) else: new_titles.append(title) index += 1 spreadsheet.initialize(len(new_titles)) spreadsheet.write_table_head(new_titles) index = 0 for top in self.stats_list: spreadsheet.set_row(index % 2) index += 1 spreadsheet.write_table_data(top, skip_columns) spreadsheet.finalize()
def save(self): """ save action """ doc = ODSTab(len(self.stats_list)) doc.creator(self.db.get_researcher().get_name()) name = self.dbstate.db.get_default_person().get_handle() + '.ods' if self.path != '.': name = os.path.join(self.path, name) try: import io io.open(name, "w", encoding='utf8') except PermissionError or IsADirectoryError: WarningDialog(_("You do not have write rights on this folder")) return spreadsheet = TableReport(name, doc) new_titles = [] skip_columns = [] index = 0 for title in self.titles: if title == 'sort': skip_columns.append(index) else: new_titles.append(title) index += 1 spreadsheet.initialize(len(new_titles)) spreadsheet.write_table_head(new_titles) index = 0 for top in self.stats_list: spreadsheet.set_row(index%2) index += 1 spreadsheet.write_table_data(top, skip_columns) spreadsheet.finalize()
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()