コード例 #1
0
ファイル: clockthree.py プロジェクト: rupello/ClockTHREEjr
def map(style):
    wtfpath = findwtf(style)
    if wtfpath is not None:
        data = Simulate.readwtf(wtfpath)
        return clockwords.data2json(data)
    else:
        abort(404)
コード例 #2
0
ファイル: wtfhelpers.py プロジェクト: rupello/ClockTHREEjr
def loadwtfs(folder):
    """ load wtfs in folder"""
    wtfbyname = {}
    for wtfpath in wtffiles(folder):
        try:
            name = wtfname(wtfpath)
            wtfdata = Simulate.readwtf(wtfpath)
            wtfbyname[name] = {}
            wtfbyname[name]['wtfpath'] = wtfpath
            wtfbyname[name]['wtfdata'] = wtfdata
        except Exception as exc:
            print exc

    return wtfbyname
コード例 #3
0
ファイル: clockthree.py プロジェクト: rupello/ClockTHREEjr
def cells(style):
    wtfpath = findwtf(style)
    if wtfpath is not None:
        fontname = request.args.get('font')
        try:
            fontsize = int(request.args.get('fontsize','30'))
        except ValueError:
            fontsize = 30
        data = Simulate.readwtf(wtfpath)
        return render_template('cells.html',
                               cells=clockface.build_cells(fontpath=findfontpath(style,fontname),
                                                           fontsize=fontsize,
                                                           style=data['letters'],
                                                           case=lower),
                               style=style,
                               fontname=fontname,
                               fontsize=fontsize)
    else:
        abort(404)
コード例 #4
0
ファイル: clockthree.py プロジェクト: rupello/ClockTHREEjr
def clockfaceimg(style):
    wtfpath = findwtf(style)
    if wtfpath is not None:
        data = Simulate.readwtf(wtfpath)
        fgcolor = request.args.get('fg', '#303030')
        fontname = request.args.get('font')
        try:
            fontsize = int(request.args.get('fontsize','30'))
        except ValueError:
            fontsize = 30
        img = clockface.drawclock(fontpath=findfontpath(style,fontname),
                                    fontsize=fontsize,
                                    fgcolor=fgcolor,
                                    bgcolor=clockface.BLACK,
                                    style=data['letters'],
                                    case=lower,
                                    drawLEDs=False)
        io = StringIO.StringIO()
        img.save(io, format='JPEG')
        return Response(io.getvalue(), mimetype='image/jpeg')
    else:
        abort(404)
コード例 #5
0
ファイル: clockface.py プロジェクト: rupello/ClockTHREEjr
            
            cells.append({'id'    :'%s%d'%(chr(97+i),j),
                          'title' :'%s %d'%(chr(97+i),j),
                          'left'  : x,
                          'top'   : y,
                          'width' : text_width + text_off_x,
                          'height' : asc+desc,
                          })

    del draw
    return cells


if __name__ == '__main__':

    data = Simulate.readwtf('langs/Hebrew_v1.wtf')
    data = Simulate.readwtf('langs/German_v1.wtf')
    #data = Simulate.readwtf('langs/English_v3.wtf')
    fontpath = r"./fonts/FreeSans.ttf"
    #fontpath = r'c:\windows\fonts\tahoma.ttf'
    #fontpath = r'c:\windows\fonts\mriamc.ttf'
    fontsize = 40
    build_cells(fontpath=fontpath,
                fontsize=fontsize,
                style=data['letters'],
                case=lower)


    img = drawclock(fontpath=fontpath,
                    fontsize=fontsize,
                    fgcolor=PALEYELLOW,
コード例 #6
0
ファイル: clockwords.py プロジェクト: rupello/ClockTHREEjr
import numpy

import Simulate

def rowcol2div(row,col):
    "returns div id ef '#a0' for row=0, col=0, '#b1' for col=1, row=2  etc.."
    return '#{}{}'.format(chr(97+col),row)

def makeworddivs(data):
    "return a list of jquery selectors for each word"
    worddivs=[]
    for i,w in enumerate(data['words']):
        row = data['rows'][i]    # the row index of w
        col = data['cols'][i]    # the starting column index of w
        wlen = data['lens'][i]   # the length of w (in leds)
        worddivs.append(','.join([rowcol2div((col+offset),row) for offset in range(wlen)]))
    return worddivs

def makesentences(data):
    "return a list of word indeces for each sentence"
    return [(numpy.where(sentence)[0]).tolist() for sentence in data['data']]

def data2json(data):
    worddivs = makeworddivs(data)
    sentences = makesentences(data)
    return json.dumps({'words':worddivs,'sentences':sentences})

if __name__ == '__main__':
    data = Simulate.readwtf('langs/English_v2.wtf')
    print data2json(data)[:100]