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

cca

view Interface.py @ 8:cda6324b8518

+ change_size
author is_rusinov
date Sat, 04 Dec 2010 16:26:02 +0300
parents e56a5e838f37
children 2b99826c4d29 9d820c8401c0
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 frame1.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 frame1=Frame(root, background="grey")
157 state_list=Listbox(frame1, selectmode="extended")
158 for state in states:
159 state_list.insert("end", state)
160 state_list.pack(side="top", fill="y")
161 up = Button(frame1, text="Up", state="disable")
162 up.config(bg="red")
163 down = Button(frame1, text="Down", state="disable")
164 down.config(bg="orange")
165 to_top = Button(frame1, text="To Top", state="disable")
166 to_top.config(bg="yellow")
167 to_bottom = Button(frame1, text="To Bottom", state="disable")
168 to_bottom.config(bg="green")
169 hide = Button(frame1, text="hide", command=frame1.forget)
170 hide.config(bg="cyan")
171 up.pack(side="top", fill="x")
172 down.pack(side="top", fill="x")
173 to_top.pack(side="top", fill="x")
174 to_bottom.pack(side="top", fill="x")
175 hide.pack(side="bottom", fill="x")
178 menubar = Menu(root)
179 root.config(menu=menubar)
181 menu_file = Menu(menubar)
182 menu_file.add_command(label="New")
183 menu_file.add_command(label="Open...")
184 menu_file.add_command(label="Save...")
185 menu_file.add_separator()
186 menu_file.add_command(label="Exit")
187 menubar.add_cascade(label="File", menu=menu_file)
189 menu_action = Menu(menubar)
190 menu_action.add_command(label="Start")
191 menu_action.add_command(label="Stop")
192 menu_action.add_command(label="Next Step")
193 menu_action.add_command(label="Increase speed")
194 menu_action.add_command(label="Decrease speed")
195 menu_action.add_command(label="Zoom In")
196 menu_action.add_command(label="Zoom Out")
197 menu_action.add_command(label="Clean field")
198 menu_action.add_command(label="Fill randomly")
199 menubar.add_cascade(label="Action", menu=menu_action)
201 menubar.add_command(label="Automata", command=handlers.automata_frame)
203 menubar.add_command(label="Help")
205 root.mainloop()