From f09ea95c848a29492b682f954610a23daf753e15 Mon Sep 17 00:00:00 2001 From: ryuslash Date: Thu, 11 Feb 2010 22:05:37 +0100 Subject: Added --thread With --thread a signle thread ID or thread URL can be entered. If thread is a URL, it will download it. If thread is an ID, a category must also be set. --- progressbar.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'progressbar.py') diff --git a/progressbar.py b/progressbar.py index 2074f8d..0163c12 100644 --- a/progressbar.py +++ b/progressbar.py @@ -30,15 +30,35 @@ class Progress(): self.show_progress(0) + def __get_true_maxwidth(self, vallen, maxvallen): + return self.maxwidth - 4 - vallen - maxvallen + def show_progress(self, value): str_value = str(value) str_maxvalue = str(self.maxvalue) - true_maxwidth = self.maxwidth - 4 - len(str_value) - len(str_maxvalue) - progress = int(round((true_maxwidth/float(self.maxvalue))*value)) + #true_maxwidth = self.maxwidth - 4 - len(str_value) - len(str_maxvalue) + true_maxwidth = self.__get_true_maxwidth(len(str_value), len(str_maxvalue)) + #print true_maxwidth, ":", self.maxvalue, ":", value # for debugging purposes + + if self.maxvalue == 0: + progress = true_maxwidth + else: + progress = int(round((true_maxwidth/float(self.maxvalue))*value)) + + #self.fd.write("\r%s/%s [%s%s]" % (str_value, str_maxvalue, self.prog_char * progress, self.fill_char * (true_maxwidth - progress))) + #self.fd.flush() + self.__write_progress(str_value, str_maxvalue, progress, true_maxwidth) + + def __write_progress(self, str_value, str_maxvalue, progress, true_maxwidth): self.fd.write("\r%s/%s [%s%s]" % (str_value, str_maxvalue, self.prog_char * progress, self.fill_char * (true_maxwidth - progress))) self.fd.flush() - if value == self.maxvalue: - self.fd.write("\n") + + def complete(self): + str_maxvalue = str(self.maxvalue) + vallen = len(str_maxvalue) + true_maxwidth = self.__get_true_maxwidth(vallen, vallen) + self.__write_progress(str_maxvalue, str_maxvalue, true_maxwidth, true_maxwidth) + self.fd.write("\n") if __name__ == "__main__": prog = Progress(200) -- cgit v1.2.3-54-g00ecf