Anonymous avatar Anonymous committed e1d1609

move toward dynamic, functional code

Comments (0)

Files changed (1)

 from gimpfu import *
 from string import Template
+from datetime import datetime, date, time
 import gtk
 import os
 import collections
 import re
 import pprint
 
-"""
-in the documentation, but not defined in gimpfu
-PF_REGION:"PF_REGION"
-"""
-VAR_TYPES = {PF_INT8:"PF_INT8",PF_INT16:"PF_INT16",PF_INT32:"PF_INT32",PF_INT:"PF_INT",PF_FLOAT:"PF_FLOAT",PF_STRING:"PF_STRING",PF_VALUE:"PF_VALUE",PF_COLOR:"PF_COLOR",PF_COLOUR:"PF_COLOUR",PF_IMAGE:"PF_IMAGE",PF_LAYER:"PF_LAYER",PF_CHANNEL:"PF_CHANNEL",PF_DRAWABLE:"PF_DRAWABLE",PF_TOGGLE:"PF_TOGGLE",PF_BOOL:"PF_BOOL",PF_RADIO:"PF_RADIO",PF_SLIDER:"PF_SLIDER",PF_SPINNER:"PF_SPINNER",PF_ADJUSTMENT:"PF_ADJUSTMENT",PF_FONT:"PF_FONT",PF_FILE:"PF_FILE",PF_BRUSH:"PF_BRUSH",PF_PATTERN:"PF_PATTERN",PF_GRADIENT:"PF_GRADIENT",PF_PALETTE:"PF_PALETTE"}
-
-PROC_TYPES = {PLUGIN:"PROC_PLUG_IN",EXTENSION:"PROC_EXTENSION",TEMPORARY:"PROC_TEMPORARY"}
-
 PROC_CSS = """html, body
 {
         width:100%;
 body
 {
         width:578px;
+        max-width:578px;
         margin:24px auto 0px 36px;
 }
 
                                 </tr>
 
 """
