""" Docgen plugin to generate the GtkAda Reference Manual. Invoke with: gps -Pgenerate_docs.gpr --load=python:docgen_gtkada.py """ import GPS, re, os import shutil class ScreenshotTagHandler (GPS.DocgenTagHandler): """Handling for screenshots""" def __init__ (self): GPS.DocgenTagHandler.__init__ ( self, "screenshot", on_match = self.on_match, on_start=self.on_start, on_exit=self.on_exit) def on_start (self, docgen): self.pictureslist = {} def on_match (self, docgen, attrs, value, entity_name, entity_href): file = docgen.get_current_file() srcdir = os.path.normpath (GPS.Project.root().file().directory()) fullfile = os.path.join (srcdir, value.strip()) screenshot_found = False for extension in ["", ".png", ".jpg"]: if os.path.exists(fullfile + extension): pict = value.strip() + extension screenshot_found = True break if not screenshot_found: GPS.Console ("Messages").write ("could not find screenshot %s\n" % (fullfile)) return "" docdir = os.path.join (docgen.get_doc_dir ().name(), "screenshots") if not os.path.exists (docdir): os.mkdir(docdir) shutil.copy (os.path.join(srcdir,pict), docdir) img = """""" % (pict, pict) self.pictureslist[entity_name] = [entity_href, img] return """
Index
""" content += """""" n = 0 for pict in sorted(self.pictureslist.keys()): content += """- %s
""" % (n, pict)
n += 1
content += """
%s