def create_module_manual(moduleName): sys.stdout = open(pmwDocHtmlDir + moduleName + '.html', 'w') print header( title = 'Pmw.' + moduleName + ' reference manual', heading = 'Pmw.' + moduleName ) print '<dl>' textModule = __import__(moduleName + '_text') print '<dt> <h3>Name</h3></dt><dd>' text = 'Pmw.' + moduleName + ' - ' + textModule.name print StructuredText.gethtml(text) print '</dd>' print '<dt> <h3>Description</h3></dt><dd>' text = textModule.description print StructuredText.gethtml(text) print '</dd>' functionNames = [] module = __import__('Pmw' + moduleName) for name, value in module.__dict__.items(): if name[0] != '_' and type(value) == types.FunctionType: functionNames.append((name, value)) functionNames.sort() print '<dt> <h3>Functions</h3></dt><dd>' print 'The following functions are available.<p></p>' functions_with_text = textModule.text['functions'].keys() print '<dl>' for name, function in functionNames: args = getFunctionArgs(function) print '<dt> <strong>Pmw.' + moduleName + '.' + name + '</strong>' + args + '</dt><dd>' if name in textModule.text['functions']: text = textModule.text['functions'][name] text = StructuredText.gethtml(text) if text[:3] == '<p>': print text[3:] else: print text functions_with_text.remove(name) else: sys.stderr.write('ERROR: no text for function ' + name + '\n') print '<p></p>' print '</dd>' print '</dl>' print '</dd></dl>' if len(functions_with_text) > 0: sys.stderr.write('ERROR: unknown functions ' + str(functions_with_text) + ' for module' + moduleName + '\n') print blue_line() if textModule.reviewdate != '': extra = '<br>Manual page last reviewed: ' + textModule.reviewdate else: extra = '' print trailer(extra = extra)
def create_tree_Object(self, docobj): """Default implementation for generating doctrees.""" self.trace_msg( "Creating tree for %s %s" % (docobj.tag(), docobj.name()), 2) oneliner, doc = docstring.split_doc(docobj.docstring()) try: oneliner = eval("self.fix_oneliner_%s(oneliner)" % docobj.tag()) except AttributeError: pass doc, hyperdef_doc = docstring.split_hyper(doc) st = StructuredText.StructuredText(doc) if oneliner: node = doctree.Oneliner('') self._create_markup_node(oneliner, node) self.__doctree.add_child(node) marker = doctree.DocNode('', 'Marker') self.__doctree.add_child(marker) for child in docobj.subobjects(): dtree = child.document(Markup) self.__doctree.add_child_sorted(dtree, after=marker) self.__doctree.remove_child(marker) desc = doctree.Description() self.__doctree.add_child(desc) self.__parse_hyperdef(hyperdef_doc, docobj) self.__parse(st.structure, desc, docobj)
def create_page(moduleName, pageName, title): sys.stdout = open(pmwDocHtmlDir + pageName, 'w') print header(title = title, heading = title) module = __import__(moduleName) text = StructuredText.gethtml(module.text) print text print blue_line() print trailer()
def format_stx( text, level=1 ): """ Render STX to HTML. """ st = StructuredText.Basic( text ) # Creates the basic DOM if not st: # If it's an empty object return "" # return now or have errors! doc = CMFDocumentClass( st ) html = CMFHtmlWithImages( doc, level ) return html
def create_function_manual(): sys.stdout = open(pmwDocHtmlDir + 'PmwFunctions.html', 'w') print header( title = 'Pmw functions reference manual', heading = 'Pmw functions', ) functionNames = [] import PmwBase for name, value in PmwBase.__dict__.items(): if name[0] != '_' and type(value) == types.FunctionType: args = getFunctionArgs(value) functionNames.append((name, args)) for name in _functions.keys(): value = getattr(Pmw, name) if hasattr(value, 'func_code'): args = getFunctionArgs(value) functionNames.append((name, args)) elif name not in ('OK', 'ERROR', 'PARTIAL'): sys.stderr.write('ERROR: ' + name + ' is not a function\n') import PmwLoader cls = PmwLoader.PmwLoader for name, value in cls.__dict__.items(): if name[0] != '_' and type(value) == types.FunctionType: args = getFunctionArgs(value, 1) functionNames.append((name, args)) functionNames.sort() import PmwFunctions_text print '<dl>' for name, args in functionNames: print '<dt> <strong>Pmw.' + name + '</strong>' + args + '</dt><dd>' if hasattr(PmwFunctions_text, name): text = getattr(PmwFunctions_text, name) text = StructuredText.gethtml(text) print text else: sys.stderr.write('ERROR: no text for function ' + name + '\n') print '<p></p>' print '</dd>' print '</dl>' print blue_line() print trailer()
def structured_text(v, name='(Unknown name)', md={}): global StructuredText if StructuredText is None: import StructuredText return str(StructuredText.html_with_references(str(v), 3))
def printSection(widgetName, sectionName): global sectionsUsed info = widgetInfo[widgetName] fullWidgetName = 'Pmw.' + widgetName for name, after, relative, text in info['text'].sections: if not after and relative == sectionName: sectionsUsed = sectionsUsed + 1 print '<dt> <h3>' + name + '</h3></dt><dd>' print StructuredText.gethtml(text) print '</dd>' if sectionName == 'Name': print '<dt> <h3>Name</h3></dt><dd>' text = fullWidgetName + '() - ' + info['text'].name print StructuredText.gethtml(text) print '</dd>' elif sectionName == 'Inherits': if len(info['bases']) > 0: print '<dt> <h3>Inherits</h3></dt><dd>' for base in info['bases']: print link(base) + '<br>' print '</dd>' elif sectionName == 'Description': print '<dt> <h3>Description</h3></dt><dd>' text = info['text'].description print StructuredText.gethtml(text) print '</dd>' elif sectionName == 'Options': if len(info['options']) > 0: print '<dt> <h3>Options</h3></dt><dd>' print 'Options for this megawidget and its base' print 'classes are described below.<p></p>' options_with_text = info['text'].text['options'].keys() for option, default, isinit in info['options']: print '<a name=option.' + option + '></a>' print '<dl><dt> <strong>' + option print '</strong></dt><dd>' text = '' if isinit: text = 'Initialisation option. ' else: text = '' optionText = getPartText(widgetName, option, 'options') if optionText is None: sys.stderr.write('ERROR: no text for ' + widgetName + ' option ' + option + '\n') else: text = text + optionText if option in info['text'].text['options']: options_with_text.remove(option) if option not in info['text'].no_auto_default: if type(default) == type(()) and len(default) > 0: text = text + ' The default is *(' for s in default: text = text + "\\'" + default[0] + "\\', " if len(default) == 1: text = text[:-1] else: text = text[:-2] text = text + ")*." else: text = text + ' The default is *' + getRepr(default) + '*.' text = StructuredText.gethtml(text) if text[:3] == '<p>': print text[3:] else: print text print '</dd></dl>' print '</dd>' if len(options_with_text) > 0: sys.stderr.write('ERROR: unknown options ' + str(options_with_text) + ' for ' + fullWidgetName + '\n') elif sectionName == 'Components': global componentClass componentClass = {} if len(info['components']) > 0: print '<dt> <h3>Components</h3></dt><dd>' print 'Components created by this megawidget and its base' print 'classes are described below.<p></p>' components_with_text = info['text'].text['components'].keys() for component, megawidget, cls, group in info['components']: componentClass[component] = cls print '<a name=component.' + component + '></a>' print '<dl><dt> <strong>' + component print '</strong></dt><dd>' componentText = getPartText(widgetName, component, 'components') if componentText is None: sys.stderr.write('ERROR: no text for ' + widgetName + ' component ' + component + '\n') text = '' else: text = componentText if component in info['text'].text['components']: components_with_text.remove(component) text = text + ' By default, this component is a ' + \ link(cls, style = 'structured') + '.' if group is not None: text = text + ' Its component group is *' + group + '*.' text = StructuredText.gethtml(text) if text[:3] == '<p>': print text[3:] else: print text print '</dd></dl>' print '</dd>' if len(components_with_text) > 0: sys.stderr.write('ERROR: unknown components ' + str(components_with_text) + ' for ' + fullWidgetName + '\n') elif sectionName == 'Component aliases': if len(info['aliases']) > 0: print '<dt> <h3>Component aliases</h3></dt><dd>' print 'Sub-components of components of this megawidget' print 'may be accessed via the following aliases.<p></p>' for alias, name in info['aliases']: print '<dl><dt> <strong>' + alias print '</strong></dt><dd>' print 'Alias for <strong>' + name + '</strong>.' print '</dd></dl>' print '</dd>' elif sectionName == 'Methods': print '<a name=methods></a>' print '<dt> <h3>Methods</h3></dt><dd>' bases = info['bases'] if len(bases) > 0: if len(info['methods']) == 0: print 'This megawidget has no methods of its own.' else: print 'Only methods specific to this megawidget are ' + \ 'described below.' print 'For a description of its inherited methods, see the' if len(bases) == 1: base = bases[0] print 'manual for its base class' print '<strong>' + link(base, 'methods') + '</strong>.' else: print 'manuals for its base classes ' linkText = '<strong>' + link(base, 'methods') + '</strong>.' for i in len(bases): base = bases[i] if i == len(bases) - 1: print linkText + '.' elif i == len(bases) - 2: print linkText + ' and ' else: print linkText + ', ' if len(info['forwardedcomponents']) > 0: if len(info['forwardedcomponents']) == 1: cls = componentClass[info['forwardedcomponents'][0]] component = info['forwardedcomponents'][0] print 'In addition, methods from the' print '<strong>' + link(cls, 'methods') + '</strong> class' print 'are forwarded by this megawidget to the' print '<strong>' + component + '</strong> component.' else: print 'In addition, methods from the following classes' print 'are forwarded by this megawidget.' for component in info['forwardedcomponents']: cls = componentClass[component] print 'Methods from <strong>' + \ link(cls, 'methods') + '</strong>' print 'are forwarded to the' print '<strong>' + component + '</strong> component.' print 'Forwarded methods are searched in the order given.' print '<p></p>' methods_with_text = info['text'].text['methods'].keys() for method, args in info['methods']: if method == 'destroy' and \ widgetName not in ('MegaToplevel', 'MegaArchetype'): # Many widgets need to override destroy() just to unset timers. continue print '<a name=method.' + method + '></a>' print '<dl><dt> <strong>' + method + '</strong>' + args + '</dt><dd>' text = getPartText(widgetName, method, 'methods') if text is None: sys.stderr.write('ERROR: no text for ' + widgetName + ' method ' + method + '\n') print '<p></p>' else: text = StructuredText.gethtml(text) if text[:3] == '<p>': print text[3:] else: print text if method in info['text'].text['methods']: methods_with_text.remove(method) print '</dd></dl>' print '</dd>' if len(methods_with_text) > 0: sys.stderr.write('ERROR: unknown methods ' + str(methods_with_text) + ' for ' + fullWidgetName + '\n') elif sectionName == 'Example': demoFile = '../demos/' + widgetName + '.py' if os.path.isfile(demoFile): print '<dt> <h3>Example</h3></dt><dd>' if gotImage: print 'The image at the top of this manual is a snapshot' print 'of the window (or part of the window) produced' print 'by the following code.<p></p>' else: print 'Example code using %s.<p></p>' % fullWidgetName lines = [] for line in open(demoFile).readlines(): if len(lines) != 0: if line == ('#' * 70) + '\n': # End of Demo class break else: lines.append(line) if line == 'class Demo:\n': lines.append(line) while lines[-1] == '\n': del lines[-1] print '<pre>' escapedText = cgi.escape(''.join(lines)) print StructuredText.untabify(escapedText) print '</pre>' print '</dd>' else: if widgetName not in baseClassList: sys.stderr.write('ERROR: no %s demo for %s\n' % (demoFile, fullWidgetName)) for name, after, relative, text in info['text'].sections: if after and relative == sectionName: sectionsUsed = sectionsUsed + 1 print '<dt> <h3>' + name + '</h3></dt><dd>' print StructuredText.gethtml(text) print '</dd>'