Moved the 'gevent' and 'pygame' imports and the 'PixelVloedServer' class to inside the 'if __name__ == '__main__'' section. This will make it possible for users to use the client code, without needing to install gevent and pygame.
This commit is contained in:
parent
44b38071fc
commit
c38cab64b6
1 changed files with 26 additions and 25 deletions
51
vloed.py
51
vloed.py
|
|
@ -8,20 +8,10 @@ code from https://github.com/defnull/pixelflut/
|
|||
__version__ = 0.3
|
||||
__author__ = "Jan Klopper <jan@underdark.nl>"
|
||||
|
||||
# import gevent monkeypatching and perform patch_all before anything else to
|
||||
# avoid nasty eception on python closing time
|
||||
from gevent import spawn, monkey
|
||||
monkey.patch_all()
|
||||
|
||||
import pygame
|
||||
from pygame import locals as pygamelocals
|
||||
import struct
|
||||
import time
|
||||
import socket
|
||||
|
||||
from gevent.server import DatagramServer
|
||||
from gevent.queue import Queue
|
||||
|
||||
UDP_IP = "127.0.0.1"
|
||||
UDP_PORT = 5005
|
||||
DISCOVER_PORT = 5006
|
||||
|
|
@ -173,21 +163,6 @@ class Canvas(object):
|
|||
"""Clean up any sockets we created"""
|
||||
self.broadcastsocket.close()
|
||||
|
||||
class PixelVloedServer(DatagramServer):
|
||||
"""PixelVloed server class"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Set up some vars for this instance"""
|
||||
self.queue = Queue()
|
||||
pixelcanvas = Canvas(self.queue, kwargs['options'])
|
||||
__request_processing_greenlet = spawn(pixelcanvas.CanvasUpdate)
|
||||
del (kwargs['options'])
|
||||
DatagramServer.__init__(self, *args, **kwargs)
|
||||
|
||||
def handle(self, data, _address):
|
||||
"""Is called by the DataGramServer whenever an udp package is received"""
|
||||
self.queue.put(data)
|
||||
|
||||
class PixelVloedClient(object):
|
||||
"""Sets up a client
|
||||
|
||||
|
|
@ -326,6 +301,32 @@ def RunServer(options):
|
|||
options=options).serve_forever()
|
||||
|
||||
if __name__ == '__main__':
|
||||
# import gevent monkeypatching and perform patch_all before anything else to
|
||||
# avoid nasty eception on python closing time
|
||||
from gevent import spawn, monkey
|
||||
monkey.patch_all()
|
||||
|
||||
import pygame
|
||||
from pygame import locals as pygamelocals
|
||||
|
||||
from gevent.server import DatagramServer
|
||||
from gevent.queue import Queue
|
||||
|
||||
class PixelVloedServer(DatagramServer):
|
||||
"""PixelVloed server class"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Set up some vars for this instance"""
|
||||
self.queue = Queue()
|
||||
pixelcanvas = Canvas(self.queue, kwargs['options'])
|
||||
__request_processing_greenlet = spawn(pixelcanvas.CanvasUpdate)
|
||||
del (kwargs['options'])
|
||||
DatagramServer.__init__(self, *args, **kwargs)
|
||||
|
||||
def handle(self, data, _address):
|
||||
"""Is called by the DataGramServer whenever an udp package is received"""
|
||||
self.queue.put(data)
|
||||
|
||||
import optparse
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option('-v', action="store_true", dest="debug", default=False)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue