def OnIdle(self, event): if self.didresize: if BUFFERED: # Initialize the buffer bitmap. No real DC is needed at this point. if self.maxWidth > 0 and self.maxHeight > 0: self.buffer = wx.EmptyBitmap(self.maxWidth, self.maxHeight) else: self.buffer = None if stopwatch: t = stopwatch.Timer() self.UpdateDrawing() if stopwatch: t.stop() print("Updating took: " + str(t.elapsed)) self.didresize = 0
def Draw(self, dc): if stopwatch: t2 = stopwatch.Timer() if self.doc is None: # dc.BeginDrawing() dc.SetBackground(wx.Brush(self.GetBackgroundColour())) dc.Clear() # dc.EndDrawing() return fillColor = wx.Colour(162, 205, 242) lineColor = wx.Colour(30, 121, 198) frameCol = wx.Colour(192, 192, 192) frameTextCol = wx.Colour(64, 64, 64) playBackCol = wx.Colour(255, 127, 127) playForeCol = wx.Colour(209, 102, 121) playOutlineCol = wx.Colour(128, 0, 0) textCol = wx.Colour(64, 64, 64) phraseFillCol = wx.Colour(205, 242, 162) phraseOutlineCol = wx.Colour(121, 198, 30) wordFillCol = wx.Colour(242, 205, 162) wordOutlineCol = wx.Colour(198, 121, 30) phonemeFillCol = wx.Colour(231, 185, 210) phonemeOutlineCol = wx.Colour(173, 114, 146) font = wx.Font(6, wx.SWISS, wx.NORMAL, wx.NORMAL) drawPlayMarker = False curFrame = self.curFrame cs = self.GetClientSize() halfClientHeight = cs.height / 2 # dc.BeginDrawing() dc.SetBackground(wx.Brush(self.GetBackgroundColour())) dc.Clear() firstSample = 0 lastSample = len(self.amp) if (self.doc is not None) and (self.doc.sound is not None ) and self.doc.sound.IsPlaying() and ( not self.isDragging): if curFrame >= self.oldFrame: firstSample = (self.oldFrame - 1) * self.samplesPerFrame if firstSample < 0: firstSample = 0 lastSample = (curFrame + 2) * self.samplesPerFrame if lastSample > len(self.amp): lastSample = len(self.amp) drawPlayMarker = True x = curFrame * self.frameWidth # print("OldFrame: ",self.oldFrame) # print("X for cursor :", x) # background of playback marker dc.SetBrush(wx.Brush(playBackCol)) dc.SetPen(wx.TRANSPARENT_PEN) dc.DrawRectangle(x, 0, self.frameWidth + 1, cs.height) elif self.isDragging: scrollX, scrollY = self.CalcScrolledPosition(0, 0) firstSample = int(-scrollX / self.sampleWidth) - 1 if self.basicScrubbing: firstSample = self.oldFrame * self.samplesPerFrame lastSample = firstSample + int(cs.width / self.sampleWidth) + 3 if self.basicScrubbing: lastSample = self.scrubFrame * self.samplesPerFrame if firstSample > lastSample: firstSample, lastSample = lastSample, firstSample firstSample -= self.samplesPerFrame * 2 lastSample += self.samplesPerFrame * 3 if firstSample < 0: firstSample = 0 if firstSample > len(self.amp): firstSample = len(self.amp) if lastSample < 0: lastSample = 0 if lastSample > len(self.amp): lastSample = len(self.amp) drawPlayMarker = True curFrame = self.scrubFrame x = curFrame * self.frameWidth # background of playback marker dc.SetBrush(wx.Brush(playBackCol)) dc.SetPen(wx.TRANSPARENT_PEN) dc.DrawRectangle(x, 0, self.frameWidth + 1, cs.height) # draw the audio samples dc.SetBrush(wx.Brush(fillColor)) dc.SetPen(wx.Pen(lineColor)) dc.SetTextForeground(frameTextCol) dc.SetFont(font) textWidth, topBorder = dc.GetTextExtent("Ojyg") x = firstSample * self.sampleWidth frame = firstSample / self.samplesPerFrame fps = int(round(self.doc.fps)) sample = firstSample lastHeight = -1 lastHalfHeight = 1 amp = 0 faster_drawing = True for i in range(int(firstSample), int(lastSample)): if stopwatch: if i % 100 == 0: print("Sample " + str(i) + " Time " + str(t2.elapsed)) if (sample + 1) % self.samplesPerFrame == 0: # draw frame marker dc.SetPen(wx.Pen(frameCol)) # +0.06 seconds frameX = (frame + 1) * self.frameWidth # print("framex: ",frameX) if (self.frameWidth > 2) or ((frame + 2) % fps == 0): dc.DrawLine(frameX, topBorder, frameX, cs.height) # +0.01 seconds # draw frame label if (self.frameWidth > 30) or ((frame + 2) % 5 == 0): # These three take about 0.01 seconds dc.DrawLine(frameX, 0, frameX, topBorder) dc.DrawLine(frameX + 1, 0, frameX + 1, cs.height) dc.DrawLabel(str(frame + 2), wx.Rect(frameX + 1, 0, 128, 128)) dc.SetBrush(wx.Brush(fillColor)) # +0.04 seconds dc.SetPen(wx.Pen(lineColor)) # +0.07 seconds amp = self.amp[i] height = round(cs.height * amp) halfHeight = height / 2 if drawPlayMarker and (frame == curFrame): dc.SetBrush(wx.Brush(playForeCol)) dc.SetPen(wx.TRANSPARENT_PEN) if SIMPLE_DISPLAY: dc.DrawLine(x, halfClientHeight - halfHeight, x, halfClientHeight + halfHeight) else: dc.DrawRectangle(x, halfClientHeight - halfHeight, self.sampleWidth + 1, height) # Only doing this takes 0.12 seconds if not faster_drawing: if drawPlayMarker and (frame == curFrame): dc.SetBrush(wx.Brush(fillColor)) dc.SetPen(wx.Pen(lineColor)) if lastHeight > 0 and not (drawPlayMarker and frame == curFrame): if lastHeight > height: lastHeight = height lastHalfHeight = halfHeight dc.SetPen(wx.Pen(fillColor)) # +0.16 seconds dc.DrawLine(x, halfClientHeight - lastHalfHeight + 1, x, halfClientHeight + lastHalfHeight - 1) dc.SetPen(wx.Pen(lineColor)) # +0.175 seconds x += self.sampleWidth sample += 1 if sample % self.samplesPerFrame == 0: frame += 1 """ # draw frame markers frameX = frame * self.frameWidth dc.SetPen(wx.Pen(frameCol)) dc.DrawLine(frameX, topBorder, frameX, cs.height) dc.SetBrush(wx.Brush(fillColor)) dc.SetPen(wx.Pen(lineColor)) """ lastHeight = height lastHalfHeight = halfHeight if faster_drawing: # This fills in the lines between samples. Doing this separately saves between 0.11 and 0.25 seconds here. dc.SetBrush(wx.Brush(fillColor)) dc.SetPen(wx.Pen(lineColor)) dc.SetTextForeground(frameTextCol) dc.SetFont(font) textWidth, topBorder = dc.GetTextExtent("Ojyg") x = firstSample * self.sampleWidth frame = firstSample / self.samplesPerFrame fps = int(round(self.doc.fps)) sample = firstSample lastHeight = -1 lastHalfHeight = 1 amp = 0 dc.SetPen(wx.Pen(fillColor)) for i in range(int(firstSample), int(lastSample)): amp = self.amp[i] height = round(cs.height * amp) halfHeight = height / 2 if not SIMPLE_DISPLAY: if drawPlayMarker and (frame == curFrame): dc.SetBrush(wx.Brush(fillColor)) dc.SetPen(wx.Pen(lineColor)) if lastHeight > 0 and not (drawPlayMarker and frame == curFrame): if lastHeight > height: lastHeight = height lastHalfHeight = halfHeight dc.DrawLine(x, halfClientHeight - lastHalfHeight + 1, x, halfClientHeight + lastHalfHeight - 1) x += self.sampleWidth sample += 1 if sample % self.samplesPerFrame == 0: frame += 1 """ # draw frame markers frameX = frame * self.frameWidth dc.SetPen(wx.Pen(frameCol)) dc.DrawLine(frameX, topBorder, frameX, cs.height) dc.SetBrush(wx.Brush(fillColor)) dc.SetPen(wx.Pen(lineColor)) """ lastHeight = height lastHalfHeight = halfHeight dc.SetPen(wx.Pen(lineColor)) # draw the phrases/words/phonemes if self.doc.currentVoice is not None: topBorder += 4 font.SetPointSize(8) font.SetWeight(wx.BOLD) dc.SetFont(font) textWidth, textHeight = dc.GetTextExtent("Ojyg") textHeight += 6 self.phraseBottom = topBorder + textHeight self.wordBottom = topBorder + 4 + textHeight + textHeight + textHeight self.phonemeTop = cs.height - 4 - textHeight - textHeight dc.SetTextForeground(textCol) for phrase in self.doc.currentVoice.phrases: dc.SetBrush(wx.Brush(phraseFillCol)) dc.SetPen(wx.Pen(phraseOutlineCol)) r = wx.Rect(phrase.startFrame * self.frameWidth, topBorder, (phrase.endFrame - phrase.startFrame + 1) * self.frameWidth + 1, textHeight) if (self.clipRect is not None) and (not r.Intersects(self.clipRect)): continue # speed things up by skipping off-screen phrases phrase.top = r.y phrase.bottom = r.y + r.height dc.DrawRectangle(r.x, r.y, r.width, r.height) r.Inflate(-4, 0) if not self.isWxPhoenix: dc.SetClippingRect(r) else: # WxWidgets - Phoenix dc.SetClippingRegion(r) dc.DrawLabel(phrase.text, r, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL) dc.DestroyClippingRegion() if self.clipRect is not None: if not self.isWxPhoenix: dc.SetClippingRect(self.clipRect) else: # WxWidgets - Phoenix dc.SetClippingRegion(self.clipRect) wordCount = 0 for word in phrase.words: dc.SetBrush(wx.Brush(wordFillCol)) dc.SetPen(wx.Pen(wordOutlineCol)) r = wx.Rect(word.startFrame * self.frameWidth, topBorder + 4 + textHeight, (word.endFrame - word.startFrame + 1) * self.frameWidth + 1, textHeight) if wordCount % 2: r.y += textHeight word.top = r.y word.bottom = r.y + r.height dc.DrawRectangle(r.x, r.y, r.width, r.height) r.Inflate(-4, 0) if not self.isWxPhoenix: dc.SetClippingRect(r) else: # WxWidgets - Phoenix dc.SetClippingRegion(r) dc.DrawLabel(word.text, r, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL) dc.DestroyClippingRegion() if self.clipRect is not None: if not self.isWxPhoenix: dc.SetClippingRect(self.clipRect) else: # WxWidgets - Phoenix dc.SetClippingRegion(self.clipRect) dc.SetBrush(wx.Brush(phonemeFillCol)) dc.SetPen(wx.Pen(phonemeOutlineCol)) phonemeCount = 0 for phoneme in word.phonemes: r = wx.Rect(phoneme.frame * self.frameWidth, cs.height - 4 - textHeight, self.frameWidth + 1, textHeight) if phonemeCount % 2: r.y -= textHeight phoneme.top = r.y phoneme.bottom = r.y + r.height dc.DrawRectangle(r.x, r.y, r.width, r.height) dc.DrawLabel(phoneme.text, r, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL) phonemeCount += 1 wordCount += 1 # draw the play marker if drawPlayMarker: x = curFrame * self.frameWidth # foreground height = round(cs.height * amp) # outline dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.SetPen(wx.Pen(playOutlineCol)) dc.DrawRectangle(x, 0, self.frameWidth + 1, cs.height) # Draw Big Fat Frame Marker if self.isDragging: dc.DestroyClippingRegion() font.SetPointSize(16) font.SetWeight(wx.BOLD) dc.SetFont(font) dc.DrawLabel(str(curFrame + 1), wx.Rect(x - 50, cs.height * 0.4, 100, 125), wx.ALIGN_CENTER) try: dc.EndDrawing() except AttributeError: pass if stopwatch: t2.stop() print("Drawing took: " + str(t2.elapsed))
def setUp(self): self.timer = simplestopwatch.Timer()
# if __name__ == '__main__': # urls = [ # 'https://postman-echo.com/get?foo1=bar1&foo2=bar2', # 'https://postman-echo.com/get?foo3=bar3&foo4=bar4' # ] # responses = streamer(urls) # for r in responses: # print(r) # print() NUM_URLS = 1000 def urls_gen(): for _ in range(NUM_URLS): yield 'http://localhost:8080/' if __name__ == '__main__': print("Running main") timer = sw.Timer() responses = streamer(urls_gen()) for r in responses: pass timer.stop() print() print("Time elapsed:", timer.elapsed) print("Human time:", timer.elapsed_human) print("Rate:", NUM_URLS / timer.elapsed) print("Ending main")