Skip to content

Commit

Permalink
Merge pull request #36 from BigRoy/bugfix/action_checkable_qt_compati…
Browse files Browse the repository at this point in the history
…bility

Bugfix: Fix action states in Viewer context menu
  • Loading branch information
BigRoy authored Dec 1, 2023
2 parents a8b27ee + f42fee2 commit dbf5c1b
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions usd_qtpy/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pxr import Usd, UsdGeom, Tf
from pxr.Usdviewq.stageView import StageView
from pxr.Usdviewq import common
from pxr.UsdAppUtils.complexityArgs import RefinementComplexities

try:
# Use C++ implementation of USD View
Expand Down Expand Up @@ -301,27 +302,33 @@ def set_rendermode(action):
group = QtWidgets.QActionGroup(menu)
group.setExclusive(True)
for mode in common.RenderModes:
action = QtWidgets.QAction(
mode,
checkable=True,
checked=self.model.viewSettings.renderMode == mode
)
shading_menu.addAction(action)
action = shading_menu.addAction(mode)
action.setCheckable(True)
action.setChecked(self.model.viewSettings.renderMode == mode)
group.addAction(action)
group.triggered.connect(set_rendermode)

# Complexity
complexity_menu = menu.addMenu("Complexity")
current_complexity_name = self.model.viewSettings.complexity.name
for complexity in RefinementComplexities.ordered():
action = complexity_menu.addAction(complexity.name)
action.setCheckable(True)
action.setChecked(complexity.name == current_complexity_name)
def set_complexity(complexity):
self.model.viewSettings.complexity = complexity

action.triggered.connect(partial(set_complexity, complexity))
# TODO: Set view settings

purpose_menu = menu.addMenu("Display Purpose")
for purpose in ["Guide", "Proxy", "Render"]:
key = f"display{purpose}"
state = getattr(self.model.viewSettings, key) == purpose
action = QtWidgets.QAction(
purpose,
checkable=True,
checked=state)
purpose_menu.addAction(action)
action.triggered.connect(
partial(setattr, self.model.viewSettings, key, not state)
action = purpose_menu.addAction(purpose)
action.setCheckable(True)
action.setChecked(getattr(self.model.viewSettings, key))
action.toggled.connect(
partial(setattr, self.model.viewSettings, key)
)

# help(self.model.viewSettings)
Expand Down Expand Up @@ -359,14 +366,17 @@ def set_rendermode(action):
camera_menu = menu.addMenu("Camera")
fit = camera_menu.addAction("Fit to view")
fit.triggered.connect(partial(self.view.resetCam, 2.0))
current_camera_prim = self.model.viewSettings.cameraPrim
free_cam = camera_menu.addAction("<Free camera>")
free_cam.setCheckable(True)
free_cam.setChecked(not current_camera_prim)
free_cam.triggered.connect(self.view.switchToFreeCamera)
for cam in cameras:
cam_path = str(cam.GetPath())

action = QtGui.QAction(cam_path, camera_menu)
action.setCheckable(True)
action.setChecked(self.model.viewSettings.cameraPrim == cam)
action.setChecked(current_camera_prim == cam)
action.triggered.connect(partial(self.set_camera, cam))

camera_menu.addAction(action)
Expand Down Expand Up @@ -399,16 +409,12 @@ def set_rendermode(action):
# TODO: Expose renderer specific settings like USD view does?

aov_menu = menu.addMenu("Renderer AOV")
current_aov = None
current_aov = self.view.rendererAovName
for aov in self.view.GetRendererAovs():
action = aov_menu.addAction(
aov,
checkable=True,
checked=aov == current_aov
)
action.triggered.connect(
partial(self.view.SetRendererAov, aov)
)
action = aov_menu.addAction(aov)
action.setCheckable(True)
action.setChecked(aov == current_aov)
action.triggered.connect(partial(self.view.SetRendererAov, aov))
if not aov_menu.actions():
aov_menu.setEnabled(False)

Expand Down

0 comments on commit dbf5c1b

Please sign in to comment.