Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.68 KB | None | 0 0
  1. # umount /run/user/131/gvfs
  2. # rm -r /run/user/131/gvfs
  3. from Tkinter import *
  4. import subprocess
  5. import tkMessageBox
  6.  
  7. root = Tk()
  8. root.title("Find GUI")
  9.  
  10. option_a = IntVar()
  11. option_b = IntVar()
  12. option_c = IntVar()
  13. option_d = IntVar()
  14.  
  15.  
  16. def b():
  17. if tb_SoF1.get() != "" or tb_SoF1.get() != "":
  18.  
  19. tb_TextSFN.delete(0,END)
  20. tb_TextSFN.configure(state=DISABLED)
  21. cb_option_a.configure(state=DISABLED)
  22. cb_option_b.configure(state=DISABLED)
  23. cb_option_c.configure(state=DISABLED)
  24. cb_option_d.configure(state=DISABLED)
  25. tkMessageBox.showinfo("Title", "only choose one option in the same time")
  26.  
  27. def a():
  28. a1 = "12.3"
  29. a2 = 123
  30. print int(float(a1))
  31. output = subprocess.check_output(CG,shell=True)
  32. return output
  33. #Delete button
  34. def Del():
  35. #print "Del: " + str(tb_TextSFN.get())
  36. output =""
  37. DelCommand="find ~ "
  38. if tb_TextSFN.get() is not "":
  39. print "Delete Successful!"
  40. DelCommand += "-name "+tb_TextSFN.get()+".* -delete"
  41. output = subprocess.check_output(DelCommand,shell=True)
  42. else : print "Please input Delete target"
  43. return output
  44.  
  45. #bind othe options
  46. def aBindOther():
  47. if option_a.get() != 1:
  48. tb_TextSFN.configure(state=NORMAL)
  49. tb_SoF1.configure(state=NORMAL)
  50. tb_SoF2.configure(state=NORMAL)
  51. cb_option_b.configure(state=NORMAL)
  52. cb_option_c.configure(state=NORMAL)
  53. cb_option_d.configure(state=NORMAL)
  54. else:
  55. cb_option_b.configure(state=DISABLED)
  56. cb_option_c.configure(state=DISABLED)
  57. cb_option_d.configure(state=DISABLED)
  58. tb_TextSFN.configure(state=DISABLED)
  59. tb_SoF1.configure(state=DISABLED)
  60. tb_SoF2.configure(state=DISABLED)
  61.  
  62. def bBindOther():
  63. if option_b.get() != 1:
  64. tb_TextSFN.configure(state=NORMAL)
  65. tb_SoF1.configure(state=NORMAL)
  66. tb_SoF2.configure(state=NORMAL)
  67. cb_option_a.configure(state=NORMAL)
  68. cb_option_c.configure(state=NORMAL)
  69. cb_option_d.configure(state=NORMAL)
  70. else:
  71. cb_option_a.configure(state=DISABLED)
  72. cb_option_c.configure(state=DISABLED)
  73. cb_option_d.configure(state=DISABLED)
  74. tb_TextSFN.configure(state=DISABLED)
  75. tb_SoF1.configure(state=DISABLED)
  76. tb_SoF2.configure(state=DISABLED)
  77.  
  78.  
  79. def cBindOther():
  80. if option_c.get() != 1:
  81. tb_TextSFN.configure(state=NORMAL)
  82. tb_SoF1.configure(state=NORMAL)
  83. tb_SoF2.configure(state=NORMAL)
  84. cb_option_a.configure(state=NORMAL)
  85. cb_option_b.configure(state=NORMAL)
  86. cb_option_d.configure(state=NORMAL)
  87. else:
  88. cb_option_a.configure(state=DISABLED)
  89. cb_option_b.configure(state=DISABLED)
  90. cb_option_d.configure(state=DISABLED)
  91. tb_TextSFN.configure(state=DISABLED)
  92. tb_SoF1.configure(state=DISABLED)
  93. tb_SoF2.configure(state=DISABLED)
  94.  
  95. def dBindOther():
  96. if option_d.get() != 1:
  97. tb_TextSFN.configure(state=NORMAL)
  98. tb_SoF1.configure(state=NORMAL)
  99. tb_SoF2.configure(state=NORMAL)
  100. cb_option_a.configure(state=NORMAL)
  101. cb_option_b.configure(state=NORMAL)
  102. cb_option_c.configure(state=NORMAL)
  103. else:
  104. cb_option_a.configure(state=DISABLED)
  105. cb_option_b.configure(state=DISABLED)
  106. cb_option_c.configure(state=DISABLED)
  107. tb_TextSFN.configure(state=DISABLED)
  108. tb_SoF1.configure(state=DISABLED)
  109. tb_SoF2.configure(state=DISABLED)
  110.  
  111.  
  112. #Reset button
  113. def ReSet():
  114. print "Reset Successful!"
  115. tb_TextSFN.configure(state=NORMAL)
  116. tb_SoF1.configure(state=NORMAL)
  117. tb_SoF2.configure(state=NORMAL)
  118. cb_option_a.configure(state=NORMAL)
  119. cb_option_b.configure(state=NORMAL)
  120. cb_option_c.configure(state=NORMAL)
  121. cb_option_d.configure(state=NORMAL)
  122.  
  123. tb_TextSFN.delete(0,END)
  124. tb_SoF1.delete(0,END)
  125. tb_SoF2.delete(0,END)
  126. option_a.set(0)
  127. option_b.set(0)
  128. option_c.set(0)
  129. option_d.set(0)
  130. txtarea_output.delete(1.0,END)
  131.  
  132. #Command processing
  133. def startfind():
  134. #print "Start find button clicked!"
  135. commandresult = runcommand()
  136. print commandresult
  137.  
  138. def command_gen():
  139. #The Basic of the "Find" command
  140. #print "Generate the find command details!"
  141. command = "find ~ "
  142.  
  143. #Option a is find the file that have changed in last 1 hour
  144. #print "option a: " + str(option_a.get())
  145. if option_a.get():
  146. command = command + "-mtime 0 -type d"
  147.  
  148. #Option b is find the empty file
  149. #print "option b: " + str(option_b.get())
  150. if option_b.get():
  151. command = command + "-type f -empty"
  152.  
  153. #Option c is find the file that are hidden
  154. #print "option c: " + str(option_c.get())
  155. if option_c.get():
  156. command = command + "-type f -name \.\*"
  157.  
  158. #Option c is show the help option of "find"
  159. #print "option d: " + str(option_d.get())
  160. if option_d.get():
  161. command = "find -help"
  162.  
  163. #tb_TextSFN is use to store the user input the name of searching file
  164. #print "Search File Name: " + str(tb_TextSFN.get())
  165. if tb_TextSFN.get() is not "" and not option_b.get():
  166. command += "-name "+tb_TextSFN.get()+".*"
  167. tb_SoF1.delete(0,END)
  168. tb_SoF2.delete(0,END)
  169. tb_SoF1.configure(state=DISABLED)
  170. tb_SoF2.configure(state=DISABLED)
  171. cb_option_a.configure(state=DISABLED)
  172. cb_option_b.configure(state=DISABLED)
  173. cb_option_c.configure(state=DISABLED)
  174. cb_option_d.configure(state=DISABLED)
  175. tb_SoF1.configure(state=DISABLED)
  176. tb_SoF2.configure(state=DISABLED)
  177. tkMessageBox.showinfo("Title", "only choose one option in the same time")
  178.  
  179. #SoF1 and SoF2 is use to store the range of the target file e.g 10MB - 100MB
  180. #print "Range of file size: " + str(tb_SoF1.get()) + " To " + str(tb_SoF2.get())
  181. SoF1 =tb_SoF1.get()
  182. SoF2 =tb_SoF2.get()
  183. if tb_SoF1.get() != ""or tb_SoF2.get() != "":
  184. try:
  185. if int(float(SoF1)) and int(float(SoF2)):
  186. #print "yes"
  187. if tb_SoF1.get() is not "" and tb_SoF2.get() is not "":
  188. command +="-size +" + tb_SoF1.get() + "M -size -" + tb_SoF2.get()+"M"
  189. print command
  190. except ValueError:
  191. tkMessageBox.showinfo("Title", "Not a valid input,auto to searching all of file")
  192.  
  193.  
  194. result = command
  195. return result
  196.  
  197. def runcommand():
  198. #print "Run command and get return!"
  199. print "Looking for: "+ tb_TextSFN.get() +"..."
  200. CG = command_gen()
  201. output = subprocess.check_output(CG,shell=True)
  202. txtarea_output.insert(INSERT, output)
  203. return output
  204.  
  205. #body
  206. lb_SFN = Label(root, text="Search File Name (default search all of file) : ",justify=LEFT)
  207. lb_SFN.grid(row=0, column=0)
  208.  
  209. tb_TextSFN = Entry(root, width=50, bd=4)
  210. tb_TextSFN.grid(row=0, column=1, columnspan=3)
  211.  
  212. lb_lbSoF = Label(root, text="Size of File(MB): ",justify=RIGHT)
  213. lb_lbSoF.grid(row=10, column=0)
  214.  
  215. tb_SoF1 = Entry(root, width=10, bd=4)
  216. tb_SoF1.grid(row=10, column=1)
  217.  
  218. lb_ToSize = Label(root, text="To",justify=RIGHT)
  219. lb_ToSize.grid(row=10, column=2)
  220.  
  221. tb_SoF2 = Entry(root, width=10, bd=4)
  222. tb_SoF2.grid(row=10, column=3)
  223.  
  224.  
  225. #options
  226. cb_option_a = Checkbutton(root, text = "Changed File in Last 1 Hour", variable=option_a ,justify=LEFT,command=aBindOther)
  227. cb_option_a.grid(row=20, column=0, padx=5, pady=5, sticky=W)
  228.  
  229. cb_option_b = Checkbutton(root, text="Search Empty File", variable=option_b ,justify=LEFT,command=bBindOther)
  230. cb_option_b.grid(row=20, column=1, padx=5, pady=5, sticky=W)
  231.  
  232. cb_option_c = Checkbutton(root, text="Find Hidden File", variable=option_c ,justify=LEFT,command=cBindOther)
  233. cb_option_c.grid(row=20, column=2,padx=5, pady=5, sticky=W)
  234.  
  235. cb_option_d = Checkbutton(root, text="Help", variable=option_d ,justify=LEFT,command=dBindOther)
  236. cb_option_d.grid(row=20, column=3,padx=5, pady=5, sticky=W)
  237.  
  238. #button
  239.  
  240. btn_reset = Button(root, text="Reset",justify=RIGHT, command=ReSet)
  241. btn_reset.grid(row=40, column=0, columnspan=2,padx=5, pady=5, sticky=E)
  242.  
  243. btn_del = Button(root, text="Delete",justify=RIGHT, command=a)
  244. btn_del.grid(row=40, column=1, columnspan=2,padx=5, pady=5, sticky=E)
  245.  
  246. btn_run = Button(root, text="Search",justify=RIGHT, command=startfind)
  247. btn_run.grid(row=40, column=3, columnspan=2,padx=5, pady=5, sticky=E)
  248.  
  249.  
  250. #output box
  251. lb_commandoutput = Label(root, text="Result are the following:", fg="red", justify=LEFT)
  252. lb_commandoutput.grid(row=50, column=0, padx=2, pady=0)
  253.  
  254. txtarea_output = Text(root, height=30, width=100)
  255. txtarea_output.grid(row=60, column=0, columnspan=4, padx=10, pady= 10)
  256.  
  257.  
  258. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement