Esempio n. 1
0
def output_gui_html(webpage_path):
    '''Output an HTML page for each non-module help item'''
    icons_relpath = relpath(cellprofiler.icons.__path__[0])
    
    help_text = """
<h2>Using CellProfiler</a></h2>"""
    
    def write_menu(prefix, h, help_text):
        help_text += "<ul>\n"
        for key, value in h:
            help_text += "<li>"
            if hasattr(value, "__iter__") and not isinstance(value, (str, unicode)):
                help_text += "<b>%s</b>"%key
                help_text = write_menu(prefix+"_"+key, value, help_text)
            else:
                cleaned_up_key = re.sub("[/\\\?%\*:\|\"<>\.\+]","",key) # Replace special characters with blanks
                cleaned_up_key = re.sub(" ","_",cleaned_up_key) # Replace spaces with underscores
                file_name = "%s_%s.html" % (prefix, cleaned_up_key)
                fd = open(os.path.join(webpage_path, file_name),"w")
                fd.write("<html style=""font-family:arial""><head><title>%s</title></head>\n" % key)
                fd.write("<body><h1>%s</h1>\n<div>\n" % key)
                # Replace the relative paths to the icons with the relative path to the image dir
                value = value.replace(icons_relpath,'images')
                fd.write(value)
                fd.write("</div></body>\n")
                fd.close()
                help_text += "<a href='%s'>%s</a>\n" % (file_name, key)
            help_text += "</li>\n"
        help_text += "</ul>\n"
        return help_text
        
    help_text = write_menu("Help", MAIN_HELP, help_text)
    help_text += "\n"
    
    return help_text
Esempio n. 2
0
def output_module_html(webpage_path):
    '''Output an HTML page for each module'''
        
    icons_relpath = relpath(cellprofiler.icons.__path__[0])
    all_png_icons = glob(os.path.join(icons_relpath, "*.png"))
    icon_names = [os.path.basename(f)[:-4] for f in all_png_icons]
    
    help_text = """
<h2>Help for CellProfiler Modules</a></h2>
<ul>\n"""
    d = {}
    module_path = webpage_path
    if not (os.path.exists(module_path) and os.path.isdir(module_path)):
        try:
            os.mkdir(module_path)
        except IOError:
            raise ValueError("Could not create directory %s" % module_path)
        
    for module_name in sorted(get_module_names()):
        module = instantiate_module(module_name)
        location = os.path.split(
            module.create_settings.im_func.func_code.co_filename)[0]
        if location == cpprefs.get_plugin_directory():
            continue
        if isinstance(module.category, (str,unicode)):
            module.category = [module.category]
        for category in module.category:
            if not d.has_key(category):
                d[category] = {}
            d[category][module_name] = module
        result = module.get_help()
        if result is None:
            continue
        result = result.replace('<body><h1>','<body><h1>Module: ')
        
        # Replace refs to icons in memory with the relative path to the image dir (see above)
        result = re.sub("memory:",os.path.join("images","").encode('string-escape'),result)        

        # Check if a corresponding image exists for the module
        if module_name in icon_names:
            # Strip out end html tags so I can add more stuff
            result = result.replace('</body>','').replace('</html>','')
            
            # Include images specific to the module, relative to html files ('images' dir)
            LOCATION_MODULE_IMAGES = os.path.join('images','%s.png'%(module_name))
            result += '\n\n<div><p><img src="%s", width="50%%"></p></div>\n'%LOCATION_MODULE_IMAGES
            
            # Now end the help text
            result += '</body></html>'
        fd = open(os.path.join(module_path,"%s.html" % module_name), "w")
        fd.write(result)
        fd.close()
    for category in sorted(d.keys()):
        sub_d = d[category]
        help_text += "<li><b>%s</b><br><ul>\n"%category
        for module_name in sorted(sub_d.keys()):
            help_text += "<li><a href='%s.html'>%s</a></li>\n" % (module_name, module_name)
        help_text += "</ul></li>\n"
    help_text += "</ul>\n"
    return help_text
