Ejemplo n.º 1
0
def test(fontdir=".", outfile="/tmp/out.png"):
    from .Choose import Choose
    from .Repeat import Repeat
    from .RepeatDelimited import RepeatDelimited
    from .Optional import Optional
    from .Choose import Choose
    from .Sequence import Sequence
    from skimpyGimpy import canvas
    c = canvas.Canvas()
    c.addFont("propell", fontdir + "/propell.bdf")
    nonterm = "ARGUMENTS"
    section = Nonterminal("SECTION", c)
    setid = Nonterminal("SETID", c)
    setcgi = Nonterminal("SETCGI", c)
    page = Nonterminal("PAGE", c)
    complexArg = Choose([section, setid, setcgi], c)
    complexArgs = Repeat(complexArg, c)
    definition = Optional(Choose([page, complexArgs], c), c)
    D = Define(nonterm, definition, c)
    D.drawAt(0, 0)
    name = Nonterminal("name", c)
    json = Nonterminal("json", c)
    pair = Sequence([name, ":", json], c)
    pairs = Optional(RepeatDelimited(pair, ",", c), c)
    D2 = Define(["ENV", "PAIRS"], pairs, c)
    D2.drawAt(0, 200)
    pageenv = Optional(["PAGE", "ENV"], c)
    pageparams = Optional(["PAGE", "PARAMS"], c)
    pagecomponents = Optional(["PAGE", "COMPONENTS"], c)
    D3 = Define("PAGE", [pageenv, pageparams, pagecomponents], c)
    D3.drawAt(0, 350)
    c.dumpToPNG(outfile)
    print("output to", outfile)
Ejemplo n.º 2
0
def test3(fontdir=".", outfile="/tmp/out3.png"):
    from skimpyGimpy import canvas
    from .entity import Entity
    c = canvas.Canvas()
    c.addFont("propell", fontdir+"/propell.bdf")
    d = Drawing(c)
    d.addEntity("EMPLOYEE", 0, 0)
    d.addEntity("DEPT", 200, 0)
    d.addEntity("PROJECT", 400, 0)
    d.addRelationship(("WORKS", "FOR"), 100, 100)
    d.addRelationship(("MANAGES"), 100, -50)
    d.addRelationship("WORKS-ON", 300, -100)
    d.addRelationship("OWNS", 300, 0)
    d.addAttribute("ssn", "EMPLOYEE", 0, -50, iskey=True)
    d.participate("DEPT", "OWNS", "dept", 1, "many")
    d.participate("PROJECT", "OWNS", "p", 1, "many")
    d.participate("EMPLOYEE", ("WORKS", "FOR"), "EMP", 1, 1)
    d.participate("DEPT", ("WORKS", "FOR"), "dept", 0, "many")
    d.participate("EMPLOYEE", "MANAGES", "EMP", 0, 1)
    d.participate("DEPT", "MANAGES", "dept", 1, 1)
    d.participate("EMPLOYEE", "WORKS-ON", "emp", 0, "many")
    d.participate("PROJECT", "WORKS-ON", "proj", 0, "many")
    d.addAttribute("enum", "EMPLOYEE", 0,-100)
    d.addAttribute("first", "EMPLOYEE", 0,50)
    d.addAttribute("last", "EMPLOYEE", 0,100)
    d.addAttribute("dnum", "DEPT", 200, -50, iskey=True)
    d.addAttribute("title", ("WORKS", "FOR"), 100, 150)
    d.addAttribute("since", "OWNS", 300, 60)
    d.prepare()
    d.draw()
    c.dumpToPNG(outfile)
    print("test output to", outfile)
Ejemplo n.º 3
0
def plotStates(outfile="AllStates.png", jsFile="AllStates.js", scaleFactor=5.0):
    import random
    from skimpyGimpy import canvas
    (idDict, fipsDict) = getStates()
    c = canvas.Canvas()
    c.setBackgroundCallback("out")
    c.setCap(0)
    c.setWidth(1)
    c.addFont("propell", "/skimpyGimpy_1_2/fonts/mlmfonts/propell.bdf")
    c.setFont("propell", 1)
    colors = [ ( int(random.uniform(0,128)), int(random.uniform(128,255)), int(random.uniform(0,255) )) for
               x in range(100)]
    colors2 = [ ( int(random.uniform(128,256)), int(random.uniform(0,128)), int(random.uniform(0,128) )) for
               x in range(40)]
    count = 0
    for fipsNum in list(fipsDict.keys()):
        borders = fipsDict[fipsNum]
        border0 = borders[0]
        colorV = random.choice(colors)
        c.setColorV( colorV )
        name = border0.name
        print("plotting", fipsNum, name, colorV)
        c.setCallBack(border0.name)
        for border in borders:
            border.replot(scaleFactor)
            border.plotLines(c)
        #c.setColorV(random.choice(colors2))
        #state.label(c)
        count += 1
        dumpBordersToPNG(borders, name, colorV)
    c.dumpToPNG(outfile)
    c.dumpJavascript(jsFile, imageName="AllStates", functionName="onState")
Ejemplo n.º 4
0
def test(fontdir=".", outfile="/tmp/out.png"):
    from skimpyGimpy import canvas
    c = canvas.Canvas()
    c.addFont("propell", fontdir + "/propell.bdf")
    l = Literal.Literal(["test", "literal"], c)
    r = Repeat(l, c)
    r.drawAt(100, -100)
    c.dumpToPNG(outfile)
    print("test output to", outfile)
