From d2a251430ca9503ed3395317bbe7080989a204c2 Mon Sep 17 00:00:00 2001 From: CodePanter Date: Sat, 26 Nov 2016 14:18:16 +0100 Subject: [PATCH 1/5] Removed an unnecessary print statement. --- vloed.py | 1 - 1 file changed, 1 deletion(-) diff --git a/vloed.py b/vloed.py index e3d889d..abfc689 100755 --- a/vloed.py +++ b/vloed.py @@ -58,7 +58,6 @@ class Canvas(object): """Init the pygame canvas""" pygame.init() screeninfo = pygame.display.Info() - print options.width self.width = options.width if options.width else screeninfo.current_w self.height = options.height if options.height else screeninfo.current_h pygame.mixer.quit() From 62bfc507675aad849a45b3f78192c8e2fa02727f Mon Sep 17 00:00:00 2001 From: CodePanter Date: Sat, 26 Nov 2016 15:40:14 +0100 Subject: [PATCH 2/5] Fixed the command line specified udp_ip and udp_port not being used for broadcasting in the SDL version. --- sdlvloed.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sdlvloed.py b/sdlvloed.py index b5bbf31..84bd0d9 100755 --- a/sdlvloed.py +++ b/sdlvloed.py @@ -42,8 +42,8 @@ class Canvas(object): self.pixeloffset = 2 self.fps = 30 self.screen = None - self.udp_ip = UDP_IP - self.udp_port = UDP_PORT + self.udp_ip = options.ip if options.ip else UDP_IP + self.udp_port = options.port if options.port else UDP_PORT self.factor = options.factor if options.factor else 1 self.width = options.width if options.width else DEFAULT_WIDTH self.height = options.height if options.height else DEFAULT_HEIGHT @@ -67,11 +67,11 @@ class Canvas(object): def canvas(self): """Init the pygame canvas""" sdl2.ext.init() - self.screen = sdl2.ext.Window(self.set_title(), + self.screen = sdl2.ext.Window(self.set_title(), size=(self.width, self.height)) self.screen.show() self.surface = self.screen.get_surface() - + def Pixel(self, x, y, r, g, b, a=255): # pylint: disable=C0103 """Print a pixel to the screen""" try: @@ -108,7 +108,7 @@ class Canvas(object): # break if time.time() - lastbroadcast > 2: lastbroadcast = time.time() - self.SendDiscoveryPacket() + self.SendDiscoveryPacket() if time.time() - lasttime >= 1.0 / self.fps and changed: self.pixels = None # release the lock on these pixels so we can flip @@ -117,7 +117,7 @@ class Canvas(object): lasttime = time.time() else: time.sleep(1.0 / self.fps) - + def Draw(self): """Draws pixels specified in the received packages in the queue""" if self.queue.empty(): @@ -163,7 +163,7 @@ class Canvas(object): self.broadcastsocket.sendto( '%s:%f %s:%d %d*%d' % ( PROTOCOL_PREAMBLE, PROTOCOL_VERSION, - UDP_IP, UDP_PORT, + self.udp_ip, self.udp_port, self.width/self.factor, self.height/self.factor), ('', DISCOVER_PORT)) if self.debug: From 6e27713ace13503ef63c0afb4eb17f53499e9e85 Mon Sep 17 00:00:00 2001 From: CodePanter Date: Sat, 26 Nov 2016 15:41:41 +0100 Subject: [PATCH 3/5] Added extra usability in the SendPacket function of the SDL version. --- sdlvloed.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdlvloed.py b/sdlvloed.py index 84bd0d9..47e7e06 100755 --- a/sdlvloed.py +++ b/sdlvloed.py @@ -237,16 +237,16 @@ class PixelVloedClient(object): """Sleeps the designated amount of time""" time.sleep(duration if duration else self.sleep) - def SendPacket(self, message, sleep=True): + def SendPacket(self, message, sleep=0.01): """Sends the message to the udp server Arguments: message: (str, 140) - sleep: (bool) True, should the client sleep for a while? + sleep: (float) 0.01, duration of time the client should sleep """ self.sock.sendto(message, (self.ipaddress, self.port)) if sleep: - self.Sleep() + self.Sleep(duration=0.01) @staticmethod def DiscoverServers(returnfirst=False, timeout=5): From 9678939aa0c15fb0f1d546977d34180a9e2c3ce3 Mon Sep 17 00:00:00 2001 From: CodePanter Date: Sat, 26 Nov 2016 15:50:36 +0100 Subject: [PATCH 4/5] Updated the sdl version so it is just as usable as the pygame version. --- sdlvloed.py | 44 +++++++++++++++++++++++--------------------- vloed.py | 2 +- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/sdlvloed.py b/sdlvloed.py index 47e7e06..a811415 100755 --- a/sdlvloed.py +++ b/sdlvloed.py @@ -12,17 +12,14 @@ __author__ = "Jan Klopper " # 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() +if __name__ == '__main__': + from gevent import spawn, monkey + monkey.patch_all() -import sdl2.ext 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 @@ -176,21 +173,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 +308,26 @@ def RunServer(options): options=options).serve_forever() if __name__ == '__main__': + import sdl2.ext + + 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) diff --git a/vloed.py b/vloed.py index abfc689..fbea3ce 100755 --- a/vloed.py +++ b/vloed.py @@ -9,7 +9,7 @@ __version__ = 0.3 __author__ = "Jan Klopper " if __name__ == '__main__': - # avoid nasty eception on python closing time + # avoid nasty exception on python closing time from gevent import spawn, monkey monkey.patch_all() From 1e9694d4a1e10ef1f826d05f54ec29e3b19de95e Mon Sep 17 00:00:00 2001 From: CodePanter Date: Sun, 27 Nov 2016 11:34:37 +0100 Subject: [PATCH 5/5] Implemented display resolution autodetection for the sdl server version. --- sdlvloed.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/sdlvloed.py b/sdlvloed.py index a811415..555c3fd 100755 --- a/sdlvloed.py +++ b/sdlvloed.py @@ -16,6 +16,11 @@ if __name__ == '__main__': from gevent import spawn, monkey monkey.patch_all() +try: + import gtk +except ImportError: + gtk = None + import struct import time import socket @@ -27,8 +32,8 @@ PROTOCOL_VERSION = 1 MAX_PROTOCOL_VERSION = 1 PROTOCOL_PREAMBLE = "pixelvloed" MAX_PIXELS = 140 -DEFAULT_WIDTH = 786 -DEFAULT_HEIGHT = 1366 +DEFAULT_WIDTH = 1366 +DEFAULT_HEIGHT = 786 class Canvas(object): """PixelVloed display class""" @@ -42,8 +47,6 @@ class Canvas(object): self.udp_ip = options.ip if options.ip else UDP_IP self.udp_port = options.port if options.port else UDP_PORT self.factor = options.factor if options.factor else 1 - self.width = options.width if options.width else DEFAULT_WIDTH - self.height = options.height if options.height else DEFAULT_HEIGHT self.canvas() self.queue = queue @@ -64,6 +67,13 @@ class Canvas(object): def canvas(self): """Init the pygame canvas""" sdl2.ext.init() + if gtk: + window = gtk.Window() + screen = window.get_screen() + self.width = gtk.gdk.screen_width() if gtk else DEFAULT_WIDTH + self.height = gtk.gdk.screen_height() if gtk else DEFAULT_HEIGHT + self.width = options.width if options.width else self.width + self.height = options.height if options.height else self.height self.screen = sdl2.ext.Window(self.set_title(), size=(self.width, self.height)) self.screen.show() @@ -334,10 +344,8 @@ if __name__ == '__main__': parser.add_option('-i', action="store", dest="ip", default=UDP_IP) parser.add_option('-p', action="store", dest="port", default=UDP_PORT, type="int") - parser.add_option('-x', action="store", dest="width", default=DEFAULT_WIDTH, - type="int") - parser.add_option('-y', action="store", dest="height", default=DEFAULT_HEIGHT, - type="int") + parser.add_option('-x', action="store", dest="width", type="int") + parser.add_option('-y', action="store", dest="height", type="int") parser.add_option('-m', action="store", dest="maxpixels", default=MAX_PIXELS, type="int") parser.add_option('-f', action="store", dest="factor", default=1,