Äîêóìåíò âçÿò èç êýøà ïîèñêîâîé ìàøèíû. Àäðåñ îðèãèíàëüíîãî äîêóìåíòà : http://kodomo.cmm.msu.su/trac/cca/browser/Interface.py?rev=11%3Aa40cbd127d39
Äàòà èçìåíåíèÿ: Unknown
Äàòà èíäåêñèðîâàíèÿ: Mon Apr 11 03:42:00 2016
Êîäèðîâêà: IBM-866
Interface.py òÀÓ Cyclyc Cell Automata

source: Interface.py @ 10:de4aaf1071ec

Revision 10:de4aaf1071ec, 8.4 KB checked in by Ilia, 5 years ago (diff)

some correction

Lineˆà
1fromˆàTkinterˆàimportˆà*
2
3classˆàHandlers(object):
4ˆà ˆà ˆà ˆà
5ˆà ˆà ˆà ˆà defˆà__init__(self,ˆàcell_size=5,ˆàdelay=10,ˆàoffset_x=0,ˆàoffset_y=0):# cell_size is size of cell, including line width, if there is it
6ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.cell_size =ˆàcell_size
7ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.delay =ˆàdelay
8ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.offset_x =ˆàoffset_x
9ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.offset_y =ˆàoffset_y
10ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.after_id =ˆà0
11ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.is_started =ˆàFalse
12ˆà ˆà ˆà ˆà
13ˆà ˆà ˆà ˆà defˆàstart(self):
14ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ifˆànotˆàself.is_started:
15ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.is_started =ˆàTrue
16ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.next_step()
17ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.after_id =ˆàcanvas.after(self.delay,ˆàself.start)
18ˆà ˆà ˆà ˆà
19ˆà ˆà ˆà ˆà defˆàstop(self):
20ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.canvas.after_cancel(self.after_id)
21ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.is_started =ˆàFalse
22ˆà ˆà ˆà ˆà
23ˆà ˆà ˆà ˆà defˆànext_step(self):
24ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà automata.next_step()
25ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.draw()
26ˆà ˆà ˆà ˆà
27ˆà ˆà ˆà ˆà defˆàsave_file():
28ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass
29ˆà ˆà ˆà ˆà
30ˆà ˆà ˆà ˆà defˆàopen_file():
31ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass
32ˆà ˆà ˆà ˆà
33ˆà ˆà ˆà ˆà defˆàhelp():
34ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass
35ˆà ˆà ˆà ˆà
36ˆà ˆà ˆà ˆà defˆàclose_help_window
37ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass
38ˆà ˆà ˆà ˆà
39ˆà ˆà ˆà ˆà defˆàzoom_in(self,ˆàzoom_rate=1):
40ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ifˆàself.cell_size <ˆà50:
41ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.cell_size =ˆàself.cell_size +ˆàzoom_rate
42ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.draw()
43ˆà ˆà ˆà ˆà
44ˆà ˆà ˆà ˆà defˆàzoom_out(self,ˆàzoom_rate=1):
45ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ifˆàself.cell_size >ˆà1:
46ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.cell_size =ˆàself.cell_size -ˆàzoom_rate
47ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.draw()
48ˆà ˆà ˆà ˆà
49ˆà ˆà ˆà ˆà defˆàslower(self,ˆàspeed_rate=1):
50ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.delay =ˆàself.delay +ˆàspeed_rate
51ˆà ˆà ˆà ˆà
52ˆà ˆà ˆà ˆà defˆàfaster(self,ˆàspeed_rate=1):
53ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ifˆàself.speed >ˆàspeed_rate:
54ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.delay =ˆàself.delay -ˆàspeed_rate
55ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà else:
56ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.delay =ˆà0
57ˆà ˆà ˆà ˆà
58ˆà ˆà ˆà ˆà defˆàchange_size(dx,ˆàdy,ˆàposition=0):
59ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ifˆàposition <ˆà9:
60ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ifˆàposition ==ˆà0ˆàorˆàposition ==ˆà3ˆàorˆàposition ==ˆà6:
61ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà automata.change_size(dx,ˆà3)
62ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà elifˆàposition ==ˆà1ˆàorˆàposition ==ˆà4ˆàorˆàposition ==ˆà7:
63ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà automata.change_size(dx /ˆà2,ˆà3)
64ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà automata.change_size(dx -ˆàdx /ˆà2,ˆà1)
65ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà elseˆà
66ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà automata.change_size(dx,ˆà1)
67ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ifˆàposition ==ˆà0ˆàorˆàposition ==ˆà1ˆàorˆàposition ==ˆà2:
68ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà automata.change_size(dy,ˆà0)
69ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà elifˆàposition ==ˆà3ˆàorˆàposition ==ˆà4ˆàorˆàposition ==ˆà5:
70ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà automata.change_size(dy /ˆà2,ˆà0)
71ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà automata.change_size(dy -ˆàdy /ˆà2,ˆà2)
72ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà elseˆà
73ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà automata.change_size(dy,ˆà2)
74ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà self.draw()
75ˆà ˆà ˆà ˆà
76ˆà ˆà ˆà ˆà defˆàdraw():
77ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass
78ˆà ˆà ˆà ˆà
79ˆà ˆà ˆà ˆà defˆàpress1(self,ˆàevent):# drawer
80ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass
81ˆà ˆà ˆà ˆà
82ˆà ˆà ˆà ˆà defˆàmotion1(self,ˆàevent):# drawer
83ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass
84ˆà ˆà ˆà ˆà
85ˆà ˆà ˆà ˆà defˆàpress3(self,ˆàevent):# drawer
86ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass
87ˆà ˆà ˆà ˆà
88ˆà ˆà ˆà ˆà defˆàmotion3(self,ˆàevent):# drawer
89ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass
90ˆà ˆà ˆà ˆà
91ˆà ˆà ˆà ˆà defˆàpress_key1(self,ˆàevent):# drawer+change_scale (B1+ctrl)
92ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass
93ˆà ˆà ˆà ˆà
94ˆà ˆà ˆà ˆà defˆàmotion_key1(self,ˆàevent):# drawer+change_scale (B1+ctrl)
95ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass
96ˆà ˆà ˆà ˆà
97ˆà ˆà ˆà ˆà defˆàpress12(self,ˆàevent):# zoom
98ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass
99ˆà ˆà ˆà ˆà
100ˆà ˆà ˆà ˆà defˆàmotion12(self,ˆàevent):# zoom
101ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass
102ˆà ˆà ˆà ˆà
103ˆà ˆà ˆà ˆà defˆàautomata_frame(self):# show automata_frame
104ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà automata_frame.pack(side="right",ˆàfill="y",ˆàexpand="no",ˆàbefore=canvas)
105ˆà ˆà ˆà ˆà
106ˆà ˆà ˆà ˆà defˆàto_top(self):# replace choosen state to top
107ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà index =ˆàsymbols.get(state_list.get("active").split()[1])
108ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà state =ˆàstates[index]
109ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà delˆàstates[index]
110ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà states.insert(0,ˆàstate)
111ˆà ˆà ˆà ˆà
112ˆà ˆà ˆà ˆà defˆàto_bottom(self):# replace choosen state to botton
113ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà index =ˆàsymbols.get(state_list.get("active").split()[1])
114ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà state =ˆàstates[index]
115ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà delˆàstates[index]
116ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà states.append(state)
117ˆà ˆà ˆà ˆà
118ˆà ˆà ˆà ˆà defˆàupwards(self):
119ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà index =ˆàsymbols.get(state_list.get("active").split()[1])
120ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà state =ˆàstates[index]
121ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà delˆàstates[index]
122ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà states.insert(index -ˆà1,ˆàstate)
123ˆà ˆà ˆà ˆà
124ˆà ˆà ˆà ˆà defˆàdownwards(self):
125ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà index =ˆàsymbols.get(state_list.get("active").split()[1])
126ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà state =ˆàstates[index]
127ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà delˆàstates[index]
128ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà states.insert(index +ˆà1,ˆàstate)
129ˆà ˆà ˆà ˆà
130ˆà ˆà ˆà ˆà defˆàdelete_state(self):# delete choosen state
131ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà index =ˆàsymbols.get(state_list.get("active").split()[1])
132ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà delˆàstates[index]
133ˆà ˆà ˆà ˆà
134ˆà ˆà ˆà ˆà defˆàadd():# add new state
135ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass
136ˆà ˆà ˆà ˆà
137ˆà ˆà ˆà ˆà defˆàchange():# change chosen state
138ˆà ˆà ˆà ˆà ˆà ˆà ˆà ˆà pass
139ˆà ˆà ˆà ˆà
140
141
142root =ˆàTk()
143root.title("Cyclyc Cell Automata")
144
145canvas =ˆàCanvas(root,ˆàbackground="white")
146canvas.config(width=500,ˆàheight=400)
147canvas.pack(fill="both",ˆàexpand="yes")
148
149automata =ˆàAutomata()ˆà
150handlers =ˆàHandlers(1,ˆà1,ˆà0,ˆà0)
151
152states =ˆà[]
153symboles =ˆàdict()
154
155#infoPanel=Frame
156automata_frame=Frame(root,ˆàbackground="grey")
157
158headline_frame=Frame(automata_frame,ˆàbackground="white")
159head =ˆàLabel(headline_frame,ˆàtext=ˆà"Automata Panel",ˆàfont=16)
160head.pack(side="left",ˆàexpand="yes")
161hide =ˆàButton(headline_frame,ˆàtext="X",ˆàcommand=automata_frame.forget)
162hide.config(bg="grey")
163hide.pack(side="right")
164headline_frame.pack(side="top",fill="both",ˆàexpand="no")
165
166Label(automata_frame,ˆàtext=ˆà"State Box:").pack(side="top",ˆàfill="x")
167state_list=Listbox(automata_frame,ˆàselectmode="extended")
168forˆàstate inˆàstates:
169ˆà ˆà ˆà ˆà state_list.insert("end",ˆàstate)
170state_list.pack(side="top",ˆàfill="y")
171up =ˆàButton(automata_frame,ˆàtext="Up",ˆàstate="DISABLED")
172up.config(bg="red")
173down =ˆàButton(automata_frame,ˆàtext="Down",ˆàstate="DISABLED")
174down.config(bg="orange")
175to_top =ˆàButton(automata_frame,ˆàtext="To Top",ˆàstate="DISABLED")
176to_top.config(bg="yellow")
177to_bottom =ˆàButton(automata_frame,ˆàtext="To Bottom",ˆàstate="DISABLED")
178to_bottom.config(bg="green")
179delete =ˆàButton(automata_frame,ˆàtext="Delete",ˆàcommand=callback,ˆàstate="disabled")
180delete.config(bg="cyan")
181up.pack(side="top",ˆàfill="x")
182down.pack(side="top",ˆàfill="x")
183to_top.pack(side="top",ˆàfill="x")
184to_bottom.pack(side="top",ˆàfill="x")
185delete.pack(side="top",ˆàfill="x")
186
187
188information =ˆàLabel(automata_frame,ˆàtext=ˆà"Information of State")
189information.pack(side="top",ˆàfill="x")
190info_frame=Frame(automata_frame,ˆàbackground="white")
191Label(info_frame,ˆàtext="Name").grid(row=0,ˆàcolumn=0)
192state_name =ˆàEntry(info_frame)
193state_name.grid(row=0,ˆàcolumn=1)
194Label(info_frame,ˆàtext="Symbol").grid(row=1,ˆàcolumn=0)
195state_symbol =ˆàEntry(info_frame)
196state_symbol.grid(row=1,ˆàcolumn=1)
197Label(info_frame,ˆàtext="Color").grid(row=2,ˆàcolumn=0)
198state_color =ˆàEntry(info_frame)
199state_color.grid(row=2,ˆàcolumn=1)
200Label(info_frame,ˆàtext="Key").grid(row=3,ˆàcolumn=0)
201state_key =ˆàEntry(info_frame)
202state_key.grid(row=3,ˆàcolumn=1)
203info_frame.pack(side="top")
204
205
206condition =ˆàLabel(automata_frame,ˆàtext=ˆà"Condition of conversion")
207condition.pack(side="top",ˆàfill="x")
208condition_frame=Frame(automata_frame,ˆàbackground="white")
209Label(condition_frame,ˆàtext="0: ").grid(row=0,ˆàcolumn=0)
210check_box_0 =ˆàCheckbutton(condition_frame)
211check_box_0.grid(row=0,ˆàcolumn=1)
212Label(condition_frame,ˆàtext="1: ").grid(row=0,ˆàcolumn=2)
213check_box_1 =ˆàCheckbutton(condition_frame)
214check_box_1.grid(row=0,ˆàcolumn=3)
215Label(condition_frame,ˆàtext="2: ").grid(row=0,ˆàcolumn=4)
216check_box_2 =ˆàCheckbutton(condition_frame)
217check_box_2.grid(row=0,ˆàcolumn=5)
218Label(condition_frame,ˆàtext="3: ").grid(row=1,ˆàcolumn=0)
219check_box_0 =ˆàCheckbutton(condition_frame)
220check_box_0.grid(row=1,ˆàcolumn=1)
221Label(condition_frame,ˆàtext="4: ").grid(row=1,ˆàcolumn=2)
222check_box_1 =ˆàCheckbutton(condition_frame)
223check_box_1.grid(row=1,ˆàcolumn=3)
224Label(condition_frame,ˆàtext="5: ").grid(row=1,ˆàcolumn=4)
225check_box_2 =ˆàCheckbutton(condition_frame)
226check_box_2.grid(row=1,ˆàcolumn=5)
227Label(condition_frame,ˆàtext="6: ").grid(row=2,ˆàcolumn=0)
228check_box_0 =ˆàCheckbutton(condition_frame)
229check_box_0.grid(row=2,ˆàcolumn=1)
230Label(condition_frame,ˆàtext="7: ").grid(row=2,ˆàcolumn=2)
231check_box_1 =ˆàCheckbutton(condition_frame)
232check_box_1.grid(row=2,ˆàcolumn=3)
233Label(condition_frame,ˆàtext="8: ").grid(row=2,ˆàcolumn=4)
234check_box_2 =ˆàCheckbutton(condition_frame)
235check_box_2.grid(row=2,ˆàcolumn=5)
236condition_frame.pack(side="top")
237
238
239add_state =ˆàButton(automata_frame,ˆàtext="ADD",ˆàcommand=callback,ˆàstate="disabled")
240add_state.config(bg="blue")
241change_state =ˆàButton(automata_frame,ˆàtext="Change",ˆàcommand=callback,ˆàstate="disabled")
242change_state.config(bg="violet")
243add_state.pack(side="top",ˆàfill="x")
244change_state.pack(side="top",ˆàfill="x")
245
246error=Label(automata_frame)
247error.pack(side="top",ˆàfill="x")
248
249
250menubar =ˆàMenu(root)
251root.config(menu=menubar)
252
253menu_file =ˆàMenu(menubar)
254menu_file.add_command(label="New")
255menu_file.add_command(label="Open...",ˆàcommand=handlers.open_file)
256menu_file.add_command(label="Save...",ˆàcommand=handlers.save_file)
257menu_file.add_separator()
258menu_file.add_command(label="Exit",ˆàcommand=root.destroy)
259menubar.add_cascade(label="File",ˆàmenu=menu_file)
260
261menu_action =ˆàMenu(menubar)
262menu_action.add_command(label="Start",ˆàcommand=handlers.start)
263menu_action.add_command(label="Stop",ˆàcommand=handlers.stop)
264menu_action.add_command(label="Next Step",ˆàcommand=handlers.next_step)
265menu_action.add_command(label="Increase speed",ˆàcommand=handlers.faster)
266menu_action.add_command(label="Decrease speed",ˆàcommand=handlers.slower)
267menu_action.add_command(label="Zoom In",ˆàcommand=handlers.zoom_in)
268menu_action.add_command(label="Zoom Out",ˆàcommand=handlers.zoom_out)
269menu_action.add_command(label="Clean field")
270menu_action.add_command(label="Fill randomly")
271menubar.add_cascade(label="Action",ˆàmenu=menu_action)
272
273menubar.add_command(label="Automata",ˆàcommand=handlers.automata_frame)
274
275menubar.add_command(label="Help")
276
277root.mainloop()
278
Note: See TracBrowser for help on using the repository browser.