Created
September 12, 2014 06:00
-
-
Save JesseEisen/0097b8ce930c814845a9 to your computer and use it in GitHub Desktop.
This is my owner tools,use to review my note easily. without to view in floder.just click. Support save the modify.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Tkinter import * | |
from tkMessageBox import * | |
from FileDialog import * | |
import os | |
root=Tk() | |
root.title('Reviewer') | |
root.geometry('900x600') | |
#this is a function to get file list | |
def getfilelist(p): | |
p = str(p) | |
if p == "": | |
return [ ] | |
p = p.replace('/','\\') | |
if p[-1] != "\\": | |
p = p+"\\" | |
a= os.listdir(p) | |
b = [x for x in a if os.path.isfile(p + x)] | |
return b | |
#this is function to show list | |
def show_inlistbox(*direct): | |
lb.delete(0,END) | |
for i in direct: | |
lb.insert(END,i) | |
#this is the path we can define customly | |
p = "C:\Users\Believe\Desktop\python" | |
#here will create menubar | |
def showcurrent_list(): | |
global path | |
end=V.get() | |
path=p + '\\' + end | |
direct=getfilelist(path) | |
show_inlistbox(*direct) | |
#this is function to read file context | |
def show_intext(event): | |
global fn | |
t.delete(1.0,END) | |
indexs=lb.curselection() | |
filename=lb.get(indexs) | |
newpath=p +'\\'+ V.get()+'\\'+ filename | |
fn= open(newpath,'r+') | |
i = 1 | |
for line in fn: | |
t.insert(END,line) | |
i += 1 | |
#opendialog | |
def OpenDia(): | |
global fn | |
fd=LoadFileDialog(root) | |
filepath=fd.go() | |
sta=askokcancel(title="Open",message="open it?") | |
if sta: | |
t.delete(1.0,END) | |
fn = open(filepath,'r+') | |
i = 1 | |
for line in fn: | |
t.insert(END,line) | |
i += 1 | |
else: | |
pass | |
#saveDia | |
def SaveDia(): | |
context=[] | |
stat=askokcancel(title="Save",message="sure to save?") | |
if stat: | |
sd=SaveFileDialog(root) | |
spath=sd.go() | |
fs=open(spath,'w') | |
for fline in t.get(1.0,END): | |
fs.writelines(fline) | |
else: | |
pass | |
#bind variable for language | |
V = StringVar() | |
#create a menubar | |
menubar = Menu(root) | |
#filemenu | |
filemenu=Menu(menubar,tearoff=0) | |
filemenu.add_command(label="Open",command=OpenDia) | |
filemenu.add_command(label="Save as",command=SaveDia) | |
filemenu.add_separator() | |
filemenu.add_command(label="Exit",command=root.quit) | |
menubar.add_cascade(label="File",menu=filemenu) | |
#Langugagemenu | |
Languagemenu = Menu(menubar,tearoff=0) | |
Languagemenu.add_radiobutton(label="Shell",command=showcurrent_list,variable=V) | |
Languagemenu.add_radiobutton(label="Python",command=showcurrent_list,variable=V) | |
Languagemenu.add_radiobutton(label="Tkinter",command=showcurrent_list,variable=V) | |
Languagemenu.add_separator() | |
Languagemenu.add_command(label="Close",command=root.quit) | |
#add the cascade | |
menubar.add_cascade(label="Language",menu=Languagemenu) | |
#Tools | |
toolsmenu = Menu(menubar,tearoff=0) | |
toolsmenu.add_radiobutton(label="Sed",command=showcurrent_list,variable=V) | |
toolsmenu.add_radiobutton(label="Awk",command=showcurrent_list,variable=V) | |
toolsmenu.add_radiobutton(label="Git",command=showcurrent_list,variable=V) | |
toolsmenu.add_radiobutton(label="Gdb",command=showcurrent_list,variable=V) | |
toolsmenu.add_radiobutton(label="Vim",command=showcurrent_list,variable=V) | |
toolsmenu.add_separator() | |
toolsmenu.add_radiobutton(label="Other",command=showcurrent_list,variable=V) | |
#add the cascade | |
menubar.add_cascade(label="Tools",menu=toolsmenu) | |
Hightlight = 0 | |
def Hightlight_p(event=None): | |
global Hightlight | |
Hightlight = not Hightlight | |
if Hightlight: | |
t.tag_configure("current_line",background="gray") | |
t.bind("<Motion>",Hightlight_p) | |
t.tag_remove("current_line",1.0,"end") | |
t.tag_add("current_line","current linestart","current lineend+1c") | |
else: | |
pass #todo need to cancel this attribute | |
def donothing(): | |
pass | |
#Options | |
optionmenu=Menu(menubar,tearoff=0) | |
optionmenu.add_radiobutton(label="Hightlight",command=Hightlight_p) | |
optionmenu.add_separator() | |
optionmenu.add_radiobutton(label="other",command=donothing) | |
menubar.add_cascade(label="Options",menu=optionmenu) | |
#helpmenu function | |
def showUsage(): | |
showinfo(title="Usage",message="double click the note you want to review") | |
#helpmenu About | |
def showAbout(): | |
askquestion(title="About",message="This just a note reviewer, see more about usage.Any question?") | |
#helpmenu Help | |
def showHelp(): | |
askokcancel(title="Help",message="Please Access to site:http://jesseeisen.github.com") | |
#helpmenu | |
helpmenu=Menu(menubar,tearoff=0) | |
helpmenu.add_radiobutton(label="Usage",command=showUsage) | |
helpmenu.add_radiobutton(label="About",command=showAbout) | |
helpmenu.add_separator() | |
helpmenu.add_radiobutton(label="Help",command=showHelp) | |
#add the cascade | |
menubar.add_cascade(label='Help',menu=helpmenu) | |
root['menu'] = menubar | |
#this is top frame | |
frame_t = Frame(root,width=50,height=2) | |
frame_t.pack() | |
#create a title for my software | |
L= Label(frame_t,text="Review Viewer",fg='purple') | |
L.config(font='Helvetica -38 bold') | |
L.pack() | |
#this is a frame locate in the left for listbox and scrollbox | |
frame=Frame(root,width=200,height=600,bg='gray') | |
frame.propagate(False) | |
frame.pack(side=LEFT) | |
#this is frame inside above frame | |
frame_lb=Frame(frame,width=200,height=100) | |
frame_lb.propagate(False) | |
frame_lb.pack(side=BOTTOM,fill=X,expand=1) | |
#this is frame inseid frame_l, | |
frame_lt=Frame(frame,width=200,height=100) | |
frame_lt.propagate(False) | |
frame_lt.pack(side=TOP,fill=X,expand=0) | |
#this is a frame located in right hold a text widget | |
frame_r=Frame(root,width=800,height=700,bg='gray') | |
frame_r.propagate(False) | |
frame_r.pack(side=LEFT,fill=BOTH,expand=1) | |
#create a frame in frame_r | |
frame_rb=Frame(frame_r,width=800,height=1) | |
frame_rb.propagate(False) | |
frame_rb.pack(side=BOTTOM,fill=BOTH,expand=1) | |
#get the lineno | |
def getlineno(event): | |
lineno = t.index('current') | |
strlist=lineno.split('.') | |
ln = strlist[0] | |
col = strlist[1] | |
entryL= 'Ln:' + ln | |
varl.set(entryL) | |
entryR= 'Col:'+ col | |
varc.set(entryR) | |
#create Text frame | |
t=Text(frame_r) | |
t.config(font='Helvetica -16 ') | |
t.pack(fill=BOTH,expand=1) | |
t.bind("<Button-1>",getlineno) | |
varl=StringVar() | |
varc=StringVar() | |
entryr=Entry(frame_rb,textvariable=varc,bg='gray',width=7) | |
entryr['state']='readonly' | |
#entryr.resizable(width=True,height=False) | |
entryr.pack(side=RIGHT) | |
entryl=Entry(frame_rb,textvariable=varl,bg='gray',width=7) | |
entryl['state']='readonly' | |
#entryl.resizable(width=True,height=False) | |
entryl.pack(side=RIGHT) | |
#here i will create a listbox and scrollbox combine | |
v = StringVar() | |
lb=Listbox(frame,width=200,height=500,listvariable=v) | |
sl=Scrollbar(frame) | |
sl.pack(side=RIGHT,fill=Y) | |
lb['yscrollcommand'] = sl.set | |
lb.bind('<Double-Button-1>',show_intext) | |
lb.pack(side=LEFT) | |
sl['command']=lb.yview | |
#charge font size in Text | |
def resize(ev=None): | |
t.config(font="Helvetica -%d bold" %sc.get()) | |
#create scale | |
sc=Scale(frame_lb,from_=8,to=40,orient=HORIZONTAL,label='Font size:',command=resize) | |
sc.set(16) | |
sc.pack(fill=X,expand=1) | |
#find file | |
def FindFile(Fname): | |
Slen=len(Fname) | |
Flist=getfilelist(path) | |
for name in Flist: | |
disposname=name[0:Slen+1] | |
if cmp(Fname,disposname): | |
return name | |
else: | |
return None | |
#openit_text | |
def openit_text(filename): | |
global fn | |
t.delete(1.0,END) | |
fpath=p+'\\'+V.get()+'\\' + filename | |
fn = open(fpath,'r+') | |
i = 1 | |
for line in fn: | |
input_line = str(i)+' ' + line | |
t.insert(END,input_line) | |
i += 1 | |
#this is search function | |
def AskUser(): | |
Fname=VE.get() | |
Realname = FindFile(Fname) #this is a function | |
if (len(Realname)==0): | |
status =showinfo(title="Result",message="Can't find this") | |
else: | |
status=askokcancel(title="Result",message="Find it and open it?") | |
if status: | |
openit_text(Realname) | |
else: | |
pass | |
VE= StringVar() | |
#create a seachbar | |
et=Entry(frame_lt,textvariable=VE) | |
et.pack(side=LEFT) | |
btn=Button(frame_lt,width=10,text="Search",command=AskUser) | |
btn.pack(side=LEFT,padx=2) | |
#windows keep | |
root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment