Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/cca/rev/d2705c3ee7a7
Дата изменения: Unknown
Дата индексирования: Mon Oct 1 23:09:53 2012
Кодировка:
cca: d2705c3ee7a7

cca

changeset 18:d2705c3ee7a7

something strange with hg fetch
author is_rusinov
date Sat, 04 Dec 2010 22:42:50 +0300
parents 38f357feb56e
children 3d1a72f49417
files Interface.py
diffstat 1 files changed, 85 insertions(+), 32 deletions(-) [+]
line diff
     1.1 --- a/Interface.py	Sat Dec 04 22:38:04 2010 +0300
     1.2 +++ b/Interface.py	Sat Dec 04 22:42:50 2010 +0300
     1.3 @@ -1,15 +1,24 @@
     1.4  from Tkinter import *
     1.5  
     1.6 +from State import *
     1.7 +from Automata import *
     1.8 +
     1.9 +
    1.10  class Handlers(object):
    1.11  	
    1.12 -	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
    1.13 +	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
    1.14  		self.cell_size = cell_size
    1.15 +		self.line_width = line_width
    1.16  		self.delay = delay
    1.17  		self.offset_x = offset_x
    1.18  		self.offset_y = offset_y
    1.19  		self.after_id = 0
    1.20 +		self.mouse_x = 0
    1.21 +		self.mouse_y = 0
    1.22 +		self.mouse_zoom = 0
    1.23 +		self.zoom_divisor = 10
    1.24  		self.is_started = False
    1.25 -	
    1.26 +		self.keys = dict()
    1.27  	def start(self):
    1.28  		if not self.is_started:
    1.29  			self.is_started = True
    1.30 @@ -24,16 +33,16 @@
    1.31  		automata.next_step()
    1.32  		self.draw()
    1.33  	
    1.34 -	def save_file():
    1.35 +	def save_file(self):
    1.36  		pass
    1.37  	
    1.38 -	def open_file():
    1.39 +	def open_file(self):
    1.40  		pass
    1.41  	
    1.42 -	def help():
    1.43 +	def help(self):
    1.44  		pass
    1.45  	
    1.46 -	def close_help_window
    1.47 +	def close_help_window(self):
    1.48  		pass
    1.49  	
    1.50  	def zoom_in(self, zoom_rate=1):
    1.51 @@ -55,21 +64,21 @@
    1.52  		else:
    1.53  			self.delay = 0
    1.54  	
    1.55 -	def change_size(dx, dy, position=0):
    1.56 +	def change_size(self, dx, dy, position=0):
    1.57  		if position < 9:
    1.58  			if position == 0 or position == 3 or position == 6:
    1.59  				automata.change_size(dx, 3)
    1.60  			elif position == 1 or position == 4 or position == 7:
    1.61  				automata.change_size(dx / 2, 3)
    1.62  				automata.change_size(dx - dx / 2, 1)
    1.63 -			else 
    1.64 +			else:
    1.65  				automata.change_size(dx, 1)
    1.66  			if position == 0 or position == 1 or position == 2:
    1.67  				automata.change_size(dy, 0)
    1.68  			elif position == 3 or position == 4 or position == 5:
    1.69  				automata.change_size(dy / 2, 0)
    1.70  				automata.change_size(dy - dy / 2, 2)
    1.71 -			else 
    1.72 +			else:
    1.73  				automata.change_size(dy, 2)
    1.74  			self.draw()
    1.75  	
    1.76 @@ -77,28 +86,70 @@
    1.77  		pass
    1.78  	
    1.79  	def press1(self, event):# drawer
    1.80 -		pass
    1.81 +		column = (event.x - self.offset_x) / (self.cell_size + self.line_width)
    1.82 +		row = (event.y - self.offset_y) / (self.cell_size + self.line_width)
    1.83 +		index = (automata.symbols[automata.field[row][column]] + 1) % len(automata.states)
    1.84 +		automata.field[row][column] = automata.states[index].symbol
    1.85 +		self.draw()
    1.86  	
    1.87  	def motion1(self, event):# drawer
    1.88 -		pass
    1.89 +		column = (event.x - self.offset_x) / (self.cell_size + self.line_width)
    1.90 +		row = (event.y - self.offset_y) / (self.cell_size + self.line_width)
    1.91 +		index = (automata.symbols[automata.field[row][column]] + 1) % len(automata.states)
    1.92 +		automata.field[row][column] = automata.states[index].symbol
    1.93 +		self.draw()
    1.94  	
    1.95  	def press3(self, event):# drawer
    1.96 -		pass
    1.97 +		column = (event.x - self.offset_x) / (self.cell_size + self.line_width)
    1.98 +		row = (event.y - self.offset_y) / (self.cell_size + self.line_width)
    1.99 +		index = (automata.symbols[automata.field[row][column]] + len(automata.states) - 1) % len(automata.states)
   1.100 +		automata.field[row][column] = automata.states[index].symbol
   1.101 +		self.draw()
   1.102  	
   1.103  	def motion3(self, event):# drawer
   1.104 -		pass
   1.105 +		column = (event.x - self.offset_x) / (self.cell_size + self.line_width)
   1.106 +		row = (event.y - self.offset_y) / (self.cell_size + self.line_width)
   1.107 +		index = (automata.symbols[automata.field[row][column]] + len(automata.states) - 1) % len(automata.states)
   1.108 +		automata.field[row][column] = automata.states[index].symbol
   1.109 +		self.draw()
   1.110  	
   1.111 -	def press_key1(self, event):# drawer+change_scale (B1+ctrl)
   1.112 -		pass
   1.113 +	def press1_key(self, event):# drawer
   1.114 +		if keys.has_key(event.char):
   1.115 +			column = (event.x - self.offset_x) / (self.cell_size + self.line_width)
   1.116 +			row = (event.y - self.offset_y) / (self.cell_size + self.line_width)
   1.117 +			automata.field[row][column] = automata.states[keys[event.char]].symbol
   1.118 +			self.draw()
   1.119  	
   1.120 -	def motion_key1(self, event):# drawer+change_scale (B1+ctrl)
   1.121 -		pass
   1.122 +	def motion1_key(self, event):# drawer
   1.123 +		if keys.has_key(event.char):
   1.124 +			column = (event.x - self.offset_x) / (self.cell_size + self.line_width)
   1.125 +			row = (event.y - self.offset_y) / (self.cell_size + self.line_width)
   1.126 +			automata.field[row][column] = automata.states[keys[event.char]].symbol
   1.127 +			self.draw()
   1.128 +	
   1.129 +	def press1_ctrl(self, event):# change_scale (B1+ctrl)
   1.130 +		self.mouse_x = event.x
   1.131 +		self.mouse_y = event.y
   1.132 +	
   1.133 +	def motion1_ctrl(self, event):# change_scale (B1+ctrl)
   1.134 +		self.offset_x = event.x - self.mouse_x
   1.135 +		self.offset_y = event.y - self.mouse_y
   1.136 +		self.mouse_x = event.x
   1.137 +		self.mouse_y = event.y
   1.138 +		self.draw()
   1.139  	
   1.140  	def press12(self, event):# zoom
   1.141 -		pass
   1.142 +		self.mouse_zoom = event.y
   1.143  	
   1.144  	def motion12(self, event):# zoom
   1.145 -		pass
   1.146 +		delta = (event.y - self.mouse_zoom) / self.zoom_divisor
   1.147 +		self.cell_size = self.cell_size + delta
   1.148 +		if self.cell_size > 50:
   1.149 +			self.cell_size = 50
   1.150 +		if self.cell_size < 1:
   1.151 +			self.cell_size = 1
   1.152 +		self.mouse_zoom = event.y
   1.153 +		self.draw()
   1.154  	
   1.155  	def automata_frame(self):# show automata_frame
   1.156  		automata_frame.pack(side="right", fill="y", expand="no", before=canvas)
   1.157 @@ -131,12 +182,15 @@
   1.158  		index = symbols.get(state_list.get("active").split()[1])
   1.159  		del states[index]
   1.160  	
   1.161 -	def add():# add new state
   1.162 +	def add(self):# add new state
   1.163  		pass
   1.164  	
   1.165 -	def change():# change chosen state
   1.166 +	def change(self):# change chosen state
   1.167  		pass
   1.168 -	
   1.169 +	def show_size_window(self):
   1.170 +		size_window.deiconify()
   1.171 +	def hide_size_window(self):
   1.172 +		size_window.withdraw()
   1.173  
   1.174  
   1.175  root = Tk()
   1.176 @@ -153,7 +207,7 @@
   1.177  symboles = dict()
   1.178  
   1.179  #infoPanel=Frame
   1.180 -automata_frame=Frame(root, background="white")
   1.181 +automata_frame=Frame(root, background="grey")
   1.182  
   1.183  headline_frame=Frame(automata_frame, background="white")
   1.184  head = Label(headline_frame, text= "Automata Panel", font=16)
   1.185 @@ -168,15 +222,15 @@
   1.186  for state in states:
   1.187  	state_list.insert("end", state)
   1.188  state_list.pack(side="top", fill="y")
   1.189 -up = Button(automata_frame, text="Up", state="disabled")
   1.190 +up = Button(automata_frame, text="Up", state="DISABLED")
   1.191  up.config(bg="red")
   1.192 -down = Button(automata_frame, text="Down", state="disabled")
   1.193 +down = Button(automata_frame, text="Down", state="DISABLED")
   1.194  down.config(bg="orange")
   1.195 -to_top = Button(automata_frame, text="To Top", state="disabled")
   1.196 +to_top = Button(automata_frame, text="To Top", state="DISABLED")
   1.197  to_top.config(bg="yellow")
   1.198 -to_bottom = Button(automata_frame, text="To Bottom", state="disabled")
   1.199 +to_bottom = Button(automata_frame, text="To Bottom", state="DISABLED")
   1.200  to_bottom.config(bg="green")
   1.201 -delete = Button(automata_frame, text="Delete", state="disabled")
   1.202 +delete = Button(automata_frame, text="Delete", state="DISABLED")
   1.203  delete.config(bg="cyan")
   1.204  up.pack(side="top", fill="x")
   1.205  down.pack(side="top", fill="x")
   1.206 @@ -236,9 +290,9 @@
   1.207  condition_frame.pack(side="top")
   1.208  
   1.209  
   1.210 -add_state = Button(automata_frame, text="ADD", state="disabled")
   1.211 +add_state = Button(automata_frame, text="ADD", state="DISABLED")
   1.212  add_state.config(bg="blue")
   1.213 -change_state = Button(automata_frame, text="Change", state="disabled")
   1.214 +change_state = Button(automata_frame, text="Change", state="DISABLED")
   1.215  change_state.config(bg="violet")
   1.216  add_state.pack(side="top", fill="x")
   1.217  change_state.pack(side="top", fill="x")
   1.218 @@ -254,8 +308,7 @@
   1.219  size_window.withdraw()
   1.220  size_window.protocol("WM_DELETE_WINDOW", handlers.hide_size_window)
   1.221  Label(size_window, text= "Current size of window:").pack(side="top", fill="x")
   1.222 -size = Label(size_window, text= str(len(automata.field)) + " x " + str(len(automata.field[0])))
   1.223 -size.pack(side="top", fill="x")
   1.224 +Label(size_window, text= "X x Y").pack(side="top", fill="x")
   1.225  Label(size_window, text= "New size:").pack(side="top", fill="x")
   1.226  new_size = Frame(size_window)
   1.227  size_x = Entry(new_size, width=5)