Skip to content

Commit

Permalink
Renamed CheckBox to BoolWidget and added different display modes.
Browse files Browse the repository at this point in the history
The display modes are CheckBox (like before) and Switch.
  • Loading branch information
johnhaddon committed Oct 9, 2013
1 parent 8abe0e5 commit 2279851
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 43 deletions.
18 changes: 9 additions & 9 deletions python/GafferUI/BoolPlugValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,31 @@

class BoolPlugValueWidget( GafferUI.PlugValueWidget ) :

def __init__( self, plug, **kw ) :
def __init__( self, plug, displayMode=GafferUI.BoolWidget.DisplayMode.CheckBox, **kw ) :

self.__checkBox = GafferUI.CheckBox()
self.__boolWidget = GafferUI.BoolWidget( displayMode=displayMode )

GafferUI.PlugValueWidget.__init__( self, self.__checkBox, plug, **kw )
GafferUI.PlugValueWidget.__init__( self, self.__boolWidget, plug, **kw )

self._addPopupMenu( self.__checkBox )
self._addPopupMenu( self.__boolWidget )

self.__stateChangedConnection = self.__checkBox.stateChangedSignal().connect( Gaffer.WeakMethod( self.__stateChanged ) )
self.__stateChangedConnection = self.__boolWidget.stateChangedSignal().connect( Gaffer.WeakMethod( self.__stateChanged ) )

self._updateFromPlug()

def setHighlighted( self, highlighted ) :

GafferUI.PlugValueWidget.setHighlighted( self, highlighted )
self.__checkBox.setHighlighted( highlighted )
self.__boolWidget.setHighlighted( highlighted )

def _updateFromPlug( self ) :

if self.getPlug() is not None :
with self.getContext() :
with Gaffer.BlockedConnection( self.__stateChangedConnection ) :
self.__checkBox.setState( self.getPlug().getValue() )
self.__boolWidget.setState( self.getPlug().getValue() )

self.__checkBox.setEnabled( self._editable() )
self.__boolWidget.setEnabled( self._editable() )

def __stateChanged( self, widget ) :

Expand All @@ -80,6 +80,6 @@ def __setPlugValue( self ) :

with Gaffer.UndoContext( self.getPlug().ancestor( Gaffer.ScriptNode.staticTypeId() ) ) :

self.getPlug().setValue( self.__checkBox.getState() )
self.getPlug().setValue( self.__boolWidget.getState() )

GafferUI.PlugValueWidget.registerType( Gaffer.BoolPlug.staticTypeId(), BoolPlugValueWidget )
14 changes: 12 additions & 2 deletions python/GafferUI/CheckBox.py → python/GafferUI/BoolWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,19 @@
#
##########################################################################

import IECore

import Gaffer
import GafferUI

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

class CheckBox( GafferUI.Widget ) :
class BoolWidget( GafferUI.Widget ) :

DisplayMode = IECore.Enum.create( "CheckBox", "Switch" )

def __init__( self, text="", checked=False, **kw ) :
def __init__( self, text="", checked=False, displayMode=DisplayMode.CheckBox, **kw ) :

GafferUI.Widget.__init__( self, QtGui.QCheckBox( text ), **kw )

Expand All @@ -52,6 +56,9 @@ def __init__( self, text="", checked=False, **kw ) :

self._qtWidget().stateChanged.connect( Gaffer.WeakMethod( self.__stateChanged ) )

if displayMode == self.DisplayMode.Switch :
self._qtWidget().setObjectName( "gafferBoolWidgetSwitch" )

def setText( self, text ) :

self._qtWidget().setText( text )
Expand All @@ -75,3 +82,6 @@ def stateChangedSignal( self ) :
def __stateChanged( self, state ) :

self.__stateChangedSignal( self )