-INDEX_TEMPLATE = """
+INDEX_TEMPLATE = """<!DOCTYPE html>
+<html>
+        <head>
+                <title>pdb: index</title>
+
+                <meta name="description" content="">
+                <meta name="author" content="Code Fox">
+                <meta charset="UTF-8">
+
+                <link rel="stylesheet" type="text/css" href="pdb/main.css">
+
+                </style>
+        </head>
+        <body>
+                <div style="display:inline-block;">
+                        <h1>Gimp Plugin Database</h1>
+                        <div id="author">
+                                <span class="date">
+                                        ${date}
+                                </span>
+                        </div>
+                </div>
+                ${body}
+        </body>
+</html>
 """
 
 MessageBox = ctypes.windll.user32.MessageBoxA
 
         return None
 
+
 def var_type(t) :
-        if (t not in VAR_TYPES) :
+        """
+        in the documentation, but not defined in gimpfu
+        PF_REGION:"PF_REGION"
+        """
+        if (t not in {PF_INT8:"PF_INT8",PF_INT16:"PF_INT16",PF_INT32:"PF_INT32",PF_INT:"PF_INT",PF_FLOAT:"PF_FLOAT",PF_STRING:"PF_STRING",PF_VALUE:"PF_VALUE",PF_COLOR:"PF_COLOR",PF_COLOUR:"PF_COLOUR",PF_IMAGE:"PF_IMAGE",PF_LAYER:"PF_LAYER",PF_CHANNEL:"PF_CHANNEL",PF_DRAWABLE:"PF_DRAWABLE",PF_TOGGLE:"PF_TOGGLE",PF_BOOL:"PF_BOOL",PF_RADIO:"PF_RADIO",PF_SLIDER:"PF_SLIDER",PF_SPINNER:"PF_SPINNER",PF_ADJUSTMENT:"PF_ADJUSTMENT",PF_FONT:"PF_FONT",PF_FILE:"PF_FILE",PF_BRUSH:"PF_BRUSH",PF_PATTERN:"PF_PATTERN",PF_GRADIENT:"PF_GRADIENT",PF_PALETTE:"PF_PALETTE"}) :
                 return "unknown"
 
         return VAR_TYPES[t]
 
 def proc_type(t) :
-        if (t not in PROC_TYPES) :
+        if (t not in {PLUGIN:"PROC_PLUG_IN",EXTENSION:"PROC_EXTENSION",TEMPORARY:"PROC_TEMPORARY"}) :
                 return "unknown"
 
         return PROC_TYPES[t]
 
         return None
 
-def fname(pname) :
-        return "%s.html"%(slugify(pname))
+def file_name(name) :
+        return "%s.html"%(slugify(name))
+
+def plain_table(lst, heading=None, length=5):
+        if (None == heading) :
+                heading = "sentinel"
+
+        buf = ""
+        buf += Template('\t\t<a id="${heading}"><h4>${heading}</h4></a>\n').safe_substitute({"heading":heading})
+        buf += '\t\t<table>\n\t\t\t<tr>\n'
+        count = 0
+        for item in lst:
+                count += 1
+                # special
+                buf += Template('\t\t\t\t<td><a href="pdb/${file}.html">${item}</a></td>\n').safe_substitute({"file":file_name(item), "item":item[len(heading):]})
+                # special
+                if 0 == (count % length):
+                        buf += '\t\t\t</tr>\n\t\t\t<tr>\n'
+
+        buf += '\t\t\t</tr>\n\t\t</table>\n\t\t<nav><a href="#top">top</a></nav>\n'
+
+        if (0 == count) :
+                return ""
+
+
+
+        return buf
+
+def headings(procs, root, delimiter="-", minCount=10, minDepth=0):
+
+        MessageBox = ctypes.windll.user32.MessageBoxA
+
+        hdls = list()
+        namespaces = dict()
+
+        # initialize namespaces
+        for ns in procs:
+                namespaces[ns] = 1;
+
+        with open(os.path.join(root,"fu.log"), "w+") as f :
+
+                loop = 0
+                # while namespaces can be further reduced
+                while 0 != len(namespaces):
+                        loop += 1
+
+                        f.write("loop:%d\n"%(loop))
+                        f.write("\tbegin\n")
+                        f.write("\thndls:\n%s\n"%(str(hdls)))
+                        f.write("\tnamespaces:\n%s\n"%(str(namespaces)))
+
+                        # append any namespace with >= minCount entries
+                        hdls.extend(filter(lambda ns: ns not in hdls,filter(lambda ns: namespaces[ns] >= minCount, namespaces)))
+                        # remove items from namespaces
+                        namespaces = dict((k, v) for (k, v) in namespaces.items() if(v < minCount))
+
+                        f.write("\tafter minCount\n")
+                        f.write("\thndls:\n%s\n"%(str(hdls)))
+                        f.write("\tnamespaces:\n%s\n"%(str(namespaces)))
+
+                        # append any namespace that cant be decreased further
+                        hdls.extend(filter(lambda ns: ns not in hdls,filter(lambda ns: minDepth >= ns.count(delimiter),namespaces)))
+                        # remove items from namespaces
+                        namespaces = dict((k, v) for (k, v) in namespaces.items() if(minDepth < k.count(delimiter)))
+
+                        f.write("\tafter minDepth\n")
+                        f.write("\thndls:\n%s\n"%(str(hdls)))
+                        f.write("\tnamespaces:\n%s\n"%(str(namespaces)))
+
+                        # decrease all namespaces by one indent
+                        tmp = dict()
+                        for ns in namespaces:
+                                ns = reduce(lambda x,y: x + delimiter + y, ns.split(delimiter)[:-1])
+                                if(ns in tmp):
+                                        tmp[ns] += 1
+                                else:
+                                        tmp[ns] = 1
+
+                        namespaces = tmp
+
+                        f.write("\tafter decrease\n")
+                        f.write("\tnamespaces:\n%s\n"%(str(namespaces)))
+
+        hdls.sort(reverse=True)
+        MessageBox(0,"len:%d\nout:\n%s\n"%(len(hdls),str(hdls)),"title",0)
+
+        return map(lambda x: x + "-", hdls);
+
+def index(procs, root) :
+        buf = ""
+        for heading in headings(procs, root) :
+
+                buf += plain_table(filter(lambda name: name.startswith(heading),procs), heading)
+                procs = filter(lambda name: not name.startswith(heading),procs)
+
+        buf += plain_table(procs)
+
+
+        return buf
 
 def dump_pdb() :
 
         procs = gimp.pdb.query()
         procs.sort()
 
-        with open(os.path.join(root,"pdb","procs.txt"), "w+") as f :
-                f.write("whattttt\n")
-                for p in procs:
-                        f.write(p + "\n")
+        with open(os.path.join(root,"index.html"), "w+") as f :
+                f.write(Template(INDEX_TEMPLATE).safe_substitute({"date":datetime.now().strftime("%A, %d. %B %Y %I:%M%p"),"body":index(procs, root)}))
 
 
         """
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.