示例#1
0
clients which may have some interdependence (say, peer to peer OSC 
connections) that the session is fully loaded and all their peers 
are available.
Do not use it to auto-connect jack connections. No auto-conncect from
within a session! Jack connections are stored in a seperate NSM client
which belongs to the session.
"""

optionalFunctions = {
		"function_quit" : None,  #Accept zero parameters. Return True or False
		"function_showGui" : None, #Accept zero parameters. Return True or False
		"function_hideGui" : None, #Accept zero parameters. Return True or False
		"function_sessionIsLoaded" : None, #No return value needed.
		} 

ourNsmClient, process = nsmclient.init(prettyName = YourApplicationName, capabilities = capabilities, requiredFunctions = requiredFunctions, optionalFunctions = optionalFunctions,  sleepValueMs = 0) 

#Direct send only functions for your program.
#ourNsmClient.updateProgress(value from 0.1 to 1.0) #give percentage during load, save and other heavy operations
#ourNsmClient.setDirty(True or False) #Inform NSM of the save status. Are there unsaved changes?
#ourNsmClient.sendError(errorCode or String, message string) #for a list of error codes: http://non.tuxfamily.org/nsm/API.html#n:1.2.5.

"""Instead of this while loop, call this function from your own event 
loop. Whatever that might be. A Gui event loop, a python module, or 
indeed a while loop. Don't worry about performance in THIS while 
loop, don't input a sleep value. choose a ms value in the init() 
function.

If you are running this in a Qt timer or similar, good, 
unblocking manner just let sleepValueMs at 0 ms because cpu load management is 
done by another part of the program. sleepValueMs over 0 are just 
示例#2
0
def myShowGui():
    window.show()
    return True
    
def myHideGui():
    window.hide()
    return True

def myQuit():
    window.destroy()
    webcam.die()
    return True

#Optional functions
optionalFunctions = {
        "function_quit" : myQuit,  #Accept zero parameters. Return True or False
        "function_showGui" : myShowGui, #Accept zero parameters. Return True or False
        "function_hideGui" : myHideGui, #Accept zero parameters. Return True or False
        "function_sessionIsLoaded" : None, #No return value needed.
        } 

ourNsmClient, process = nsmclient.init(prettyName = prettyName, capabilities = capabilities, requiredFunctions = requiredFunctions, optionalFunctions = optionalFunctions,  sleepValueMs = 100) 

#Direct send only functions for your program.
#ourNsmClient.updateProgress(value from 0.1 to 1.0) #give percentage during load, save and other heavy operations
#ourNsmClient.setDirty(True or False) #Inform NSM of the save status. Are there unsaved changes?
#ourNsmClient.sendError(errorCode or String, message string) #for a list of error codes: http://non.tuxfamily.org/nsm/API.html#n:1.2.5.

while True:
    process()
requiredFunctions = {
	"function_open" : myLoadFunction, #Accept two parameters. Return two values. A bool and a status string. Otherwise you'll get a message that does not help at all: "Exception TypeError: "'NoneType' object is not iterable" in 'liblo._callback' ignored"
	"function_save" : mySaveFunction, #Accept one parameter. Return two values. A bool and a status string. Otherwise you'll get a message that does not help at all: "Exception TypeError: "'NoneType' object is not iterable" in 'liblo._callback' ignored"					
	}

def quitty():
	ourNsmClient.sendStatusMessage("Preparing to quit. Wait for progress to finish")
	#Fake quit process
	ourNsmClient.updateProgress(0.1)
	sleep(0.5)
	ourNsmClient.updateProgress(0.5)
	sleep(0.5)
	ourNsmClient.updateProgress(0.9)
	ourNsmClient.updateProgress(1.0)
	return True

optionalFunctions = {
		"function_quit" : quitty,  #Accept zero parameters. Return True or False
		"function_showGui" : None, #Accept zero parameters. Return True or False
		"function_hideGui" : None, #Accept zero parameters. Return True or False
		"function_sessionIsLoaded" : None, #No return value needed.
		} 

ourNsmClient, process = nsmclient.init(prettyName = "PyNsmTestClient", capabilities = capabilities, requiredFunctions = requiredFunctions, optionalFunctions = optionalFunctions,  sleepValueMs = 100) 
#Direct send only functions for your program.
#ourNsmClient.updateProgress(value from 0.1 to 1.0) #give percentage during load, save and other heavy operations
#ourNsmClient.setDirty(True or False) #Inform NSM of the save status. Are there unsaved changes?

while True:
	process()