## \todo Backwards compatibility - remove for version 1.0
CheckBox = BoolWidget
2 changes: 1 addition & 1 deletion python/GafferUI/OpDialogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init__(

if self.__postExecuteBehaviour in ( self.PostExecuteBehaviour.NoneByDefault, self.PostExecuteBehaviour.CloseByDefault ) :
with GafferUI.ListContainer( GafferUI.ListContainer.Orientation.Horizontal ) :
self.__keepWindowOpen = GafferUI.CheckBox(
self.__keepWindowOpen = GafferUI.BoolWidget(
"Keep window open",
self.__postExecuteBehaviour == self.PostExecuteBehaviour.NoneByDefault
)
Expand Down
4 changes: 2 additions & 2 deletions python/GafferUI/PathFilterWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class BasicPathFilterWidget( PathFilterWidget ) :

def __init__( self, pathFilter ) :

self.__checkBox = GafferUI.CheckBox( str( pathFilter ) )
self.__checkBox = GafferUI.BoolWidget( str( pathFilter ) )

PathFilterWidget.__init__( self, self.__checkBox, pathFilter )

Expand All @@ -128,4 +128,4 @@ def __stateChanged( self, checkBox ) :
invertEnabled = self.pathFilter().userData()["UI"]["invertEnabled"]
self.pathFilter().setEnabled( checkBox.getState() is not invertEnabled )

PathFilterWidget.registerType( Gaffer.PathFilter, BasicPathFilterWidget )
PathFilterWidget.registerType( Gaffer.PathFilter, BasicPathFilterWidget )
33 changes: 33 additions & 0 deletions python/GafferUI/Widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,8 @@ def _setStyleSheet( self ):
image : url($GAFFER_ROOT/graphics/collapsibleArrowDown.png);
}
/* checkbox */
QCheckBox::indicator {
width: 20px;
height: 20px;
Expand Down Expand Up @@ -1346,6 +1348,37 @@ def _setStyleSheet( self ):
QCheckBox::indicator:unchecked:disabled {
image: url($GAFFER_ROOT/graphics/checkBoxUncheckedDisabled.png);
}
/* boolwidget drawn as switch */
QCheckBox#gafferBoolWidgetSwitch::indicator:unchecked {
image: url($GAFFER_ROOT/graphics/toggleOff.png);
}
QCheckBox#gafferBoolWidgetSwitch::indicator:unchecked:hover,
QCheckBox#gafferBoolWidgetSwitch::indicator:unchecked:focus,
QCheckBox#gafferBoolWidgetSwitch[gafferHighlighted=\"true\"]::indicator:unchecked {
image: url($GAFFER_ROOT/graphics/toggleOffHover.png);
}
QCheckBox#gafferBoolWidgetSwitch::indicator:checked:hover,
QCheckBox#gafferBoolWidgetSwitch::indicator:checked:focus,
QCheckBox#gafferBoolWidgetSwitch[gafferHighlighted=\"true\"]::indicator:checked {
image: url($GAFFER_ROOT/graphics/toggleOnHover.png);
}
QCheckBox#gafferBoolWidgetSwitch::indicator:checked {
image: url($GAFFER_ROOT/graphics/toggleOn.png);
}
QCheckBox#gafferBoolWidgetSwitch::indicator:checked:disabled {
image: url($GAFFER_ROOT/graphics/toggleOnDisabled.png);
}
QCheckBox#gafferBoolWidgetSwitch::indicator:unchecked:disabled {
image: url($GAFFER_ROOT/graphics/toggleOffDisabled.png);
}
/* frame */
.QFrame#borderStyleNone {
border: 1px solid transparent;
Expand Down
2 changes: 1 addition & 1 deletion python/GafferUI/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def _qtImport( name, lazy=False ) :
from Slider import Slider
from ShowURL import showURL
from Spacer import Spacer
from CheckBox import CheckBox
from BoolWidget import BoolWidget, CheckBox
from Image import Image
from ErrorDialogue import ErrorDialogue
from _Variant import _Variant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
import GafferUI
import GafferUITest

class CheckBoxTest( GafferUITest.TestCase ) :
class BoolWidgetTest( GafferUITest.TestCase ) :

def testLifespan( self ) :

w = GafferUI.CheckBox()
w = GafferUI.BoolWidget()
r = weakref.ref( w )

self.failUnless( r() is w )
Expand All @@ -59,7 +59,7 @@ def testStateChangedSignal( self ) :
def f( w ) :
self.emissions += 1

w = GafferUI.CheckBox()
w = GafferUI.BoolWidget()
c = w.stateChangedSignal().connect( f )

w.setState( True )
Expand All @@ -69,7 +69,7 @@ def f( w ) :

def testState( self ) :

w = GafferUI.CheckBox()
w = GafferUI.BoolWidget()
self.assertEqual( w.getState(), False )

w.setState( True )
Expand All @@ -80,7 +80,7 @@ def testState( self ) :

def testText( self ) :

w = GafferUI.CheckBox( "a" )
w = GafferUI.BoolWidget( "a" )
self.assertEqual( w.getText(), "a" )

w.setText( "b" )
Expand Down
2 changes: 1 addition & 1 deletion python/GafferUITest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
from EventLoopTest import EventLoopTest
from SplinePlugGadgetTest import SplinePlugGadgetTest
from TextWidgetTest import TextWidgetTest
from CheckBoxTest import CheckBoxTest
from BoolWidgetTest import BoolWidgetTest
from ImageTest import ImageTest
from ButtonTest import ButtonTest
from CollapsibleTest import CollapsibleTest
Expand Down
62 changes: 40 additions & 22 deletions resources/graphics.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2279851

Please sign in to comment.