home *** CD-ROM | disk | FTP | other *** search
Wrap
from math import sqrt,pi,sin,cos,tan,cosh,sinh,tanh,atan,asin,acos,atan2,degrees,radians,e,log,log10 last_dms = "" dic_dms = {"░":"'","'":"\"","\"":"░","":"░"} def Focus():D.SetFocus();D.SelStart = len(D.Text) def KeyPress(S, K): global last_dms if K.Value in "+-*/": last_dms = "" if ord(K.Value) == 13: K.Value = None Eval(1) def Key(S): global last_dms c = S.Caption T = D.Text if c == "DMS": if T == "": Focus();return l = T[-1] if l in "░'\"": D.Text = T[:-1] + dic_dms[l] else: if "░" in T: last_dms = dic_dms[last_dms] else: last_dms = "░" D.Text += last_dms else: if not c in "0123456789": last_dms = "" if len(c) > 2 or c == "ln": c += "(" if c == "¼": D.Text = T[:-1] elif c == "AC": D.Text = "" else: D.Text += {"e":"e^","╓":"sqrt(","p":"pi","EE":"E","Log(":"Log("}.get(c, c.lower()) Focus() def Eval(S): global last_dms D.Font.Color = 0 if S != 1 and not "=" in D.Text: return D.Text = s = D.Text.replace("=", "") dms = "░" in s or "'" in s or "\"" in s rp = {"░":"*1.0+","'":"/60.0+","\"":"/3600.0",",":".","▓":"**2","^":"**","%":"*0.01","/":"*1.0/","û":"-","deg(":"degrees(","rad(":"radians(","Log(":"log10(","ln(":"log("} for k in rp: s = s.replace(k, rp[k]) if s[-1] == "+": s = s[:-1] try: R = str(eval(s)) if dms: R = float(R) d = int(R) R = (R - d) * 60 m = int(R) s = int((R - m) * 60) D.Text = "%d░ %d' %d\"" %(d, m, s) else: D.Text = R last_dms = "" except: D.Font.Color = 0x000000CC Focus() f = CreateComponent("TForm", None) f.SetProps(Position="poMainFormCenter", Width=510, Height=300, Caption="Calculatrice BankPerfect", BorderStyle="bsSingle", BorderIcons=["biSystemMenu"]) f.Font.Name = "Arial" f.Font.Size = 11 D = CreateComponent("TEdit", f) D.SetProps(Parent=f, Left=20, Top=20, Width=470, Color = 0x00CEFFF4, OnChange=Eval, OnKeyPress=KeyPress) for i, c in enumerate(["AC","¼","╓","DMS","EE","cos","Acos","cosH","7","8","9","/","%","sin","Asin","sinH","4","5","6","*","^","tan","Atan","tanH","1","2","3","û","(","Deg","Rad","p",".","0","=","+",")","ln","Log","e"]): p = CreateComponent("TBitBtn", f) p.SetProps(Parent=f, Left=20+60*(i%8), Top=60+40*(i/8), Width=50, Height=30, Caption=c, OnClick=Key) if c in "lnLoge": p.Font.Color = 0x00CC0000 elif c in "AtanHAcosHAsinHDegRadp": p.Font.Color = 0x00007700 elif c in "AC¼+û*/=╓DMS%^EE()": p.Font.Color = 0x000000CC if c in "¼╓p": p.Font.Name = "Symbol" f.ShowModal()