/
MotionDetector.py
executable file
·92 lines (73 loc) · 3.33 KB
/
MotionDetector.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#! /usr/bin/env python3
import nsmclient
import MotionDetectorWindow
#import MotionDetectorWebcam
import MotionDetectorKinnect
import config
import pickle
import os
conf = config.Config()
dataFile = False
prettyName = "MotionDetector"
INI_FILE = prettyName + ".obj"
window = MotionDetectorWindow.MotionDetectorWindow()
#webcam = MotionDetectorWebcam.MotionDetectorWebcam()
webcam = MotionDetectorKinnect.MotionDetectorKinnect()
capabilities = {
"switch" : False, #client is capable of responding to multiple `open` messages without restarting
"dirty" : False, #client knows when it has unsaved changes
"progress" : False, #client can send progress updates during time-consuming operations
"message" : True, #client can send textual status updates
"optional-gui" : True, #client has an optional GUI
}
#requiredFunctions
def myLoadFunction(path, name):
global conf, dataFile
dataFile = path + "/" + INI_FILE
if not os.path.exists(dataFile):
return True, "Found no file to be loaded."
return True, "Found no file to load."
filehandler = open(dataFile, 'rb')
conf = pickle.load(filehandler)
conf.prettyPrint()
window.setConfig(conf)
webcam.start(conf)
return True, dataFile + " loaded!"
def mySaveFunction(path):
global conf, dataFile
if dataFile == False:
return True, "Don't know where to save."
if not os.path.exists(dataFile):
os.makedirs(os.path.dirname(dataFile))
conf.prettyPrint()
filehandler = open(dataFile, 'wb')
pickle.dump(conf, filehandler)
return True, dataFile + " saved!"
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 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()