File: docgen_gtkada.py

package info (click to toggle)
libgtkada 21.0.0.785f3cf4-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 41,160 kB
  • sloc: ada: 203,114; xml: 8,403; python: 4,501; perl: 3,838; ansic: 2,949; sh: 2,851; makefile: 351; objc: 160; javascript: 100
file content (124 lines) | stat: -rw-r--r-- 4,013 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
"""
   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 = """<img src="screenshots/%s" alt="%s" style="border: 0px;"/>""" % (pict, pict)

      self.pictureslist[entity_name] = [entity_href, img]
      return """</div>
        <div class='profile'>
          <h3>Screenshot</h3>
          %s
        </div>
        <div class='comment'>""" % (img)

   def on_exit (self, docgen):
      if len (self.pictureslist) == 0:
         return

      # first print the right-side box containing the group index
      content=""
      content += """<div class='default' id='rightSide'>"""
      content += """<div id='rightSideInside'>"""
      content += """<div id='Index'>"""
      content += """<h2>Index</h2>"""
      content += """<ul>"""
      n = 0
      for pict in sorted(self.pictureslist.keys()):
         content += """<li><a href="#%d">%s</a></li>""" % (n, pict)
         n += 1
      content += """</ul></div></div></div>"""

      content += """<div class='default' id='documentation'>"""
      content += """<div class="title">Widget Screenshots</div>"""
      n = 0
      for pict in sorted(self.pictureslist.keys()):
         content += """
            <div class='subprograms'>
              <div class='class'>
                <a name="%d"></a>
                <h3>%s</h3>
                <div class='comment'>
                  <a href="%s">%s</a>
                </div>
              </div>
            </div>""" % (n, pict, self.pictureslist[pict][0], self.pictureslist[pict][1])
         n += 1
      content += """</div>"""

      docgen.generate_index_file ("Widget Screenshots", "screenshots.html", content);

class ExampleTagHandler (GPS.DocgenTagHandler):
   """Handling for <example> tags"""
   def __init__ (self):
      GPS.DocgenTagHandler.__init__ (
        self, "example",
        on_match = self.on_match)

   def on_match (self, docgen, attrs, value, entity_name, entity_href):
      return """<div class="code">%s</div>""" % value

def on_gps_start (hook):
   # Disable launching of browser on exit
   GPS.Preference ("Doc-Spawn-Browser").set(False)

   GPS.Docgen.register_tag_handler (ScreenshotTagHandler ())
   GPS.Docgen.register_tag_handler (ExampleTagHandler ())
   GPS.Docgen.register_css (GPS.File ("gtkada.css"))
   GPS.Docgen.register_main_index (GPS.File ("gtkada_rm/groups.html"))

   GPS.Project.root().generate_doc (True)
   GPS.Timeout (500, wait_doc)

def wait_doc(timeout):
   txt = GPS.Console("Messages").get_text()
   if txt.find("Documentation generated") == -1:
       return True
   else:
       # Log the output in log.txt
       f=open("log.txt", "w")
       f.write(GPS.Console ("Messages").get_text())
       f.close()
       GPS.exit()

GPS.Hook ("gps_started").add (on_gps_start)