def __init__(self, master, device, ntfsvol): threading.Thread.__init__(self) self.model = MftModel() self.model.root = device[0] self.ntfsvol = ntfsvol master.title('Scaning...') self.canvas = Tk.Canvas(master, relief=Tk.GROOVE, width=400, height=50) self.canvas.pack() self.cancel = False Tk.Button(master, text='Cancel', command=self.exit).pack(pady=5) master.protocol("WM_DELETE_WINDOW", self.exit)
class ProgressGui(threading.Thread): def __init__(self, master, device, ntfsvol): threading.Thread.__init__(self) self.model = MftModel() self.model.root = device[0] self.ntfsvol = ntfsvol master.title('Scaning...') self.canvas = Tk.Canvas(master, relief=Tk.GROOVE, width=400, height=50) self.canvas.pack() self.cancel = False Tk.Button(master, text='Cancel', command=self.exit).pack(pady=5) master.protocol("WM_DELETE_WINDOW", self.exit) def show(self, pos): """display progress :param percent: 0-100 """ self.canvas.create_rectangle(0, 0, 4*pos, 50, fill="blue") def run(self): total = self.ntfsvol.total_mft() #total = 200 pos = 0 for i in range(24, total): if self.cancel: break if pos < int(i*100/total): pos = pos + 1 self.show(pos) # gui refresh cost time much! mftr = self.ntfsvol.read_mft(i) if mftr: self.model.add(i, mftr) else: self.canvas.master.after(100, self.exit) def exit(self): self.cancel = True self.join() self.canvas.master.destroy()