August'24: Kamaelia is in maintenance mode and will recieve periodic updates, about twice a year, primarily targeted around Python 3 and ecosystem compatibility. PRs are always welcome. Latest Release: 1.14.32 (2024/3/24)
Cookbook Example
How can I...?
Example 6: How to build a network controllable graph viewer. Components used:TopologyViewerServer
#!/usr/bin/python
from Kamaelia.Visualisation.PhysicsGraph.TopologyViewerServer import TopologyViewerServer
def parseArgs(argv, extraShortArgs="", extraLongArgs=[]):
import getopt
= "fh" + extraShortArgs
shortargs = list("help","fullscreen","resolution=","port=") + extraLongArgs
longargs
= getopt.getopt(argv, shortargs, longargs)
optlist, remargs
= {}
dictArgs for o,a in optlist:
if o in ("-h","--help"):
'help'] = "Arguments:\n" + \
dictArgs[" -h, --help\n" + \
" This help message\n\n" + \
" -f, --fullscreen\n" + \
" Full screen mode\n\n" + \
" --resolution=WxH\n" + \
" Set window size to W by H pixels\n\n" + \
" --port=N\n" + \
" Listen on port N (default is 1500)\n\n"
elif o in ("-f","--fullscreen"):
'fullscreen'] = True
dictArgs[
elif o in ("--resolution"):
= re.match(r"^(\d+)[x,-](\d+)$", a)
match =int(match.group(1))
x=int(match.group(2))
y'screensize'] = (x,y)
dictArgs[
elif o in ("--port"):
'serverPort'] = int(a)
dictArgs[
return dictArgs, optlist, remargs
if __name__=="__main__":
import sys
= parseArgs(sys.argv[1:])
dictArgs, remargs, junk
if "help" in dictArgs:
print dictArgs["help"]
else:
**dictArgs).run() TopologyViewerServer(
Source: Examples/example6/TopologyVisualiser.py