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()
def undo(self, mod: modules.Module): props = mod.get_exposed_props() if self.before and self.before.keys() == props.keys() \ and props() == self.after: mod.set_exposed_props(self.before) return mod else: print("tried to undo, but the target props are", self.before, "while the current are", props) return None
def do(self, mod: modules.Module, pos: base.Vec2d) -> modules.Module: self.pos = pos self.before = mod_props = mod.get_exposed_props() for name, change in self.changes.items(): if name in mod_props and self.type_test(change): mod_props[name] = change else: return mod self.after = mod_props mod.set_exposed_props(mod_props) return mod
def open_modules(): """ Function that will load all modules """ dirs = os.listdir(path + "modules/") modules = {} for dir in dirs: modules[dir] = Module(dir, path) return modules
def test_gif(gif_path): anim = Module.gif_anim(gif_path) matrix = EzMatrix() while True: matrix.run_anim(anim)
def test_img(image_path): cvs = Module.image_canvas_from_path(image_path) matrix = EzMatrix() while True: matrix.draw_canvas(cvs)
def run(self): temp_cvs = Module.temperature_canvas(self.unit, self.zip_code, self.temp_color) tme = int(time.time()) while not self.should_stop: if int(time.time()) - tme == self.ref_rate: temp_cvs = Module.temperature_canvas(self.unit, self.zip_code, self.temp_color) tme = int(time.time()) time_cvs = Canvas(25, 19).add_subcanvas( Module.time_canvas(self.region, self.day_color, self.date_color, self.hour_color, self.hour_color, self.minute_color), Point(0, 6)) time_cvs.add_subcanvas(temp_cvs, Point(9, 0)) matrix.draw_canvas(Canvas().add_subcanvas(time_cvs, Point(3, 6)))
def draw_dashboard(ref_rate=3): # includes clock and temperature """ ref_rate is the interval (in minutes) between weather API calls """ temp_cvs = Module.temperature_canvas('f', '94103', Color.green()) ref_rate = ref_rate * 60 tme = int(time.time()) matrix = EzMatrix() while True: if int(time.time()) - tme == ref_rate: temp_cvs = Module.temperature_canvas('f', '94103', Color.green()) tme = int(time.time()) time_cvs = Canvas(25, 19).add_subcanvas(Module.time_canvas('US/Pacific'), Point(0, 6)) time_cvs.add_subcanvas(temp_cvs, Point(9, 0)) matrix.draw_canvas(Canvas().add_subcanvas(time_cvs, Point(3, 6)))
def lipo(self, platform, *frameworks): merged = super(FrameworkModule, self).lipo(platform, *frameworks) framework_module = FrameworkModule(Module( merged.name, merged.library_path, glob('{}/Headers/*.h'.format(merged.framework_path)), self.module.umbrella_header, self.module.submodules )) framework_module.framework_path = 'Frameworks/{}/{}.framework'.format( platform.name, self.name) framework_module.is_created = True framework_module.abs_path = os.path.abspath(merged.framework_path) return framework_module
def dice(d, file): """Output a Tracery module simulating a given dice roll using NdS notation.""" n, s = d.split('d') n = int(n) s = int(s) possibility_space = itertools.product([i+1 for i in range(s)], repeat=n) possibility_space = [sum(x) for x in possibility_space] virtual_name = 'dice({0})'.format(d) return Module( name=virtual_name, file_path='!dice({0})'.format(d), productions={ virtual_name: ['{0}'.format(x) for x in possibility_space] }, external=True, variables=set(), links=set() )
def __init__(self, *args, **kwargs): """Constructor""" Module.__init__(self, kwargs=kwargs)
def __init__(self, parser): Module.__init__(self, parser, self.name) self.hook_on = clang.cindex.CursorKind.CALL_EXPR
if manufacturer is None: return [ i['inverter'] for i in json.loads(open(SPATH + '/si.json').read()) ] else: a = [] for i in json.loads(open(SPATH + '/si.json').read()): if i['inverter'].find(manufacturer) != -1: a.append(i['inverter']) return a if __name__ == "__main__": from modules import Module, Array PANEL = Module('Mage Solar : Powertec Plus 245-6 PL *') INVERTER = Inverter("Enphase Energy: M215-60-SIE-S2x 240V", Array(PANEL, [{ 'series': 1 }])) print INVERTER.array print "" print INVERTER.dump() # si = sb6000us(s) print INVERTER.p_ac(950) print INVERTER.i_ac(960, 240) INVERTER = Inverter("SMA America: SB7000US-11 277V", Array(PANEL, [{ 'series': 11,
def postag(sentence): return Module.extract_agents(sentence)
def clock(): # does not include temperature matrix = EzMatrix() while True: matrix.draw_canvas(Canvas().add_subcanvas( Module.time_canvas('US/Pacific'), Point(3, 9)))
def p_newMod(p): 'modName : MODULE NAME' nonlocal curentMod curentMod = Module(p[2])