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

cca

diff Interface.py @ 58:dd3e42d72f44

state_list change handlers and fill of entries
author is_rusinov
date Wed, 08 Dec 2010 02:33:39 +0300
parents 9bc9d3b37525
children 9a80d2c6acbf
line diff
     1.1 --- a/Interface.py	Tue Dec 07 16:05:28 2010 +0300
     1.2 +++ b/Interface.py	Wed Dec 08 02:33:39 2010 +0300
     1.3 @@ -194,41 +194,67 @@
     1.4  		self.draw()
     1.5  	
     1.6  	def to_top(self):# replace choosen state to top
     1.7 -		index = automata.symbols.get(state_list.get("active").split()[0])
     1.8 -		state = automata.states[index]
     1.9 -		del automata.states[index]
    1.10 -		automata.states.insert(0, state)
    1.11 -		state_list.delete(index)
    1.12 -		state_list.insert(0, state)
    1.13 +		selected = state_list.curselection()
    1.14 +		if len(selected):
    1.15 +			index = int(selected[0])
    1.16 +			state = automata.states[index]
    1.17 +			print state
    1.18 +			del automata.states[index]
    1.19 +			automata.states.insert(0, state)
    1.20 +			self.refresh_list()
    1.21 +			state_list.selection_set(0)
    1.22 +			print automata.states
    1.23  	
    1.24  	def to_bottom(self):# replace choosen state to botton
    1.25 -		index = automata.symbols.get(state_list.get("active").split()[0])
    1.26 -		state = automata.states[index]
    1.27 -		del automata.states[index]
    1.28 -		automata.states.append(state)
    1.29 -		state_list.delete(index)
    1.30 -		state_list.insert("end", state)
    1.31 +		selected = state_list.curselection()
    1.32 +		if len(selected):
    1.33 +			index = int(selected[0])
    1.34 +			state = automata.states[index]
    1.35 +			print state
    1.36 +			del automata.states[index]
    1.37 +			automata.states.append(state)
    1.38 +			self.refresh_list()
    1.39 +			state_list.selection_set("end")
    1.40 +			print automata.states
    1.41  	
    1.42  	def upwards(self):
    1.43 -		index = automata.symbols.get(state_list.get("active").split()[0])
    1.44 -		state = automata.states[index]
    1.45 -		del automata.states[index]
    1.46 -		automata.states.insert(index - 1, state)
    1.47 -		state_list.delete(index)
    1.48 -		state_list.insert(index - 1, state)
    1.49 +		selected = state_list.curselection()
    1.50 +		if len(selected):
    1.51 +			index = int(selected[0])
    1.52 +			if index > 0:
    1.53 +				state = automata.states[index]
    1.54 +				print state
    1.55 +				del automata.states[index]
    1.56 +				automata.states.insert(index - 1, state)
    1.57 +				self.refresh_list()
    1.58 +				state_list.selection_set(index - 1)
    1.59 +				print automata.states
    1.60  	
    1.61  	def downwards(self):
    1.62 -		index = automata.symbols.get(state_list.get("active").split()[0])
    1.63 -		state = automata.states[index]
    1.64 -		del automata.states[index]
    1.65 -		automata.states.insert(index + 1, state)
    1.66 -		state_list.delete(index)
    1.67 -		state_list.insert(index + 1, state)
    1.68 +		selected = state_list.curselection()
    1.69 +		if len(selected):
    1.70 +			index = int(selected[0])
    1.71 +			if index < state_list.size() - 1:
    1.72 +				state = automata.states[index]
    1.73 +				print state
    1.74 +				del automata.states[index]
    1.75 +				automata.states.insert(index + 1, state)
    1.76 +				self.refresh_list()
    1.77 +				state_list.selection_set(index + 1)
    1.78 +				print automata.states
    1.79  	
    1.80  	def delete_state(self):# delete choosen state
    1.81 -		index = automata.symbols.get(state_list.get("active").split()[0])
    1.82 -		del automata.states[index]
    1.83 -		state_list.delete(index)
    1.84 +		selected = state_list.curselection()
    1.85 +		if len(selected):
    1.86 +			index = int(selected[0])
    1.87 +			print automata.states[index]
    1.88 +			del automata.symbols[automata.states[index].symbol]
    1.89 +			for key in self.keys.keys():
    1.90 +				if self.keys[key] == index:
    1.91 +					del self.keys[key]
    1.92 +			del automata.states[index]
    1.93 +			self.refresh_list()
    1.94 +			print automata.states
    1.95  	
    1.96  	def add(self):# add new state
    1.97  		name = state_name.get()
    1.98 @@ -256,39 +282,42 @@
    1.99  			automata.states.append(state)
   1.100  			automata.symbols[symbol] = len(automata.states) - 1
   1.101  			self.keys[key] = len(automata.states) - 1
   1.102 -			state_list.insert("end", state)
   1.103 +			error.config(text="")
   1.104 +			self.refresh_list()
   1.105  	
   1.106  	def change(self):# change chosen state
   1.107 -		index = automata.symbols.get(state_list.get("active").split()[0])
   1.108 -		name = state_name.get()
   1.109 -		symbol = state_symbol.get()
   1.110 -		key = state_key.get().lower()
   1.111 -		color = state_color.get()
   1.112 -		nums = []
   1.113 -		for i, value in enumerate(ckeckbox_nums):
   1.114 -			print i, value.get()
   1.115 -			if value.get() == 1:
   1.116 -				nums.append(i)
   1.117 -		print nums
   1.118 -		if self.keys.has_key(key) and self.keys[key] != index:
   1.119 -			error.config(text="State with such key has already existed")
   1.120 -			state_key.focus()
   1.121 -		elif len(key) != 1:
   1.122 -			error.config(text="Bad key for state")
   1.123 -			state_key.focus()
   1.124 -		elif automata.symbols.has_key(symbol)  and automata.symbols[symbol] != index:
   1.125 -			error.config(text="State with such symbol has already existed")
   1.126 -			state_symbol.focus()
   1.127 -		elif len(symbol) != 1:
   1.128 -			error.config(text="Bad symbol for state")
   1.129 -			state_symbol.focus()
   1.130 -		else:
   1.131 -			state = State(name, symbol, color, nums)
   1.132 -			automata.states[index] = state
   1.133 -			automata.symbols[symbol] = index
   1.134 -			self.keys[key] = index
   1.135 -			state_list.delete(index)
   1.136 -			state_list.insert(index, state)
   1.137 +		selected = state_list.curselection()
   1.138 +		if len(selected):
   1.139 +			index = int(selected[0])
   1.140 +			name = state_name.get()
   1.141 +			symbol = state_symbol.get()
   1.142 +			key = state_key.get().lower()
   1.143 +			color = state_color.get()
   1.144 +			nums = []
   1.145 +			for i, value in enumerate(ckeckbox_nums):
   1.146 +				print i, value.get()
   1.147 +				if value.get() == 1:
   1.148 +					nums.append(i)
   1.149 +			print nums
   1.150 +			if self.keys.has_key(key) and self.keys[key] != index:
   1.151 +				error.config(text="State with such key has already existed")
   1.152 +				state_key.focus()
   1.153 +			elif len(key) != 1:
   1.154 +				error.config(text="Bad key for state")
   1.155 +				state_key.focus()
   1.156 +			elif automata.symbols.has_key(symbol)  and automata.symbols[symbol] != index:
   1.157 +				error.config(text="State with such symbol has already existed")
   1.158 +				state_symbol.focus()
   1.159 +			elif len(symbol) != 1:
   1.160 +				error.config(text="Bad symbol for state")
   1.161 +				state_symbol.focus()
   1.162 +			else:
   1.163 +				state = State(name, symbol, color, nums)
   1.164 +				automata.states[index] = state
   1.165 +				automata.symbols[symbol] = index
   1.166 +				self.keys[key] = index
   1.167 +				error.config(text="")
   1.168 +				self.refresh_list()
   1.169  	
   1.170  	def show_size_window(self):
   1.171  		size_window.deiconify()
   1.172 @@ -301,7 +330,28 @@
   1.173  	
   1.174  	def hide_automata_window(self):
   1.175  		automata_window.withdraw()
   1.176 -		
   1.177 +	def refresh_list(self):
   1.178 +		state_list.delete(0, "end")
   1.179 +		for state in automata.states:
   1.180 +			state_list.insert("end", state)
   1.181 +	def list_mouse_release(self, event):
   1.182 +		print 'hello'
   1.183 +		selected = state_list.curselection()
   1.184 +		if len(selected):
   1.185 +			index = int(selected[0])
   1.186 +			state = automata.states[index]
   1.187 +			state_name.delete(0, "end")
   1.188 +			state_name.insert(0, state.name)
   1.189 +			state_symbol.delete(0, "end")
   1.190 +			state_symbol.insert(0, state.symbol)
   1.191 +			for key in self.keys.keys():
   1.192 +				if self.keys[key] == index:
   1.193 +					state_key.delete(0, "end")
   1.194 +					state_key.insert(0, key)
   1.195 +			state_color.delete(0, "end")
   1.196 +			state_color.insert(0, state.color)
   1.197 +			for i in range(9):
   1.198 +				ckeckbox_nums[i].set(i in state.nums)
   1.199  
   1.200  
   1.201  
   1.202 @@ -342,10 +392,9 @@
   1.203  list_frame=Frame(automata_window)
   1.204  scrollbar = Scrollbar(list_frame)
   1.205  scrollbar.pack(side="right", fill="y")
   1.206 -state_list=Listbox(list_frame, yscrollcommand=scrollbar.set, 
   1.207 -											selectmode="extended")
   1.208 -for state in automata.states:
   1.209 -	state_list.insert("end", state)
   1.210 +state_list=Listbox(list_frame, yscrollcommand=scrollbar.set, activestyle="none", selectmode="single")
   1.211 +handlers.refresh_list()
   1.212 +state_list.bind("<ButtonRelease-1>", handlers.list_mouse_release)
   1.213  state_list.pack(side="top", fill="y")
   1.214  scrollbar.config(command=state_list.yview)
   1.215  list_frame.pack(side="top")