mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-06 20:10:08 +01:00
Docs: save inheritance diagrams as svg and small design changes
This commit is contained in:
@@ -10,22 +10,19 @@
|
|||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
|
||||||
# Standard library imports
|
# Standard library imports
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import errno
|
import errno
|
||||||
from subprocess import Popen, PIPE
|
from subprocess import Popen, PIPE
|
||||||
|
|
||||||
# Phoenix-specific imports
|
# Phoenix-specific imports
|
||||||
|
from .utilities import formatExternalLink
|
||||||
from .utilities import wx2Sphinx, formatExternalLink
|
|
||||||
from .constants import INHERITANCEROOT
|
from .constants import INHERITANCEROOT
|
||||||
|
|
||||||
ENOENT = getattr(errno, 'ENOENT', 0)
|
ENOENT = getattr(errno, 'ENOENT', 0)
|
||||||
EPIPE = getattr(errno, 'EPIPE', 0)
|
EPIPE = getattr(errno, 'EPIPE', 0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class InheritanceDiagram:
|
class InheritanceDiagram:
|
||||||
"""
|
"""
|
||||||
Given a list of classes, determines the set of classes that they inherit
|
Given a list of classes, determines the set of classes that they inherit
|
||||||
@@ -123,7 +120,8 @@ class InheritanceDiagram:
|
|||||||
def _format_graph_attrs(self, attrs):
|
def _format_graph_attrs(self, attrs):
|
||||||
return ''.join(['%s=%s;\n' % x for x in list(attrs.items())])
|
return ''.join(['%s=%s;\n' % x for x in list(attrs.items())])
|
||||||
|
|
||||||
def generate_dot(self, class_summary, name="dummy", graph_attrs={}, node_attrs={}, edge_attrs={}):
|
def generate_dot(self, class_summary, name="dummy",
|
||||||
|
graph_attrs={}, node_attrs={}, edge_attrs={}):
|
||||||
"""Generate a graphviz dot graph from the classes that were passed in
|
"""Generate a graphviz dot graph from the classes that were passed in
|
||||||
to __init__.
|
to __init__.
|
||||||
|
|
||||||
@@ -133,18 +131,21 @@ class InheritanceDiagram:
|
|||||||
key/value pairs to pass on as graphviz properties.
|
key/value pairs to pass on as graphviz properties.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
inheritance_graph_attrs = dict(fontsize=9, ratio='auto', size='""', rankdir="TB")
|
inheritance_graph_attrs = {"fontsize": 9, "ratio": 'auto',
|
||||||
inheritance_node_attrs = {"align": "center", 'shape': 'box',
|
"size": '""', "rankdir": "TB"}
|
||||||
'fontsize': 10, 'height': 0.3,
|
|
||||||
'fontname': '"Vera Sans, DejaVu Sans, Liberation Sans, '
|
|
||||||
'Arial, Helvetica, sans"', 'style': '"setlinewidth(0.5)"',
|
|
||||||
'labelloc': 'c', 'fontcolor': 'grey45'}
|
|
||||||
|
|
||||||
inheritance_edge_attrs = {'arrowsize': 0.5,
|
inheritance_node_attrs = {"align": "center", 'shape': 'box',
|
||||||
'style': '"setlinewidth(0.5)"',
|
'fontsize': 12, 'height': 0.3,
|
||||||
'color': '"#23238E"',
|
'fontname': '"Vera Sans, DejaVu Sans, Liberation Sans, '
|
||||||
|
'Arial, Helvetica, sans"', 'style': '"setlinewidth(0.8), rounded"',
|
||||||
|
'labelloc': 'c', 'fontcolor': 'grey45',
|
||||||
|
"color": "dodgerblue4"}
|
||||||
|
|
||||||
|
inheritance_edge_attrs = {'arrowsize': 0.6,
|
||||||
|
'style': '"setlinewidth(0.8)"',
|
||||||
|
'color': 'dodgerblue4',
|
||||||
'dir': 'back',
|
'dir': 'back',
|
||||||
'arrowtail': 'open',
|
'arrowtail': 'normal',
|
||||||
}
|
}
|
||||||
|
|
||||||
g_attrs = self.default_graph_attrs.copy()
|
g_attrs = self.default_graph_attrs.copy()
|
||||||
@@ -163,9 +164,9 @@ class InheritanceDiagram:
|
|||||||
this_node_attrs = n_attrs.copy()
|
this_node_attrs = n_attrs.copy()
|
||||||
|
|
||||||
if fullname in self.specials:
|
if fullname in self.specials:
|
||||||
this_node_attrs['fontcolor'] = 'black'
|
this_node_attrs['fontcolor'] = 'dodgerblue4'
|
||||||
this_node_attrs['color'] = 'blue'
|
this_node_attrs['color'] = 'dodgerblue2'
|
||||||
this_node_attrs['style'] = 'bold'
|
this_node_attrs['style'] = '"bold, rounded"'
|
||||||
|
|
||||||
if class_summary is None:
|
if class_summary is None:
|
||||||
# Phoenix base classes, assume there is always a link
|
# Phoenix base classes, assume there is always a link
|
||||||
@@ -185,7 +186,7 @@ class InheritanceDiagram:
|
|||||||
for base_name in bases:
|
for base_name in bases:
|
||||||
this_edge_attrs = e_attrs.copy()
|
this_edge_attrs = e_attrs.copy()
|
||||||
if fullname in self.specials:
|
if fullname in self.specials:
|
||||||
this_edge_attrs['color'] = 'red'
|
this_edge_attrs['color'] = 'darkorange1'
|
||||||
|
|
||||||
res.append(' "%s" -> "%s" [%s];\n' %
|
res.append(' "%s" -> "%s" [%s];\n' %
|
||||||
(base_name, fullname,
|
(base_name, fullname,
|
||||||
@@ -198,7 +199,7 @@ class InheritanceDiagram:
|
|||||||
|
|
||||||
def makeInheritanceDiagram(self, class_summary=None):
|
def makeInheritanceDiagram(self, class_summary=None):
|
||||||
"""
|
"""
|
||||||
Actually generates the inheritance diagram as a PNG file plus the corresponding
|
Actually generates the inheritance diagram as a SVG file plus the corresponding
|
||||||
MAP file for mouse navigation over the inheritance boxes.
|
MAP file for mouse navigation over the inheritance boxes.
|
||||||
|
|
||||||
These two files are saved into the ``INHERITANCEROOT`` folder (see `sphinxtools/constants.py`
|
These two files are saved into the ``INHERITANCEROOT`` folder (see `sphinxtools/constants.py`
|
||||||
@@ -209,7 +210,7 @@ class InheritanceDiagram:
|
|||||||
|
|
||||||
:rtype: `tuple`
|
:rtype: `tuple`
|
||||||
|
|
||||||
:returns: a tuple containing the PNG file name and a string representing the content
|
:returns: a tuple containing the SVG file name and a string representing the content
|
||||||
of the MAP file (with newlines stripped away).
|
of the MAP file (with newlines stripped away).
|
||||||
|
|
||||||
.. note:: The MAP file is deleted as soon as its content has been read.
|
.. note:: The MAP file is deleted as soon as its content has been read.
|
||||||
@@ -224,13 +225,13 @@ class InheritanceDiagram:
|
|||||||
else:
|
else:
|
||||||
filename = self.specials[0]
|
filename = self.specials[0]
|
||||||
|
|
||||||
outfn = os.path.join(static_root, filename + '_inheritance.png')
|
outfn = os.path.join(static_root, filename + '_inheritance.svg')
|
||||||
mapfile = outfn + '.map'
|
mapfile = outfn + '.map'
|
||||||
|
|
||||||
if os.path.isfile(outfn) and os.path.isfile(mapfile):
|
if os.path.isfile(outfn) and os.path.isfile(mapfile):
|
||||||
with open(mapfile, 'rt') as fid:
|
with open(mapfile, 'rt', encoding="utf-8") as fid:
|
||||||
map = fid.read()
|
mp = fid.read()
|
||||||
return os.path.split(outfn)[1], map.replace('\n', ' ')
|
return os.path.split(outfn)[1], mp.replace('\n', ' ')
|
||||||
|
|
||||||
code = self.generate_dot(class_summary)
|
code = self.generate_dot(class_summary)
|
||||||
|
|
||||||
@@ -245,7 +246,7 @@ class InheritanceDiagram:
|
|||||||
if os.path.isfile(mapfile):
|
if os.path.isfile(mapfile):
|
||||||
os.remove(mapfile)
|
os.remove(mapfile)
|
||||||
|
|
||||||
dot_args.extend(['-Tpng', '-o' + outfn])
|
dot_args.extend(['-Tsvg', '-o' + outfn])
|
||||||
dot_args.extend(['-Tcmapx', '-o' + mapfile])
|
dot_args.extend(['-Tcmapx', '-o' + mapfile])
|
||||||
|
|
||||||
popen_args = {
|
popen_args = {
|
||||||
@@ -283,7 +284,7 @@ class InheritanceDiagram:
|
|||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
print(('\nERROR: Graphviz `dot` command exited with error:\n[stderr]\n%s\n[stdout]\n%s\n\n' % (stderr, stdout)))
|
print(('\nERROR: Graphviz `dot` command exited with error:\n[stderr]\n%s\n[stdout]\n%s\n\n' % (stderr, stdout)))
|
||||||
|
|
||||||
with open(mapfile, 'rt') as fid:
|
with open(mapfile, 'rt', encoding="utf-8") as fid:
|
||||||
map = fid.read()
|
mp = fid.read()
|
||||||
|
|
||||||
return os.path.split(outfn)[1], map.replace('\n', ' ')
|
return os.path.split(outfn)[1], mp.replace('\n', ' ')
|
||||||
|
|||||||
Reference in New Issue
Block a user