def Stop(self, flush): self._StopTime = Time.GetCurrMS() self._Stopped = True if True == flush: self._Flush() if self._Bytes > 0: Playback.get().SetData(self._RecordedData)
def sliderUpdate(self, event): number = Playback.get().GetCurrentNumber() strVal = str(number) + "/" + str(Playback.get().GetDataCount()) if GuiMgr.get().GetRepeatMode()[0] != Playback.RepeatMode.NONE: strVal = strVal + " Loop: " + str(Playback.get().GetLoopCount()) self.lblPacketNumber.config(text=strVal)
def sliderHandler(self, event): if GuiMgr.get().Playback_Playing: return percent = float(self.slider.get()) / 100.0 number = int(Playback.get().GetDataCount() * percent) Playback.get().SetCurrentNumber(number) strVal = str(number) + "/" + str(Playback.get().GetDataCount()) self.lblPacketNumber.config(text=strVal)
def onStopLoopBtn(self): currNum = Playback.get().GetCurrentNumber() currStart = Playback.get().GetLoopMode()[1] maxNum = Playback.get().GetDataCount() if currStart >= currNum : GuiMgr.MessageBox_Error("Error","You cannot set the end of a loop to be before the start") return Playback.get().SetLoopMode(Playback.RepeatMode.LOOP,currStart,currNum)
def onStartLoopBtn(self): currNum = Playback.get().GetCurrentNumber() currEnd = Playback.get().GetLoopMode()[2] maxNum = Playback.get().GetDataCount() if currNum >= currEnd: GuiMgr.MessageBox_Error("Error","You cannot set the beginning of a loop to be beyond the end") return Playback.get().SetLoopMode(Playback.RepeatMode.LOOP,currNum,currEnd)
def OnSetPlaybackSpeed(self,speed): if not Utility.IsNumeric(speed): Log.getLogger().error("Tried to set playback speed to invalid value: " + str(speed)) return if speed<=0 : Log.getLogger().error("Tried to set playback speed to invalid value: " + str(speed)) return Playback.get().SetPlaybackSpeed(speed)
def OnStartPlayback(self): if False == self.Playback_Active: return if True == self.Playback_Playing: return self.Playback_Playing = True self.Playback_Stopped = False self.Playback_Paused = False Playback.get().Start()
def updatePlaybackTime(self): currTime = Playback.get().GetCurrentPlaybackTime() if currTime > 0: currTime = str(int(currTime / 1000)) else: currTime = "0" endTime = Playback.get().GetPlayTime() if endTime > 0: endTime = str(int(endTime / 1000)) else: endTime = "0" strVal = currTime + "/" + endTime + " secs" self.lblPlaybackTime.config(text=strVal)
def ReadFromFile(self,filename): if Playback.get().ReadFromFile(filename): self.OnEnablePlayback() self.ClearDataView() Recorder.get().OnSaved() return True return False
def updateGui(self): gm = GuiMgr.get() if gm.Live_Receiving or gm.Playback_Playing: val = DISABLED else: val = NORMAL if self._PreviousFileMenuStatus != val: #will kill performance if you do this every loop! self.FileMenu.entryconfigure(self.SaveAsCSV, state=val) self.FileMenu.entryconfigure(self.SaveStr, state=val) self.FileMenu.entryconfigure(self.OpenStr, state=val) self.FileMenu.entryconfigure(self.ExportToDB, state=val) self._PreviousFileMenuStatus = val self.__KludgeCounter = 0 if val == NORMAL: if Playback.get().GetDataCount() < 1: self.FileMenu.entryconfigure(self.SaveStr, state=DISABLED) self.FileMenu.entryconfigure(self.SaveAsCSV, state=DISABLED) self.FileMenu.entryconfigure(self.ExportToDB, state=DISABLED) else: self.__KludgeCounter += 1 # easy to get out of sync if stopped live, but no data, etc. Quick hack if self.__KludgeCounter > 100: self._PreviousFileMenuStatus = None self.__KludgeCounter = 0
def performBatchConvert(filematch): import os import fnmatch GuiMgr.Initialize(GuiMgr.UI.NONE,None,None) #dir_path = os.path.dirname(os.path.realpath(filematch)) convertCount = 0 rel_path,filename = os.path.split(filematch) if len(rel_path) < 1: rel_path='.' for file in os.listdir(rel_path): if fnmatch.fnmatch(file, filename): inputFilename = os.path.join(rel_path,file) if Playback.get().ReadFromFile(inputFilename): baseName,ext = os.path.splitext(inputFilename) csvFilename = baseName+".csv" Playback.get().WriteCSVFile(csvFilename,1) print("{0} --> {1}".format(inputFilename,csvFilename)) convertCount += 1 Playback.get().Clear() print("Converted {0} files".format(convertCount)) GuiMgr.Quit()
def updateGui(self): playbackMgr = Playback.get() guiMgr = GuiMgr.get() if False == guiMgr.Playback_Active and False == self.Visible: return self.updatePlaybackSpeed() self.updateLoopValue() self.updatePlaybackTime() if guiMgr.Playback_Active and False == self.Visible: self.root.grid() self.Visible = True self.slider.set(0) self.lstBoxRepeatMode.current(0) self.lstBoxPlaybackSpeed.current(4) if guiMgr.Live_Receiving and self.Visible: self.Visible = False guiMgr.ShowPlayback(False) self.root.grid_remove() if guiMgr.GetRepeatMode( )[0] == Playback.RepeatMode.LOOP and False == self.LoopValuesVisible: self.LoopValuesVisible = True self.lblEndLoop.grid() self.lblStartLoop.grid() if guiMgr.GetRepeatMode( )[0] != Playback.RepeatMode.LOOP and True == self.LoopValuesVisible: self.LoopValuesVisible = False self.lblEndLoop.grid_remove() self.lblStartLoop.grid_remove() if guiMgr.Playback_Playing and not (enabled(self.btnPausePlayback) or enabled(self.btnStopPlayback)): enable(self.btnPausePlayback) enable(self.btnStopPlayback) disable(self.btnStartPlayback) if not guiMgr.Playback_Playing and (enabled(self.btnPausePlayback) or enabled(self.btnStopPlayback)): disable(self.btnPausePlayback) disable(self.btnStopPlayback) enable(self.btnStartPlayback) if guiMgr.Playback_Playing and enabled(self.slider): disable(self.slider) if not guiMgr.Playback_Playing and not enabled(self.slider): enable(self.slider) currNum = playbackMgr.GetCurrentNumber() total = playbackMgr.GetDataCount() if guiMgr.Playback_Playing: enable(self.slider) self.slider.set(int(currNum * 100 / total)) disable(self.slider) elif currNum == total and self.slider.get() != 100: self.slider.set(100) if guiMgr.GetRepeatMode()[0] != Playback.RepeatMode.LOOP and enabled( self.btnStartLoop): disable(self.btnStartLoop) self.btnStartLoop.grid_remove() self.btnStopLoop.grid_remove() if guiMgr.Playback_Playing and enabled(self.btnStartLoop): disable(self.btnStartLoop) self.btnStartLoop.grid_remove() self.btnStopLoop.grid_remove() if not guiMgr.Playback_Playing and guiMgr.GetRepeatMode( )[0] == Playback.RepeatMode.LOOP and not enabled(self.btnStartLoop): enable(self.btnStartLoop) self.btnStartLoop.grid() self.btnStopLoop.grid() if True == self.LoopValuesVisible: mode = guiMgr.GetRepeatMode() self.lblStartLoop.config(text=str(mode[1])) self.lblEndLoop.config(text=str(mode[2]))
def OnStartLiveData(self): self._upstreamServer.DropPackets(False) self.Live_Receiving = True Playback.get().Clear() Recorder.get().Clear()
def OnStopPlayback(self): self.Playback_Stopped = True self.Playback_Playing = False Playback.get().Stop()
def OnPausePlayback(self): self.Playback_Playing = False self.Playback_Paused = True Playback.get().Pause()
def GetPlaybackSpeed(self): return Playback.get().GetPlaybackSpeed()
def PerformPlayFileTask(self, Params): #<?xml version="1.0" encoding="utf-8"?> #<Marvin Type="OscarTask"> # <Version>1.0</Version> # <OscarID>DemoOscar</OscarID> # <Task>Playback</Task> # <Param>speed=2</Param> #</Marvin> #<?xml version="1.0" encoding="utf-8"?> #<Marvin Type="OscarTask"> # <Version>1.0</Version> # <OscarID>DemoOscar</OscarID> # <Task>Playback</Task> # <Param>speed=2</Param> # <Param>repeat</Param> #</Marvin> #<?xml version="1.0" encoding="utf-8"?> #<Marvin Type="OscarTask"> # <Version>1.0</Version> # <OscarID>DemoOscar</OscarID> # <Task>Playback</Task> # <Param>loop</Param> # <Param>speed=2</Param> # <Param>start=10</Param> # <Param>end=2400</Param> #</Marvin> speed = 1 start = 0 end = Playback.get().GetDataCount() type = Playback.RepeatMode.NONE file = None for param in Params: tParam = Alias.Alias(param.lower()) if tParam == "repeat": type = Playback.RepeatMode.REPEAT elif tParam == "loop": type = Playback.RepeatMode.LOOP else: parts = tParam.split("=") if len(parts) == 2: if parts[0].lower() == 'start' and Utility.IsNumeric( Alias.Alias(parts[1])): start = int(parts[1]) elif parts[0].lower() == 'end' and Utility.IsNumeric( Alias.Alias(parts[1])): end = int(parts[1]) elif parts[0].lower() == 'speed' and Utility.IsNumeric( Alias.Alias(parts[1])): speed = int(parts[1]) elif parts[0].lower() == 'file': file = parts[1] if False == self.PerformLoadFileTask([file]): return end = Playback.get().GetDataCount() else: Log.getLogger().info( "Received unknown Oscar Play parameter: " + param) return else: Log.getLogger().info( "Received unknown Oscar Play parameter: " + param) return if Playback.get().GetDataCount() == 0: Log.getLogger().info("Oscar Play received - but no file loaded.") return if start >= end: Log.getLogger().info("Oscar Play Loop - but start > end.") return Log.getLogger().info("Performing Oscar task: Start Playback.") GuiMgr.OnStopRecording(True) #drop all recorded packets GuiMgr.OnStopLiveData() GuiMgr.OnSetPlaybackSpeed(speed) GuiMgr.OnSetRepeatMode(type, start, end) GuiMgr.OnStartPlayback()
def WriteCSVFile(self,filename,interval): Playback.get().WriteCSVFile(filename,interval)
def WriteToFile(self,filename): if Playback.get().WriteToFile(filename): Recorder.get().OnSaved()
def OnSetRepeatMode(self,mode,startIndex=0,endIndex=None): Playback.get().SetLoopMode(mode,startIndex,endIndex)
def GetRepeatMode(self): return Playback.get().GetLoopMode()