Ejemplo n.º 5
0
def test(fontdir=".", outfile="/tmp/out.png"):
    from skimpyGimpy import canvas
    c = canvas.Canvas()
    c.addFont("propell", fontdir + "/propell.bdf")
    l = Nonterminal("test nonterminal", c)
    l2 = Nonterminal(["another", "test", "nonterminal"], c)
    l.drawAt(20, 60, test=True)
    l2.drawAt(-20, -20, test=True)
    c.dumpToPNG(outfile)
    print("test output to", outfile)
Ejemplo n.º 6
0
def test(fontdir=".", outfile="/tmp/out.png"):
    from skimpyGimpy import canvas
    c = canvas.Canvas()
    c.setColor(55, 55, 95)
    c.addFont("propell", fontdir + "/propell.bdf")
    l = Literal.Literal("test literal", c)
    l2 = Literal.Literal(["another", "test literal"], c)
    ch = Choose([l, l2], c)
    l3 = Literal.Literal("nothing", c)
    ch2 = Choose([ch, l3, l2], c)
    ch2.drawAt(120, 190)
    c.dumpToPNG(outfile)
    print("test output to", outfile)
Ejemplo n.º 7
0
def test(fontdir=".", outfile="/tmp/out.png"):
    from skimpyGimpy import canvas
    c = canvas.Canvas()
    c.addFont("propell", fontdir + "/propell.bdf")
    #c.setFont("propell", 1.0)
    #c.setColor(55,55,55)
    #c.centerText(0,0,"hi there!")
    l = Literal("test literal", c)
    l2 = Literal(["another", "test", "literal"], c)
    l.drawAt(120, 160, test=True)
    l2.drawAt(-120, -120, test=True)
    c.dumpToPNG(outfile)
    print("test output to", outfile)
Ejemplo n.º 8
0
def test(fontdir=".", outfile="/tmp/out.png"):
    from .Choose import Choose
    from .Repeat import Repeat
    from skimpyGimpy import canvas
    c = canvas.Canvas()
    c.addFont("propell", fontdir + "/propell.bdf")
    l = Literal.Literal(["test", "literal"], c)
    l2 = Literal.Literal(["another", "test", "literal"], c)
    ch = Choose([l, l2], c)
    l3 = Repeat(Literal.Literal("nothing", c), c)
    ch2 = Sequence([ch, l3, l2], c)
    ch2.drawAt(20, 100)
    c.dumpToPNG(outfile)
    print("test output to", outfile)
Ejemplo n.º 9
0
def test(fontdir=".", outfile="/tmp/out.png"):
    from skimpyGimpy import canvas
    c = canvas.Canvas()
    c.addFont("propell", fontdir+"/propell.bdf")
    c.addFont("propell", fontdir+"/atari-small.bdf")
    #c.setFont("propell", 1.0)
    #c.setColor(55,55,55)
    #c.centerText(0,0,"hi there!")
    l = Entity("test literal", c, 120, 160)
    l2 = Entity(["another", "test", "literal"], c, -120, -120)
    l.draw()
    l2.draw()
    c.dumpToPNG(outfile)
    print("test output to", outfile)
Ejemplo n.º 10
0
def dumpBordersToPNG(borders, name, colorV):  
    from skimpyGimpy import canvas
    filename = name.lower()+".png"
    allcoords = []
    for border in borders:
        allcoords.extend(border.pairs)
    mE = maxExtent(allcoords)
    scaleFactor = 100.0/mE
    print(filename, scaleFactor)
    c = canvas.Canvas()
    c.setColorV(colorV)
    for border in borders:
        border.replot(scaleFactor)
        border.plotLines(c)
    c.dumpToPNG(filename)
Ejemplo n.º 11
0
def test1():
    f = open(filename)
    state = stateBoundary()
    state.parse(f)
    print("got", len(state.d), "points")
    state.prepare()
    print("dimensions", (state.minlat, state.maxlat), (state.minlon, state.maxlon), (state.maxlat-state.minlat,
                                                                                     state.maxlon-state.minlon))
    state.preplot()
    print("plot points", len(state.plotpoints))
    from skimpyGimpy import canvas
    c = canvas.Canvas()
    c.setColor(255,0,0)
    c.setCap(0)
    c.setWidth(1)
    state.plotLines(c)
    c.dumpToPNG("alaska.png")
Ejemplo n.º 12
0
def test(outfile="/tmp/out.png"):
    from skimpyGimpy import canvas
    c = canvas.Canvas()
    c.setColor(0, 0, 0)
    (upx, upy) = (0, 1)
    (rightx, righty) = (1, 0)
    delta = 8
    x = 0
    y = 0
    for orientation in range(4):
        x = 0
        for minimum in MINS:
            for maximum in MAXS:
                card = Cardinality(minimum, maximum, upx, upy, rightx, righty,
                                   delta, c)
                card.drawAt(x, y, True)
                x += 5 * delta
        # rotate
        (upy, upx, rightx, righty) = (righty, -rightx, upx, upy)
        y += 5 * delta
    c.dumpToPNG(outfile)
    print("test output to", outfile)
Ejemplo n.º 13
0
def getc(fontdir=fontdir):
    c = canvas.Canvas()
    c.addFont("propell", fontdir + "/propell.bdf")
    #c.addFont("propell", fontdir+"/5x7.bdf")
    return c