Skip to content

Commit

Permalink
Merge pull request #657 from johnhaddon/frameIncrementDecrement
Browse files Browse the repository at this point in the history
Added Left/Right shortcuts for Timeline frame increment/decrement.
  • Loading branch information
andrewkaufman committed Nov 19, 2013
2 parents 862f6b1 + 0948f94 commit 231abe0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
9 changes: 9 additions & 0 deletions python/GafferUI/PathListingWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,15 @@ def sizeHint( self ) :

return result

def event( self, event ) :

if event.type() == event.ShortcutOverride :
if event.key() in ( QtCore.Qt.Key_Up, QtCore.Qt.Key_Down, QtCore.Qt.Key_Left, QtCore.Qt.Key_Right ) :
event.accept()
return True

return QtGui.QTreeView.event( self, event )

def mousePressEvent( self, event ) :

# we store the modifiers so that we can turn single
Expand Down
31 changes: 29 additions & 2 deletions python/GafferUI/Slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def __init__( self, position=None, positions=None, **kw ) :
self.__selectedIndex = None
self.__sizeEditable = False
self.__minimumSize = 1
self.__positionIncrement = None
self._entered = False

self.__enterConnection = self.enterSignal().connect( Gaffer.WeakMethod( self.__enter ) )
Expand Down Expand Up @@ -190,6 +191,20 @@ def getMinimumSize( self ) :

return self.__minimumSize

## Sets the size of the position increment added/subtracted
# when using the cursor keys. The default value of None
# uses an increment equivalent to the size of one pixel at
# the current slider size. An increment of 0 can be specified
# to disable the behaviour entirely.
## \todo Add setValueIncrement() method on NumericSlider.
def setPositionIncrement( self, increment ) :

self.__positionIncrement = increment

def getPositionIncrement( self ) :

return self.__positionIncrement

## May be overridden by derived classes if necessary, but
# implementations must call the base class implementation
# after performing their own work, as the base class is
Expand Down Expand Up @@ -343,8 +358,16 @@ def __keyPress( self, widget, event ) :

if event.key in ( "Left", "Right", "Up", "Down" ) :

if self.__positionIncrement == 0 :
return False

if self.__positionIncrement is None :
pixelIncrement = 1
else :
pixelIncrement = self.__positionIncrement * self.size().x

x = self.getPositions()[self.getSelectedIndex()] * self.size().x
x += 1 if event.key in ( "Right", "Up" ) else - 1
x += pixelIncrement if event.key in ( "Right", "Up" ) else -pixelIncrement
self.__setPositionInternal( self.getSelectedIndex(), x, self.PositionChangedReason.Increment )
return True

Expand Down Expand Up @@ -421,5 +444,9 @@ def event( self, event ) :
if event.key() in ( QtCore.Qt.Key_Delete, QtCore.Qt.Key_Backspace ) :
event.accept()
return True

if event.key() in ( QtCore.Qt.Key_Up, QtCore.Qt.Key_Down, QtCore.Qt.Key_Left, QtCore.Qt.Key_Right ) :
if GafferUI.Widget._owner( self ).getPositionIncrement() != 0 :
event.accept()
return True

return QtGui.QWidget.event( self, event )
22 changes: 17 additions & 5 deletions python/GafferUI/Timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@
#
##########################################################################

import IECore

import Gaffer
import GafferUI

QtCore = GafferUI._qtImport( "QtCore" )
QtGui = GafferUI._qtImport( "QtGui" )

## The Timeline presents a time slider which edits the frame
# entry of a context.
Expand All @@ -51,7 +54,7 @@ def __init__( self, scriptNode, **kw ) :
GafferUI.EditorWidget.__init__( self, self.__row, scriptNode, **kw )

self.__playTimer = QtCore.QTimer()
self.__playTimer.timeout.connect( Gaffer.WeakMethod( self.__playTimeout ) )
self.__playTimer.timeout.connect( Gaffer.WeakMethod( self.__incrementFrame ) )

with self.__row :

Expand All @@ -73,6 +76,7 @@ def __init__( self, scriptNode, **kw ) :
max = float( scriptNode["frameRange"]["end"].getValue() ),
expand = 1
)
self.__slider.setPositionIncrement( 0 ) # disable so the slider doesn't mask our global frame increment shortcut
self.__sliderValueChangedConnection = self.__slider.valueChangedSignal().connect( Gaffer.WeakMethod( self.__sliderChanged ) )

self.__startButton = GafferUI.Button( image = "timelineStart.png", hasFrame=False )
Expand Down Expand Up @@ -100,6 +104,12 @@ def __init__( self, scriptNode, **kw ) :

self.__scriptNodePlugSetConnection = scriptNode.plugSetSignal().connect( Gaffer.WeakMethod( self.__scriptNodePlugSet ) )

frameIncrementShortcut = QtGui.QShortcut( QtGui.QKeySequence( "Right" ), self._qtWidget() )
frameIncrementShortcut.activated.connect( Gaffer.WeakMethod( self.__incrementFrame ) )

frameDecrementShortcut = QtGui.QShortcut( QtGui.QKeySequence( "Left" ), self._qtWidget() )
frameDecrementShortcut.activated.connect( IECore.curry( Gaffer.WeakMethod( self.__incrementFrame ), -1 ) )

def _updateFromContext( self, modifiedItems ) :

if "frame" not in modifiedItems :
Expand Down Expand Up @@ -208,14 +218,16 @@ def __startOrEndButtonClicked( self, button ) :
self.getContext().setFrame( self.__sliderRangeStart.getValue() )
else :
self.getContext().setFrame( self.__sliderRangeEnd.getValue() )

def __playTimeout( self ) :
def __incrementFrame( self, increment = 1 ) :

frame = self.getContext().getFrame()
frame += 1
frame += increment
if frame > self.__sliderRangeEnd.getValue() :
frame = self.__sliderRangeStart.getValue()

elif frame < self.__sliderRangeStart.getValue() :
frame = self.__sliderRangeEnd.getValue()

self.getContext().setFrame( frame )

def __repr__( self ) :
Expand Down

0 comments on commit 231abe0

Please sign in to comment.