Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.cmm.msu.su/hg/petri_dish/diff/69a4724e7cac/scale.py
Дата изменения: Unknown
Дата индексирования: Fri Feb 28 06:03:00 2014
Кодировка:
petri_dish: scale.py diff

petri_dish

diff scale.py @ 22:69a4724e7cac

added help and statistics
author Yashina Ksenia <ksenia_yashina@kodomo.fbb.msu.ru>
date Thu, 23 Dec 2010 16:58:48 +0300
parents 2df48c61bd42
children
line diff
     1.1 --- a/scale.py	Mon Dec 20 02:38:11 2010 +0300
     1.2 +++ b/scale.py	Thu Dec 23 16:58:48 2010 +0300
     1.3 @@ -4,9 +4,10 @@
     1.4  import petri
     1.5  import random
     1.6  import vector
     1.7 +import webbrowser
     1.8  
     1.9  class IF(object):
    1.10 -    def __init__(self,delay=2,diam=300,num=1,env=1,reprod_a=False,reprod_s=False,life=1):
    1.11 +    def __init__(self,delay=2,diam=300,num=0,env=1,reprod_a=False,reprod_s=False,life=0,stat=True):
    1.12          self.delay=delay
    1.13          self.diam=diam
    1.14          self.num=num
    1.15 @@ -14,18 +15,21 @@
    1.16          self.reprod_s=reprod_s
    1.17          self.reprod_a=reprod_a
    1.18          self.life=life
    1.19 +        self.stat=stat
    1.20  
    1.21      def __repr__(self):
    1.22 -        return "<%s,%s,%s,%s,%s,%s,%s>"%(self.delay,self.diam,self.num,\
    1.23 +        return "<%s,%s,%s,%s,%s,%s,%s,%s>"%(self.delay,self.diam,self.num,\
    1.24                                           self.env,self.reprod_a,\
    1.25 -                                         self.reprod_s,self.life)
    1.26 +                                         self.reprod_s,self.life,self.stat)
    1.27      def mutate(self):
    1.28          for bact in p.bacteria:
    1.29              if not(bact.mutated):
    1.30                  bact.mutated=True
    1.31 +                p.total_mut+=1
    1.32                  return
    1.33  
    1.34      def sbmt(self):
    1.35 +        
    1.36          b=[]
    1.37          submit.config(text="Stop",command=self.stop)
    1.38          scl1.config(state=DISABLED)
    1.39 @@ -33,6 +37,7 @@
    1.40          scl3.config(state=DISABLED)
    1.41          cb1.config(state=DISABLED)
    1.42          cb2.config(state=DISABLED)
    1.43 +        show_stat.config(state=DISABLED)
    1.44          self.num=scl1.get()
    1.45          self.diam=scl2.get()
    1.46          self.life=scl3.get()
    1.47 @@ -49,6 +54,12 @@
    1.48          for bact in b:
    1.49              bact.velocity = bact.rnd_velocity(pi/4*random.randrange(0,8))
    1.50          p.num=self.num
    1.51 +        p.total=self.num
    1.52 +        p.total_max=self.num
    1.53 +        p.total_min=self.num
    1.54 +        p.total_mut=0
    1.55 +        p.s_num=0
    1.56 +        p.a_num=0
    1.57          p.bacteria=b
    1.58          p.radius=self.diam/2
    1.59          p.delta=5
    1.60 @@ -56,15 +67,35 @@
    1.61          p.full_lifetime=self.life
    1.62          self.depict()
    1.63  
    1.64 +    def pop_up(self):
    1.65 +        stat_fr=Toplevel()
    1.66 +        stat_fr.title("Statistics")
    1.67 +        init_stat=LabelFrame(stat_fr,text="Initial parameters")
    1.68 +        init_txt="Number of cells: %s\nDiameter of Petri dish: %s\nCell's lifetime: %s\n"%(self.num,self.diam,
    1.69 +                                                                                           self.life)
    1.70 +        init_txt+="Asexual reproduction allowed: %s\nSexual reproduction allowed: %s"%(self.reprod_a,self.reprod_s)
    1.71 +        init_stat.grid(padx=15,pady=10)
    1.72 +        init_lbl = Label(init_stat,text=init_txt)
    1.73 +        init_lbl.grid(padx=10)
    1.74 +        stat_frame=LabelFrame(stat_fr,text="Statistics")
    1.75 +        stat_frame.grid(padx=15,pady=10)
    1.76 +        stat_txt="Total number of cells: %s\nMaximum number of cells in dish: %s\n"%(p.total,p.total_max)
    1.77 +        stat_txt+="Minimum number of cells in dish: %s\nTotal number of mutated cells: %s\n"%(p.total_min,p.total_mut)
    1.78 +        stat_txt+="Number of asexual reproduction events: %s\nNumber of sexual reproduction events: %s"%(p.a_num,p.s_num)
    1.79 +        stat_lbl = Label(stat_frame,text=stat_txt)
    1.80 +        stat_lbl.grid(padx=10)
    1.81 +
    1.82      def stop(self):
    1.83          c.after_cancel(self.rep)
    1.84          c.delete("all")
    1.85 +        dish=c.create_oval(10,10,self.diam+10,self.diam+10,fill="white")        
    1.86          submit.config(text="Submit",command=self.sbmt)
    1.87          scl1.config(state=NORMAL)
    1.88          scl2.config(state=NORMAL)
    1.89          scl3.config(state=NORMAL)
    1.90          cb1.config(state=NORMAL)
    1.91          cb2.config(state=NORMAL)
    1.92 +        show_stat.config(state=NORMAL)
    1.93  
    1.94      def new_reprod_a(self):
    1.95          self.reprod_a=not(self.reprod_a)
    1.96 @@ -75,25 +106,25 @@
    1.97          return
    1.98  
    1.99      def help(self):
   1.100 -        pass
   1.101 +        url = 'About.html'
   1.102 +        webbrowser.open(url, new=1, autoraise=True)
   1.103  
   1.104 -    def pause(self):
   1.105 -        pass
   1.106 -    
   1.107      def depict(self):
   1.108          c.delete("all")
   1.109          dish=c.create_oval(10,10,self.diam+10,self.diam+10,fill="white")
   1.110          env=scl.get()
   1.111 -        p.step(0.5,int(env),self.reprod_a,self.reprod_s)
   1.112 -        for bact in p.bacteria:
   1.113 -            if bact.mutated:
   1.114 -                color="black"
   1.115 -            else:
   1.116 -                color="white"
   1.117 -            c.create_oval(10+self.diam/2+bact.position.x-p.bact_r,10+self.diam/2+bact.position.y-p.bact_r,\
   1.118 -                          10+self.diam/2+bact.position.x+p.bact_r*2,\
   1.119 -                          10+self.diam/2+bact.position.y+p.bact_r*2,fill=color)
   1.120 -        self.rep=c.after(self.delay,self.depict)
   1.121 +        if p.step(0.5,int(env),self.reprod_a,self.reprod_s):
   1.122 +            for bact in p.bacteria:
   1.123 +                if bact.mutated:
   1.124 +                    color="black"
   1.125 +                else:
   1.126 +                    color="white"
   1.127 +                c.create_oval(10+self.diam/2+bact.position.x-p.bact_r,10+self.diam/2+bact.position.y-p.bact_r,\
   1.128 +                              10+self.diam/2+bact.position.x+p.bact_r*2,\
   1.129 +                              10+self.diam/2+bact.position.y+p.bact_r*2,fill=color)
   1.130 +            self.rep=c.after(self.delay,self.depict)
   1.131 +        else:
   1.132 +            self.stop()
   1.133  
   1.134      def update_scale(widget, times):
   1.135          value = widget.get()
   1.136 @@ -120,7 +151,6 @@
   1.137  controlsmenu.add_command(label="Add mutation", command=intf.mutate)
   1.138  controlsmenu.add_separator()
   1.139  controlsmenu.add_command(label="Exit", command=root.destroy)
   1.140 -#controlmenu.add_command(label="Pause", command=intf.pause)
   1.141  menubar.add_cascade(label="Controls", menu=controlsmenu)
   1.142  
   1.143  helpmenu = Menu(menubar, tearoff=0)
   1.144 @@ -170,6 +200,9 @@
   1.145  btn = Button(chng_frame,text="Add mutation",width=25,command=intf.mutate)
   1.146  btn.grid(row=1,column=0,columnspan=2,pady=10)
   1.147  
   1.148 +show_stat = Button(root,text="Show statistics",width=25,command=intf.pop_up)
   1.149 +show_stat.grid(pady=10,padx=10)
   1.150 +
   1.151  #root.after(intf.delay,intf.depict())
   1.152  
   1.153  mainloop()