<s> import os <EOL> import PythonQt <EOL> from PythonQt import QtCore , QtGui , QtUiTools <EOL> from director . timercallback import TimerCallback <EOL> import director . objectmodel as om <EOL> from director import lcmUtils <EOL> from director import cameraview <EOL> from director import vtkAll as vtk <EOL> import json <EOL> import drc as lcmdrc <EOL> CAPTURE_CHANNEL = '<STR_LIT>' <EOL> def startApplication ( enableQuitTimer = False ) : <EOL> appInstance = QtGui . QApplication . instance ( ) <EOL> if enableQuitTimer : <EOL> quitTimer = TimerCallback ( ) <EOL> quitTimer . callback = appInstance . quit <EOL> quitTimer . singleShot ( <NUM_LIT:0.1> ) <EOL> appInstance . exec_ ( ) <EOL> def addShortcut ( keySequence , widget , slot ) : <EOL> shortcut = QtGui . QShortcut ( QtGui . QKeySequence ( keySequence ) , widget ) <EOL> shortcut . connect ( '<STR_LIT>' , slot ) <EOL> def addConsoleShortcut ( widget ) : <EOL> addShortcut ( '<STR_LIT>' , widget , _console . show ) <EOL> def addWidgetsToDict ( widgets , d ) : <EOL> for widget in widgets : <EOL> if widget . objectName : <EOL> d [ str ( widget . objectName ) ] = widget <EOL> addWidgetsToDict ( widget . children ( ) , d ) <EOL> class WidgetDict ( object ) : <EOL> def __init__ ( self , widgets ) : <EOL> addWidgetsToDict ( widgets , self . __dict__ ) <EOL> def clearLayout ( w ) : <EOL> children = w . findChildren ( QtGui . QWidget ) <EOL> for child in children : <EOL> child . delete ( ) <EOL> class FieldData ( object ) : <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . __dict__ . update ( kwargs ) <EOL> def __repr__ ( self ) : <EOL> keys = self . __dict__ . keys ( ) <EOL> return '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( [ '<STR_LIT>' % ( k , v ) for k , v in self . __dict__ . iteritems ( ) ] ) <EOL> class VideoPlayer ( object ) : <EOL> def __init__ ( self ) : <EOL> self . pid = os . getpid ( ) <EOL> self . loadUi ( ) <EOL> self . setupUi ( ) <EOL> self . setupImageStreams ( ) <EOL> self . enableLiveMode ( ) <EOL> def loadUi ( self ) : <EOL> loader = QtUiTools . QUiLoader ( ) <EOL> uifile = QtCore . QFile ( '<STR_LIT>' ) <EOL> assert uifile . open ( uifile . ReadOnly ) <EOL> self . widget = loader . load ( uifile ) <EOL> uifile . close ( ) <EOL> self . ui = WidgetDict ( self . widget . children ( ) ) <EOL> def setupImageStreams ( self ) : <EOL> streams = [ <EOL> CAPTURE_CHANNEL , <EOL> '<STR_LIT>' ] <EOL> self . imageManager = cameraview . ImageManager ( ) <EOL> for channelName in streams : <EOL> self . imageManager . queue . addCameraStream ( channelName ) <EOL> self . imageManager . addImage ( channelName ) <EOL> self . currentStream = streams [ <NUM_LIT:0> ] <EOL> self . cameraView = cameraview . CameraImageView ( self . imageManager , self . currentStream , view = self . view ) <EOL> self . cameraView . eventFilterEnabled = False <EOL> self . view . renderWindow ( ) . GetInteractor ( ) . SetInteractorStyle ( vtk . vtkInteractorStyleImage ( ) ) <EOL> def printImageDimensions ( self ) : <EOL> image = self . imageManager . images [ self . currentStream ] <EOL> print image . GetDimensions ( ) <EOL> def setupUi ( self ) : <EOL> addConsoleShortcut ( self . widget ) <EOL> _pythonManager . setupConsole ( self . widget ) <EOL> addShortcut ( '<STR_LIT>' , self . widget , self . widget . close ) <EOL> addShortcut ( '<STR_LIT>' , self . widget , self . widget . close ) <EOL> self . view = PythonQt . dd . ddQVTKWidgetView ( ) <EOL> self . view . orientationMarkerWidget ( ) . Off ( ) <EOL> self . view . renderer ( ) . SetBackground ( [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> self . view . renderer ( ) . SetBackground2 ( [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> self . ui . logSyncButton . visible = True <EOL> self . ui . reviewButton . visible = True <EOL> self . ui . resumeButton . visible = False <EOL> self . ui . playbackControlsFrame . visible = False <EOL> self . ui . playbackSliderFrame . visible = False <EOL> self . ui . seekForwardButton . visible = False <EOL> self . ui . seekBackwardButton . visible = False <EOL> self . ui . timeLabel . visible = False <EOL> self . ui . slider . connect ( '<STR_LIT>' , self . onSliderChanged ) <EOL> self . ui . resumeButton . connect ( '<STR_LIT>' , self . onResumeClicked ) <EOL> self . ui . logSyncButton . connect ( '<STR_LIT>' , self . onLogSyncClicked ) <EOL> self . ui . reviewButton . connect ( '<STR_LIT>' , self . onReviewClicked ) <EOL> self . ui . playButton . connect ( '<STR_LIT>' , self . onPlayClicked ) <EOL> self . ui . mainWidget . layout ( ) . addWidget ( self . view ) <EOL> self . widget . resize ( <NUM_LIT> , <NUM_LIT> + self . ui . controlsFrame . height ) <EOL> self . widget . show ( ) <EOL> self . ui . slider . clearFocus ( ) <EOL> def sendCommand ( self , channel , ** kwargs ) : <EOL> msg = lcmdrc . behavior_command_t ( ) <EOL> msg . command = json . dumps ( kwargs ) <EOL> lcmUtils . publish ( channel , msg ) <EOL> def unwrapCommand ( self , msg ) : <EOL> argDict = json . loads ( msg . command ) <EOL> return FieldData ( ** argDict ) <EOL> def onResumeClicked ( self ) : <EOL> self . enableLiveMode ( ) <EOL> def onLogSyncClicked ( self ) : <EOL> self . enableLogSyncMode ( ) <EOL> def onReviewClicked ( self ) : <EOL> self . enableReviewMode ( ) <EOL> def enableReviewMode ( self ) : <EOL> self . sendCommand ( '<STR_LIT>' , command = '<STR_LIT>' ) <EOL> self . cameraView . setImageName ( '<STR_LIT>' ) <EOL> self . ui . logSyncButton . visible = False <EOL> self . ui . reviewButton . visible = False <EOL> self . ui . resumeButton . visible = True <EOL> self . ui . playbackControlsFrame . visible = True <EOL> self . ui . playbackSliderFrame . visible = True <EOL> self . ui . slider . blockSignals ( True ) <EOL> self . ui . slider . setValue ( self . ui . slider . maximum ) <EOL> self . ui . slider . blockSignals ( False ) <EOL> def enableLiveMode ( self ) : <EOL> self . sendCommand ( '<STR_LIT>' , command = '<STR_LIT>' ) <EOL> self . cameraView . setImageName ( CAPTURE_CHANNEL ) <EOL> self . ui . logSyncButton . visible = True <EOL> self . ui . reviewButton . visible = True <EOL> self . ui . resumeButton . visible = False <EOL> self . ui . playbackControlsFrame . visible = False <EOL> self . ui . playbackSliderFrame . visible = False <EOL> def enableLogSyncMode ( self ) : <EOL> self . sendCommand ( '<STR_LIT>' , command = '<STR_LIT>' ) <EOL> self . cameraView . setImageName ( '<STR_LIT>' ) <EOL> self . ui . logSyncButton . visible = False <EOL> self . ui . reviewButton . visible = False <EOL> self . ui . resumeButton . visible = True <EOL> self . ui . playbackControlsFrame . visible = False <EOL> self . ui . playbackSliderFrame . visible = False <EOL> def getSliderValue ( self ) : <EOL> return ( self . ui . slider . value / float ( self . ui . slider . maximum ) ) <EOL> def onSliderChanged ( self , sliderValue ) : <EOL> self . sendCommand ( '<STR_LIT>' , command = '<STR_LIT>' , value = self . getSliderValue ( ) , pid = self . pid ) <EOL> self . cameraView . setImageName ( '<STR_LIT>' ) <EOL> def onPlayClicked ( self ) : <EOL> self . sendCommand ( '<STR_LIT>' , command = '<STR_LIT>' , value = self . getSliderValue ( ) , pid = self . pid , speed = self . ui . playbackSpeedSpin . value ) <EOL> def main ( ) : <EOL> global videoPlayer <EOL> videoPlayer = VideoPlayer ( ) <EOL> videoPlayer . widget . show ( ) <EOL> startApplication ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
