Clean Up your HDD (GUI)

09.12.2006 by kerim in gui | hddcleaner | python

I finished a small prototype with an “acceptable” GUI.
The functionality for going through the disk(s) and sorting all files according to size was already nearly finished last time.

So i more or less only had to add a way to represent the results in a GUI.

Its not perfect and i have some ideas to make it better and more functional, but it works the way it is and honestly i don’t think there is soooo much to do.

Note: The code needs some cleanup. If you want a copy, mail me or leave a comment.

class Display(wx.Frame):  
     def _ _init_ _(self,files):  
         wx.Frame.__init__(self,None,-1,"HDD Clean",size=wx.DefaultSize)  
         self.sizer = wx.BoxSizer(wx.VERTICAL)  
         self.btn=wx.Button(self, ID_DELETE, "Delete", pos=wx.Point(20, 0))  
         wx.EVT_BUTTON(self, ID_DELETE, self.OnDelete)  
         for i in files:  
              sampleList.append(str(i[0])+" ("+str(i[1])+")")  
         self.listBox= wx.CheckListBox(self, -1, pos=(20,30), size=wx.DefaultSize, style=wx.LB_HSCROLL,validator=wx.DefaultValidator, name="listBox",choices= sampleList)  
         self.sizer.Add(self.btn,flag=wx.GROW, proportion=0)  
         self.sizer.Add(self.listBox,flag=wx.GROW, proportion=1)  

What did I do.... I used a Frame with one button, one checkboxlist and a Sizer (which means a Panel that can resize its children if the Frame is resized).
Buttonevents are bound to a method “OnDelete”.
To create the GUI i go through all files (already sorted accoring to size) and create a checkboxitem for the list containin size and path of the file.
What i needed in the end was an implementation of the OnDelete method. I am not yet satisfied with it. I am sure (remember i am still just learning python) that there is a simpler way to have a loop running from a HIGH number to a LOW one than the way i used here:

 def OnDelete(self, event):  
         #this is ugly. is there no way to have a loop starting from top ?  
         end = self.listBox.GetCount()-1   
         for index in range(self.listBox.GetCount()):  
              if self.listBox.IsChecked(end-index):  

I will post the complete code once i got the time to clean it up enough to not embarass me more than those snipplets already do ;-)

Here a picture:

Directories are not shown and can’t be deleted. All you can delete are files. So if you delete all files in a directory it will still continue to exist.
Changes for the future:
-Performance depends to a high degree on the number of files to sort. I bet that not everyone will need a complete list of all files (or all types) so it might be better to allow for command line options filtering certain types or limiting the resultset.
-Performance depends even more on the GUI ! It might be sufficient to have a list without the GUI, so i would make it optional too.
-GUI is not really satisfactory yet. Might be better to show the relations of the sizes in a different way, using colors, treeviews etc.

I tested the program on my thinkpad T41 (Pentium M 1.7 GHz, 1 GB RAM, 40 GB HDD, 2 partitions)
First i used the properties dialog in the windows explorer to test the performance of windows itself, then i started my program.

For drive c windows takes 1:40 mintutes to determine the amount of files/dir/hdd-usage. (75190 files, 17.9GB used, 1.58 GB free)
For drive d (53342 files, 22.7 GB used, 3.87 GB free) it takes 2:06 minutes

c: 2:07
d: 2:18
Not bad if you consider that the gui must be generated.

comments powered by Disqus