def run(self): global exit_ self.tv_model1 = self.tv1.get_model() if not self.tv_model1: self.tv_model1 = Gtk.ListStore(str, str, str, str, str, str, str) self.tv1.set_model(self.tv_model1) top_iter = self.tv_model1.get_iter_first() iter_ = top_iter all_files = [] def get_icon(i): icon = Gtk.STOCK_APPLY if i.completed else Gtk.STOCK_MEDIA_PLAY icon = Gtk.STOCK_MEDIA_PAUSE if (i.pause and not i.completed) else icon icon = Gtk.STOCK_DIALOG_ERROR if i.error else icon return icon def add_new_row(i): self.tv_model1.append([get_file_name(i), i.url, str(threaded_downloader.humansize(i.progress)), str(i.percentage_written), str(i.speed), i.time_remaining_str, get_icon(i)]) total_speed = 0 for i in threaded_downloader.download_manager_instances: found_row_for_i = False try: total_speed += float(i.speed) except: pass for row in self.tv_model1: if row[0] == get_file_name(i): # update the details for the row found_row_for_i = True for index, item in enumerate([get_file_name(i), i.url, str(threaded_downloader.humansize(i.progress)), str(i.percentage_written), str(i.speed), i.time_remaining_str, get_icon(i)]): row[index] = item break if not found_row_for_i: add_new_row(i) self.builder.get_object("label_speed").set_markup("Approximate Total Speed: <b>%s</b> kbps" % total_speed) if exit_: self.window_main.emit("delete-event", original_delete_event) return True
def add_new_row(i): self.tv_model1.append([get_file_name(i), i.url, str(threaded_downloader.humansize(i.progress)), str(i.percentage_written), str(i.speed), i.time_remaining_str, get_icon(i)])