Disable GUI functions

I attempted to speed up a loop over 200 files by using the mimics.disable_update_gui() method, but the gui definitely still updates. I’m using it just like it was used in the 4D hear cineloop demo script. I used this block of script to detect if any disabling or enabling was detected by mimics. It usually came back False, False, False, but sometimes came back False, None, None.

Any tips or does this just not actually work? I tried from Pycharm and from within Mimics.

print(mimics.is_update_gui_enabled())
mimics.disable_update_gui()
print(mimics.is_update_gui_enabled())
mimics.enable_update_gui()
print(mimics.is_update_gui_enabled())

Hey Nathan,

In case you have multiple update_gui commands, it’s interesting to know that Mimics works with a ‘counter’. Everytime you disable the gui, it goes up with 1 and when you enable the gui, it goes down with 1. Only when the counter is on 0, you will get a ‘true’. Thus perhaps you have the disable gui multiple times in your script and this is why you are getting a ‘false’
Regarding the ‘None’ return, this should not happen. If you are able to provide Danielle with the script and case where this occurs, we can investigate this further.

Suggested solution:
You can use the special context manager API instead of the other API’s
with mimics.disabled_gui_update():
# put your code here that should be executed without GUI update

Example of the counter:
print(mimics.is_update_gui_enabled())

mimics.disable_update_gui() # disable only once, counter becomes 1

print(mimics.is_update_gui_enabled()) # counter is 1, updates disabled

mimics.disable_update_gui() # disable once again, counter becomes 2

mimics.enable_update_gui() # enable only once, counter becomes 1

print(mimics.is_update_gui_enabled()) # counter is 1, not zero, so it is still disabled

mimics.enable_update_gui() # enable once again, counter becomes 0

print(mimics.is_update_gui_enabled()) # counter is 0, updates enabled

Hope this helps

Sorry for the late reply. I get None when I try to use the function from Pycharm. I ran some test code similar to what I ran above and it worked as long as I ran it within Mimics. I was aware of the counter but thought I had handled it correctly. I have a better way now using a while loop. I’m truly not sure why it’s working now from within Mimics, but I think I must have disabled the gui one more time than I enabled it.

Test Code: Note that this left the gui disabled. Not sure why.

import time
import mimics
mc = mimics.data.parts.find(PART_NAME)
print(mimics.is_update_gui_enabled())
mimics.disable_update_gui()
print(mimics.is_update_gui_enabled())
mc.color = (1,0,0)
time.sleep(2)
mc.color = (0,1,0)
mimics.enable_update_gui()
print(mimics.is_update_gui_enabled())

Test using context manager (What I’ll be using when possible)

import time
import mimics
mc = mimics.data.parts.find(PART_NAME)
with mimics.disabled_gui_update():
    print(mimics.is_update_gui_enabled())
    mc.color = (1,0,0)  # red, but you shouldn't see it turn
    time.sleep(2)
    mc.color = (0,1,0)  # green
time.sleep(2)  # see the green part for 2 seconds
mc.color = (0, 0, 1)  # see it change to blue

Loop until enabled (if some other poor soul stumbles into this problem like me)

while mimics.is_update_gui_enabled() is False:
    mimics.enable_update_gui()