cca
changeset 63:bbe2a8e64826
Merge
author | darkhan |
---|---|
date | Sat, 11 Dec 2010 00:47:07 +0300 |
parents | 3ff0fdc7ce7a f9244666211a |
children | 6f328d849ba8 |
files | |
diffstat | 1 files changed, 141 insertions(+), 93 deletions(-) [+] |
line diff
1.1 --- a/Interface.py Sat Dec 11 00:46:25 2010 +0300 1.2 +++ b/Interface.py Sat Dec 11 00:47:07 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,29 +392,29 @@ 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") 1.216 1.217 -up = Button(automata_window, text="Up", command=handlers.upwards) 1.218 -up.config(bg="red") 1.219 -down = Button(automata_window, text="Down", command=handlers.downwards) 1.220 -down.config(bg="orange") 1.221 -to_top = Button(automata_window, text="To Top", command=handlers.to_top) 1.222 -to_top.config(bg="yellow") 1.223 -to_bottom = Button(automata_window, text="To Bottom", command=handlers.to_bottom) 1.224 -to_bottom.config(bg="green") 1.225 -delete = Button(automata_window, text="Delete", command=handlers.delete_state) 1.226 -delete.config(bg="cyan") 1.227 -up.pack(side="top", fill="x") 1.228 -down.pack(side="top", fill="x") 1.229 -to_top.pack(side="top", fill="x") 1.230 -to_bottom.pack(side="top", fill="x") 1.231 -delete.pack(side="top", fill="x") 1.232 +manip_frame1 = Frame(automata_window, padx=10, pady=5) 1.233 +up = Button(manip_frame1, text="Up", command=handlers.upwards, width=10) 1.234 +to_top = Button(manip_frame1, text="To Top", command=handlers.to_top, width=10) 1.235 +up.pack(side="left", fill="x") 1.236 +to_top.pack(side="right", fill="x") 1.237 +manip_frame1.pack(side="top", fill="x") 1.238 + 1.239 +manip_frame2 = Frame(automata_window, padx=10, pady=5) 1.240 +down = Button(manip_frame2, text="Down", command=handlers.downwards, width=10) 1.241 +to_bottom = Button(manip_frame2, text="To Bottom", command=handlers.to_bottom, width=10) 1.242 +down.pack(side="left", fill="x") 1.243 +to_bottom.pack(side="right", fill="x") 1.244 +manip_frame2.pack(side="top", fill="x") 1.245 + 1.246 +delete = Button(automata_window, text="Delete", command=handlers.delete_state, width=10) 1.247 +delete.pack(side="top") 1.248 1.249 1.250 information = Label(automata_window, text= "Information of State") 1.251 @@ -376,12 +426,12 @@ 1.252 Label(info_frame, text="Symbol").grid(row=1, column=0) 1.253 state_symbol = Entry(info_frame) 1.254 state_symbol.grid(row=1, column=1) 1.255 -Label(info_frame, text="Color").grid(row=2, column=0) 1.256 -state_color = Entry(info_frame) 1.257 -state_color.grid(row=2, column=1) 1.258 -Label(info_frame, text="Key").grid(row=3, column=0) 1.259 +Label(info_frame, text="Key").grid(row=2, column=0) 1.260 state_key = Entry(info_frame) 1.261 -state_key.grid(row=3, column=1) 1.262 +state_key.grid(row=2, column=1) 1.263 +Label(info_frame, text="Color").grid(row=3, column=0) 1.264 +state_color = Label(info_frame, background="white", cursor="plus") 1.265 +state_color.grid(row=3, column=1, sticky="ew") 1.266 info_frame.pack(side="top") 1.267 1.268 1.269 @@ -421,12 +471,12 @@ 1.270 condition_frame.pack(side="top") 1.271 1.272 1.273 -add_state = Button(automata_window, text="Add", command=handlers.add) 1.274 -add_state.config(bg="blue") 1.275 -change_state = Button(automata_window, text="Change", command=handlers.change) 1.276 -change_state.config(bg="violet") 1.277 -add_state.pack(side="top", fill="x") 1.278 -change_state.pack(side="top", fill="x") 1.279 +add_frame = Frame(automata_window, padx=10, pady=5) 1.280 +add_state = Button(add_frame, text="Add", command=handlers.add, width=10) 1.281 +change_state = Button(add_frame, text="Change", command=handlers.change, width=10) 1.282 +add_state.pack(side="left", fill="x") 1.283 +change_state.pack(side="right", fill="x") 1.284 +add_frame.pack(side="top", fill="x") 1.285 1.286 error=Label(automata_window) 1.287 error.pack(side="top", fill="x") 1.288 @@ -474,11 +524,9 @@ 1.289 expansion.pack(side="top") 1.290 Label(size_window).pack(side="top", fill="x") 1.291 apply_frame = Frame(size_window, padx=10, pady=5) 1.292 -apply_size = Button(apply_frame, text="Apply") 1.293 -apply_size.config(bg="yellow") 1.294 +apply_size = Button(apply_frame, text="Apply", width=6) 1.295 apply_size.pack(side="left", fill="x") 1.296 -close_size = Button(apply_frame, text="Close", command=handlers.hide_size_window) 1.297 -close_size.config(bg="green") 1.298 +close_size = Button(apply_frame, text="Close", command=handlers.hide_size_window, width=6) 1.299 close_size.pack(side="right", fill="x") 1.300 apply_frame.pack(side="top", fill="x") 1.301