view Interface.py @ 7:e56a5e838f37
+ zoom, speed and state order manipulations
author |
is_rusinov |
date |
Sat, 04 Dec 2010 00:50:50 +0300 |
parents |
721fdbb815c8 |
children |
cda6324b8518 |
line source
3 class Handlers(object):
5 def __init__(self, cell_size, delay, offset_x, offset_y):# cell_size is size of cell, including line width, if there is it
6 self.cell_size = cell_size
8 self.offset_x = offset_x
9 self.offset_y = offset_y
11 self.is_started = False
15 self.is_started = True
17 self.after_id = canvas.after(self.delay, self.start)
20 self.canvas.after_cancel(self.after_id)
21 self.is_started = False
39 if self.cell_size < 50:
44 if self.cell_size > 1:
48 def slower(self, speed_rate):
49 self.delay = self.delay + speed_rate
51 def faster(self, speed_rate):
52 if self.speed > speed_rate:
53 self.delay = self.delay - speed_rate
57 def change_size(x, y):
58 automata.change_size(x, y)
64 def press1(self, event):# drawer
67 def motion1(self, event):# drawer
70 def press3(self, event):# drawer
73 def motion3(self, event):# drawer
76 def press_key1(self, event):# drawer+change_scale (B1+ctrl)
79 def motion_key1(self, event):# drawer+change_scale (B1+ctrl)
82 def press12(self, event):# zoom
85 def motion12(self, event):# zoom
88 def automata_frame():# show automata_frame
89 frame1.pack(side="right", fill="y", expand="no", before=canvas)
91 def to_top():# replace choosen state to top
92 index = symbols.get(state_list.get("active").split()[1])
95 states.insert(0, state)
97 def to_bottom():# replace choosen state to botton
98 index = symbols.get(state_list.get("active").split()[1])
104 index = symbols.get(state_list.get("active").split()[1])
105 state = states[index]
107 states.insert(index - 1, state)
110 index = symbols.get(state_list.get("active").split()[1])
111 state = states[index]
113 states.insert(index + 1, state)
115 def delete_state():# delete choosen state
116 index = symbols.get(state_list.get("active").split()[1])
119 def add():# add new state
122 def change():# change chosen state
128 root.title("Cyclyc Cell Automata")
130 canvas = Canvas(root, background="white")
131 canvas.config(width=500, height=400)
132 canvas.pack(fill="both", expand="yes")
134 automata = Automata()
135 handlers = Handlers(1, 1, 0, 0)
141 frame1=Frame(root, background="grey")
142 state_list=Listbox(frame1, selectmode="extended")
144 state_list.insert("end", state)
145 state_list.pack(side="top", fill="y")
146 up = Button(frame1, text="Up", state="disable")
148 down = Button(frame1, text="Down", state="disable")
149 down.config(bg="orange")
150 to_top = Button(frame1, text="To Top", state="disable")
151 to_top.config(bg="yellow")
152 to_bottom = Button(frame1, text="To Bottom", state="disable")
153 to_bottom.config(bg="green")
154 hide = Button(frame1, text="hide", command=frame1.forget)
155 hide.config(bg="cyan")
156 up.pack(side="top", fill="x")
157 down.pack(side="top", fill="x")
158 to_top.pack(side="top", fill="x")
159 to_bottom.pack(side="top", fill="x")
160 hide.pack(side="bottom", fill="x")
164 root.config(menu=menubar)
166 menu_file = Menu(menubar)
167 menu_file.add_command(label="New")
168 menu_file.add_command(label="Open...")
169 menu_file.add_command(label="Save...")
170 menu_file.add_separator()
171 menu_file.add_command(label="Exit")
172 menubar.add_cascade(label="File", menu=menu_file)
174 menu_action = Menu(menubar)
175 menu_action.add_command(label="Start")
176 menu_action.add_command(label="Stop")
177 menu_action.add_command(label="Next Step")
178 menu_action.add_command(label="Increase speed")
179 menu_action.add_command(label="Decrease speed")
180 menu_action.add_command(label="Zoom In")
181 menu_action.add_command(label="Zoom Out")
182 menu_action.add_command(label="Clean field")
183 menu_action.add_command(label="Fill randomly")
184 menubar.add_cascade(label="Action", menu=menu_action)
186 menubar.add_command(label="Automata", command=handlers.automata_frame)
188 menubar.add_command(label="Help")