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

# HG changeset patch
# User darkhan
# Date 1292017627 -10800
# Node ID bbe2a8e64826ae0d4e9e08240237b0ee68a8b296
# Parent 3ff0fdc7ce7a4b9f7483faa2b992e401cdf52154# Parent f9244666211aa54d65758cb1ff49ba502688045c
Merge

diff -r 3ff0fdc7ce7a -r bbe2a8e64826 Interface.py
--- a/Interface.py Sat Dec 11 00:46:25 2010 +0300
+++ b/Interface.py Sat Dec 11 00:47:07 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,29 +392,29 @@
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")

-up = Button(automata_window, text="Up", command=handlers.upwards)
-up.config(bg="red")
-down = Button(automata_window, text="Down", command=handlers.downwards)
-down.config(bg="orange")
-to_top = Button(automata_window, text="To Top", command=handlers.to_top)
-to_top.config(bg="yellow")
-to_bottom = Button(automata_window, text="To Bottom", command=handlers.to_bottom)
-to_bottom.config(bg="green")
-delete = Button(automata_window, text="Delete", command=handlers.delete_state)
-delete.config(bg="cyan")
-up.pack(side="top", fill="x")
-down.pack(side="top", fill="x")
-to_top.pack(side="top", fill="x")
-to_bottom.pack(side="top", fill="x")
-delete.pack(side="top", fill="x")
+manip_frame1 = Frame(automata_window, padx=10, pady=5)
+up = Button(manip_frame1, text="Up", command=handlers.upwards, width=10)
+to_top = Button(manip_frame1, text="To Top", command=handlers.to_top, width=10)
+up.pack(side="left", fill="x")
+to_top.pack(side="right", fill="x")
+manip_frame1.pack(side="top", fill="x")
+
+manip_frame2 = Frame(automata_window, padx=10, pady=5)
+down = Button(manip_frame2, text="Down", command=handlers.downwards, width=10)
+to_bottom = Button(manip_frame2, text="To Bottom", command=handlers.to_bottom, width=10)
+down.pack(side="left", fill="x")
+to_bottom.pack(side="right", fill="x")
+manip_frame2.pack(side="top", fill="x")
+
+delete = Button(automata_window, text="Delete", command=handlers.delete_state, width=10)
+delete.pack(side="top")


information = Label(automata_window, text= "Information of State")
@@ -376,12 +426,12 @@
Label(info_frame, text="Symbol").grid(row=1, column=0)
state_symbol = Entry(info_frame)
state_symbol.grid(row=1, column=1)
-Label(info_frame, text="Color").grid(row=2, column=0)
-state_color = Entry(info_frame)
-state_color.grid(row=2, column=1)
-Label(info_frame, text="Key").grid(row=3, column=0)
+Label(info_frame, text="Key").grid(row=2, column=0)
state_key = Entry(info_frame)
-state_key.grid(row=3, column=1)
+state_key.grid(row=2, column=1)
+Label(info_frame, text="Color").grid(row=3, column=0)
+state_color = Label(info_frame, background="white", cursor="plus")
+state_color.grid(row=3, column=1, sticky="ew")
info_frame.pack(side="top")


@@ -421,12 +471,12 @@
condition_frame.pack(side="top")


-add_state = Button(automata_window, text="Add", command=handlers.add)
-add_state.config(bg="blue")
-change_state = Button(automata_window, text="Change", command=handlers.change)
-change_state.config(bg="violet")
-add_state.pack(side="top", fill="x")
-change_state.pack(side="top", fill="x")
+add_frame = Frame(automata_window, padx=10, pady=5)
+add_state = Button(add_frame, text="Add", command=handlers.add, width=10)
+change_state = Button(add_frame, text="Change", command=handlers.change, width=10)
+add_state.pack(side="left", fill="x")
+change_state.pack(side="right", fill="x")
+add_frame.pack(side="top", fill="x")

error=Label(automata_window)
error.pack(side="top", fill="x")
@@ -474,11 +524,9 @@
expansion.pack(side="top")
Label(size_window).pack(side="top", fill="x")
apply_frame = Frame(size_window, padx=10, pady=5)
-apply_size = Button(apply_frame, text="Apply")
-apply_size.config(bg="yellow")
+apply_size = Button(apply_frame, text="Apply", width=6)
apply_size.pack(side="left", fill="x")
-close_size = Button(apply_frame, text="Close", command=handlers.hide_size_window)
-close_size.config(bg="green")
+close_size = Button(apply_frame, text="Close", command=handlers.hide_size_window, width=6)
close_size.pack(side="right", fill="x")
apply_frame.pack(side="top", fill="x")