def cl_book(database, name, book, options_str_dict): clr = CommandLineReport(database, name, CATEGORY_BOOK, ReportOptions, options_str_dict) # Exit here if show option was given if clr.show: return # write report doc = clr.format( None, PaperStyle(clr.paper, clr.orien, clr.marginl, clr.marginr, clr.margint, clr.marginb)) user = User() rptlist = [] selected_style = StyleSheet() for item in book.get_item_list(): # The option values were loaded magically by the book parser. # But they still need to be applied to the menu options. opt_dict = item.option_class.options_dict menu = item.option_class.menu for optname in opt_dict: menu_option = menu.get_option_by_name(optname) if menu_option: menu_option.set_value(opt_dict[optname]) item.option_class.set_document(doc) report_class = item.get_write_item() obj = write_book_item(database, report_class, item.option_class, user) if obj: append_styles(selected_style, item) rptlist.append(obj) doc.set_style_sheet(selected_style) doc.open(clr.option_class.get_output()) doc.init() newpage = 0 for rpt in rptlist: if newpage: doc.page_break() newpage = 1 rpt.begin_report() rpt.write_report() doc.close()
def make_document(self): """Create a document of the type requested by the user.""" user = User() self.rptlist = [] selected_style = StyleSheet() pstyle = self.paper_frame.get_paper_style() self.doc = self.format(None, pstyle) for item in self.book.get_item_list(): item.option_class.set_document(self.doc) report_class = item.get_write_item() obj = write_book_item(self.database, report_class, item.option_class, user) self.rptlist.append(obj) append_styles(selected_style, item) self.doc.set_style_sheet(selected_style) self.doc.open(self.target_path)
def setup_style_frame(self): """Set up the style frame of the dialog. This function relies on other routines to create the default style for this report, and to read in any user-defined styles for this report. It then builds a menu of all the available styles for the user to choose from.""" # Build the default style set for this report. self.default_style = StyleSheet() self.options.make_default_style(self.default_style) if self.default_style.is_empty(): # Don't display the option if no styles are used return # Styles Frame label = Gtk.Label(label="%s:" % _("Style")) label.set_halign(Gtk.Align.START) self.style_menu = StyleComboBox() self.style_menu.set_hexpand(True) self.style_button = Gtk.Button("%s..." % _("Style Editor")) self.style_button.connect('clicked', self.on_style_edit_clicked) self.grid.attach(label, 1, self.row, 1, 1) self.grid.attach(self.style_menu, 2, self.row, 1, 1) self.grid.attach(self.style_button, 3, self.row, 1, 1) self.row += 1 # Build the initial list of available styles sets. This # includes the default style set and any style sets saved from # previous invocations of gramps. self.style_sheet_list = StyleSheetList( self.options.handler.get_stylesheet_savefile(), self.default_style) # Now build the actual menu. style = self.options.handler.get_default_stylesheet_name() self.build_style_menu(style)
def test_write_report(self): """ Creates a report from test data. """ options = FamilyChroniclesOptions("Familiy Chronicles", self.db) options.load_previous_values() options.menu.get_option_by_name('pid').set_value(TEST_PERSON_ID) docgen_plugin = Familychroniclestest.__get_docgen_plugin('latexdoc') doc_class = docgen_plugin.get_basedoc() styles = StyleSheet() options.make_default_style(styles) paper_layout = PaperStyle(PaperSize("a4", None, None), PAPER_LANDSCAPE) doc = doc_class(styles, paper_layout, []) options.set_document(doc) options.set_output(TEST_OUTPUT) # Initialization sequence inspired by _reportdialog.py, report() my_report = FamilyChronicles(self.db, options, User()) my_report.doc.init() my_report.begin_report() my_report.write_report() my_report.end_report()
def parse_options(self): """ Load the options that the user has entered. """ if not hasattr(self.option_class, "menu"): menu = None else: menu = self.option_class.menu menu_opt_names = menu.get_all_option_names() _format_str = self.options_str_dict.pop('off', None) if _format_str: self.options_dict['off'] = _format_str self.css_filename = None _chosen_format = None self.doc_option_class = None if self.category in [CATEGORY_TEXT, CATEGORY_DRAW, CATEGORY_BOOK]: if self.category == CATEGORY_TEXT: plugins = self.__textdoc_plugins self.css_filename = self.options_dict['css'] elif self.category == CATEGORY_DRAW: plugins = self.__drawdoc_plugins elif self.category == CATEGORY_BOOK: plugins = self.__bookdoc_plugins for plugin in plugins: if plugin.get_extension() == self.options_dict['off']: self.format = plugin.get_basedoc() self.doc_option_class = plugin.get_doc_option_class() if self.format is None: # Pick the first one as the default. plugin = plugins[0] self.format = plugin.get_basedoc() self.doc_option_class = plugin.get_doc_option_class() _chosen_format = plugin.get_extension() elif self.category == CATEGORY_GRAPHVIZ: for graph_format in graphdoc.FORMATS: if graph_format['type'] == self.options_dict['off']: if not self.format: # choose the first one, not the last self.format = graph_format["class"] if self.format is None: # Pick the first one as the default. self.format = graphdoc.FORMATS[0]["class"] _chosen_format = graphdoc.FORMATS[0]["type"] else: self.format = None if _chosen_format and _format_str: print(_("Ignoring '%(notranslate1)s=%(notranslate2)s' " "and using '%(notranslate1)s=%(notranslate3)s'.") % { 'notranslate1': "off", 'notranslate2': self.options_dict['off'], 'notranslate3': _chosen_format }, file=sys.stderr) print(_("Use '%(notranslate)s' to see valid values.") % {'notranslate': "show=off"}, file=sys.stderr) self.do_doc_options() for opt in self.options_str_dict: if opt in self.options_dict: self.options_dict[opt] = \ _convert_str_to_match_type(self.options_str_dict[opt], self.options_dict[opt]) self.option_class.handler.options_dict[opt] = \ self.options_dict[opt] if menu and opt in menu_opt_names: option = menu.get_option_by_name(opt) option.set_value(self.options_dict[opt]) else: print(_("Ignoring unknown option: %s") % opt, file=sys.stderr) print(_(" Valid options are:"), ", ".join(list(self.options_dict.keys())), file=sys.stderr) print(_(" Use '%(donottranslate)s' to see description " "and acceptable values") % {'donottranslate': "show=option"}, file=sys.stderr) self.option_class.handler.output = self.options_dict['of'] self.paper = paper_sizes[0] # make sure one exists for paper in paper_sizes: if paper.get_name() == self.options_dict['papers']: self.paper = paper self.option_class.handler.set_paper(self.paper) self.orien = self.options_dict['papero'] self.marginl = self.options_dict['paperml'] self.marginr = self.options_dict['papermr'] self.margint = self.options_dict['papermt'] self.marginb = self.options_dict['papermb'] if self.category in (CATEGORY_TEXT, CATEGORY_DRAW): default_style = StyleSheet() self.option_class.make_default_style(default_style) # Read all style sheets available for this item style_file = self.option_class.handler.get_stylesheet_savefile() self.style_list = StyleSheetList(style_file, default_style) # Get the selected stylesheet style_name = self.option_class.handler.get_default_stylesheet_name( ) self.selected_style = self.style_list.get_style_sheet(style_name)
def init_standard_options(self, noopt): """ Initialize the options that are hard-coded into the report system. """ self.options_dict = { 'of' : self.option_class.handler.module_name, 'off' : self.option_class.handler.get_format_name(), 'style' : \ self.option_class.handler.get_default_stylesheet_name(), 'papers' : self.option_class.handler.get_paper_name(), 'papero' : self.option_class.handler.get_orientation(), 'paperml' : self.option_class.handler.get_margins()[0], 'papermr' : self.option_class.handler.get_margins()[1], 'papermt' : self.option_class.handler.get_margins()[2], 'papermb' : self.option_class.handler.get_margins()[3], 'css' : self.option_class.handler.get_css_filename(), } self.options_help = { 'of': [_("=filename"), _("Output file name. MANDATORY"), ""], 'off': [_("=format"), _("Output file format."), []], 'style': [_("=name"), _("Style name."), ""], 'papers': [_("=name"), _("Paper size name."), ""], 'papero': [_("=number"), _("Paper orientation number."), ""], 'paperml': [_("=number"), _("Left paper margin"), _("Size in cm")], 'papermr': [_("=number"), _("Right paper margin"), _("Size in cm")], 'papermt': [_("=number"), _("Top paper margin"), _("Size in cm")], 'papermb': [_("=number"), _("Bottom paper margin"), _("Size in cm")], 'css': [ _("=css filename"), _("CSS filename to use, " "html format only"), "" ], } if noopt: return self.options_help['of'][2] = os.path.join(USER_HOME, "whatever_name") if self.category == CATEGORY_TEXT: for plugin in self.__textdoc_plugins: self.options_help['off'][2].append(plugin.get_extension() + "\t" + plugin.get_description()) elif self.category == CATEGORY_DRAW: for plugin in self.__drawdoc_plugins: self.options_help['off'][2].append(plugin.get_extension() + "\t" + plugin.get_description()) elif self.category == CATEGORY_BOOK: for plugin in self.__bookdoc_plugins: self.options_help['off'][2].append(plugin.get_extension() + "\t" + plugin.get_description()) elif self.category == CATEGORY_GRAPHVIZ: for graph_format in graphdoc.FORMATS: self.options_help['off'][2].append(graph_format["type"] + "\t" + graph_format["descr"]) else: self.options_help['off'][2] = "NA" self.options_help['papers'][2] = \ [ paper.get_name() for paper in paper_sizes if paper.get_name() != 'Custom Size' ] self.options_help['papero'][2] = [ "%d\tPortrait" % PAPER_PORTRAIT, "%d\tLandscape" % PAPER_LANDSCAPE ] self.options_help['css'][2] = os.path.join(USER_HOME, "whatever_name.css") if self.category in (CATEGORY_TEXT, CATEGORY_DRAW): default_style = StyleSheet() self.option_class.make_default_style(default_style) # Read all style sheets available for this item style_file = self.option_class.handler.get_stylesheet_savefile() self.style_list = StyleSheetList(style_file, default_style) self.options_help['style'][2] = self.style_list.get_style_names()
def __init__(self, name, style, parent): """ Create the StyleEditor. name - name of the style that is to be edited style - style object that is to be edited parent - StyleListDisplay object that called the editor """ self.current_style = None self.current_name = None self.style = StyleSheet(style) self.parent = parent self.top = Glade(toplevel='editor') self.window = self.top.toplevel self.top.connect_signals({ "on_save_style_clicked": self.on_save_style_clicked, "destroy_passed_object": self.__close, "on_ok_clicked": dummy_callback, "on_add_clicked": dummy_callback, "on_delete_clicked": dummy_callback, "on_button_press": dummy_callback, "on_edit_clicked": dummy_callback, }) self.pname = self.top.get_object('pname') self.pdescription = self.top.get_object('pdescription') self.notebook = self.top.get_object('notebook1') self.vbox = self.top.get_object('column_widths') self.line_style = self.top.get_object('line_style') line_styles = Gtk.ListStore(int, str) line_styles.append([0, "Solid"]) line_styles.append([1, "Dashed"]) line_styles.append([2, "Dotted"]) self.line_style.set_model(line_styles) renderer_text = Gtk.CellRendererText() self.line_style.pack_start(renderer_text, True) self.line_style.add_attribute(renderer_text, "text", 1) set_titles(self.window, self.top.get_object('title'), _('Style editor')) self.top.get_object("label6").set_text(_("point size|pt")) titles = [(_('Style'), 0, 130)] self.plist = ListModel(self.top.get_object("ptree"), titles, self.change_display) for widget_name in ('color', 'bgcolor', 'line_color', 'fill_color'): color = self.top.get_object(widget_name) label = self.top.get_object(widget_name + '_code') color.connect('notify::color', self.color_changed, label) self.top.get_object("style_name").set_text(name) def _alphanumeric_sort(iterable): """ sort the given iterable in the way that humans expect """ convert = lambda text: int(text) if text.isdigit() else text sort_key = lambda k: [convert(c) for c in re.split('([0-9]+)', k)] return sorted(iterable, key=sort_key) names = _alphanumeric_sort(self.style.get_paragraph_style_names()) for p_name in names: self.plist.add([p_name], self.style.get_paragraph_style(p_name)) names = _alphanumeric_sort(self.style.get_table_style_names()) for t_name in names: self.plist.add([t_name], self.style.get_table_style(t_name)) names = _alphanumeric_sort(self.style.get_cell_style_names()) for c_name in names: self.plist.add([c_name], self.style.get_cell_style(c_name)) names = _alphanumeric_sort(self.style.get_draw_style_names()) for d_name in names: self.plist.add([d_name], self.style.get_draw_style(d_name)) self.plist.select_row(0) if self.parent: self.window.set_transient_for(parent.window) self.window.run() self.window.destroy()
def __init__(self, name, style, parent): """ Create the StyleEditor. name - name of the style that is to be edited style - style object to be edited: a :class:`.StyleSheet` instance parent - StyleListDisplay object that called the editor """ ManagedWindow.__init__(self, parent.uistate, parent.track, self.__class__, modal=True) # the self.window.run() below makes Gtk make it modal, so any change # to the previous line's "modal" would require that line to be changed self.current_style = None self.current_name = None self.style = StyleSheet(style) self.parent = parent self.top = Glade(toplevel='editor') self.set_window(self.top.toplevel, self.top.get_object('title'), _('Style editor')) self.setup_configs('interface.styleeditor', 550, 610) self.show() self.top.connect_signals({ "on_save_style_clicked": self.on_save_style_clicked, "on_cancel_style_clicked": self.__cancel, "on_cancel_clicked": dummy_callback, "on_ok_clicked": dummy_callback, "on_add_clicked": dummy_callback, "on_delete_clicked": dummy_callback, "on_button_press": dummy_callback, "on_edit_clicked": dummy_callback, }) self.pname = self.top.get_object('pname') self.pdescription = self.top.get_object('pdescription') self.notebook = self.top.get_object('notebook1') self.vbox = self.top.get_object('column_widths') self.line_style = self.top.get_object('line_style') line_styles = Gtk.ListStore(int, str) line_styles.append([0, "Solid"]) line_styles.append([1, "Dashed"]) line_styles.append([2, "Dotted"]) self.line_style.set_model(line_styles) renderer_text = Gtk.CellRendererText() self.line_style.pack_start(renderer_text, True) self.line_style.add_attribute(renderer_text, "text", 1) self.top.get_object("label6").set_text(_("point size|pt")) titles = [(_('Style'), 0, 130)] self.plist = ListModel(self.top.get_object("ptree"), titles, self.change_display) for widget_name in ('color', 'bgcolor', 'line_color', 'fill_color'): color = self.top.get_object(widget_name) label = self.top.get_object(widget_name + '_code') color.connect('notify::color', self.color_changed, label) self.top.get_object("style_name").set_text(name) def _alphanumeric_sort(iterable): """ sort the given iterable in the way that humans expect """ convert = lambda text: int(text) if text.isdigit() else text sort_key = lambda k: [convert(c) for c in re.split('([0-9]+)', k)] return sorted(iterable, key=sort_key) names = _alphanumeric_sort(self.style.get_paragraph_style_names()) for p_name in names: self.plist.add([p_name], self.style.get_paragraph_style(p_name)) names = _alphanumeric_sort(self.style.get_table_style_names()) for t_name in names: self.plist.add([t_name], self.style.get_table_style(t_name)) names = _alphanumeric_sort(self.style.get_cell_style_names()) for c_name in names: self.plist.add([c_name], self.style.get_cell_style(c_name)) names = _alphanumeric_sort(self.style.get_draw_style_names()) for d_name in names: self.plist.add([d_name], self.style.get_draw_style(d_name)) self.plist.select_row(0) # the self.window.run() makes Gtk make it modal, so any change to that # line would require the ManagedWindow.__init__ to be changed also self.window.run() if self.opened: self.close()