diff --git a/direct/src/http/webNotifyDebug.py b/direct/src/http/webNotifyDebug.py
new file mode 100755
index 0000000000..c5c9bc2b6c
--- /dev/null
+++ b/direct/src/http/webNotifyDebug.py
@@ -0,0 +1,148 @@
+from direct.task import Task
+from direct.http import WebRequest
+from direct.directnotify import DirectNotifyGlobal
+
+class webNotifyDebug:
+ def __init__(self, portNumber = 8888):
+
+ self.portNumber = portNumber
+ self.web = WebRequest.WebRequestDispatcher()
+ self.web.listenOnPort(int(self.portNumber))
+ # 'debug' will be the name of the page we have to hit
+ self.web.registerGETHandler('debug', self.debug)
+ self.startCheckingIncomingHTTP()
+
+ def listAllCategories(self, replyTo, optionalMessage = None):
+ # Return a web page with a list of all registered notify categories
+ # along with an HTML widget to chage their debug state
+
+ completeList = DirectNotifyGlobal.directNotify.getCategories()
+
+ # Define the static head of the response
+
+ if not optionalMessage:
+ head = '\n
\n\nDirectNotify - List All Categories\n\n\nDirectNotify - Listing All Categories
\n\n\nCategory | Debug Status |
\n'
+ else:
+ head = '\n\n\nDirectNotify - List All Categories\n\n\nDirectNotify - Listing All Categories
\n
%s
\n\nCategory | Debug Status |
\n' % (optionalMessage)
+
+ # define the static foot
+
+ foot = '
Main Menu'
+
+ # Sort our catagory list into alpha order
+
+ completeList.sort()
+
+ # Now generate the body of the page response
+
+ body = ''
+ for item in completeList:
+ select = '%s | ' % (item)
+ tempCategory = DirectNotifyGlobal.directNotify.getCategory(item)
+ debugStatus = tempCategory.getDebug()
+ if debugStatus == 0:
+ body = '%s%sOff |
' % (body, select, item)
+ else:
+ body = '%s%sOn' % (body, select, item)
+
+ replyTo.respond('%s\n%s\n%s\n' % (head, body, foot))
+
+ def turnCatOn(self, item, replyTo, sString = None):
+ # Used to turn a catagory (item), to the on state
+ try:
+ notifyItem = DirectNotifyGlobal.directNotify.getCategory(item)
+ notifyItem.setDebug(1)
+ updateMessage = 'Category %s, has been turned on' % (item)
+ if not sString:
+ self.listAllCategories(replyTo, updateMessage)
+ else:
+ self.searchForCat(sString, replyTo, updateMessage)
+ except AttributeError:
+ replyTo.respond('Invalid Category Passed')
+
+ def turnCatOff(self, item, replyTo, sString = None):
+ # Used to turn a catagory (item), to the off state
+ try:
+ notifyItem = DirectNotifyGlobal.directNotify.getCategory(item)
+ notifyItem.setDebug(0)
+ updateMessage = 'Category %s, has been turned off' % (item)
+ if not sString:
+ self.listAllCategories(replyTo, updateMessage)
+ else:
+ self.searchForCat(sString, replyTo, updateMessage)
+ except AttributeError:
+ replyTo.respond('Invalid Category Passed')
+
+ def searchForCat(self, searchString, replyTo, toggle = None):
+ # Used to execute a substring search for a category
+ completeList = DirectNotifyGlobal.directNotify.getCategories()
+ resultList = []
+ while completeList:
+ item = completeList.pop()
+ if item.find(searchString) != -1:
+ resultList.append(item)
+ # Now that we have the results, present them
+ # First, sort the list
+ resultList.sort()
+ if not toggle:
+ head = '\n\n\nDirectNotify - Search Results\n\n\nDirectNotify - Listing All Categories
\n\n\nCategory | Debug Status |
\n'
+ else:
+ head = '\n\n\nDirectNotify - Search Results\n\n\nDirectNotify - Listing All Categories
\n
%s
\n\nCategory | Debug Status |
\n' % (toggle)
+ foot = '
Main Menu'
+ body = ''
+ for item in resultList:
+ select = '%s | ' % (item)
+ tempCategory = DirectNotifyGlobal.directNotify.getCategory(item)
+ debugStatus = tempCategory.getDebug()
+ if debugStatus == 0:
+ body = '%s%sOff |
' % (body, select, item, searchString)
+ else:
+ body = '%s%sOn' % (body, select, item, searchString)
+
+ replyTo.respond('%s\n%s\n%s\n' % (head, body, foot))
+
+
+
+
+ def debug(self, replyTo, **kw):
+ try:
+ command = kw['command']
+ if command == 'listAll':
+ self.listAllCategories(replyTo)
+ elif command == 'on':
+ item = kw['item']
+ try:
+ sString = kw['sString']
+ self.turnCatOn(item, replyTo, sString)
+ except KeyError:
+ self.turnCatOn(item, replyTo)
+ elif command == 'off':
+ item = kw['item']
+ try:
+ sString = kw['sString']
+ self.turnCatOff(item, replyTo, sString)
+ except KeyError:
+ self.turnCatOff(item, replyTo)
+ elif command == 'search':
+ searchString = kw['searchString']
+ self.searchForCat(searchString, replyTo)
+ else:
+ replyTo.respond('Error: Invalid args')
+ return
+ except KeyError:
+ pass
+ # Basic Index Page
+
+ replyTo.respond('\n\nDirectNotify Web Interface\n\n\n\n
DirectNotify Web Interface
\n\n
\n\n
\nDisplay all DirectNotify Categories\n\n')
+
+
+ def startCheckingIncomingHTTP(self):
+ taskMgr.remove('pollDirectDebugHTTPTask')
+ taskMgr.doMethodLater(0.3,self.pollDirectDebugHTTPTask,'pollDirectDebugHTTPTask')
+
+ def stopCheckingIncomingHTTP(self):
+ taskMgr.remove('pollDirectDebugHTTPTask')
+
+ def pollDirectDebugHTTPTask(self,task):
+ self.web.poll()
+ return Task.again