Example #1
0
    def __init__(self, port: int):

        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.socket.connect(("127.0.0.1", port))

        do_threaded(self.socket_listener)

        pass
Example #2
0
 def __init__(self, deck):
     self.image_path = "Assets/empty.png"
     self.is_visible = False
     self.current_space = 0
     self.is_pressed = False
     self.deck = deck
     self.initialize()
     do_threaded(self._update_loop)
     return
Example #3
0
    def __init__(self, deck, action_id):

        self.events_lock = Lock()

        event_names = [
            "initialize", "on_visible", "on_invisible", "on_pressed",
            "on_hold_down", "on_released", "on_update_sec", "on_update",
            "on_exit"
        ]

        f = open("Action/AHK/ahkglue.ahk", "r")
        gluetext = f.read()
        f.close()
        action_path = os.path.abspath(
            'Action/CustomActions/{}/AutoHotkeyAction.ahk'.format(action_id))
        gluetext = gluetext.replace("${ActionPath}", action_path)

        f = open(action_path, "r")
        action_text = f.read()
        unused_func = "\n"
        for e in event_names:
            if not "{}(){{".format(e) in action_text:
                unused_func += "{}(){{\nreturn\n}}\n".format(e)
        gluetext = gluetext.replace("${DefinitionOfUnusedFunctions}",
                                    unused_func)

        self.action_folder = os.path.abspath(
            'Action/CustomActions/{}/'.format(action_id))
        gluepath = self.action_folder + "/glue.ahk"
        f = open(gluepath, "w")
        f.write(gluetext)
        f.close()

        f = open(self.action_folder + "\\events.pipe", "w")
        f.write("")
        f.close()

        f = open(self.action_folder + "\\image.pipe", "w")
        f.write("")
        f.close()

        self.proc = subprocess.Popen(
            "Action/AHK/AutoHotkeyU64.exe {}".format(gluepath))
        do_threaded(self.image_listener)

        super().__init__(deck)
        return
Example #4
0
    def __init__(self, deck, action_id):

        f = open("Action/Python3/py3glue.py", "r")
        gluetext = f.read()
        f.close()

        self.action_folder = os.path.abspath(
            'Action/CustomActions/{}/'.format(action_id))
        gluepath = self.action_folder + "/glue.py"
        f = open(gluepath, "w")
        f.write(gluetext)
        f.close()

        self.proc = subprocess.Popen(
            "Action/Python3/venv/Scripts/python.exe {}".format(gluepath),
            stdout=subprocess.PIPE,
            stdin=subprocess.PIPE)

        do_threaded(self.image_listener)

        super().__init__(deck)
        return
Example #5
0
    def create_ui(self):
        self.ui_process = subprocess.Popen("npm start --prefix ..\\Electron",
                                           shell=True,
                                           close_fds=True,
                                           stdout=PIPE)

        def listen_out():
            while True:
                line = self.ui_process.stdout.readline()
                line = line.decode()
                line: str = line.rstrip()
                if len(line) > 0:
                    print(line)
                    for msg in list(filter(None, line.split(';'))):
                        spl = msg.split(":")
                        cmd = spl[0]

                        if cmd == "PORT":
                            args = spl[1].split(",")
                            print("Electron Started com server " + args[0])
                            UICommunicator(int(args[0]))
                            return

        self.out_listener = do_threaded(listen_out)
Example #6
0
 def listen_connections(self):
     self.connector_thread = do_threaded(self.connector_listener)
     return
Example #7
0
    def read(self):

        # self.client_socket.settimeout(5)

        def listener():
            while not self.disconnected:
                try:
                    data = self.client_socket.recv(1024)
                    stream = data.decode('utf-8')
                    if len(stream) > 1:
                        print("Received: {}".format(stream))
                    for msg in list(filter(None, stream.split(';'))):
                        spl = msg.split(":")
                        cmd = spl[0]
                        if cmd == "PING":
                            self.send("PONG;")

                        elif cmd == "PONG":
                            pass

                        elif cmd == "CLOSE":
                            self.disconnect()
                            return

                        elif cmd == "BTNEVENT":
                            args = spl[1].split(",")
                            self.on_key_status_change(args[0], args[1])

                        elif cmd == "CONN":
                            args = spl[1].split(",")
                            self.id = args[0]
                            if self.id in self.device_manager.Decks:
                                self.send("CONN:{};".format(get_uid()))
                                self.reset()
                                self.device_manager.on_connected(self)
                            else:
                                self.disconnect()

                        elif cmd == "SYNCREQ":
                            args = spl[1].split(",")
                            self.id = args[0]
                            self.send("SYNCTRY:{},{};".format(get_uid(), randint(100000, 999999)))

                        elif cmd == "SYNCACCEPT":
                            args = spl[1].split(",")
                            uid = args[0]
                            password = args[1]
                            self.device_manager.Decks[uid] = {"connected": True, "pass": password}
                            self.device_manager.save_deck_info()
                            self.send("CONN:{},{};".format(get_uid(), password))

                except Exception as e:
                    print(e)
                    self.disconnect()
                    return

        self.read_thread = do_threaded(listener)

        # def pinger():
        #     while not self.disconnected:
        #         try:
        #             self.send("PING;")
        #             time.sleep(3)
        #         except Exception as e:
        #             print(e)
        #             self.disconnect()
        #             return
        #
        # self.ping_thread = threading.Thread(target=pinger)
        # self.ping_thread.start()

        #self.deviceManager.on_connected(self)
        return