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

petri_dish

annotate scale.py @ 13:f350d610c986

added menu bar
author Yashina Ksenia <ksenia_yashina@kodomo.fbb.msu.ru>
date Tue, 14 Dec 2010 17:10:59 +0300
parents 53672899af16
children 05518686d7af
rev   line source
ksenia_yashina@8 1 from Tkinter import *
ksenia_yashina@11 2 import Bacteria
ksenia_yashina@11 3 import Petri
ksenia_yashina@11 4
ksenia_yashina@13 5 class IF(object):
ksenia_yashina@11 6 def __init__(self,delay=10,diam=300,num=1,env=1,reprod_a=False,reprod_s=False,life=1):
ksenia_yashina@11 7 self.delay=delay
ksenia_yashina@11 8 self.diam=diam
ksenia_yashina@11 9 self.num=num
ksenia_yashina@11 10 self.env=env
ksenia_yashina@11 11 self.reprod_s=reprod_s
ksenia_yashina@11 12 self.reprod_a=reprod_a
ksenia_yashina@11 13 self.life=life
ksenia_yashina@11 14
ksenia_yashina@11 15 def __repr__(self):
ksenia_yashina@11 16 return "<%s,%s,%s,%s,%s,%s,%s>"%(self.delay,self.diam,self.num,\
ksenia_yashina@11 17 self.env,self.reprod_a,\
ksenia_yashina@11 18 self.reprod_s,self.life)
ksenia_yashina@13 19 def mutate():
ksenia_yashina@13 20 pass
ksenia_yashina@11 21
ksenia_yashina@11 22 def sbmt(self):
ksenia_yashina@11 23 submit.config(text="Stop",command=self.stop)
ksenia_yashina@11 24 scl1.config(state=DISABLED)
ksenia_yashina@11 25 scl2.config(state=DISABLED)
ksenia_yashina@11 26 scl3.config(state=DISABLED)
ksenia_yashina@11 27 cb1.config(state=DISABLED)
ksenia_yashina@11 28 cb2.config(state=DISABLED)
ksenia_yashina@11 29 self.num=scl1.get()
ksenia_yashina@11 30 self.diam=scl2.get()
ksenia_yashina@11 31 self.life=scl3.get()
ksenia_yashina@11 32 c.config(height=self.diam+20,width=self.diam+20,bg="gray75")
ksenia_yashina@11 33 filler=c.create_rectangle(0,0,self.diam+22,self.diam+22,fill="lightgrey")
ksenia_yashina@11 34 c.grid(row=0,column=2,rowspan=6,padx=50,pady=10)
ksenia_yashina@11 35 dish=c.create_oval(10,10,self.diam+10,self.diam+10,fill="white")
ksenia_yashina@11 36 print self
ksenia_yashina@11 37
ksenia_yashina@11 38 def stop(self):
ksenia_yashina@11 39 submit.config(text="Submit",command=self.sbmt)
ksenia_yashina@11 40 scl1.config(state=NORMAL)
ksenia_yashina@11 41 scl2.config(state=NORMAL)
ksenia_yashina@11 42 scl3.config(state=NORMAL)
ksenia_yashina@11 43 cb1.config(state=NORMAL)
ksenia_yashina@11 44 cb2.config(state=NORMAL)
ksenia_yashina@11 45
ksenia_yashina@11 46 def new_reprod_a(self):
ksenia_yashina@11 47 self.reprod_a=not(self.reprod_a)
ksenia_yashina@11 48 return
ksenia_yashina@11 49
ksenia_yashina@11 50 def new_reprod_s(self):
ksenia_yashina@11 51 self.reprod_s=not(self.reprod_s)
ksenia_yashina@11 52 return
ksenia_yashina@13 53
ksenia_yashina@13 54 def help(self):
ksenia_yashina@13 55 pass
ksenia_yashina@13 56
ksenia_yashina@13 57 def pause(self):
ksenia_yashina@13 58 pass
ksenia_yashina@11 59
ksenia_yashina@13 60 def depict(self):
ksenia_yashina@13 61 pass
ksenia_yashina@11 62
ksenia_yashina@8 63 root = Tk()
ksenia_yashina@8 64 root.title("Interface")
ksenia_yashina@11 65 intf=IF()
ksenia_yashina@11 66 c=Canvas()
ksenia_yashina@8 67
ksenia_yashina@13 68 menubar = Menu(root)
ksenia_yashina@13 69
ksenia_yashina@13 70 # create a pulldown menu, and add it to the menu bar
ksenia_yashina@13 71 controlsmenu = Menu(menubar, tearoff=0)
ksenia_yashina@13 72 controlsmenu.add_command(label="Start", command=intf.sbmt)
ksenia_yashina@13 73 controlsmenu.add_command(label="Stop", command=intf.stop)
ksenia_yashina@13 74 controlsmenu.add_command(label="Add mutation", command=intf.mutate)
ksenia_yashina@13 75 controlsmenu.add_separator()
ksenia_yashina@13 76 controlsmenu.add_command(label="Exit", command=root.destroy)
ksenia_yashina@13 77 #controlmenu.add_command(label="Pause", command=intf.pause)
ksenia_yashina@13 78 menubar.add_cascade(label="Controls", menu=controlsmenu)
ksenia_yashina@13 79
ksenia_yashina@13 80 helpmenu = Menu(menubar, tearoff=0)
ksenia_yashina@13 81 helpmenu.add_command(label="About", command=intf.help)
ksenia_yashina@13 82 menubar.add_cascade(label="Help", menu=helpmenu)
ksenia_yashina@13 83
ksenia_yashina@13 84 # display the menu
ksenia_yashina@13 85 root.config(menu=menubar)
ksenia_yashina@13 86
ksenia_yashina@13 87
ksenia_yashina@13 88
ksenia_yashina@8 89 init_frame=LabelFrame(root,text="Initial parameters")
ksenia_yashina@8 90 init_frame.grid(padx=15,pady=10)
ksenia_yashina@10 91 scl1 = Scale(init_frame,orient=HORIZONTAL,length=100,from_=1,\
ksenia_yashina@10 92 to=50,sliderlength=7,width=10)
ksenia_yashina@10 93 scl1.grid(row=0, column=0,padx=10,pady=5)
ksenia_yashina@10 94 lbl1 = Label(init_frame,text="number of cells",bg="white")
ksenia_yashina@10 95 lbl1.grid(row=0,column=1,padx=10)
ksenia_yashina@11 96 scl2 = Scale(init_frame,orient=HORIZONTAL,length=100,from_=100,\
ksenia_yashina@10 97 to=500,sliderlength=7,width=10)
ksenia_yashina@10 98 scl2.grid(row=1, column=0,padx=10,pady=5)
ksenia_yashina@10 99 lbl2 = Label(init_frame,text="diameter of Petri dish",bg="white")
ksenia_yashina@10 100 lbl2.grid(row=1,column=1,padx=10)
ksenia_yashina@10 101 scl3 = Scale(init_frame,orient=HORIZONTAL,length=100,from_=1,\
ksenia_yashina@10 102 to=30,sliderlength=7,width=10)
ksenia_yashina@10 103 scl3.grid(row=2, column=0,padx=10,pady=5)
ksenia_yashina@10 104 lbl3 = Label(init_frame,text="cells' lifetime",bg="white")
ksenia_yashina@10 105 lbl3.grid(row=2,column=1,padx=10)
ksenia_yashina@8 106 lbl_frame=LabelFrame(init_frame,text="Reproduction")
ksenia_yashina@8 107 lbl_frame.grid(row=4,column=0,columnspan=2,padx=15,pady=10)
ksenia_yashina@8 108 list=["Asexual","Sexual"]
ksenia_yashina@11 109 cb1 = Checkbutton(lbl_frame,text="Asexual",command=intf.new_reprod_a)
ksenia_yashina@10 110 cb1.pack()
ksenia_yashina@11 111 cb2 = Checkbutton(lbl_frame,text="Sexual",command=intf.new_reprod_s)
ksenia_yashina@10 112 cb2.pack()
ksenia_yashina@10 113
ksenia_yashina@11 114 submit=Button(root,text="Submit",width=25,command=intf.sbmt)
ksenia_yashina@8 115 submit.grid(row=1,column=0,columnspan=2,pady=10)
ksenia_yashina@8 116
ksenia_yashina@11 117 chng_frame=LabelFrame(root,text="Changeable parameters")
ksenia_yashina@8 118 chng_frame.grid(padx=15,pady=10)
ksenia_yashina@8 119 scl = Scale(chng_frame,orient=HORIZONTAL,length=100,from_=1,\
ksenia_yashina@8 120 to=100,sliderlength=7,width=10)
ksenia_yashina@8 121 scl.grid(row=0, column=0,padx=10,pady=5)
ksenia_yashina@8 122 lbl = Label(chng_frame,text="environment",bg="white")
ksenia_yashina@8 123 lbl.grid(row=0,column=1,padx=10)
ksenia_yashina@13 124 btn = Button(chng_frame,text="Add mutation",width=25,command=intf.mutate)
ksenia_yashina@8 125 btn.grid(row=1,column=0,columnspan=2,pady=10)
ksenia_yashina@8 126
ksenia_yashina@11 127 #root.after(intf.delay,intf.depict())
ksenia_yashina@11 128
ksenia_yashina@8 129 mainloop()