Пример #1
0
def toNumber(args,env):
    if len(args) != 1:
        raise ArgumentError
    for item in NI.interpret(args[0], env):
        if ((not item in NI.map_num) and item != u'.' and item != u'-'):
            raise NotANumber
    return (NI.interpret(args[0], env))
Пример #2
0
def writefile(args,env):
    id = args[0]
    file = NI.env_lookup(id,env)
    for items in args[1]:
        a = NI.interpret(items,env)
        file.write(a)
    return
Пример #3
0
def writefileln(args,env):
    id = args[0]
    file = NI.env_lookup(id,env)
    for items in args[1]:
        file.write(NI.interpret(items,env))
    file.write(u"\n")
    return
Пример #4
0
def keyboardgetkeys(args,env):
    if args:
        raise ArgumentError()
    global keyboard_keys
    if keyboard_keys:
        return NI.to_unicode (keyboard_keys.pop(0))
    else:
        return NI.to_unicode(0)
Пример #5
0
def replaceString(args, env):
    if len(args) != 3:
        raise ArgumentError
    s = NI.interpret(args[0], env)
    os = NI.interpret(args[1], env)
    ns = NI.interpret(args[2], env)
    if type(s) != type(u'ल') \
        or type(u'ल') != type(os)\
        or type(ns) != type(u'ल'):
        raise ArgumentError
    return s.replace(os, ns)
Пример #6
0
def breakString(args, env):
    if (len(args) != 2):
        raise ArgumentError

    string = NI.interpret(args[0], env)
    pattern = NI.interpret(args[1], env)

    # type checking we accept only unicode string
    if type(string) != type(u'ल') or type(u'ल') != type(pattern):
        raise ArgumentError

    return string.split(pattern)
Пример #7
0
def drawpoint(args):
    if len(args)<4 or len(args) > 6:
        raise ArgumentError()
    argnum = len(args)
    c1 = int(NI.to_ascii(args[2]))
    c2 = int(NI.to_ascii(args[3]))
    width = int(NI.to_ascii(args[4])) if argnum>4 else None
    outline = to_col[args[5]] if argnum>5 else None
    root,canvas = args[0]
    canvas.create_rectangle(c1,c2,c1,c2,width=width,outline=outline)
    root.update()
    return
Пример #8
0
 def RunProgram(self, e):
     try:
         input = self.tc2.GetValue()
         lexer = lex.lex(module=NepL)
         parser = yacc.yacc(module=NepP)
         ast = parser.parse(input, lexer=lexer)
         #print ast
         self.tc3.SetValue('')
         self.running = True
         NepI.interpret(ast, None, self)
         NepI._envclear()
     except KeyboardInterrupt, e:
         self.tc3.SetValue(self.tc3.GetValue() + u"\nबन्द गरियो\n")
Пример #9
0
 def RunProgram(self, e):
     try:
         input = self.tc2.GetValue()
         lexer = lex.lex(module=NepL)
         parser = yacc.yacc(module=NepP)
         ast = parser.parse(input, lexer=lexer)
         #print ast
         self.tc3.SetValue('')
         self.running = True
         NepI.interpret(ast,None,self)
         NepI._envclear()
     except KeyboardInterrupt,e:
         self.tc3.SetValue(self.tc3.GetValue() + u"\nबन्द गरियो\n")
Пример #10
0
def drawtext(args):
    if len(args)<5 or len(args) > 7:
        raise ArgumentError()
    argnum = len(args)
    c1 = int(NI.to_ascii(args[2]))
    c2 = int(NI.to_ascii(args[3]))
    text = args[4].encode("UTF8")
    size = int(NI.to_ascii(args[5])) if argnum>5 else None
    color = to_col[args[6]] if argnum>6 else None
    font = "a " + str(size) if size is not None else "0 "
    root,canvas = args[0]
    canvas.create_text(c1,c2,text=text,font=font,fill=color,anchor="nw")
    root.update()
    return
Пример #11
0
def drawline(args):
    'requires the canvas, 4 coords compulsory and width and foreground color optional'
    if len(args) < 6 or len(args) > 8:
        raise ArgumentError()
    argnum = len(args)
    root,canvas = args[0]
    c1 = int(NI.to_ascii(args[2]))
    c2 = int(NI.to_ascii(args[3]))
    c3 = int(NI.to_ascii(args[4]))
    c4 = int(NI.to_ascii(args[5]))
    width = int(NI.to_ascii(args[6])) if argnum > 6 else None
    fill = to_col[args[7]] if argnum>7 else None
    canvas.create_line(c1,c2,c3,c4,width=width,fill=fill)
    canvas.update()
    return
Пример #12
0
def drawcircle(args):
    'requres canvas, 2 coords, radius compulsory; width, outline, fill optional'
    if len(args) < 5 or len(args) > 8:
        raise ArgumentError()
    argnum = len(args)
    root,canvas = args[0]
    x = int(NI.to_ascii(args[2]))
    y = int(NI.to_ascii(args[3]))
    r = int(NI.to_ascii(args[4]))
    width = int(NI.to_ascii(args[5])) if argnum>5 else None
    outline = to_col[args[6]] if argnum>6 else None
    fill = to_col[args[7]] if argnum>7 else None
    canvas.create_oval(x-r,y-r,x+r,y+r,width=width,fill=fill,outline=outline)
    canvas.update()
    return
