Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # umount /run/user/131/gvfs
- # rm -r /run/user/131/gvfs
- from Tkinter import *
- import subprocess
- import tkMessageBox
- root = Tk()
- root.title("Find GUI")
- option_a = IntVar()
- option_b = IntVar()
- option_c = IntVar()
- option_d = IntVar()
- def b():
- if tb_SoF1.get() != "" or tb_SoF1.get() != "":
- tb_TextSFN.delete(0,END)
- tb_TextSFN.configure(state=DISABLED)
- cb_option_a.configure(state=DISABLED)
- cb_option_b.configure(state=DISABLED)
- cb_option_c.configure(state=DISABLED)
- cb_option_d.configure(state=DISABLED)
- tkMessageBox.showinfo("Title", "only choose one option in the same time")
- def a():
- a1 = "12.3"
- a2 = 123
- print int(float(a1))
- output = subprocess.check_output(CG,shell=True)
- return output
- #Delete button
- def Del():
- #print "Del: " + str(tb_TextSFN.get())
- output =""
- DelCommand="find ~ "
- if tb_TextSFN.get() is not "":
- print "Delete Successful!"
- DelCommand += "-name "+tb_TextSFN.get()+".* -delete"
- output = subprocess.check_output(DelCommand,shell=True)
- else : print "Please input Delete target"
- return output
- #bind othe options
- def aBindOther():
- if option_a.get() != 1:
- tb_TextSFN.configure(state=NORMAL)
- tb_SoF1.configure(state=NORMAL)
- tb_SoF2.configure(state=NORMAL)
- cb_option_b.configure(state=NORMAL)
- cb_option_c.configure(state=NORMAL)
- cb_option_d.configure(state=NORMAL)
- else:
- cb_option_b.configure(state=DISABLED)
- cb_option_c.configure(state=DISABLED)
- cb_option_d.configure(state=DISABLED)
- tb_TextSFN.configure(state=DISABLED)
- tb_SoF1.configure(state=DISABLED)
- tb_SoF2.configure(state=DISABLED)
- def bBindOther():
- if option_b.get() != 1:
- tb_TextSFN.configure(state=NORMAL)
- tb_SoF1.configure(state=NORMAL)
- tb_SoF2.configure(state=NORMAL)
- cb_option_a.configure(state=NORMAL)
- cb_option_c.configure(state=NORMAL)
- cb_option_d.configure(state=NORMAL)
- else:
- cb_option_a.configure(state=DISABLED)
- cb_option_c.configure(state=DISABLED)
- cb_option_d.configure(state=DISABLED)
- tb_TextSFN.configure(state=DISABLED)
- tb_SoF1.configure(state=DISABLED)
- tb_SoF2.configure(state=DISABLED)
- def cBindOther():
- if option_c.get() != 1:
- tb_TextSFN.configure(state=NORMAL)
- tb_SoF1.configure(state=NORMAL)
- tb_SoF2.configure(state=NORMAL)
- cb_option_a.configure(state=NORMAL)
- cb_option_b.configure(state=NORMAL)
- cb_option_d.configure(state=NORMAL)
- else:
- cb_option_a.configure(state=DISABLED)
- cb_option_b.configure(state=DISABLED)
- cb_option_d.configure(state=DISABLED)
- tb_TextSFN.configure(state=DISABLED)
- tb_SoF1.configure(state=DISABLED)
- tb_SoF2.configure(state=DISABLED)
- def dBindOther():
- if option_d.get() != 1:
- tb_TextSFN.configure(state=NORMAL)
- tb_SoF1.configure(state=NORMAL)
- tb_SoF2.configure(state=NORMAL)
- cb_option_a.configure(state=NORMAL)
- cb_option_b.configure(state=NORMAL)
- cb_option_c.configure(state=NORMAL)
- else:
- cb_option_a.configure(state=DISABLED)
- cb_option_b.configure(state=DISABLED)
- cb_option_c.configure(state=DISABLED)
- tb_TextSFN.configure(state=DISABLED)
- tb_SoF1.configure(state=DISABLED)
- tb_SoF2.configure(state=DISABLED)
- #Reset button
- def ReSet():
- print "Reset Successful!"
- tb_TextSFN.configure(state=NORMAL)
- tb_SoF1.configure(state=NORMAL)
- tb_SoF2.configure(state=NORMAL)
- cb_option_a.configure(state=NORMAL)
- cb_option_b.configure(state=NORMAL)
- cb_option_c.configure(state=NORMAL)
- cb_option_d.configure(state=NORMAL)
- tb_TextSFN.delete(0,END)
- tb_SoF1.delete(0,END)
- tb_SoF2.delete(0,END)
- option_a.set(0)
- option_b.set(0)
- option_c.set(0)
- option_d.set(0)
- txtarea_output.delete(1.0,END)
- #Command processing
- def startfind():
- #print "Start find button clicked!"
- commandresult = runcommand()
- print commandresult
- def command_gen():
- #The Basic of the "Find" command
- #print "Generate the find command details!"
- command = "find ~ "
- #Option a is find the file that have changed in last 1 hour
- #print "option a: " + str(option_a.get())
- if option_a.get():
- command = command + "-mtime 0 -type d"
- #Option b is find the empty file
- #print "option b: " + str(option_b.get())
- if option_b.get():
- command = command + "-type f -empty"
- #Option c is find the file that are hidden
- #print "option c: " + str(option_c.get())
- if option_c.get():
- command = command + "-type f -name \.\*"
- #Option c is show the help option of "find"
- #print "option d: " + str(option_d.get())
- if option_d.get():
- command = "find -help"
- #tb_TextSFN is use to store the user input the name of searching file
- #print "Search File Name: " + str(tb_TextSFN.get())
- if tb_TextSFN.get() is not "" and not option_b.get():
- command += "-name "+tb_TextSFN.get()+".*"
- tb_SoF1.delete(0,END)
- tb_SoF2.delete(0,END)
- tb_SoF1.configure(state=DISABLED)
- tb_SoF2.configure(state=DISABLED)
- cb_option_a.configure(state=DISABLED)
- cb_option_b.configure(state=DISABLED)
- cb_option_c.configure(state=DISABLED)
- cb_option_d.configure(state=DISABLED)
- tb_SoF1.configure(state=DISABLED)
- tb_SoF2.configure(state=DISABLED)
- tkMessageBox.showinfo("Title", "only choose one option in the same time")
- #SoF1 and SoF2 is use to store the range of the target file e.g 10MB - 100MB
- #print "Range of file size: " + str(tb_SoF1.get()) + " To " + str(tb_SoF2.get())
- SoF1 =tb_SoF1.get()
- SoF2 =tb_SoF2.get()
- if tb_SoF1.get() != ""or tb_SoF2.get() != "":
- try:
- if int(float(SoF1)) and int(float(SoF2)):
- #print "yes"
- if tb_SoF1.get() is not "" and tb_SoF2.get() is not "":
- command +="-size +" + tb_SoF1.get() + "M -size -" + tb_SoF2.get()+"M"
- print command
- except ValueError:
- tkMessageBox.showinfo("Title", "Not a valid input,auto to searching all of file")
- result = command
- return result
- def runcommand():
- #print "Run command and get return!"
- print "Looking for: "+ tb_TextSFN.get() +"..."
- CG = command_gen()
- output = subprocess.check_output(CG,shell=True)
- txtarea_output.insert(INSERT, output)
- return output
- #body
- lb_SFN = Label(root, text="Search File Name (default search all of file) : ",justify=LEFT)
- lb_SFN.grid(row=0, column=0)
- tb_TextSFN = Entry(root, width=50, bd=4)
- tb_TextSFN.grid(row=0, column=1, columnspan=3)
- lb_lbSoF = Label(root, text="Size of File(MB): ",justify=RIGHT)
- lb_lbSoF.grid(row=10, column=0)
- tb_SoF1 = Entry(root, width=10, bd=4)
- tb_SoF1.grid(row=10, column=1)
- lb_ToSize = Label(root, text="To",justify=RIGHT)
- lb_ToSize.grid(row=10, column=2)
- tb_SoF2 = Entry(root, width=10, bd=4)
- tb_SoF2.grid(row=10, column=3)
- #options
- cb_option_a = Checkbutton(root, text = "Changed File in Last 1 Hour", variable=option_a ,justify=LEFT,command=aBindOther)
- cb_option_a.grid(row=20, column=0, padx=5, pady=5, sticky=W)
- cb_option_b = Checkbutton(root, text="Search Empty File", variable=option_b ,justify=LEFT,command=bBindOther)
- cb_option_b.grid(row=20, column=1, padx=5, pady=5, sticky=W)
- cb_option_c = Checkbutton(root, text="Find Hidden File", variable=option_c ,justify=LEFT,command=cBindOther)
- cb_option_c.grid(row=20, column=2,padx=5, pady=5, sticky=W)
- cb_option_d = Checkbutton(root, text="Help", variable=option_d ,justify=LEFT,command=dBindOther)
- cb_option_d.grid(row=20, column=3,padx=5, pady=5, sticky=W)
- #button
- btn_reset = Button(root, text="Reset",justify=RIGHT, command=ReSet)
- btn_reset.grid(row=40, column=0, columnspan=2,padx=5, pady=5, sticky=E)
- btn_del = Button(root, text="Delete",justify=RIGHT, command=a)
- btn_del.grid(row=40, column=1, columnspan=2,padx=5, pady=5, sticky=E)
- btn_run = Button(root, text="Search",justify=RIGHT, command=startfind)
- btn_run.grid(row=40, column=3, columnspan=2,padx=5, pady=5, sticky=E)
- #output box
- lb_commandoutput = Label(root, text="Result are the following:", fg="red", justify=LEFT)
- lb_commandoutput.grid(row=50, column=0, padx=2, pady=0)
- txtarea_output = Text(root, height=30, width=100)
- txtarea_output.grid(row=60, column=0, columnspan=4, padx=10, pady= 10)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement