Skip to content

Commit

Permalink
[cuegui] Fix FrameContextMenu and test_rightClickItem to handle NoneT…
Browse files Browse the repository at this point in the history
…ype job attribute (AcademySoftwareFoundation#1561)

- Ensure the job attribute is set before triggering the context menu
event.
- Mock the getLayers method to return an empty list to avoid NoneType
errors.
  • Loading branch information
ramonfigueiredo authored Oct 29, 2024
1 parent e25b56c commit a92fca4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
37 changes: 19 additions & 18 deletions cuegui/cuegui/FrameMonitorTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,24 +915,25 @@ def __init__(self, widget, filterSelectedLayersCallback, readonly=False):

if cuegui.Constants.OUTPUT_VIEWERS:
job = widget.getJob()
outputPaths = []
selectedFrames = widget.selectedObjects()

layers_dict = {layer.name(): layer for layer in job.getLayers()}

for frame in selectedFrames:
layer_name = frame.layer()
layer = layers_dict.get(layer_name)
if layer:
outputPaths.extend(cuegui.Utils.getOutputFromFrame(layer, frame))

if outputPaths:
for viewer in cuegui.Constants.OUTPUT_VIEWERS:
self.addAction(viewer['action_text'],
functools.partial(cuegui.Utils.viewFramesOutput,
job,
selectedFrames,
viewer['action_text']))
if job is not None:
outputPaths = []
selectedFrames = widget.selectedObjects()

layers_dict = {layer.name(): layer for layer in job.getLayers()}

for frame in selectedFrames:
layer_name = frame.layer()
layer = layers_dict.get(layer_name)
if layer:
outputPaths.extend(cuegui.Utils.getOutputFromFrame(layer, frame))

if outputPaths:
for viewer in cuegui.Constants.OUTPUT_VIEWERS:
self.addAction(viewer['action_text'],
functools.partial(cuegui.Utils.viewFramesOutput,
job,
selectedFrames,
viewer['action_text']))

if self.app.applicationName() == "CueCommander":
self.__menuActions.frames().addAction(self, "viewHost")
Expand Down
8 changes: 5 additions & 3 deletions cuegui/tests/FrameMonitorTree_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ def test_rightClickItem(self, execMock):
# Ensure the job attribute is set
self.frameMonitorTree.setJob(self.job)

self.frameMonitorTree.contextMenuEvent(
qtpy.QtGui.QContextMenuEvent(
qtpy.QtGui.QContextMenuEvent.Reason.Mouse, mouse_position, mouse_position))
# Mock the getLayers method to return an empty list or a list of mock layers
with mock.patch.object(self.job, 'getLayers', return_value=[]):
self.frameMonitorTree.contextMenuEvent(
qtpy.QtGui.QContextMenuEvent(
qtpy.QtGui.QContextMenuEvent.Reason.Mouse, mouse_position, mouse_position))

execMock.assert_called_with(mouse_position)

Expand Down

0 comments on commit a92fca4

Please sign in to comment.