Esempio n. 3
0
def output_module_html(webpage_path):
    '''Output an HTML page for each module'''

    icons_relpath = relpath(cellprofiler.icons.__path__[0])
    all_png_icons = glob(os.path.join(icons_relpath, "*.png"))
    icon_names = [os.path.basename(f)[:-4] for f in all_png_icons]

    help_text = """
<h2>Help for CellProfiler Modules</a></h2>
<ul>\n"""
    d = {}
    module_path = webpage_path
    if not (os.path.exists(module_path) and os.path.isdir(module_path)):
        try:
            os.mkdir(module_path)
        except IOError:
            raise ValueError("Could not create directory %s" % module_path)

    for module_name in sorted(get_module_names()):
        module = instantiate_module(module_name)
        location = os.path.split(
            module.create_settings.im_func.func_code.co_filename)[0]
        if location == cpprefs.get_plugin_directory():
            continue
        if isinstance(module.category, (str,unicode)):
            module.category = [module.category]
        for category in module.category:
            if not d.has_key(category):
                d[category] = {}
            d[category][module_name] = module
        result = module.get_help()
        if result is None:
            continue
        result = result.replace('<body><h1>','<body><h1>Module: ')

        # Replace refs to icons in memory with the relative path to the image dir (see above)
        result = re.sub("memory:",os.path.join("images","").encode('string-escape'),result)

        # Check if a corresponding image exists for the module
        if module_name in icon_names:
            # Strip out end html tags so I can add more stuff
            result = result.replace('</body>','').replace('</html>','')

            # Include images specific to the module, relative to html files ('images' dir)
            LOCATION_MODULE_IMAGES = os.path.join('images','%s.png'%(module_name))
            result += '\n\n<div><p><img src="%s", width="50%%"></p></div>\n'%LOCATION_MODULE_IMAGES

            # Now end the help text
            result += '</body></html>'
        fd = open(os.path.join(module_path,"%s.html" % module_name), "w")
        fd.write(result)
        fd.close()
    for category in sorted(d.keys()):
        sub_d = d[category]
        help_text += "<li><b>%s</b><br><ul>\n"%category
        for module_name in sorted(sub_d.keys()):
            help_text += "<li><a href='%s.html'>%s</a></li>\n" % (module_name, module_name)
        help_text += "</ul></li>\n"
    help_text += "</ul>\n"
    return help_text
Esempio n. 4
0
def output_gui_html(webpage_path):
    """Output an HTML page for each non-module help item"""
    icons_relpath = relpath(cellprofiler.icons.__path__[0])

    help_text = """
<h2>Using CellProfiler</a></h2>"""

    def write_menu(prefix, h, help_text):
        help_text += "<ul>\n"
        for key, value in h:
            help_text += "<li>"
            if hasattr(value, "__iter__") and not isinstance(value, (str, unicode)):
                help_text += "<b>%s</b>" % key
                help_text = write_menu(prefix + "_" + key, value, help_text)
            else:
                # Replace special characters with blanks
                cleaned_up_key = re.sub('[/\\\?%\*:\|"<>\.\+]', "", key)
                # Replace spaces with underscores
                cleaned_up_key = re.sub(" ", "_", cleaned_up_key)
                file_name = "%s_%s.html" % (prefix, cleaned_up_key)

                fd = open(os.path.join(webpage_path, file_name), "w")
                fd.write("<html style=" "font-family:arial" "><head><title>%s</title></head>\n" % key)
                fd.write("<body><h1>%s</h1>\n<div>\n" % key)

                # Replace the relative paths to the icons with the relative path to the image dir
                value = value.replace(icons_relpath, "images")
                # Replace refs to icons in memory with the relative path to the image dir
                #  Slashes need to be escaped: http://stackoverflow.com/questions/4427174/python-re-bogus-escape-error
                value = re.sub("memory:", os.path.join("images", "").encode("string-escape"), value)

                fd.write(value)
                fd.write("</div></body>\n")
                fd.close()
                help_text += "<a href='%s'>%s</a>\n" % (file_name, key)
            help_text += "</li>\n"
        help_text += "</ul>\n"
        return help_text

    help_text = write_menu("Help", MAIN_HELP, help_text)
    help_text += "\n"

    return help_text