class ProgressBox(PopupBox): """ x x coordinate. Integer y y coordinate. Integer width Integer height Integer text String to print. icon icon """ def __init__(self, text, x=None, y=None, width=0, height=0, icon=None, vertical_expansion=1, text_prop=None, full=0, parent='osd'): PopupBox.__init__(self, text, None, x, y, width, height, icon, vertical_expansion, text_prop, parent) self.progressbar = Progressbar(full=full, width=self.content.width - 20) self.add_child(self.progressbar) def tick(self): self.progressbar.tick() self.draw(update=True)
class ProgressBox(PopupBox): """ x x coordinate. Integer y y coordinate. Integer width Integer height Integer text String to print. icon icon """ def __init__(self, text, x=None, y=None, width=0, height=0, icon=None, vertical_expansion=1, text_prop=None, full=0, parent='osd'): PopupBox.__init__(self, text, None, x, y, width, height, icon, vertical_expansion, text_prop, parent) self.progressbar = Progressbar(full=full, width=self.content.width-20) self.add_child(self.progressbar) def tick(self): if not skin.active(): return; self.progressbar.tick() self.draw(update=True)
def __init__(self, text, x=None, y=None, width=0, height=0, icon=None, vertical_expansion=1, text_prop=None, full=0, parent='osd'): PopupBox.__init__(self, text, None, x, y, width, height, icon, vertical_expansion, text_prop, parent) self.progressbar = Progressbar(full=full, width=self.content.width-20) self.add_child(self.progressbar)
def count_parts(self, is_voice, nparts): parts = [] n = 767 sums = map(sum, self.chunks(is_voice, n)) parts = [] progressbar = Progressbar(50, len(sums)) for i,s in enumerate(sums): progressbar.update(i) if s>n/2: if len(parts)==0 or len(parts[-1])==2: parts.append([i*n]) elif len(parts)>0 and len(parts[-1])<2: parts[-1].append(min((i+1)*n, len(is_voice))) if len(parts)>0 and len(parts[-1])<2: parts[-1].append(len(is_voice)) if len(parts) > nparts: diff = len(parts) - nparts parts_rms = map(lambda (i,x): x+[(self.rms_from(x[0],x[1]-x[0])), i], enumerate(parts)) parts_rms = sorted(parts_rms, key=lambda x:x[2]) waste = parts_rms[:diff] waste_rms = map(lambda x: x[2], waste) waste_rms_mean = float(sum(waste_rms[:len(waste)/2]))/(len(waste)/2) waste_rms_stdd = numpy.std(waste_rms[:len(waste)/2]) t = 1.2 voice_parts = parts_rms[diff:] parts = map(lambda x: x+[True], voice_parts) + map(lambda x: x+[False], waste) parts = sorted(parts, key=lambda x: x[3]) parts_is_voice = map(lambda x: x[4], parts) for w in waste: try: next_voice_index=parts_is_voice[w[3]:].index(True)+w[3] dist_to_next_voice = parts[next_voice_index][0]-w[1] except ValueError: dist_to_next_voice = float('inf') try: prev_voice_index=w[3]-parts_is_voice[w[3]:][::-1].index(True) dist_to_prev_voice = w[0]-parts[prev_voice_index][1] except ValueError: if dist_to_prev_voice==float('inf'): break dist_to_voice = min(dist_to_prev_voice, dist_to_next_voice) if ( ( (w[2]-waste_rms_mean)/waste_rms_stdd > 16*t and dist_to_voice<=n*3 ) or ( (w[2]-waste_rms_mean)/waste_rms_stdd > t and dist_to_next_voice<=n ) ): voice_parts.append(w) parts = sorted(voice_parts, key=lambda x: x[0]) #concat some parts holes = map(lambda (i,x): [x[1],parts[i+1][0]], enumerate(parts[:-1])) diff = len(holes)-(nparts-1) if diff>0: holes.sort(key=lambda x: x[1]-x[0]) holes = holes[diff:] holes.sort(key=lambda x: x[0]) c_parts = [ [parts[0][0], holes[0][0]] ] c_parts += map(lambda (i,x): [x[1], holes[i+1][0]], enumerate(holes[:-1])) c_parts += [ [holes[-1][1],parts[-1][1]] ] parts = c_parts progressbar.finish() return parts
y += pointLeftOf.y newLine.addPoint(Point(x, y)) pointLeftOf = point plt.plot(newLine.xArray(), newLine.yArray(), '-o') if len(newLine.points) > 1: createSubLine(newLine, t) else: bezierLine.addPoint(newLine.points[0]) filenames = [] progessbar = Progressbar() print("calculating...") for t in range(0, 101, 1): plt.plot(line.xArray(), line.yArray(), '-o') createSubLine(line, t) plt.plot(bezierLine.xArray(), bezierLine.yArray()) os.makedirs(os.path.normpath(path) + "\\img\\", exist_ok=True) plt.savefig(os.path.normpath(path) + "\\img\\" + "pic" + str(t) + ".png", dpi=dpi) filenames.append( os.path.normpath(path) + "\\img\\" + "pic" + str(t) + ".png") plt.close() progessbar.print(t) print("\ncreate gif...")