def send_message(self,_): message = self.new_message.text self.new_message.text = "" if message: self.history.update_chat_history(f"[color=dd2020]{chat_app.connect_page.username.text}[/color] > {message}") socket_client.send(message) Clock.schedule_once(self.focus_text_input,0.1)
def next_action(self): if self.slots['to_city'] is None: print(1) self.get_to_city() elif self.slots['from_city'] is None: self.get_from_city() elif self.slots['date'] is None or self.slots['month'] is None: self.get_date() else: train_info = Railway().train_between_station( self.slots['from_city'], self.slots['to_city'], str(self.slots['date']) + '-' + str(self.slots['month']) + '-' + str(self.slots['year'])) self.slots['to_city'] = None self.slots['from_city'] = None self.slots['date'] = None self.slots['month'] = None self.slots['year'] = None self.slots = {} print("!!!!!!!!!!!!!!!!!!!!!!!!!!!", self.slots) socket_client.send(train_info) self.message = '' # socket_client.send("Which train do you want to choose?") # self.choose_train = True self.count = 0
def send_message(self, _): message = self.new_message.text self.new_message.text = "" if message: self.history.update_chat_history( f"[color=dd2020]{chat_app.connect_patge.username.text}[/color] > {message}" ) socket_client.send(message)
def send_message(self): msg_field = self.ids.msg_field message = msg_field.text if message: self.update_chat_history(f"""[color=dd2020]{connectWin.get_screen( 'Connect').ids.user_field.text}[/color] > {message}""") socket_client.send(message) Clock.schedule_once(self.set_focus, 0.1)
def send_button_processing(): encryption_message = RSA.Encryption(messageEntry.get(1.0, END), int(publicKeyEntry.get()), int(n_Value_of_public_entry.get()), int(privateKeyEntry.get()), int(n_Value_of_private_entry.get())) print(encryption_message) socket_client.send(encryption_message) statusLabel['text'] = "Message sent successfully"
def send_message(self, _): message = self.new_message.text self.new_message.text = '' if message: self.history.update_chat_history( f'[color=dd2020]{chat_app.connect_page.username.text}[/color] > {message}' ) socket_client.send(message) # As mentioned above, we have to shedule for refocusing to input field Clock.schedule_once(self.focus_text_input, 0.1)
def send_message(self, _): message = self.new_message.text self.new_message.text = '' if message: username = chat_app.connect_page.username.text user = username.replace(username[0], username[0].upper(), 1) self.history.update_chat_history_send( f'[color=dd2020][b][size=18]{user}[/size][/b][/color] >> [color=09020f][font_family=Arial]{message}[/font_family][/color]' ) socket_client.send(message) Clock.schedule_once(self.focus_text_input, 0.1)
def send_message(self, _): message = self.new_message.text self.new_message.text = '' if message: self.history.update_chat_history(f"[color=dd2020]{playpause_app.connect_page.name.text}[/color] > {message}") socket_client.send(message) if message == 'play' or message == 'pause': print("Triggering play/pause...") keyboard.press(Key.media_play_pause) keyboard.release(Key.media_play_pause) Clock.schedule_once(self.focus_text_input, 0.1)
def connect(image): # Get information for sockets client port = 6007 # ip = '127.0.0.1' ip = '192.168.1.100' username = '******' if not socket_client.connect(ip, port, username, show_error): return socket_client.send(image) socket_client.start_listening(incoming_message, show_error)
async def send_message_to_endpoint_and_key(self, my_ver_key, their_ver_key, msg): ''' Message is encrypted and sent to the other user through the server ''' print("\nSend message to end and key") print(my_ver_key, their_ver_key, msg) wire_message = await crypto.pack_message(self.wallet_handle, Serializer.pack(msg), [their_ver_key], my_ver_key) print("wire:", wire_message) socket_client.send(wire_message) print("SEND MESSAGE")
def send_message(self, _): #print("send a message!!!") # Get message text and clear message input field message = self.new_message.text self.new_message.text = '' # If there is any message - add it to chat history and send to the server if message: # Our messages - use red color for the name self.history.update_chat_history(f'[color=dd2020]{chat_app.connect_page.username.text}[/color] > {message}') socket_client.send(message) ## Sent the message out # As mentioned above, we have to shedule for refocusing to input field Clock.schedule_once(self.focus_text_input, 0.1)
def get_from_city(self): if self.message != '': print("whoh") print(self.message) print('111') self.slots = self.en.get_from(self.message) print(self.slots) self.message = '' # self.next_action() if self.slots['to_city'] is None: socket_client.send("Where do you want to travel to?") elif self.slots['from_city'] is None: socket_client.send( "Where will you be boarding the train from?") elif self.slots['date'] is None or self.slots['month'] is None: socket_client.send("At what date to you want to travel?") else: train_info = Railway().train_between_station( self.slots['from_city'], self.slots['to_city'], str(self.slots['date']) + '-' + str(self.slots['month']) + '-' + str(self.slots['year'])) self.slots['to_city'] = None self.slots['from_city'] = None self.slots['date'] = None self.slots['month'] = None self.slots['year'] = None self.slots = {} print("!!!!!!!!!!!!!!!!!!!!!!!!!!!", self.slots) socket_client.send(train_info) self.message = '' self.count = 0
def offload(self, func='set'): """ Send self.RequestManager_List to back to the host """ req = {'func': func, 'arg': self.RequestManager_List} dict_tracker = socket_client.send( req, self.host, self.port, )
def clicked_square(self, x, y): click_pos = self.controller.get_alphanumeric_position((y, x)) global gameid if self._selected_pos: message = ("playermoveis<---->" + self._selected_pos + "<---->" + click_pos + "<---->" + gameid) socket_client.send(message) self.shift(self._selected_pos, click_pos) self._unhighlight() self._selected_pos = None print(message) else: piece = self.controller.get_piece_at(click_pos) if not piece or piece.color != self.controller.player_turn(): return self._highlight_available_moves(piece, click_pos) self._selected_pos = click_pos
def send_message(self, _): if self.new_message.text: message = self.new_message.text data = socket_client.send(self.chat_id, message, self.token) print(data) self.message_box.update_chat_message_box( f"[color=dd2020]{self.user_name}[/color] > {message}") self.new_message.text = '' # self.fill_in_message_box() Clock.schedule_once(self.focus_text_input, 1)
def get_pnr_from_user(self): # self.message = '' if self.message != '': print("######") l = self.message.split(' ') print(l) x = None for e in l: try: int(e) x = int(e) print(x) except: pass if x: pnr = Railway().pnr_status(x) socket_client.send(pnr) self.count = 0 else: socket_client.send("wrong pnr number") self.count = 0
def get_entities(self): self.slots = self.en.entity_recog(self.message) self.message = '' # self.next_action() if self.slots['to_city'] is None: socket_client.send("Where do you want to travel to?") elif self.slots['from_city'] is None: socket_client.send("Where will you be boarding the train from?") elif self.slots['date'] is None or self.slots['month'] is None: socket_client.send("At what date to you want to travel?")
def load(self, func='get', num_links=8): """ Loads self.RequestManager_List with requests a list of RequestManager objects. arg(str): an arg to the server """ req = {'func': func, 'arg': num_links} self.run_cnt += 1 print("making request", self.run_cnt) dict_tracker = socket_client.send( req, self.host, self.port, ) self.RequestManager_List = dict_tracker['response'] if self.RequestManager_List and len(self.RequestManager_List) > 0: return True else: return False
def get_pnr(self): if self.pnr: if len(self.pnr) == 10: pnr = Railway().pnr_status(self.pnr) socket_client.send(pnr) self.count = 0 else: socket_client.send("wrong pnr number") self.count = 0 else: responses = [ 'What is your pnr number?', 'Can You tell me what your PNR number is?', 'Ok, sure tell me your pnr number', 'please tell me your pnr number' ] socket_client.send(random.choice(responses)) self.message = '' self.get_pnr_from_user()
def send_message(self, _): message = self.new_message.text global gameid self.new_message.text = "" if message.startswith("/invite"): socket_client.send(message) if message.startswith("/accept"): self.accept() message = message + " " + str(random.randint(11111, 99999)) socket_client.send(message) op = message.split() gameid = op[2] else: self.history.update_chat_history( f"[color=dd2020]{chat_app.connect_page.username.text}[/color] > {message}" ) socket_client.send(message) Clock.schedule_once(self.focus_text_input, 0.1)
def detect_intent(self): self.slots = { 'to_city': None, 'from_city': None, 'date': None, 'month': None, 'year': 2019 } intent = self.i.classify(self.message, self.vocab, self.intent_categories) self.intent = intent print(intent) if intent == "train_reservation": self.get_entities() elif intent == "greeting": responses = ["hey, I'm RailBot", "Hi there", "hey"] socket_client.send(random.choice(responses)) self.message = '' self.count = 0 elif intent == "goodbye": responses = [ 'See you later, thanks for visiting', 'Have a nice day', 'Bye! Come back again soon.' ] socket_client.send(random.choice(responses)) self.message = '' self.count = 0 elif intent == "pnr_status": self.get_pnr() self.message = '' elif intent == "thanks": responses = ['Happy to help!', 'Any time!', 'My pleasure'] socket_client.send(random.choice(responses)) self.message = '' self.count = 0 elif intent == "train_schedule": if self.message != '': print("######") l = self.message.split(' ') print(l) x = None for e in l: try: int(e) x = int(e) print(x) except: pass if x: pnr = Railway().train_schedule(x) socket_client.send(pnr) self.count = 0 else: socket_client.send("wrong train number") self.count = 0 else: self.count = 0
def count_it(num): if num == 0: fbo = Fbo(size=self.stencil.size, with_stencilbuffer=True) with fbo: ClearColor(1, 1, 1, 0) ClearBuffers() img2 = self.paintscreen.bg.texture fbo.add(self.stencil.canvas) fbo.draw() img = fbo.texture fbo.remove(self.stencil.canvas) self.remove_widget(self.paintscreen) im = np.frombuffer(img.pixels, np.uint8) data = np.reshape(im, (im.shape[0], 1)).tostring() data2 = str(data) data2 = str.encode(data2) pix = np.frombuffer(data, np.uint8) a = np.empty_like(pix) a[:] = pix texture = Texture.create(size=self.stencil.size) texture.blit_buffer(a, colorfmt='rgba', bufferfmt='ubyte') self.imge = Image(pos=(0, 0), size=self.paintscreen.stencil.size, texture=texture) #self.paintscreen.stencil.add_widget(self.imge) #img2 = self.paintscreen.grid_layout.bg.texture im2 = np.frombuffer(img2.pixels, np.uint8) data = np.reshape(im2, (im2.shape[0], 1)).tostring() data2 = str(data) data2 = str.encode(data2) pix = np.frombuffer(data, np.uint8) a2 = np.empty_like(pix) a2[:] = pix img2 = a2 print(img2.shape) print(img2) img1 = a print(img1.shape) import cv2 #setting alpha=1, beta=1, gamma=0 gives direct overlay of two images # in theory this would give a direct overlay... #img3 = cv2.addWeighted(img1, 1, img2, 1, 0) #print(img3.shape) im = img1.reshape(1200, 1200, 4) # for i in range(0, 1200): # for j in range(0,1200): # points = im[i,j,:] # if (points[3] == 0):#points[0] == 255 & points[1] == 255 & points[2] == 255): # im[i,j,:] = [255,255,255,0] img_2 = img2.reshape((1200, 1200, 4)) for i in range(0, 1200): for j in range(0, 1200): points1 = im[i, j, :] if (points1[3] != 0): img_2[i, j, :] = im[i, j, :] socket_client.send(img_2) while MESSAGE is None: pass if MESSAGE is not None: new_img = MESSAGE else: new_img = img_2 texture = Texture.create(size=(1200, 1200)) texture.blit_buffer(np.reshape(new_img, (1200 * 1200 * 4, )), colorfmt='rgba', bufferfmt='ubyte') self.paintscreen = PaintScreen() self.add_widget(self.paintscreen) self.paintscreen.bg.texture = texture return num -= 1 self.count.text = str(num) Clock.schedule_once(lambda dt: count_it(num), 1)
return socket_client.send(image) socket_client.start_listening(incoming_message, show_error) def incoming_message(username, message): # Update chat history with username and message, green color for username received.append(message) return username if __name__ == "__main__": img = cv2.imread('./office.jpg') # encode_param=[int(cv2.IMWRITE_JPEG_QUALITY),90] result, imgencode = cv2.imencode('.jpg', img) data = np.array(imgencode) stringData = data.tostring() connect(stringData) while not len(received): socket_client.send('hello') # deal with videos from datetime import datetime now = datetime.now() current_time = now.strftime("%d_%m_%Y_%H_%M_%S") with open('videos/{}.mp4'.format(current_time), 'wb') as f: f.write(received[0]) print('Done...')
def sendLedOFF(self,instance): socket_client.send('ledOFFq')
def sendFanOFF(self,instance): socket_client.send('fanOFFq')
def sendLightOFF(self,instance): socket_client.send('lightOFFq')