Add cli options to the client class, clean up the SDL version a bit

This commit is contained in:
Jan Klopper 2016-07-12 18:37:32 +02:00
parent 4e22d0187e
commit d2f58a6640
3 changed files with 24 additions and 10 deletions

View file

@ -26,15 +26,15 @@ def RandomFill(message, width, height):
message[2:] = [pixel]
yield ''.join(message)
def RunClient():
def RunClient(options):
"""Discover the servers and start sending to the first one"""
client = PixelVloedClient(True, # start as soon as we find a server
False, # show debugging output
None, # ip of the server, None for autodetect
None, # port of the server None for autodetect
None, # Screen pixels wide, None for autodetect
None # Screen pixels height, None for autodetect
options.debug, # show debugging output
options.ip, # ip of the server, None for autodetect
options.port, # port of the server None for autodetect
options.width, # Screen pixels wide, None for autodetect
options.height # Screen pixels height, None for autodetect
)
message = NewMessage() #create a new message that buffers the output etc
@ -49,7 +49,19 @@ def RunClient():
if __name__ == '__main__':
# if this script is called from the command line, and thus not imported
# start a client and start sending messages
import optparse
parser = optparse.OptionParser()
parser.add_option('-v', action="store_true", dest="debug", default=False)
parser.add_option('-i', action="store", dest="ip", default=None)
parser.add_option('-p', action="store", dest="port", default=None,
type="int")
parser.add_option('-x', action="store", dest="width", default=None,
type="int")
parser.add_option('-y', action="store", dest="height", default=None,
type="int")
options, remainder = parser.parse_args()
try:
RunClient()
RunClient(options)
except KeyboardInterrupt:
print 'Closing client'

View file

@ -16,7 +16,6 @@ from gevent import spawn, monkey
monkey.patch_all()
import sdl2.ext
from pygame import locals as pygamelocals
import struct
import time
import socket

View file

@ -225,8 +225,11 @@ class PixelVloedClient(object):
self.width = width
self.height = height
if self.debug:
print ('displaying on %(ip)s:%(port)d, %(width)d*%(height)dpx' %
self)
print ('displaying on %(ipaddress)s:%(port)d, %(width)d*%(height)dpx' %
{'ipaddress': self.ipaddress,
'port': self.port,
'width': self.width,
'height': self.height})
self.sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP