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

cca

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
1 from Tkinter import *
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
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 ! 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
38 def zoom_in(self):
39 if self.cell_size < 50:
40 self.cell_size ++
41 self.draw()
43 def zoom_out(self):
44 if self.cell_size > 1:
45 self.cell_size --
46 self.draw()
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
54 else:
55 self.delay = 0
57 def change_size(x, y):
58 automata.change_size(x, y)
59 self.draw()
61 def draw():
62 pass
64 def press1(self, event):# drawer
65 pass
67 def motion1(self, event):# drawer
68 pass
70 def press3(self, event):# drawer
71 pass
73 def motion3(self, event):# drawer
74 pass
76 def press_key1(self, event):# drawer+change_scale (B1+ctrl)
77 pass
79 def motion_key1(self, event):# drawer+change_scale (B1+ctrl)
80 pass
82 def press12(self, event):# zoom
83 pass
85 def motion12(self, event):# zoom
86 pass
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])
93 state = states[index]
94 del states[index]
95 states.insert(0, state)
97 def to_bottom():# replace choosen state to botton
98 index = symbols.get(state_list.get("active").split()[1])
99 state = states[index]
100 del states[index]
101 states.append(state)
103 def upwards():
104 index = symbols.get(state_list.get("active").split()[1])
105 state = states[index]
106 del states[index]
107 states.insert(index - 1, state)
109 def downwards():
110 index = symbols.get(state_list.get("active").split()[1])
111 state = states[index]
112 del 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])
117 del states[index]
119 def add():# add new state
120 pass
122 def change():# change chosen state
123 pass
127 root = Tk()
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)
137 states = []
138 symboles = dict()
140 #infoPanel=Frame
141 frame1=Frame(root, background="grey")
142 state_list=Listbox(frame1, selectmode="extended")
143 for state in states:
144 state_list.insert("end", state)
145 state_list.pack(side="top", fill="y")
146 up = Button(frame1, text="Up", state="disable")
147 up.config(bg="red")
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")
163 menubar = Menu(root)
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")
190 root.mainloop()