Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/cca/raw-rev/d2705c3ee7a7
Дата изменения: Unknown
Дата индексирования: Tue Oct 2 04:32:52 2012
Кодировка:

# HG changeset patch
# User is_rusinov
# Date 1291491770 -10800
# Node ID d2705c3ee7a7ac8e5e2c6dec21df27ba9321285d
# Parent 38f357feb56e114b3fe6fd44d098f6c0c65bb133
something strange with hg fetch

diff -r 38f357feb56e -r d2705c3ee7a7 Interface.py
--- a/Interface.py Sat Dec 04 22:38:04 2010 +0300
+++ b/Interface.py Sat Dec 04 22:42:50 2010 +0300
@@ -1,15 +1,24 @@
from Tkinter import *

+from State import *
+from Automata 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
+ def __init__(self, cell_size=5, line_width=1 ,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.line_width = line_width
self.delay = delay
self.offset_x = offset_x
self.offset_y = offset_y
self.after_id = 0
+ self.mouse_x = 0
+ self.mouse_y = 0
+ self.mouse_zoom = 0
+ self.zoom_divisor = 10
self.is_started = False
-
+ self.keys = dict()
def start(self):
if not self.is_started:
self.is_started = True
@@ -24,16 +33,16 @@
automata.next_step()
self.draw()

- def save_file():
+ def save_file(self):
pass

- def open_file():
+ def open_file(self):
pass

- def help():
+ def help(self):
pass

- def close_help_window
+ def close_help_window(self):
pass

def zoom_in(self, zoom_rate=1):
@@ -55,21 +64,21 @@
else:
self.delay = 0

- def change_size(dx, dy, position=0):
+ def change_size(self, 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
+ 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
+ else:
automata.change_size(dy, 2)
self.draw()

@@ -77,28 +86,70 @@
pass

def press1(self, event):# drawer
- pass
+ column = (event.x - self.offset_x) / (self.cell_size + self.line_width)
+ row = (event.y - self.offset_y) / (self.cell_size + self.line_width)
+ index = (automata.symbols[automata.field[row][column]] + 1) % len(automata.states)
+ automata.field[row][column] = automata.states[index].symbol
+ self.draw()

def motion1(self, event):# drawer
- pass
+ column = (event.x - self.offset_x) / (self.cell_size + self.line_width)
+ row = (event.y - self.offset_y) / (self.cell_size + self.line_width)
+ index = (automata.symbols[automata.field[row][column]] + 1) % len(automata.states)
+ automata.field[row][column] = automata.states[index].symbol
+ self.draw()

def press3(self, event):# drawer
- pass
+ column = (event.x - self.offset_x) / (self.cell_size + self.line_width)
+ row = (event.y - self.offset_y) / (self.cell_size + self.line_width)
+ index = (automata.symbols[automata.field[row][column]] + len(automata.states) - 1) % len(automata.states)
+ automata.field[row][column] = automata.states[index].symbol
+ self.draw()

def motion3(self, event):# drawer
- pass
+ column = (event.x - self.offset_x) / (self.cell_size + self.line_width)
+ row = (event.y - self.offset_y) / (self.cell_size + self.line_width)
+ index = (automata.symbols[automata.field[row][column]] + len(automata.states) - 1) % len(automata.states)
+ automata.field[row][column] = automata.states[index].symbol
+ self.draw()

- def press_key1(self, event):# drawer+change_scale (B1+ctrl)
- pass
+ def press1_key(self, event):# drawer
+ if keys.has_key(event.char):
+ column = (event.x - self.offset_x) / (self.cell_size + self.line_width)
+ row = (event.y - self.offset_y) / (self.cell_size + self.line_width)
+ automata.field[row][column] = automata.states[keys[event.char]].symbol
+ self.draw()

- def motion_key1(self, event):# drawer+change_scale (B1+ctrl)
- pass
+ def motion1_key(self, event):# drawer
+ if keys.has_key(event.char):
+ column = (event.x - self.offset_x) / (self.cell_size + self.line_width)
+ row = (event.y - self.offset_y) / (self.cell_size + self.line_width)
+ automata.field[row][column] = automata.states[keys[event.char]].symbol
+ self.draw()
+
+ def press1_ctrl(self, event):# change_scale (B1+ctrl)
+ self.mouse_x = event.x
+ self.mouse_y = event.y
+
+ def motion1_ctrl(self, event):# change_scale (B1+ctrl)
+ self.offset_x = event.x - self.mouse_x
+ self.offset_y = event.y - self.mouse_y
+ self.mouse_x = event.x
+ self.mouse_y = event.y
+ self.draw()

def press12(self, event):# zoom
- pass
+ self.mouse_zoom = event.y

def motion12(self, event):# zoom
- pass
+ delta = (event.y - self.mouse_zoom) / self.zoom_divisor
+ self.cell_size = self.cell_size + delta
+ if self.cell_size > 50:
+ self.cell_size = 50
+ if self.cell_size < 1:
+ self.cell_size = 1
+ self.mouse_zoom = event.y
+ self.draw()

def automata_frame(self):# show automata_frame
automata_frame.pack(side="right", fill="y", expand="no", before=canvas)
@@ -131,12 +182,15 @@
index = symbols.get(state_list.get("active").split()[1])
del states[index]

- def add():# add new state
+ def add(self):# add new state
pass

- def change():# change chosen state
+ def change(self):# change chosen state
pass
-
+ def show_size_window(self):
+ size_window.deiconify()
+ def hide_size_window(self):
+ size_window.withdraw()


root = Tk()
@@ -153,7 +207,7 @@
symboles = dict()

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

headline_frame=Frame(automata_frame, background="white")
head = Label(headline_frame, text= "Automata Panel", font=16)
@@ -168,15 +222,15 @@
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 = Button(automata_frame, text="Up", state="DISABLED")
up.config(bg="red")
-down = Button(automata_frame, text="Down", state="disabled")
+down = Button(automata_frame, text="Down", state="DISABLED")
down.config(bg="orange")
-to_top = Button(automata_frame, text="To Top", state="disabled")
+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 = Button(automata_frame, text="To Bottom", state="DISABLED")
to_bottom.config(bg="green")
-delete = Button(automata_frame, text="Delete", state="disabled")
+delete = Button(automata_frame, text="Delete", state="DISABLED")
delete.config(bg="cyan")
up.pack(side="top", fill="x")
down.pack(side="top", fill="x")
@@ -236,9 +290,9 @@
condition_frame.pack(side="top")


-add_state = Button(automata_frame, text="ADD", state="disabled")
+add_state = Button(automata_frame, text="ADD", state="DISABLED")
add_state.config(bg="blue")
-change_state = Button(automata_frame, text="Change", state="disabled")
+change_state = Button(automata_frame, text="Change", state="DISABLED")
change_state.config(bg="violet")
add_state.pack(side="top", fill="x")
change_state.pack(side="top", fill="x")
@@ -254,8 +308,7 @@
size_window.withdraw()
size_window.protocol("WM_DELETE_WINDOW", handlers.hide_size_window)
Label(size_window, text= "Current size of window:").pack(side="top", fill="x")
-size = Label(size_window, text= str(len(automata.field)) + " x " + str(len(automata.field[0])))
-size.pack(side="top", fill="x")
+Label(size_window, text= "X x Y").pack(side="top", fill="x")
Label(size_window, text= "New size:").pack(side="top", fill="x")
new_size = Frame(size_window)
size_x = Entry(new_size, width=5)