Comments (4)
Here are some context managers that can help:
import contextlib
import logging
import maya.cmds as mc
import maya.mel as mel
log = logging.getLogger(__name__)
def _get_mel_global(name):
"""Return the value of a mel global variable"""
return mel.eval("$%s = $%s;" % (name, name))
@contextlib.contextmanager
def suspend_refresh():
"""Suspend viewport refreshes"""
try:
mc.refresh(suspend=True)
yield
finally:
mc.refresh(suspend=False)
@contextlib.contextmanager
def no_panel_refresh():
"""Disable all controlled panel refreshes."""
controls = list()
for panel in mc.lsUI(panels=True, long=True):
control = mc.panel(panel, query=True, control=True)
if not control:
continue
if not mc.layout(control, query=True, visible=True):
continue
controls.append(control)
try:
for control in controls:
mc.layout(control, edit=True, manage=False)
yield
finally:
for control in controls:
try:
mc.layout(control, edit=True, manage=True)
except RuntimeError:
log.warning("Can't manage control {0}".format(control))
@contextlib.contextmanager
def no_refresh():
"""Temporarily disables Maya's UI updates
Note:
This only disabled the main pane and will sometimes still
trigger updates in torn off panels.
"""
pane = _get_mel_global('gMainPane')
state = mc.paneLayout(pane, q=1, manage=1)
mc.paneLayout(pane, e=1, manage=False)
try:
yield
finally:
mc.paneLayout(pane, e=1, manage=state)
Example usage:
with no_refresh():
# do something here
print "Work!"
I tend to use no_refresh
a lot, though I believe separated viewport panels still continue to update. Last time I checked suspend_refresh
didn't do as much speedup as the others.
from core.
Neat, haven't seen nor used the panel suspenders before.
Personally, I would call each context manager an adjective.
with refresh_suspended():
with panels_suspended():
with main_pane_suspended():
from core.
This seems to have been implemented?
from core.
Indeed!
from core.
Related Issues (20)
- Make debug behaviour consistent for all tools HOT 5
- Make sure the QApplication doesn't get garbage collected HOT 11
- Photoshop Integration HOT 13
- Unity Integration HOT 2
- TVPaint integration HOT 7
- Toon Boom Harmony Integration HOT 13
- Workfiles App Project Folders HOT 5
- Work Files tool save modified changes on scene open prompt confusing HOT 2
- Project Manager allows to add assets with new line characters HOT 3
- Scene Inventory action selection cannot pass into other actions
- No Qt Platform Plugin Initialized - but Launcher loads HOT 3
- Link Loader action against specific panel/UI of host based on user decision HOT 2
- Workfiles close on Open HOT 1
- Workfiles tool add toggle to keep open or close after scene open HOT 2
- CI test failing on sending coverage report
- Performance optimizations using Mongo Aggregation
- CI build pass even when test failed
- Opt-in Python-3.7 in CI test
- Pype & Avalon - let's sync the cores HOT 7
- Houdini: lsattr maybe use Houdini's own nodesearch
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from core.