from tkMessageBox import *
from Tkinter import *
from tkFileDialog import *
import fileinput
class TMR(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.menu_GUI()
def menu_GUI(self):
self.parent.title(“Triple Modular Redundancy”)
self.pack(fill=BOTH, expand=1)
menubar = Menu(self.parent)
self.parent.config(menu=menubar)
filemenu = Menu(menubar)
filemenu.add_command(label=“Open…”, command=self.file_open)
filemenu.add_command(label=“Save as…”, command=self.file_save)
filemenu.add_separator()
filemenu.add_command(label=“Exit”, command=self.close)
menubar.add_cascade(label=“File”, menu=filemenu)
toolmenu = Menu(menubar)
toolmenu.add_command(label=“Handle”, command=self.file_search)
menubar.add_cascade(label=“Tool”, menu=toolmenu)
aboutmenu = Menu(menubar)
aboutmenu.add_command(label=“About”, command=self.about)
menubar.add_cascade(label=“Help”, menu=aboutmenu)
self.txt = Text(self)
self.txt.pack(fill=BOTH, expand=1)
def file_open(self):
file = askopenfile(mode='rb',title='Choose file')
if file != None:
data = file.read()
print data
self.txt.delete(1.0, END)
for i in data:
self.txt.insert(END, i)
return data
“”“def file_read(self, data):
if file != None:
data1 = file.read()
return data1
print ”data1“”“”“
def close(self):
if askyesno(”Exit“, ”Do you want to quit?“):
self.parent.destroy()
def about(self):
showinfo(” “,” This is TMR editor.\nTMR is a fault- tolerant form of N-modular redundancy, in which three systems perform a process \
and that result is processed by a majority-voting system to produce a single output.\
If any one of the three systems fails, the other two systems can correct and mask the fault.“)
def file_save(self):
f = tkFileDialog.asksaveasfile(mode='w', defaultextension=”.py“)
if f is None:
return
text2save = str(self.txt.get(1.0, END))
f.write(text2save)
f.close()
def file_search(self):
text = self.file_read(data1)
print text
for _str in text:
if _str == ”if“:
print ”i find“
def main():
root = Tk()
ex = TMR(root)
root.geometry(”800x600")
root.mainloop()
if __name__ == ‘__main__’:
main()
Собственно, что получилось, но не удается производить поиск по строкам, все время ошибка с классами, помогите, пожалуйста, начать поиск в функции file_search по открытому файлу.