def __init__(self, *args, **kwargs): InstrumentsPanel.__init__(self, *args, **kwargs) self.SetDoubleBuffered(False) # needed for mplayer self.slider = wx.Slider(self, minValue=0, maxValue=1000000, size=(60, 20), pos=(6, 600)) if DEBUG: print(self.mediarc[0] + 30, self.mediarc[1]) self.sizer.Add(self.slider, pos=(self.mediarc[0], self.mediarc[1]), span=(1, 16), flag=wx.EXPAND) self.slider.Bind(wx.EVT_SCROLL_THUMBRELEASE, self.SliderSeek) self.slider.Bind(wx.EVT_SCROLL_CHANGED, self.SliderSeek) if 1: self.trendmeter = plotcanvas.BarGraphMeter(parent=self, width=40) self.trendmeter.SetYRange(ymin=-1., ymax=1.) self.trendmeter.SetForegroundColour('white') self.trendmeter.SetBackgroundColour('black') self.trendmeter.SetDoubleBuffered(True) self.trendmeter.SetXSpec('none') self.trendmeter.SetYSpec('none') #self.trendmeter.title = 'HEG Trend' trendtext = wx.StaticText(parent=self, label="HEG trend:") self.sizer.Add(trendtext, (self.r, self.c), (1, 4)) self.r += 1 self.sizer.Add(self.trendmeter, (self.r, self.c), (1, 4), flag=wx.EXPAND) self.r += 1 self.sizer.Layout() self.InitMediaCtrl(attach=self.app.userprofile['mcattached'])
def __init__(self, *args, **kwargs): InstrumentsPanel.__init__(self, *args, **kwargs) self.trendmeter = plotcanvas.BarGraphMeter(parent=self, width=40) self.trendmeter.SetYRange(ymin=-1., ymax=1.) self.trendmeter.SetForegroundColour('white') self.trendmeter.SetBackgroundColour('black') self.trendmeter.SetDoubleBuffered(True) self.trendmeter.SetXSpec('none') self.trendmeter.SetYSpec('none') #self.trendmeter.title = 'HEG Trend' trendtext = wx.StaticText(parent=self, label="HEG trend:") self.sizer.Add(trendtext, (self.r, self.c), (1,4)) self.r += 1 self.sizer.Add(self.trendmeter, (self.r, self.c), (1,4), flag=wx.EXPAND) self.r += 1 self.midplot = plotcanvas.PlotCanvas(self) if map(int, wx.version().split(' ')[0].split('.')) < [2, 8, 10]: oldwxplot = True else: oldwxplot = False if not oldwxplot: self.midplot.SetForegroundColour('blue') self.midplot.SetGridColour('blue') self.midplot.SetBackgroundColour('black') self.midplot.SetYSpec('min') self.midplot.SetEnableAntiAliasing(True) self.midplot.SetEnableHiRes(True) self.midplot.SetXSpec('min') else: self.midplot.SetYSpec('min') # Workaround for a bug which causes scrollbars to appear when they shouldn't self.midplot.SetShowScrollbars = lambda x: None self.Bind(wx.EVT_SIZE, self.OnResize) self.midplot.Update([100., 100.], [0., 1.]) self.sizer.Add(self.midplot, self.mediarc, (16,16), flag=wx.EXPAND) self.OnResize()
def OnResize(self, evt=None): InstrumentsPanel.OnResize(self, evt) self.mc.SetInitialSize() #print self.mc.GetBestSize(), self.mc.Length() totalframesize = self.parent.GetBestSize() #self.plot.SetMinSize((totalframesize[0], totalframesize[1]/5)) framesize = totalframesize[0] - 200, totalframesize[1]*4/5 if USE_MPLAYER: for i in range(10): try: videosize = self.mc.GetBestSize() except Exception: return if videosize: break else: videosize = (720, 400) controlsize = self.mc.GetSize() else: videosize = controlsize = self.mc.GetSize() try: if not self.app.userprofile['mcattached']: framesize = self.mcframe.GetSize() frameaspect = float(framesize[0])/framesize[1] videoaspect = float(videosize[0])/videosize[1] if frameaspect < videoaspect: scale = float(framesize[0]) / videosize[0] else: scale = float(framesize[1]) / videosize[1] newvideosize = map(lambda x: int(scale*x), videosize) if USE_MPLAYER: self.mc.SetInitialSize(newvideosize) self.mc.SetSize(newvideosize) else: self.mc.SetInitialSize(newvideosize) if not self.app.userprofile['mcattached']: dx = framesize[0] - newvideosize[0] dy = framesize[1] - newvideosize[1] self.mc.SetPosition((dx/2, dy/2)) self.sizer.Layout() if hasattr(self.mc, 'last_seek'): self.mc.Seek(self.mc.last_seek + .000001, 1) except ZeroDivisionError: if self.loaded: # Need to Play(), Pause() to fix DShow bug self.OnMediaLoaded() except ValueError: # happens when closing due to the config shelf being closed pass except Exception: pass except MplayerCtrl.NoMplayerRunning: pass
def UpdateMovie(self, data=None, times=None): moviepos = self.CalcMoviePos() try: moviepos = (moviepos * self.mc.Length()) % (self.mc.Length()) except ZeroDivisionError: pass InstrumentsPanel.UpdateMovie(self, data, times) #self.mc.Seek(moviepos) if not 'playpause' in self.app.cfg: self.app.cfg['playpause'] = False if self.app.cfg['playpause'] and not USE_MPLAYER: self.mc.Play() self.mc.Pause() if USE_THREADS: if not self.mcmutex.locked(): self.mcmutex.acquire() thread.start_new(self.SeekMovieAndReleaseMutex, (moviepos,)) else: self.mc.Seek(moviepos)
def UpdateMovie(self, data, times): self.midplot.Update(data[-320:], numpy.array(times[-320:]) - times[0], zero_x=False) delta = mean(data[-5:]) - mean(data[-50:]) sigma = numpy.std(data[-300:]) contrast = 1./(1+math.e**(-delta/sigma*5.))*100. - 85. zoom = 1./(1+math.e**(-delta/sigma*2.)) trend = 1./(1+math.e**(-delta/sigma)) * 2 - 1 r = int((1-max(-trend, 0))*64) g = int((1-math.fabs(trend))*64) b = int((1-max( trend, 0))*64) if trend < 0: b = 95 + int(-trend*160) else: r = 95 + int(trend*160) self.trendmeter.SetColor(wx.Color(r,g,b)) self.trendmeter.SetValue(trend) InstrumentsPanel.UpdateMovie(self, data, times)
def OnStop(self, evt=None): InstrumentsPanel.OnStop(self, evt) if not self.mc.paused: self.mc.paused = True self.mc.pausing = True self.mc.Pause()
def __init__(self, parent, id, app, blind=False, reverse=False, *args, **kwargs): InstrumentsPanel.__init__(self, parent, id, app, blind=blind, *args, **kwargs) self.blind = blind self.reverse = reverse sizer = self.sizer fgcolor = self.GetForegroundColour() bgcolor = self.GetBackgroundColour() self.loaded = False if USE_MPLAYER: self.SetDoubleBuffered(False) if not os.path.exists(mediadir): os.mkdir(mediadir) extensions = ['.avi'] if not USE_MPLAYER: extensions.extend(['.wmv', '.mp4', '.mpg', '.m4v']) self.mediafiles = [opj(mediadir, fn) for fn in os.listdir(mediadir) if fn.lower()[-4:] in extensions] self.mcmutex = thread.allocate_lock() self.SetAveragingInterval() self.SetSensitivity() r, c = self.r, self.c senstitle = wx.StaticText(parent=self, id=-1, label="Sensitivity: ") sizer.Add(senstitle, (r,c), (1,4)) r += 1 self.sens = sens = wx.SpinCtrl(parent=self, value=str(int(self.unadjusted_sensitivity)), min=1, max=1000) sens.Bind(wx.EVT_SPINCTRL, self.OnSensitivityCtrl) sizer.Add(sens, (r,c), (1,4)) r += 1 videostitle = wx.StaticText(parent=self, id=-1, label="Video: ") sizer.Add(videostitle, (r,c), (1,4)) r += 1 self.vids = vids = wx.Choice(parent=self, name="Video: ", choices=[os.path.basename(f) for f in self.mediafiles]) vids.Bind(wx.EVT_CHOICE, self.OnVideoCtrl) sizer.Add(vids, (r,c), (1,4)) r += 1 feedbacktitle = wx.StaticText(parent=self, id=-1, label="Feedback mode: ") sizer.Add(feedbacktitle, (r,c), (1,4)) r += 1 feedbackchoices = ['Responsive', 'Smooth'] self.feedback = feedback = wx.Choice(parent=self, name="Feedback mode: ", choices=feedbackchoices) feedback.SetSelection(feedbackchoices.index(self.app.userprofile['feedbackmode'])) feedback.Bind(wx.EVT_CHOICE, self.OnFeedbackMode) sizer.Add(feedback, (r,c), (1,4)) r += 1 r += 1 self.vids.SetFont(wx.Font(10, wx.FONTFAMILY_ROMAN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)) videostitle.SetForegroundColour(fgcolor) feedbacktitle.SetForegroundColour(fgcolor) senstitle.SetForegroundColour(fgcolor) self.sens.SetForegroundColour(fgcolor) self.sens.SetBackgroundColour(bgcolor) self.vids.SetForegroundColour(fgcolor) self.vids.SetBackgroundColour(bgcolor) self.r, self.c = r,c self.InitMediaCtrl(attach=self.app.userprofile['mcattached']) sizer.Layout()