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

# HG changeset patch
# User is_rusinov
# Date 1291764819 -10800
# Node ID dd3e42d72f44bb1cbe377e2ad161e9851c73ac73
# Parent 9bc9d3b375254d8078ed47d6e5466b16819bcdda
state_list change handlers and fill of entries

diff -r 9bc9d3b37525 -r dd3e42d72f44 Interface.py
--- a/Interface.py Tue Dec 07 16:05:28 2010 +0300
+++ b/Interface.py Wed Dec 08 02:33:39 2010 +0300
@@ -194,41 +194,67 @@
self.draw()

def to_top(self):# replace choosen state to top
- index = automata.symbols.get(state_list.get("active").split()[0])
- state = automata.states[index]
- del automata.states[index]
- automata.states.insert(0, state)
- state_list.delete(index)
- state_list.insert(0, state)
+ selected = state_list.curselection()
+ if len(selected):
+ index = int(selected[0])
+ state = automata.states[index]
+ print state
+ del automata.states[index]
+ automata.states.insert(0, state)
+ self.refresh_list()
+ state_list.selection_set(0)
+ print automata.states

def to_bottom(self):# replace choosen state to botton
- index = automata.symbols.get(state_list.get("active").split()[0])
- state = automata.states[index]
- del automata.states[index]
- automata.states.append(state)
- state_list.delete(index)
- state_list.insert("end", state)
+ selected = state_list.curselection()
+ if len(selected):
+ index = int(selected[0])
+ state = automata.states[index]
+ print state
+ del automata.states[index]
+ automata.states.append(state)
+ self.refresh_list()
+ state_list.selection_set("end")
+ print automata.states

def upwards(self):
- index = automata.symbols.get(state_list.get("active").split()[0])
- state = automata.states[index]
- del automata.states[index]
- automata.states.insert(index - 1, state)
- state_list.delete(index)
- state_list.insert(index - 1, state)
+ selected = state_list.curselection()
+ if len(selected):
+ index = int(selected[0])
+ if index > 0:
+ state = automata.states[index]
+ print state
+ del automata.states[index]
+ automata.states.insert(index - 1, state)
+ self.refresh_list()
+ state_list.selection_set(index - 1)
+ print automata.states

def downwards(self):
- index = automata.symbols.get(state_list.get("active").split()[0])
- state = automata.states[index]
- del automata.states[index]
- automata.states.insert(index + 1, state)
- state_list.delete(index)
- state_list.insert(index + 1, state)
+ selected = state_list.curselection()
+ if len(selected):
+ index = int(selected[0])
+ if index < state_list.size() - 1:
+ state = automata.states[index]
+ print state
+ del automata.states[index]
+ automata.states.insert(index + 1, state)
+ self.refresh_list()
+ state_list.selection_set(index + 1)
+ print automata.states

def delete_state(self):# delete choosen state
- index = automata.symbols.get(state_list.get("active").split()[0])
- del automata.states[index]
- state_list.delete(index)
+ selected = state_list.curselection()
+ if len(selected):
+ index = int(selected[0])
+ print automata.states[index]
+ del automata.symbols[automata.states[index].symbol]
+ for key in self.keys.keys():
+ if self.keys[key] == index:
+ del self.keys[key]
+ del automata.states[index]
+ self.refresh_list()
+ print automata.states

def add(self):# add new state
name = state_name.get()
@@ -256,39 +282,42 @@
automata.states.append(state)
automata.symbols[symbol] = len(automata.states) - 1
self.keys[key] = len(automata.states) - 1
- state_list.insert("end", state)
+ error.config(text="")
+ self.refresh_list()

def change(self):# change chosen state
- index = automata.symbols.get(state_list.get("active").split()[0])
- name = state_name.get()
- symbol = state_symbol.get()
- key = state_key.get().lower()
- color = state_color.get()
- nums = []
- for i, value in enumerate(ckeckbox_nums):
- print i, value.get()
- if value.get() == 1:
- nums.append(i)
- print nums
- if self.keys.has_key(key) and self.keys[key] != index:
- error.config(text="State with such key has already existed")
- state_key.focus()
- elif len(key) != 1:
- error.config(text="Bad key for state")
- state_key.focus()
- elif automata.symbols.has_key(symbol) and automata.symbols[symbol] != index:
- error.config(text="State with such symbol has already existed")
- state_symbol.focus()
- elif len(symbol) != 1:
- error.config(text="Bad symbol for state")
- state_symbol.focus()
- else:
- state = State(name, symbol, color, nums)
- automata.states[index] = state
- automata.symbols[symbol] = index
- self.keys[key] = index
- state_list.delete(index)
- state_list.insert(index, state)
+ selected = state_list.curselection()
+ if len(selected):
+ index = int(selected[0])
+ name = state_name.get()
+ symbol = state_symbol.get()
+ key = state_key.get().lower()
+ color = state_color.get()
+ nums = []
+ for i, value in enumerate(ckeckbox_nums):
+ print i, value.get()
+ if value.get() == 1:
+ nums.append(i)
+ print nums
+ if self.keys.has_key(key) and self.keys[key] != index:
+ error.config(text="State with such key has already existed")
+ state_key.focus()
+ elif len(key) != 1:
+ error.config(text="Bad key for state")
+ state_key.focus()
+ elif automata.symbols.has_key(symbol) and automata.symbols[symbol] != index:
+ error.config(text="State with such symbol has already existed")
+ state_symbol.focus()
+ elif len(symbol) != 1:
+ error.config(text="Bad symbol for state")
+ state_symbol.focus()
+ else:
+ state = State(name, symbol, color, nums)
+ automata.states[index] = state
+ automata.symbols[symbol] = index
+ self.keys[key] = index
+ error.config(text="")
+ self.refresh_list()

def show_size_window(self):
size_window.deiconify()
@@ -301,7 +330,28 @@

def hide_automata_window(self):
automata_window.withdraw()
-
+ def refresh_list(self):
+ state_list.delete(0, "end")
+ for state in automata.states:
+ state_list.insert("end", state)
+ def list_mouse_release(self, event):
+ print 'hello'
+ selected = state_list.curselection()
+ if len(selected):
+ index = int(selected[0])
+ state = automata.states[index]
+ state_name.delete(0, "end")
+ state_name.insert(0, state.name)
+ state_symbol.delete(0, "end")
+ state_symbol.insert(0, state.symbol)
+ for key in self.keys.keys():
+ if self.keys[key] == index:
+ state_key.delete(0, "end")
+ state_key.insert(0, key)
+ state_color.delete(0, "end")
+ state_color.insert(0, state.color)
+ for i in range(9):
+ ckeckbox_nums[i].set(i in state.nums)



@@ -342,10 +392,9 @@
list_frame=Frame(automata_window)
scrollbar = Scrollbar(list_frame)
scrollbar.pack(side="right", fill="y")
-state_list=Listbox(list_frame, yscrollcommand=scrollbar.set,
- selectmode="extended")
-for state in automata.states:
- state_list.insert("end", state)
+state_list=Listbox(list_frame, yscrollcommand=scrollbar.set, activestyle="none", selectmode="single")
+handlers.refresh_list()
+state_list.bind("", handlers.list_mouse_release)
state_list.pack(side="top", fill="y")
scrollbar.config(command=state_list.yview)
list_frame.pack(side="top")