Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.cmm.msu.su/trac/cca/browser/Interface.py?rev=2b99826c4d292ee036791586048c4616654e9f05&format=txt
Дата изменения: Sat Dec 4 18:21:20 2010
Дата индексирования: Sun Mar 2 06:38:51 2014
Кодировка:
from Tkinter import *

class Handlers(object):

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
self.cell_size = cell_size
self.delay = delay
self.offset_x = offset_x
self.offset_y = offset_y
self.after_id = 0
self.is_started = False

def start(self):
if not self.is_started:
self.is_started = True
self.next_step()
self.after_id = canvas.after(self.delay, self.start)

def stop(self):
self.canvas.after_cancel(self.after_id)
self.is_started = False

def next_step(self):
automata.next_step()
self.draw()

def save_file():
pass

def open_file():
pass

def help():
pass

def close_help_window
pass

def zoom_in(self, zoom_rate=1):
if self.cell_size < 50:
self.cell_size = self.cell_size + zoom_rate
self.draw()

def zoom_out(self, zoom_rate=1):
if self.cell_size > 1:
self.cell_size = self.cell_size - zoom_rate
self.draw()

def slower(self, speed_rate=1):
self.delay = self.delay + speed_rate

def faster(self, speed_rate=1):
if self.speed > speed_rate:
self.delay = self.delay - speed_rate
else:
self.delay = 0

def change_size(dx, dy, position=0):
if position < 9:
if position == 0 or position == 3 or position == 6:
automata.change_size(dx, 3)
elif position == 1 or position == 4 or position == 7:
automata.change_size(dx / 2, 3)
automata.change_size(dx - dx / 2, 1)
else
automata.change_size(dx, 1)
if position == 0 or position == 1 or position == 2:
automata.change_size(dy, 0)
elif position == 3 or position == 4 or position == 5:
automata.change_size(dy / 2, 0)
automata.change_size(dy - dy / 2, 2)
else
automata.change_size(dy, 2)
self.draw()

def draw():
pass

def press1(self, event):# drawer
pass

def motion1(self, event):# drawer
pass

def press3(self, event):# drawer
pass

def motion3(self, event):# drawer
pass

def press_key1(self, event):# drawer+change_scale (B1+ctrl)
pass

def motion_key1(self, event):# drawer+change_scale (B1+ctrl)
pass

def press12(self, event):# zoom
pass

def motion12(self, event):# zoom
pass

def automata_frame(self):# show automata_frame
automata_frame.pack(side="right", fill="y", expand="no", before=canvas)

def to_top(self):# replace choosen state to top
index = symbols.get(state_list.get("active").split()[1])
state = states[index]
del states[index]
states.insert(0, state)

def to_bottom(self):# replace choosen state to botton
index = symbols.get(state_list.get("active").split()[1])
state = states[index]
del states[index]
states.append(state)

def upwards(self):
index = symbols.get(state_list.get("active").split()[1])
state = states[index]
del states[index]
states.insert(index - 1, state)

def downwards(self):
index = symbols.get(state_list.get("active").split()[1])
state = states[index]
del states[index]
states.insert(index + 1, state)

def delete_state(self):# delete choosen state
index = symbols.get(state_list.get("active").split()[1])
del states[index]

def add():# add new state
pass

def change():# change chosen state
pass



root = Tk()
root.title("Cyclyc Cell Automata")

canvas = Canvas(root, background="white")
canvas.config(width=500, height=400)
canvas.pack(fill="both", expand="yes")

automata = Automata()
handlers = Handlers(1, 1, 0, 0)

states = []
symboles = dict()

#infoPanel=Frame
automata_frame=Frame(root, background="grey")

headline_frame=Frame(automata_frame, background="white")
head = Label(headline_frame, text= "Automata Panel", font=16)
head.pack(side="left", expand="yes")
hide = Button(headline_frame, text="X", command=automata_frame.forget)
hide.config(bg="grey")
hide.pack(side="right")
headline_frame.pack(side="top",fill="both", expand="no")

