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_alignment(0.0, 0.5) self.style_menu = StyleComboBox() self.style_button = Gtk.Button("%s..." % _("Style Editor")) self.style_button.connect('clicked', self.on_style_edit_clicked) self.tbl.attach(label, 1, 2, self.row, self.row + 1, Gtk.AttachOptions.SHRINK | Gtk.AttachOptions.FILL) self.tbl.attach(self.style_menu, 2, 3, self.row, self.row + 1, yoptions=Gtk.AttachOptions.SHRINK) self.tbl.attach(self.style_button, 3, 4, self.row, self.row + 1, xoptions=Gtk.AttachOptions.SHRINK | Gtk.AttachOptions.FILL, yoptions=Gtk.AttachOptions.SHRINK) 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 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()