Communicating with the UI
As mentioned previously, once pyblish-qml is up and running, it will also be set-up to listen on port
9090 so all we need to do in order to speak with it is connect.
import xmlrpclib proxy = xmlrpclib.ServerProxy("http://127.0.0.1:9090") proxy.show(9001) # Port number of the a host
9001 is your "business card". It let's pyblish-qml know that the client looking to communicate with it can be communicated with in return via this port. In this way, communicating is bi-directional.
Under normal circumstances, this port number is established during host initialisation.
import pyblish_maya pyblish_maya.setup() # A port number is assigned
The port number is then stored "behind the scenes" in an environment variable called
PYBLISH_CLIENT_PORT and it is this number which is automatically passed upon the user pressing the Publish menu-item.
import os assert os.environ["PYBLISH_CLIENT_PORT"] == "9001"
Note that you may see a different number, such as 9002, depending on how many hosts you currently have open. Each host has a unique number, starting from 9001.
You can also use the convenience function from within a host provided by the pyblish-qml module.
from pyblish_qml import client proxy = client.proxy() proxy.show(9001)
The convenience function is much the same, but also includes a reasonable time-out for when the host is unresponsive.
Here are some of the functionality exposed via the proxy.
||Connect with pyblish-qml, takes port and window-settings.|
||Hide the currently open pyblish-qml window, without quitting.|
||Quit the process, including clean-up.|
||Forcefully quit the process.|
||Tell pyblish-qml that you are alive, takes a port number.|
||Query pyblish-qml for the next available, unique port number.|
Without the UI running, you will get the familiar error message.
No connection could be made because the target machine actively refused it