Label(automata_frame, text= "State Box:").pack(side="top", fill="x")
statelist=Listbox(automata_frame, selectmode = "extended")
state_list=Listbox(automata_frame, selectmode="extended")
for state in states:
state_list.insert("end", state)
state_list.pack(side="top", fill="y")
up = Button(automata_frame, text="Up", state="DISABLED")
up.config(bg="red")
down = Button(automata_frame, text="Down", state="DISABLED")
down.config(bg="orange")
to_top = Button(automata_frame, text="To Top", state="DISABLED")
to_top.config(bg="yellow")
to_bottom = Button(automata_frame, text="To Bottom", state="DISABLED")
to_bottom.config(bg="green")
delete = Button(automata_frame, text="Delete", command=callback, state="disabled")
delete.config(bg="cyan")
up.pack(side="top", fill="x")
down.pack(side="top", fill="x")
to_top.pack(side="top", fill="x")
to_bottom.pack(side="top", fill="x")
delete.pack(side="top", fill="x")


information = Label(automata_frame, text= "Information of State")
information.pack(side="top", fill="x")
info_frame=Frame(automata_frame, background="white")
Label(info_frame, text="Name").grid(row=0, column=0)
state_name = Entry(info_frame)
state_name.grid(row=0, column=1)
Label(info_frame, text="Symbol").grid(row=1, column=0)
state_symbol = Entry(info_frame)
state_symbol.grid(row=1, column=1)
Label(info_frame, text="Color").grid(row=2, column=0)
state_color = Entry(info_frame)
state_color.grid(row=2, column=1)
Label(info_frame, text="Key").grid(row=3, column=0)
state_key = Entry(info_frame)
state_key.grid(row=3, column=1)
info_frame.pack(side="top")


condition = Label(automata_frame, text= "Condition of conversion")
condition.pack(side="top", fill="x")
condition_frame=Frame(automata_frame, background="white")
Label(condition_frame, text="0: ").grid(row=0, column=0)
check_box_0 = Checkbutton(condition_frame)
check_box_0.grid(row=0, column=1)
Label(condition_frame, text="1: ").grid(row=0, column=2)
check_box_1 = Checkbutton(condition_frame)
check_box_1.grid(row=0, column=3)
Label(condition_frame, text="2: ").grid(row=0, column=4)
check_box_2 = Checkbutton(condition_frame)
check_box_2.grid(row=0, column=5)
Label(condition_frame, text="3: ").grid(row=1, column=0)
check_box_0 = Checkbutton(condition_frame)
check_box_0.grid(row=1, column=1)
Label(condition_frame, text="4: ").grid(row=1, column=2)
check_box_1 = Checkbutton(condition_frame)
check_box_1.grid(row=1, column=3)
Label(condition_frame, text="5: ").grid(row=1, column=4)
check_box_2 = Checkbutton(condition_frame)
check_box_2.grid(row=1, column=5)
Label(condition_frame, text="6: ").grid(row=2, column=0)
check_box_0 = Checkbutton(condition_frame)
check_box_0.grid(row=2, column=1)
Label(condition_frame, text="7: ").grid(row=2, column=2)
check_box_1 = Checkbutton(condition_frame)
check_box_1.grid(row=2, column=3)
Label(condition_frame, text="8: ").grid(row=2, column=4)
check_box_2 = Checkbutton(condition_frame)
check_box_2.grid(row=2, column=5)
condition_frame.pack(side="top")


add_state = Button(automata_frame, text="ADD", command=callback, state="disabled")
add_state.config(bg="blue")
change_state = Button(automata_frame, text="Change", command=callback, state="disabled")
change_state.config(bg="violet")
add_state.pack(side="top", fill="x")
change_state.pack(side="top", fill="x")

error=Label(automata_frame)
error.pack(side="top", fill="x")


menubar = Menu(root)
root.config(menu=menubar)

menu_file = Menu(menubar)
menu_file.add_command(label="New")
menu_file.add_command(label="Open...", command=handlers.open_file)
menu_file.add_command(label="Save...", command=handlers.save_file)
menu_file.add_separator()
menu_file.add_command(label="Exit", command=root.destroy)
menubar.add_cascade(label="File", menu=menu_file)

menu_action = Menu(menubar)
menu_action.add_command(label="Start", command=handlers.start)
menu_action.add_command(label="Stop", command=handlers.stop)
menu_action.add_command(label="Next Step", command=handlers.next_step)
menu_action.add_command(label="Increase speed", command=handlers.faster)
menu_action.add_command(label="Decrease speed", command=handlers.slower)
menu_action.add_command(label="Zoom In", command=handlers.zoom_in)
menu_action.add_command(label="Zoom Out", command=handlers.zoom_out)
menu_action.add_command(label="Clean field")
menu_action.add_command(label="Fill randomly")
menubar.add_cascade(label="Action", menu=menu_action)

menubar.add_command(label="Automata", command=handlers.automata_frame)

menubar.add_command(label="Help")

root.mainloop()