Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/cca/file/eef739e055f4/Interface.py
Дата изменения: Unknown
Дата индексирования: Sun Feb 3 10:42:48 2013
Кодировка:
cca: eef739e055f4 Interface.py

cca

view Interface.py @ 20:eef739e055f4

Completed Automata: change_size, import from State, default states
author darkhan
date Sat, 04 Dec 2010 23:28:47 +0300
parents b9d58d90c534
children d2705c3ee7a7
line source
1 from Tkinter import *
3 class Handlers(object):
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
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)
19 def stop(self):
20 self.canvas.after_cancel(self.after_id)
21 self.is_started = False
23 def next_step(self):
24 automata.next_step()
25 self.draw()
27 def save_file():
28 pass
30 def open_file():
31 pass
33 def help():
34 pass
36 def close_help_window
37 pass
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()
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()
49 def slower(self, speed_rate=1):
50 self.delay = self.delay + speed_rate
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
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()
76 def draw():
77 pass
79 def press1(self, event):# drawer
80 pass
82 def motion1(self, event):# drawer
83 pass
85 def press3(self, event):# drawer
86 pass
88 def motion3(self, event):# drawer
89 pass
91 def press_key1(self, event):# drawer+change_scale (B1+ctrl)
92 pass
94 def motion_key1(self, event):# drawer+change_scale (B1+ctrl)
95 pass
97 def press12(self, event):# zoom
98 pass
100 def motion12(self, event):# zoom
101 pass
103 def automata_frame(self):# show automata_frame
104 automata_frame.pack(side="right", fill="y", expand="no", before=canvas)
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)
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)
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)
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)
130 def delete_state(self):# delete choosen state
131 index = symbols.get(state_list.get("active").split()[1])
132 del states[index]
134 def add():# add new state
135 pass
137 def change():# change chosen state
138 pass
142 root = Tk()
143 root.title("Cyclyc Cell Automata")
145 canvas = Canvas(root, background="white")
146 canvas.config(width=500, height=400)
147 canvas.pack(fill="both", expand="yes")
149 automata = Automata()
150 handlers = Handlers(1, 1, 0, 0)
152 states = []
153 symboles = dict()
155 #infoPanel=Frame
156 automata_frame=Frame(root, background="white")
158 headline_frame=Frame(automata_frame, background="white")
159 head = Label(headline_frame, text= "Automata Panel", font=16)
160 head.pack(side="left", expand="yes")
161 hide = Button(headline_frame, text="X", command=automata_frame.forget)
162 hide.config(bg="grey")
163 hide.pack(side="right")
164 headline_frame.pack(side="top",fill="both", expand="no")
166 Label(automata_frame, text= "State Box:").pack(side="top", fill="x")
167 state_list=Listbox(automata_frame, selectmode="extended")
168 for state in states:
169 state_list.insert("end", state)
170 state_list.pack(side="top", fill="y")
171 up = Button(automata_frame, text="Up", state="disabled")
172 up.config(bg="red")
173 down = Button(automata_frame, text="Down", state="disabled")
174 down.config(bg="orange")
175 to_top = Button(automata_frame, text="To Top", state="disabled")
176 to_top.config(bg="yellow")
177 to_bottom = Button(automata_frame, text="To Bottom", state="disabled")
178 to_bottom.config(bg="green")
179 delete = Button(automata_frame, text="Delete", state="disabled")
180 delete.config(bg="cyan")
181 up.pack(side="top", fill="x")
182 down.pack(side="top", fill="x")
183 to_top.pack(side="top", fill="x")
184 to_bottom.pack(side="top", fill="x")
185 delete.pack(side="top", fill="x")
188 information = Label(automata_frame, text= "Information of State")
189 information.pack(side="top", fill="x")
190 info_frame=Frame(automata_frame, background="white")
191 Label(info_frame, text="Name").grid(row=0, column=0)
192 state_name = Entry(info_frame)
193 state_name.grid(row=0, column=1)
194 Label(info_frame, text="Symbol").grid(row=1, column=0)
195 state_symbol = Entry(info_frame)
196 state_symbol.grid(row=1, column=1)
197 Label(info_frame, text="Color").grid(row=2, column=0)
198 state_color = Entry(info_frame)
199 state_color.grid(row=2, column=1)
200 Label(info_frame, text="Key").grid(row=3, column=0)
201 state_key = Entry(info_frame)
202 state_key.grid(row=3, column=1)
203 info_frame.pack(side="top")
206 condition = Label(automata_frame, text= "Condition of conversion")
207 condition.pack(side="top", fill="x")
208 condition_frame=Frame(automata_frame, background="white")
209 Label(condition_frame, text="0: ").grid(row=0, column=0)
210 check_box_0 = Checkbutton(condition_frame)
211 check_box_0.grid(row=0, column=1)
212 Label(condition_frame, text="1: ").grid(row=0, column=2)
213 check_box_1 = Checkbutton(condition_frame)
214 check_box_1.grid(row=0, column=3)
215 Label(condition_frame, text="2: ").grid(row=0, column=4)
216 check_box_2 = Checkbutton(condition_frame)
217 check_box_2.grid(row=0, column=5)
218 Label(condition_frame, text="3: ").grid(row=1, column=0)
219 check_box_0 = Checkbutton(condition_frame)
220 check_box_0.grid(row=1, column=1)
221 Label(condition_frame, text="4: ").grid(row=1, column=2)
222 check_box_1 = Checkbutton(condition_frame)
223 check_box_1.grid(row=1, column=3)
224 Label(condition_frame, text="5: ").grid(row=1, column=4)
225 check_box_2 = Checkbutton(condition_frame)
226 check_box_2.grid(row=1, column=5)
227 Label(condition_frame, text="6: ").grid(row=2, column=0)
228 check_box_0 = Checkbutton(condition_frame)
229 check_box_0.grid(row=2, column=1)
230 Label(condition_frame, text="7: ").grid(row=2, column=2)
231 check_box_1 = Checkbutton(condition_frame)
232 check_box_1.grid(row=2, column=3)
233 Label(condition_frame, text="8: ").grid(row=2, column=4)
234 check_box_2 = Checkbutton(condition_frame)
235 check_box_2.grid(row=2, column=5)
236 condition_frame.pack(side="top")
239 add_state = Button(automata_frame, text="ADD", state="disabled")
240 add_state.config(bg="blue")
241 change_state = Button(automata_frame, text="Change", state="disabled")
242 change_state.config(bg="violet")
243 add_state.pack(side="top", fill="x")
244 change_state.pack(side="top", fill="x")
246 error=Label(automata_frame)
247 error.pack(side="top", fill="x")
250 side = 0
252 size_window = Toplevel(root)
253 size_window.title("")
254 size_window.withdraw()
255 size_window.protocol("WM_DELETE_WINDOW", handlers.hide_size_window)
256 Label(size_window, text= "Current size of window:").pack(side="top", fill="x")
257 size = Label(size_window, text= str(len(automata.field)) + " x " + str(len(automata.field[0])))
258 size.pack(side="top", fill="x")
259 Label(size_window, text= "New size:").pack(side="top", fill="x")
260 new_size = Frame(size_window)
261 size_x = Entry(new_size, width=5)
262 size_x.grid(row=0, column=0)
263 Label(new_size, text=" x ").grid(row=0, column=1)
264 size_y = Entry(new_size, width=5)
265 size_y.grid(row=0, column=2)
266 new_size.pack(side="top")
267 Label(size_window, text= "Expansion of window:").pack(side="top", fill="x")
268 expansion = Frame(size_window)
269 r0 = Radiobutton(expansion, variable=side, value = 0, indicatoron=0, width=2, height=1)
270 r0.select()
271 r0.grid(row=0, column=0)
272 r1 = Radiobutton(expansion, variable=side, value = 1, indicatoron=0, width=2, height=1)
273 r1.grid(row=0, column=1)
274 r2 = Radiobutton(expansion, variable=side, value = 2, indicatoron=0, width=2, height=1)
275 r2.grid(row=0, column=2)
276 r3 = Radiobutton(expansion, variable=side, value = 3, indicatoron=0, width=2, height=1)
277 r3.grid(row=1, column=0)
278 r4 = Radiobutton(expansion, variable=side, value = 4, indicatoron=0, width=2, height=1)
279 r4.grid(row=1, column=1)
280 r5 = Radiobutton(expansion, variable=side, value = 5, indicatoron=0, width=2, height=1)
281 r5.grid(row=1, column=2)
282 r6 = Radiobutton(expansion, variable=side, value = 6, indicatoron=0, width=2, height=1)
283 r6.grid(row=2, column=0)
284 r7 = Radiobutton(expansion, variable=side, value = 7, indicatoron=0, width=2, height=1)
285 r7.grid(row=2, column=1)
286 r8 = Radiobutton(expansion, variable=side, value = 8, indicatoron=0, width=2, height=1)
287 r8.grid(row=2, column=2)
288 expansion.pack(side="top")
289 Label(size_window).pack(side="top", fill="x")
290 apply_frame = Frame(size_window, padx=10, pady=5)
291 apply_size = Button(apply_frame, text="Apply")
292 apply_size.config(bg="yellow")
293 apply_size.pack(side="left", fill="x")
294 close_size = Button(apply_frame, text="Close", command=handlers.hide_size_window)
295 close_size.config(bg="green")
296 close_size.pack(side="right", fill="x")
297 apply_frame.pack(side="top", fill="x")
299 menubar = Menu(root)
300 root.config(menu=menubar)
302 menu_file = Menu(menubar)
303 menu_file.add_command(label="New")
304 menu_file.add_command(label="Open...", command=handlers.open_file)
305 menu_file.add_command(label="Save...", command=handlers.save_file)
306 menu_file.add_separator()
307 menu_file.add_command(label="Exit", command=root.destroy)
308 menubar.add_cascade(label="File", menu=menu_file)
310 menu_action = Menu(menubar)
311 menu_action.add_command(label="Start", command=handlers.start)
312 menu_action.add_command(label="Stop", command=handlers.stop)
313 menu_action.add_command(label="Next Step", command=handlers.next_step)
314 menu_action.add_separator()
315 menu_action.add_command(label="Increase speed", command=handlers.faster)
316 menu_action.add_command(label="Decrease speed", command=handlers.slower)
317 menu_action.add_separator()
318 menu_action.add_command(label="Zoom In", command=handlers.zoom_in)
319 menu_action.add_command(label="Zoom Out", command=handlers.zoom_out)
320 menu_action.add_separator()
321 menu_action.add_command(label="Clean field")
322 menu_action.add_command(label="Fill randomly")
323 menu_action.add_separator()
324 menu_action.add_command(label="Change size",command=handlers.show_size_window)
325 menubar.add_cascade(label="Action", menu=menu_action)
327 menubar.add_command(label="Automata", command=handlers.automata_frame)
329 menubar.add_command(label="Help", command=handlers.help)
331 root.mainloop()