def __init__(self, parent): threading.Thread.__init__(self) self.parent = parent self.network = Network() self.storage = Storage() self.controlFrame = Frame(parent) self.controlFrame.grid(row=0, column=0, columnspan=99, padx=10, pady=10, sticky=NW) self.recordingName = Textbox(self.controlFrame, 'Name of recording: ') self.recordingName.grid(row=0, column=0, sticky=NW, padx=10) self.buttonsFrame = Frame(self.controlFrame) self.buttonsFrame.grid(row=1, column=0, sticky=NW, pady=10) self.recordButton = Toggle(self.buttonsFrame, 'Record', lambda: self.record('on'), lambda: self.record('off')) self.TCPOverride = Toggle(self.buttonsFrame, 'Enable TCP', lambda: self.tcp('on'), lambda: self.tcp('off')) self.recordButton.grid(row=0, column=0, sticky=NW, padx=10) self.TCPOverride.grid(row=0, column=1, sticky=NW, padx=10) self.camerasFrame = Frame(parent) self.camerasFrame.grid(row=1, column=0, padx=10, pady=10, sticky=NW) self.gpMaster = GoProMaster(self.camerasFrame, self.network) self.TCPServer = tcp.TCP() self.localUDP = udp.UDP() self.shouldExit = False self.load()
class Mainloop(threading.Thread): def __init__(self, parent): threading.Thread.__init__(self) self.parent = parent self.network = Network() self.storage = Storage() self.controlFrame = Frame(parent) self.controlFrame.grid(row=0, column=0, columnspan=99, padx=10, pady=10, sticky=NW) self.recordingName = Textbox(self.controlFrame, 'Name of recording: ') self.recordingName.grid(row=0, column=0, sticky=NW, padx=10) self.buttonsFrame = Frame(self.controlFrame) self.buttonsFrame.grid(row=1, column=0, sticky=NW, pady=10) self.recordButton = Toggle(self.buttonsFrame, 'Record', lambda: self.record('on'), lambda: self.record('off')) self.TCPOverride = Toggle(self.buttonsFrame, 'Enable TCP', lambda: self.tcp('on'), lambda: self.tcp('off')) self.recordButton.grid(row=0, column=0, sticky=NW, padx=10) self.TCPOverride.grid(row=0, column=1, sticky=NW, padx=10) self.camerasFrame = Frame(parent) self.camerasFrame.grid(row=1, column=0, padx=10, pady=10, sticky=NW) self.gpMaster = GoProMaster(self.camerasFrame, self.network) self.TCPServer = tcp.TCP() self.localUDP = udp.UDP() self.shouldExit = False self.load() def run(self): self.localUDP.open('127.0.0.1', 6000, 7000, timeout=0) timer = 0 while not self.shouldExit: self.save() self.addMountedCameras() self.sendAliveMessage() if self.TCPServer.isActive(): self.processMessage(self.TCPServer.get()) if timer % 20 == 0: for ssid in self.network.getSSIDList(): if self.network.isGoPro(ssid): self.addCamera(ssid) time.sleep(0.1) timer += 1 def addCamera(self, ssid): if not self.gpMaster.exists(ssid): self.gpMaster.addSlave(ssid) def record(self, state): self.gpMaster.record(state, self.recordingName.getText()) def tcp(self, state): if state == 'on': self.recordButton.disable() self.TCPServer = tcp.TCP() self.TCPServer.listen(config.getTCPInfo()[0], int(config.getTCPInfo()[1]), timeout=0.01) elif state == 'off': self.recordButton.enable() self.TCPServer.close() def processMessage(self, message): if not message: return message = message.lower() if message == 'record on': self.TCPServer.put('Starts recording') self.record('on') self.recordButton.setState(True) elif message == 'record off': self.TCPServer.put('Stops recording') self.record('off') self.recordButton.setState(False) elif message[0:7] == 'recname': self.TCPServer.put('Recording name set to: ' + message[8:]) self.recordingName.setText(message[8:]) def exit(self): self.shouldExit = True self.localUDP.close() self.TCPServer.close() self.gpMaster.exit() def save(self): toSave = self.recordingName.getText() + ',' + str(self.recordButton.getState()) self.storage.save('main', toSave) def load(self): loaded = self.storage.load('main') if not loaded: return loaded = loaded.split(',') self.recordingName.setText(loaded[0]) if loaded[1] == 'True': self.recordButton.setState(True) def addMountedCameras(self): usbids = config.getUSBids() for usbid in usbids: if syscalls.isMounted(usbid): self.addCamera(config.getSSID(usbid)) def sendAliveMessage(self): try: self.localUDP.put('alive') except: pass