def processTimingEvent(self, function_name, description, time_s, time_us, number_samples): """Process the timing event for this port. Store the timing information in self.timingData and forward the event to display if enabled.""" opname = function_name opwhere = description old_time_us = 0 old_time_s = 0 if opname not in self.timingData.keys(): print "This shouldn't really ever print, because the operations should have all already been imported" self.timingData[opname] = {} self.timingData[opname]['begin'] = [0,0,0,0,0] self.timingData[opname]['end'] = [0,0,0,0,0] old_time_s = time_s old_time_us = time_us else: old_time_s = self.timingData[opname][opwhere][0] old_time_us = self.timingData[opname][opwhere][1] self.timingData[opname][opwhere] = [time_s, time_us, number_samples, old_time_s, old_time_us] # store timing info if self.port_info_shape != None: self.port_info_shape.UpdateText() if self.GetCanvas().frame.timing_view_state: if opwhere == "end": locker = wx.MutexGuiLocker() self.SetBrush(brushList[self.brushIndex]) canvas = self.GetCanvas() dc = wx.ClientDC(canvas) canvas.PrepareDC(dc) r = self.GetRegions() x,y = r[0].GetSize() rect = wx.Rect(self.GetX()-x/2,self.GetY()-y/2,x,y) canvas.RefreshRect(rect) canvas.frame.Update() self.brushIndex = (self.brushIndex+1)%(len(brushList)) # Set local flag for timing display if not self.show_timing_display: self.show_timing_display = True else: # Timing display has been turned off, but the port display hasn't been refreshed yet if self.show_timing_display: locker = wx.MutexGuiLocker() if (self.port.type == "Uses"): self.SetBrush(wx.BLACK_BRUSH) else: self.SetBrush(wx.WHITE_BRUSH) canvas = self.GetCanvas() dc = wx.ClientDC(canvas) canvas.PrepareDC(dc) r = self.GetRegions() x,y = r[0].GetSize() rect = wx.Rect(self.GetX()-x/2,self.GetY()-y/2,x,y) canvas.RefreshRect(rect) canvas.frame.Update() self.show_timing_display = False
def ShowGauge(self, show): if show: locker = wx.MutexGuiLocker() self.show_gauge = True self.Show(True) self.gauge.Show(True) self.GetCanvas().Refresh() else: locker = wx.MutexGuiLocker() self.show_gauge = False self.Show(False) self.gauge.Show(False) self.GetCanvas().Refresh()
def UpdateText(self): ts='' for op in self.port.interface.operations: ts += op.cxxReturnType + " " + op.name + " (" for x in range(len(op.params)): param = op.params[x] ts += param.direction + " " + param.cxxType + " " + param.name if x != len(op.params)-1: ts += ", " else: ts += ")" if (self.parent_port.timingData[op.name]['end'][2] != 0): time_diff = (self.parent_port.timingData[op.name]['end'][0]-self.parent_port.timingData[op.name]['end'][3])+((self.parent_port.timingData[op.name]['end'][1]-self.parent_port.timingData[op.name]['end'][4])/1000000.0) throughput = self.parent_port.timingData[op.name]['end'][2]/time_diff ts += "\n\tThroughput: " + "%.2f" % throughput + " sps" if op != self.port.interface.operations[len(self.port.interface.operations)-1]: ts += "\n" self.text_region.SetText(ts) self.ReformatRegions(self.canvas) locker = wx.MutexGuiLocker() canvas = self.GetCanvas() dc = wx.ClientDC(canvas) canvas.PrepareDC(dc) r = self.GetRegions() x,y = r[2].GetSize() rect = wx.Rect(self.GetX()-x/2,self.GetY(),x,y) canvas.RefreshRect(rect) canvas.frame.Update()
def write(self, s): if not wx.Thread_IsMain(): locker = wx.MutexGuiLocker() res = prog_update.search(s) if res: cnt = int(res.group('cnt')) wx.PostEvent(self.output.GetGrandParent().GetParent(), ModCntUpdateEvent(cnt, 'opening')) s = s[:res.start()] ss = string.strip(s) if ss: self.output.SetLabel(ss) if sys: ## frame = sys._getframe() ## try: ## d = 0 ## while frame.f_back: ## frame = frame.f_back ## d += 1 ## except AttributeError: ## pass ## s = ' '*d + s ## try: sys.__stdout__.write(s) #+':'+sys.path[-1]) except UnicodeEncodeError: s = s.encode(sys.getdefaultencoding(), 'replace') sys.__stdout__.write(s) wx.Yield()
def processTimingEvent(self, port, description): if self.GetCanvas().frame.timing_view_state: locker = wx.MutexGuiLocker() current_value = self.gauge.GetValue() if port == self.uses_port: if self.GetCanvas().frame.timing_view_state: if current_value - self.delta < 0: self.gauge.SetValue(self.gauge_range) else: self.gauge.SetValue(current_value - self.delta) if port == self.provides_port: if self.GetCanvas().frame.timing_view_state: if current_value + self.delta > self.gauge_range: self.gauge.SetValue(0) else: self.gauge.SetValue(current_value + self.delta)
def write(self, s): if not wx.Thread_IsMain(): locker = wx.MutexGuiLocker() res = prog_update.search(s) if res: cnt = int(res.group('cnt')) wx.PostEvent(self.output.GetGrandParent().GetParent(), ModCntUpdateEvent(cnt, 'opening')) s = s[:res.start()] ss = string.strip(s) if ss: self.output.SetLabel(ss) if sys: try: sys.__stdout__.write(s) except UnicodeEncodeError: s = s.encode(sys.getdefaultencoding(), 'replace') sys.__stdout__.write(s) wx.Yield()
def write(self, string): if not wx.Thread_IsMain(): # Aquire the GUI mutex before making GUI calls. Mutex is released # when locker is deleted at the end of this function. # # TODO: This should be updated to use wx.CallAfter similarly to how # PyOnDemandOutputWindow.write was so it is not necessary # to get the gui mutex locker = wx.MutexGuiLocker() if self.Enabled: if self.f: self.f.write(string) self.f.flush() move = 1 if (hasattr(self, "text") and self.text is not None and self.text.GetInsertionPoint() != self.text.GetLastPosition()): move = 0 if not self.frame: self.frame = wx.Frame(self.parent, -1, self.title, size=(450, 300), style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE) self.text = wx.TextCtrl(self.frame, -1, "", style=wx.TE_MULTILINE | wx.TE_READONLY | wx.TE_RICH) self.frame.sb = _MyStatusBar( self.frame, callbacks=[ self.DisableOutput, self.CloseFile, self.OpenNewFile ], useopenbutton=hasattr(self, "nofile")) self.frame.SetStatusBar(self.frame.sb) self.frame.Show(True) self.frame.Bind(wx.EVT_CLOSE, self.OnCloseWindow) if hasattr(self, "nofile"): self.text.AppendText( "Please close this window (or select the " "'Dismiss' button below) when desired. By " "default all messages written to this window " "will NOT be written to a file--you " "may change this by selecting 'Open New File' " "below, allowing you to select a " "new file...\n\n") else: tempfile.tempdir = self.dir filename = '' try: self.f = tempfile.NamedTemporaryFile(mode='w', delete=False) filename = os.path.abspath(self.f.name) self.frame.sb.SetStatusText( "File '%s' opened..." % filename, 0) except EnvironmentError: self.frame.sb.SetStatusText( "File creation failed " "(filename '%s')..." % filename, 0) self.text.AppendText( "Please close this window (or select the " "'Dismiss' button below) when desired. By " "default all messages written to this window " "will also be written to the file '%s'--you " "may close this file by selecting 'Close " "File' below, whereupon this button will be " "replaced with one allowing you to select a " "new file...\n\n" % filename) self.text.AppendText(string) if move: self.text.ShowPosition(self.text.GetLastPosition()) if not hasattr(self, "no__debug__"): for m in sys.modules.values(): if m is not None: # and "__debug__" in m.__dict__: m.__dict__["__debug__"] = 1 if hasattr(self, "othermenu") and self.othermenu is not None: i = self.othermenu.FindMenuItem(self.menuname, self.disableitem) self.othermenu.Enable(i, 1) i = self.othermenu.FindMenuItem(self.menuname, self.enableitem) self.othermenu.Enable(i, 0)