Пример #13
0
def cleargraphics(args,env):
    if len(args) != 1:
        raise ArgumentError()
    root,canvas = NI.env_lookup(args[0],env)
    canvas.delete(ALL)
    root.update()
    return
Пример #14
0
def isNumber(args,env):
    if len(args) != 1:
        raise ArgumentError
    for item in NI.interpret(args[0], env):
        if ((not item in NI.map_num) and item != u'.' and item != u'-'):
            return u'०'
    return u'१'
Пример #15
0
def closefile(args,env):
    id = args[0]
    file = NI.env_lookup(id,env)
    if (isinstance(file,tuple)):
        file[0].close()
    else:
        file.close()
Пример #16
0
def showgraphics(args,env):
    if len(args) != 1:
        raise ArgumentError()
    root,canvas = NI.env_lookup(args[0],env)
    root.deiconify()
    root.update()
    return
Пример #17
0
def readfile(args,env):
    id = args[0]
    file,filegen = NI.env_lookup(id,env)
    try:
        a = filegen.next()
        return a[:-1]
    except StopIteration:
        return None
Пример #18
0
def openfile(args,env):
    filename = NI.interpret(args[0],env)
    mode = NI.interpret(args[1],env)
    if mode == u'लेख्न':
        return codecs.open(filename,"w",encoding="UTF8")
    elif mode == u'पढ्न':
        if not os.path.exists(filename):
            raise IOError
            #return a generator, then we'll just do writes

        #return the file, but also save the generator so as to use it later
        file = codecs.open(filename,"r",encoding="UTF8")
        filename += u"generator"
        gen = (i for i in file.readlines())
        return file,gen

    elif mode == u'जोड्न':
        return codecs.open(filename,"a",encoding="UTF8")
Пример #19
0
def drawgraphics(args,env):
    interpreted_args = [NI.env_lookup(args[0],env)]
    args = args[1:] #discard the root/canvas info
    for arg in args:
        if isinstance(arg,tuple) or isinstance(arg,list):
            interpreted_args.append(NI.interpret(arg))
        else:
            interpreted_args.append(arg)
    if interpreted_args[1] == u"गोलो":
        drawcircle(interpreted_args)
    elif interpreted_args[1] == u"कोठा":
        drawrectangle(interpreted_args)
    elif interpreted_args[1] == u"लाइन":
        drawline(interpreted_args)
    elif interpreted_args[1] == u"डट":
        drawpoint(interpreted_args)
    elif interpreted_args[1] == u"शब्द":
        drawtext(interpreted_args)
    return
Пример #20
0
def initgraphics(args,env):
    root = Tk()
    if len(args) < 3:
        raise ArgumentError()

    name = NI.interpret(args[0],env)
    name = name.encode('UTF8')
    height = int(NI.to_ascii(NI.interpret(args[1],env)))
    width = int(NI.to_ascii(NI.interpret(args[2],env)))
    root.title(name)
    root.configure(height=height, width=width)  #set width and height
    root.resizable(0,0)                         #disable resizing
    canvas = Canvas(root,width=width,height=height)
    canvas.pack(fill='both')

    #hide the windows
    root.withdraw()
    root.bind("<Key>",keyboardhandler)
    return root,canvas
Пример #21
0
def findString(args, env):
    if (len(args) < 2 or len(args) > 4):
        raise ArgumentError
    string = NI.interpret(args[0], env)
    pattern = NI.interpret(args[1], env)
    begin = (len(args)>2) and NI.interpret(args[2], env) or u'०'
    end =   (len(args)>3) and NI.interpret(args[3], env) or u'०'

    if type(string) != type(u'ल') \
       or type(u'ल') != type(pattern) \
       or type(u'ल') != type(pattern) \
        or type(u'ल') != type(pattern):
        raise ArgumentError

    begin = int(NI.to_ascii(begin))
    end = int(NI.to_ascii(end))
    
    if (end != 0):
        return NI.get_key_from_value(NI.map_num, string.find(pattern, begin, end))
    return NI.to_unicode(string.find(pattern, begin))
Пример #22
0
def count(args, env):
    # if (!args) raise ArgumentError
    if (len(args) != 1):
        raise ArgumentError
    return NI.to_unicode(len(NI.interpret(args[0],env)))
Пример #23
0
def trimString(args,env):
    if len(args) != 1:
        raise ArgumentError
    return NI.interpret(args[0]).strip(" ")
Пример #24
0
def hidegraphics(args,env):
    if len(args) != 1:
        raise ArgumentError()
    root,canvas = NI.env_lookup(args[0],env)
    root.withdraw()
    return
Пример #25
0
def closegraphics(args,env):
    if len(args) != 1:
        raise ArgumentError()
    root,canvas = NI.env_lookup(args[0],env)
    root.destroy()
    return
Пример #26
0
def squareRoot(args, env):
    if len(args) != 1:
        raise ArgumentError
    return NI.to_unicode(math.sqrt(NI.to_ascii(NI.interpret(args[0], env))))
Пример #27
0
def randomNumber(args, env):
    return NI.to_unicode(int(random.random()*1000))
Пример #28
0
def joinString(args, env):
    return ''.join([NI.interpret(args[0], env), NI.interpret(args[1], env)])