def _get_page1(self): page = RadioButtonPage() for importer in self.importers: name = importer.NAME desc = importer.DESCRIPTION page.add_radio_option(importer, name, desc) return page
class ExportAssistant(Assistant): def __init__(self, *args, **kwargs): Assistant.__init__(self, *args, **kwargs) self.set_modal(True) self.exporters = get_exporters() self.set_title(_('Export Assistant')) texts = [ _('Welcome to the Export Assistant.'), _('This wizard will help you to export your journal to various formats.' ), _('You can select the days you want to export and where the output will be saved.' ) ] text = '\n'.join(texts) self._add_intro_page(text) self.page1 = RadioButtonPage() for exporter in self.exporters: name = exporter.NAME desc = exporter.DESCRIPTION self.page1.add_radio_option(exporter, name, desc) self.append_page(self.page1) self.set_page_title(self.page1, _('Select Export Format') + ' (1/5)') self.set_page_complete(self.page1, True) self.page2 = DatePage(self.journal) self.append_page(self.page2) self.set_page_title(self.page2, _('Select Date Range') + ' (2/5)') self.set_page_complete(self.page2, True) self.page3 = ContentsPage(self.journal, self) self.append_page(self.page3) self.set_page_title(self.page3, _('Select Contents') + ' (3/5)') self.set_page_complete(self.page3, True) self.page3.check_selection() self.page4 = PathChooserPage(self) self.append_page(self.page4) self.set_page_title(self.page4, _('Select Export Path') + ' (4/5)') self.set_page_complete(self.page4, True) self.page5 = SummaryPage() self.append_page(self.page5) self.set_page_title(self.page5, _('Summary') + ' (5/5)') self.set_page_type(self.page5, Gtk.AssistantPageType.CONFIRM) self.set_page_complete(self.page5, True) self.exporter = None self.path = None self.set_forward_page_func(self.pageforward) def pageforward(self, page): if page == 2 and self.page2.export_selected_text(): return 4 else: return page + 1 def run(self): self.page2.refresh_dates() self.page3.refresh_categories_list() self.show_all() def _on_close(self, assistant): ''' Do the export ''' self.hide() self.export() def _on_prepare(self, assistant, page): ''' Called when a new page should be prepared, before it is shown ''' if page == self.page2: # Date Range self.exporter = self.page1.get_selected_object() self.page2.prepare() elif page == self.page3: # Categories start_date, end_date = self.page2.get_date_range() if not self.page2.export_all_days() and start_date == end_date: self.page3.filter_tags_button.set_active(False) self.page3.filter_tags_button.set_sensitive(False) else: self.page3.filter_tags_button.set_sensitive(True) elif page == self.page4: # Path self.page4.prepare(self.exporter) elif page == self.page5: # Summary self.path = self.page4.get_selected_path() self.page5.prepare() self.export_all_days = self.page2.export_all_days() self.export_selected_text = self.page2.export_selected_text() self.is_filtered = self.page3.is_filtered() self.exported_categories = self.page3.get_categories() self.page5.add_setting(_('Format'), self.exporter.NAME) self.page5.add_setting(_('Export all days'), self.yes_no(self.export_all_days)) if not self.export_all_days: start_date, end_date = self.page2.get_date_range() if start_date == end_date: self.page5.add_setting(_('Date'), start_date) self.page5.add_setting( _('Export selected text only'), self.yes_no(self.export_selected_text)) else: self.page5.add_setting(_('Start date'), start_date) self.page5.add_setting(_('End date'), end_date) if self.export_selected_text: self.exported_categories = [] else: self.page5.add_setting( _('Include text'), self.yes_no(self.page3.is_text_included())) self.page5.add_setting( _('Include tags'), self.yes_no(self.page3.is_tags_included())) if self.is_filtered: self.page5.add_setting(_('Filtered by tags'), ', '.join(self.exported_categories)) self.page5.add_setting(_('Export path'), self.path) def yes_no(self, value): return _('Yes') if value else _('No') def get_export_string(self, format): if self.export_selected_text and self.page2.selected_text: markup_string = self.page2.selected_text else: if self.export_all_days: export_days = self.journal.days else: export_days = self.journal.get_days_in_date_range( *self.page2.get_date_range()) selected_categories = self.exported_categories logging.debug('Selected Categories for Inclusion: %s' % selected_categories) # Save selected date format date_format = self.page3.date_format.get_value() self.journal.config['exportDateFormat'] = date_format markup_strings_for_each_day = [] for day in export_days: include_day = True if self.is_filtered: include_day = False catagory_pairs = day.get_category_content_pairs() for category in selected_categories: if category in catagory_pairs: include_day = True if include_day: date_string = dates.format_date(date_format, day.date) day_markup = markup.get_markup_for_day( day, with_text=self.page3.is_text_included(), with_tags=self.page3.is_tags_included(), categories=selected_categories, date=date_string) markup_strings_for_each_day.append(day_markup) markup_string = ''.join(markup_strings_for_each_day) return self.journal.convert(markup_string, format, options={'toc': 0}) def export(self): format = self.exporter.FORMAT if format == 'pdf': self.export_pdf() return export_string = self.get_export_string(format) filesystem.write_file(self.path, export_string) self.journal.show_message(_('Content exported to %s') % self.path) def export_pdf(self): logging.info('Exporting to PDF') browser.print_pdf(self.get_export_string('xhtml'), self.path) self.journal.show_message(_('Content exported to %s') % self.path)
class ExportAssistant(Assistant): def __init__(self, *args, **kwargs): Assistant.__init__(self, *args, **kwargs) self.exporters = get_exporters() self.set_title(_('Export Assistant')) texts = [_('Welcome to the Export Assistant.'), _('This wizard will help you to export your journal to various formats.'), _('You can select the days you want to export and where the output will be saved.')] text = '\n'.join(texts) self._add_intro_page(text) self.page1 = RadioButtonPage() for exporter in self.exporters: name = exporter.NAME desc = exporter.DESCRIPTION self.page1.add_radio_option(exporter, name, desc) self.append_page(self.page1) self.set_page_title(self.page1, _('Select Export Format') + ' (1/5)') self.set_page_complete(self.page1, True) self.page2 = DatePage(self.journal) self.append_page(self.page2) self.set_page_title(self.page2, _('Select Date Range') + ' (2/5)') self.set_page_complete(self.page2, True) self.page3 = ContentsPage(self.journal, self) self.append_page(self.page3) self.set_page_title(self.page3, _('Select Contents') + ' (3/5)') self.set_page_complete(self.page3, True) self.page3.check_selection() self.page4 = PathChooserPage(self) self.append_page(self.page4) self.set_page_title(self.page4, _('Select Export Path') + ' (4/5)') self.set_page_complete(self.page4, True) self.page5 = SummaryPage() self.append_page(self.page5) self.set_page_title(self.page5, _('Summary') + ' (5/5)') self.set_page_type(self.page5, gtk.ASSISTANT_PAGE_CONFIRM) self.set_page_complete(self.page5, True) self.exporter = None self.path = None def run(self): self.page2.refresh_dates() self.page3.refresh_categories_list() self.show_all() def _on_close(self, assistant): ''' Do the export ''' self.hide() self.export() def _on_prepare(self, assistant, page): ''' Called when a new page should be prepared, before it is shown ''' if page == self.page2: # Date Range self.exporter = self.page1.get_selected_object() elif page == self.page3: # Categories pass elif page == self.page4: # Path self.page4.prepare(self.exporter) elif page == self.page5: # Summary self.path = self.page4.get_selected_path() self.page5.prepare() format = self.exporter.NAME self.export_all_days = self.page2.export_all_days() self.is_text_exported = self.page3.is_text_exported() self.exported_categories = self.page3.get_categories() self.page5.add_setting(_('Format'), format) self.page5.add_setting(_('Export all days'), self.yes_no(self.export_all_days)) if not self.export_all_days: start_date, end_date = self.page2.get_date_range() self.page5.add_setting(_('Start date'), start_date) self.page5.add_setting(_('End date'), end_date) is_text_exported = self.yes_no(self.is_text_exported) self.page5.add_setting(_('Export text'), is_text_exported) self.page5.add_setting(_('Selected categories'), ', '.join(self.exported_categories)) self.page5.add_setting(_('Export path'), self.path) def yes_no(self, value): return _('Yes') if value else _('No') def get_export_string(self, format): if self.export_all_days: export_days = self.journal.days else: export_days = self.journal.get_days_in_date_range(*self.page2.get_date_range()) selected_categories = self.exported_categories logging.debug('Selected Categories for Export: %s' % selected_categories) export_text = self.is_text_exported markup_strings_for_each_day = [] for day in export_days: # Save selected date format date_format = self.page3.date_format.get_value() self.journal.config['exportDateFormat'] = date_format date_string = dates.format_date(date_format, day.date) day_markup = markup.get_markup_for_day(day, with_text=export_text, categories=selected_categories, date=date_string) markup_strings_for_each_day.append(day_markup) markup_string = ''.join(markup_strings_for_each_day) return markup.convert(markup_string, format, options={'toc': 0}) def export(self): format = self.exporter.FORMAT if format == 'pdf': self.export_pdf() return export_string = self.get_export_string(format) filesystem.write_file(self.path, export_string) self.journal.show_message(_('Content exported to %s') % self.path) def export_pdf(self): logging.info('Exporting to PDF') browser.print_pdf(self.get_export_string('xhtml'), self.path)
class ExportAssistant(Assistant): def __init__(self, *args, **kwargs): Assistant.__init__(self, *args, **kwargs) self.exporters = get_exporters() self.set_title(_('Export Assistant')) texts = [_('Welcome to the Export Assistant.'), _('This wizard will help you to export your journal to various formats.'), _('You can select the days you want to export and where the output will be saved.')] text = '\n'.join(texts) self._add_intro_page(text) self.page1 = RadioButtonPage() for exporter in self.exporters: name = exporter.NAME desc = exporter.DESCRIPTION self.page1.add_radio_option(exporter, name, desc) self.append_page(self.page1) self.set_page_title(self.page1, _('Select Export Format') + ' (1/5)') self.set_page_complete(self.page1, True) self.page2 = DatePage(self.journal) self.append_page(self.page2) self.set_page_title(self.page2, _('Select Date Range') + ' (2/5)') self.set_page_complete(self.page2, True) self.page3 = ContentsPage(self.journal, self) self.append_page(self.page3) self.set_page_title(self.page3, _('Select Contents') + ' (3/5)') self.set_page_complete(self.page3, True) self.page3.check_selection() self.page4 = PathChooserPage(self) self.append_page(self.page4) self.set_page_title(self.page4, _('Select Export Path') + ' (4/5)') self.set_page_complete(self.page4, True) self.page5 = SummaryPage() self.append_page(self.page5) self.set_page_title(self.page5, _('Summary') + ' (5/5)') self.set_page_type(self.page5, gtk.ASSISTANT_PAGE_CONFIRM) self.set_page_complete(self.page5, True) self.exporter = None self.path = None def run(self): self.page2.refresh_dates() self.page3.refresh_categories_list() self.show_all() def _on_close(self, assistant): ''' Do the export ''' self.hide() self.export() def _on_prepare(self, assistant, page): ''' Called when a new page should be prepared, before it is shown ''' if page == self.page2: # Date Range self.exporter = self.page1.get_selected_object() elif page == self.page3: # Categories pass elif page == self.page4: # Path self.page4.prepare(self.exporter) elif page == self.page5: # Summary self.path = self.page4.get_selected_path() self.page5.prepare() format = self.exporter.NAME self.export_all_days = self.page2.export_all_days() self.is_text_exported = self.page3.is_text_exported() self.exported_categories = self.page3.get_categories() self.page5.add_setting(_('Format'), format) self.page5.add_setting(_('Export all days'), self.yes_no(self.export_all_days)) if not self.export_all_days: self.start_date, self.end_date = self.page2.get_date_range() self.page5.add_setting(_('Start date'), self.start_date) self.page5.add_setting(_('End date'), self.end_date) is_text_exported = self.yes_no(self.is_text_exported) self.page5.add_setting(_('Export text'), is_text_exported) self.page5.add_setting(_('Selected categories'), ', '.join(self.exported_categories)) self.page5.add_setting(_('Export path'), self.path) def yes_no(self, value): return _('Yes') if value else _('No') def get_export_string(self, format): if self.export_all_days: export_days = self.journal.days else: start, end = sorted([self.start_date, self.end_date]) export_days = self.journal.get_days_in_date_range((start, end)) selected_categories = self.exported_categories logging.debug('Selected Categories for Export: %s' % selected_categories) export_text = self.is_text_exported markup_strings_for_each_day = [] for day in export_days: default_export_date_format = '%A, %x' # probably no one needs to configure this as i18n already exists #date_format = self.journal.config.read('exportDateFormat', # default_export_date_format) date_format = default_export_date_format date_string = dates.format_date(date_format, day.date) day_markup = markup.get_markup_for_day(day, with_text=export_text, categories=selected_categories, date=date_string) markup_strings_for_each_day.append(day_markup) markup_string = ''.join(markup_strings_for_each_day) options = {'toc': 0} return markup.convert(markup_string, format, options=options) def export(self): format = self.exporter.FORMAT if format == 'pdf': self.export_pdf() return export_string = self.get_export_string(format) filesystem.write_file(self.path, export_string) self.journal.show_message(_('Content exported to %s') % self.path) def export_pdf(self): logging.info('Exporting to PDF') html = self.get_export_string('xhtml') browser.print_pdf(html, self.path)
class ExportAssistant(Assistant): def __init__(self, *args, **kwargs): Assistant.__init__(self, *args, **kwargs) self.set_modal(True) self.exporters = get_exporters() self.set_title(_('Export Assistant')) def add_space(): self.page1.pack_start(Gtk.Label(''), False, False, 0) self.page1 = RadioButtonPage() text = '\n'.join([ _('Welcome to the Export Assistant.'), _('This wizard will help you to export your journal to various formats.'), _('You can select the days you want to export and where the output will be saved.')]) welcome_label = Gtk.Label(text) self.page1.pack_start(welcome_label, False, False, 0) add_space() for exporter in self.exporters: name = exporter.NAME desc = exporter.DESCRIPTION self.page1.add_radio_option(exporter, name, desc) add_space() pdf_label = Gtk.Label(_('PDF: export to HTML, open in browser and print to PDF file')) pdf_label.set_halign(Gtk.Align.START) self.page1.pack_start(pdf_label, False, False, 0) self.append_page(self.page1) self.set_page_title(self.page1, _('Select Export Format') + ' (1/5)') self.set_page_complete(self.page1, True) self.page2 = DatePage(self.journal) self.append_page(self.page2) self.set_page_title(self.page2, _('Select Date Range') + ' (2/5)') self.set_page_complete(self.page2, True) self.page3 = ContentsPage(self.journal, self) self.append_page(self.page3) self.set_page_title(self.page3, _('Select Contents') + ' (3/5)') self.set_page_complete(self.page3, True) self.page3.check_selection() self.page4 = PathChooserPage(self) self.append_page(self.page4) self.set_page_title(self.page4, _('Select Export Path') + ' (4/5)') self.set_page_complete(self.page4, True) self.page5 = SummaryPage() self.append_page(self.page5) self.set_page_title(self.page5, _('Summary') + ' (5/5)') self.set_page_type(self.page5, Gtk.AssistantPageType.CONFIRM) self.set_page_complete(self.page5, True) self.exporter = None self.path = None self.set_forward_page_func(self.pageforward) def pageforward(self, page): if page == 2 and self.page2.export_selected_text(): return 4 else: return page + 1 def run(self): self.page2.refresh_dates() self.page3.refresh_categories_list() self.show_all() def _on_close(self, assistant): ''' Do the export ''' self.hide() self.export() def _on_prepare(self, assistant, page): ''' Called when a new page should be prepared, before it is shown ''' if page == self.page2: # Date Range self.exporter = self.page1.get_selected_object() self.page2.prepare() elif page == self.page3: # Categories start_date, end_date = self.page2.get_date_range() if not self.page2.export_all_days() and start_date == end_date: self.page3.filter_tags_button.set_active(False) self.page3.filter_tags_button.set_sensitive(False) else: self.page3.filter_tags_button.set_sensitive(True) elif page == self.page4: # Path self.page4.prepare(self.exporter) elif page == self.page5: # Summary self.path = self.page4.get_selected_path() self.page5.prepare() self.export_all_days = self.page2.export_all_days() self.export_selected_text = self.page2.export_selected_text() self.is_filtered = self.page3.is_filtered() self.exported_categories = self.page3.get_categories() self.page5.add_setting(_('Format'), self.exporter.NAME) self.page5.add_setting(_('Export all days'), self.yes_no(self.export_all_days)) if not self.export_all_days: start_date, end_date = self.page2.get_date_range() if start_date == end_date: self.page5.add_setting(_('Date'), start_date) self.page5.add_setting( _('Export selected text only'), self.yes_no(self.export_selected_text)) else: self.page5.add_setting(_('Start date'), start_date) self.page5.add_setting(_('End date'), end_date) if self.export_selected_text: self.exported_categories = [] else: self.page5.add_setting(_('Include text'), self.yes_no(self.page3.is_text_included())) self.page5.add_setting(_('Include tags'), self.yes_no(self.page3.is_tags_included())) if self.is_filtered: self.page5.add_setting(_('Filtered by tags'), ', '.join(self.exported_categories)) self.page5.add_setting(_('Export path'), self.path) def yes_no(self, value): return _('Yes') if value else _('No') def get_export_string(self, format): if self.export_selected_text and self.page2.selected_text: markup_string = self.page2.selected_text else: if self.export_all_days: export_days = self.journal.days else: export_days = self.journal.get_days_in_date_range(*self.page2.get_date_range()) selected_categories = self.exported_categories logging.debug('Selected Categories for Inclusion: %s' % selected_categories) markup_strings_for_each_day = [] for day in export_days: include_day = True if self.is_filtered: include_day = False catagory_pairs = day.get_category_content_pairs() for category in selected_categories: if category in catagory_pairs: include_day = True if include_day: date_format = self.journal.config.read('exportDateFormat') date_string = dates.format_date(date_format, day.date) day_markup = markup.get_markup_for_day(day, with_text=self.page3.is_text_included(), with_tags=self.page3.is_tags_included(), categories=selected_categories, date=date_string) markup_strings_for_each_day.append(day_markup) markup_string = ''.join(markup_strings_for_each_day) return self.journal.convert(markup_string, format, options={'toc': 0}) def export(self): format = self.exporter.FORMAT export_string = self.get_export_string(format) filesystem.write_file(self.path, export_string) self.journal.show_message(_('Content exported to %s') % self.path)
class ExportAssistant(Assistant): def __init__(self, *args, **kwargs): Assistant.__init__(self, *args, **kwargs) self.set_modal(True) self.exporters = get_exporters() self.set_title(_("Export Assistant")) def add_space(): self.page1.pack_start(Gtk.Label(""), False, False, 0) self.page1 = RadioButtonPage() text = "\n".join([ _("Welcome to the Export Assistant."), _("This wizard will help you to export your journal to various formats." ), _("You can select the days you want to export and where the output will be saved." ), ]) welcome_label = Gtk.Label(text) self.page1.pack_start(welcome_label, False, False, 0) add_space() for exporter in self.exporters: name = exporter.NAME desc = exporter.DESCRIPTION self.page1.add_radio_option(exporter, name, desc) add_space() pdf_label = Gtk.Label( _("PDF: export to HTML, open in browser and print to PDF file")) pdf_label.set_halign(Gtk.Align.START) self.page1.pack_start(pdf_label, False, False, 0) self.append_page(self.page1) self.set_page_title(self.page1, _("Select Export Format") + " (1/5)") self.set_page_complete(self.page1, True) self.page2 = DatePage(self.journal) self.append_page(self.page2) self.set_page_title(self.page2, _("Select Date Range") + " (2/5)") self.set_page_complete(self.page2, True) self.page3 = ContentsPage(self.journal, self) self.append_page(self.page3) self.set_page_title(self.page3, _("Select Contents") + " (3/5)") self.set_page_complete(self.page3, True) self.page3.check_selection() self.page4 = PathChooserPage(self) self.append_page(self.page4) self.set_page_title(self.page4, _("Select Export Path") + " (4/5)") self.set_page_complete(self.page4, True) self.page5 = SummaryPage() self.append_page(self.page5) self.set_page_title(self.page5, _("Summary") + " (5/5)") self.set_page_type(self.page5, Gtk.AssistantPageType.CONFIRM) self.set_page_complete(self.page5, True) self.exporter = None self.path = None self.set_forward_page_func(self.pageforward) def pageforward(self, page): if page == 2 and self.page2.export_selected_text(): return 4 else: return page + 1 def run(self): self.page2.refresh_dates() self.page3.refresh_categories_list() self.show_all() def _on_close(self, assistant): """ Do the export """ self.hide() self.export() def _on_prepare(self, assistant, page): """ Called when a new page should be prepared, before it is shown """ if page == self.page2: # Date Range self.exporter = self.page1.get_selected_object() self.page2.prepare() elif page == self.page3: # Categories start_date, end_date = self.page2.get_date_range() if not self.page2.export_all_days() and start_date == end_date: self.page3.filter_tags_button.set_active(False) self.page3.filter_tags_button.set_sensitive(False) else: self.page3.filter_tags_button.set_sensitive(True) elif page == self.page4: # Path self.page4.prepare(self.exporter) elif page == self.page5: # Summary self.path = self.page4.get_selected_path() self.page5.prepare() self.export_all_days = self.page2.export_all_days() self.export_selected_text = self.page2.export_selected_text() self.is_filtered = self.page3.is_filtered() self.exported_categories = self.page3.get_categories() self.page5.add_setting(_("Format"), self.exporter.NAME) self.page5.add_setting(_("Export all days"), self.yes_no(self.export_all_days)) if not self.export_all_days: start_date, end_date = self.page2.get_date_range() if start_date == end_date: self.page5.add_setting(_("Date"), start_date) self.page5.add_setting( _("Export selected text only"), self.yes_no(self.export_selected_text), ) else: self.page5.add_setting(_("Start date"), start_date) self.page5.add_setting(_("End date"), end_date) if self.export_selected_text: self.exported_categories = [] else: self.page5.add_setting( _("Include text"), self.yes_no(self.page3.is_text_included())) self.page5.add_setting( _("Include tags"), self.yes_no(self.page3.is_tags_included())) if self.is_filtered: self.page5.add_setting(_("Filtered by tags"), ", ".join(self.exported_categories)) self.page5.add_setting(_("Export path"), self.path) def yes_no(self, value): return _("Yes") if value else _("No") def get_export_string(self, target): if self.export_selected_text and self.page2.selected_text: markup_string = self.page2.selected_text else: if self.export_all_days: export_days = self.journal.days else: export_days = self.journal.get_days_in_date_range( *self.page2.get_date_range()) selected_categories = self.exported_categories logging.debug("Selected Categories for Inclusion: %s" % selected_categories) markup_strings_for_each_day = [] for day in export_days: include_day = True if self.is_filtered: include_day = False catagory_pairs = day.get_category_content_pairs() for category in selected_categories: if category in catagory_pairs: include_day = True if include_day: date_format = self.journal.config.read("exportDateFormat") date_string = dates.format_date(date_format, day.date) day_markup = markup.get_markup_for_day( day, target, with_text=self.page3.is_text_included(), with_tags=self.page3.is_tags_included(), categories=selected_categories, date=date_string, ) markup_strings_for_each_day.append(day_markup) markup_string = "".join(markup_strings_for_each_day) return self.journal.convert(markup_string, target, options={"toc": 0}) def export(self): format = self.exporter.FORMAT export_string = self.get_export_string(format) filesystem.write_file(self.path, export_string) self.journal.show_message(_("Content exported to %s") % self.path)