def test_gif(gif_path): anim = Module.gif_anim(gif_path) matrix = EzMatrix() while True: matrix.run_anim(anim)
def interpritMessage(self, client, userdata, message): """Interprets MQTT message and handles creating/joining of threads""" try: msg = json.loads(message.payload)['message'] except ValueError: print('MISSING DELIMITER IN JSON') return if 'args' in message.payload: try: args = json.loads(message.payload)['args'] except ValueError: print('MISSING DELIMITER IN JSON') else: args = '' print('Message received: \"{}\" from topic {}'.format( msg, message.topic)) if self.thread.isAlive(): print('JOINING THREAD') self.thread.should_stop = True self.thread.join() if 'clock' in msg: clock_attrs = ClockAttributes(args) self.thread = ClockThread( 3, clock_attrs.unit, clock_attrs.zip_code, clock_attrs.region, clock_attrs.temp_color, clock_attrs.day_color, clock_attrs.date_color, clock_attrs.hour_color, clock_attrs.minute_color) self.thread.should_stop = False self.thread.start() if 'image' in msg: cvs = Module.image_canvas_from_url(args) if cvs.has_data(): self.send_message(True, 'successfully downloaded image') else: self.send_message(False, 'failed to download image') self.thread = CanvasThread(cvs) self.thread.start() if 'gif' in msg: args = './gifs/' + args + '.gif' anim = Module.gif_anim(args) if len(anim) > 1: self.send_message(True, 'successfully compiled gif') else: self.send_message(False, 'failed to compile gif') self.thread = AnimationThread(anim) self.thread.should_stop = False self.thread.start()